Skip to content

armgit / kokon

Public Imported from GitHub
0

Edit photos by describing the change, on your own GPU. A free, open-source alternative to Nano Banana and ChatGPT image editing: photos stay on your computer, no daily limit. One installer for Windows, Mac and Linux sets up the best open model (Qwen-Image 2.1). MCP server for AI agents.

mcp: add --help and -h to kokon-mcp (#36)

SHRINIVAS NEMAGOUDAR6ae1d74007a2
diff --git a/mcp/src/help.ts b/mcp/src/help.ts
new file mode 100644
index 0000000..43ce5be
--- /dev/null
+++ b/mcp/src/help.ts
@@ -0,0 +1,27 @@
+// Text printed by `kokon-mcp --help`. Kept apart from index.ts so it can be tested without
+// starting the server. The environment variables listed here are read in paths.ts,
+// service.ts and index.ts; update this text when one is added or renamed.
+
+export function helpText(version: string): string {
+ return `kokon-mcp ${version}
+
+MCP server for Kokon. It speaks the Model Context Protocol over stdio, so an MCP client
+(Claude Code, Cursor, Claude Desktop...) starts it; running it by hand just waits for input.
+It needs the Kokon desktop app installed (https://kokon.app) and starts the local engine on demand.
+
+Usage:
+ kokon-mcp start the MCP server on stdio
+ kokon-mcp --version print the version and exit
+ kokon-mcp --help print this text and exit
+
+Register it with Claude Code:
+ claude mcp add --scope user kokon -- npx -y kokon-mcp
+
+Environment variables:
+ QLS_MCP_ALLOWED_DIRS extra folders the tools may read and write, separated by semicolons
+ QLS_SERVICE_EXE path to kokon-service, if Kokon is installed in an unusual place
+ QLS_DATA_DIR Kokon's data folder (default: the app's KokonData folder)
+ CLAUDE_PROJECT_DIR project folder the tools may use (set by Claude Code; default: the
+ working directory)
+`;
+}
diff --git a/mcp/src/index.ts b/mcp/src/index.ts
index a3f4cfd..d93593b 100644
--- a/mcp/src/index.ts
+++ b/mcp/src/index.ts
@@ -6,6 +6,7 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { handlers, schemas, toErrorResult, type ToolContext, type ToolResult } from "./tools.js";
import { ServiceClient } from "./service.js";
+import { helpText } from "./help.js";
import pkg from "../package.json" with { type: "json" };
// Bundled in by esbuild: the one place to bump is package.json (see docs/releasing.md).
@@ -101,6 +102,10 @@ async function main() {
process.stdout.write(`kokon-mcp ${VERSION}\n`);
return;
}
+ if (process.argv.includes("--help") || process.argv.includes("-h")) {
+ process.stdout.write(helpText(VERSION));
+ return;
+ }
const transport = new StdioServerTransport();
await server.connect(transport);
const shutdown = async () => {
diff --git a/mcp/test/help.test.ts b/mcp/test/help.test.ts
new file mode 100644
index 0000000..ee7f384
--- /dev/null
+++ b/mcp/test/help.test.ts
@@ -0,0 +1,35 @@
+import { execFileSync } from "node:child_process";
+import { existsSync } from "node:fs";
+import path from "node:path";
+import { describe, expect, it } from "vitest";
+import { helpText } from "../src/help.js";
+
+const bundle = path.resolve(__dirname, "..", "build", "kokon-mcp.cjs");
+
+describe("helpText", () => {
+ const text = helpText("1.2.3");
+
+ it("says what the program is and how to register it", () => {
+ expect(text).toContain("kokon-mcp 1.2.3");
+ expect(text).toContain("stdio");
+ expect(text).toContain("claude mcp add --scope user kokon -- npx -y kokon-mcp");
+ });
+
+ it("lists every environment variable the server reads", () => {
+ for (const name of ["QLS_MCP_ALLOWED_DIRS", "QLS_SERVICE_EXE", "QLS_DATA_DIR", "CLAUDE_PROJECT_DIR"]) {
+ expect(text).toContain(name);
+ }
+ });
+});
+
+// Needs `npm run build` first, like the protocol test; skipped when the bundle is missing.
+describe.skipIf(!existsSync(bundle))("built bundle", () => {
+ for (const flag of ["--help", "-h"]) {
+ it(`${flag} prints usage and exits 0 without starting the server`, () => {
+ // execFileSync throws on a non-zero exit and the timeout fails the test if the server starts.
+ const out = execFileSync(process.execPath, [bundle, flag], { encoding: "utf8", timeout: 10_000 });
+ expect(out).toContain("Usage:");
+ expect(out).toContain("QLS_MCP_ALLOWED_DIRS");
+ });
+ }
+});