⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
fix(mcp): tighten install validation, merge errors, and config parsing
Tin71792690f451
diff --git a/apps/mcp/src/install/index.ts b/apps/mcp/src/install/index.tsindex 27d8385a2..af42a6888 100644--- a/apps/mcp/src/install/index.ts+++ b/apps/mcp/src/install/index.ts@@ -3,7 +3,12 @@ import { dirname } from "node:path";import { stdin as input, stdout as output } from "node:process";import { type McpServerEntry, mergeMcpServerEntry } from "./merge-config.js";import { resolvePackageEntryPath } from "./resolve-entry.js";-import { type InstallTargetId, resolveTargetConfigPath } from "./targets.js";+import {+ INSTALL_TARGETS,+ type InstallTargetId,+ resolveTargetConfigPath,+ validateCustomConfigPathInput,+} from "./targets.js";import {promptConfirmOverwrite,promptCustomConfigPath,@@ -143,12 +148,9 @@ function hasExistingServerEntry(}}-const VALID_TARGETS: readonly InstallTargetId[] = [- "cursor-user",- "cursor-project",- "claude-desktop",- "custom",-];+const VALID_TARGETS: readonly InstallTargetId[] = INSTALL_TARGETS.map(+ (t) => t.id,+);function isInstallTargetId(s: string): s is InstallTargetId {return (VALID_TARGETS as readonly string[]).includes(s);@@ -199,7 +201,7 @@ export async function runInstall(argv: string[]): Promise<void> {return;}- let customPath = parsed.output;+ let customPath = parsed.output?.trim();if (targetIds.includes("custom")) {if (!customPath) {if (input.isTTY && output.isTTY) {@@ -209,6 +211,14 @@ export async function runInstall(argv: string[]): Promise<void> {process.exitCode = 1;return;}+ } else {+ const validation = validateCustomConfigPathInput(customPath);+ if (!validation.ok) {+ console.error(`Invalid --output: ${validation.message}`);+ process.exitCode = 1;+ return;+ }+ customPath = validation.path;}}@@ -278,9 +288,11 @@ export async function runInstall(argv: string[]): Promise<void> {let merged: string;try {merged = mergeMcpServerEntry(p.existingText, parsed.name, serverConfig);- } catch {+ } catch (err: unknown) {+ const message = err instanceof Error ? err.message : String(err);+ const stack = err instanceof Error ? err.stack : undefined;console.error(- `Cannot update config (invalid JSON or merge error): ${p.configPath}`,+ `Cannot update config at ${p.configPath}: ${message}${stack ? `\n${stack}` : ""}`,);process.exitCode = 1;return;@@ -315,7 +327,7 @@ Usage:Without options, runs interactively (pick Cursor / Claude / custom path).Options:- --target <id> cursor-user | cursor-project | claude-desktop | custom+ --target <id> ${VALID_TARGETS.join(" | ")}--output <path> Required for --target custom (absolute path to JSON file)--project-dir <dir> Base directory for cursor-project (default: current dir)--name <string> MCP server key under mcpServers (default: kaneo)diff --git a/apps/mcp/src/install/merge-config.test.ts b/apps/mcp/src/install/merge-config.test.tsindex 66f9f5884..4231cd4c3 100644--- a/apps/mcp/src/install/merge-config.test.ts+++ b/apps/mcp/src/install/merge-config.test.ts@@ -17,6 +17,15 @@ describe("mergeMcpServerEntry", () => {});});+ it("rejects empty string existing config as invalid JSON", () => {+ expect(() =>+ mergeMcpServerEntry("", "kaneo", {+ command: "/usr/bin/node",+ args: ["/app/index.js"],+ }),+ ).toThrow("Existing MCP config is not valid JSON");+ });+it("merges without removing other servers or top-level keys", () => {const existing = JSON.stringify({other: true,diff --git a/apps/mcp/src/install/merge-config.ts b/apps/mcp/src/install/merge-config.tsindex 3cd3e7e59..068446fc7 100644--- a/apps/mcp/src/install/merge-config.ts+++ b/apps/mcp/src/install/merge-config.ts@@ -30,7 +30,7 @@ export function mergeMcpServerEntry(}let root: Record<string, unknown> = {};- if (existingJson) {+ if (existingJson !== null) {let parsed: unknown;try {parsed = JSON.parse(existingJson);diff --git a/apps/mcp/src/install/targets.ts b/apps/mcp/src/install/targets.tsindex bbfb969b2..a77323367 100644--- a/apps/mcp/src/install/targets.ts+++ b/apps/mcp/src/install/targets.ts@@ -1,5 +1,5 @@import { homedir } from "node:os";-import { join } from "node:path";+import path, { join } from "node:path";export type InstallTargetId =| "cursor-user"@@ -13,6 +13,26 @@ export type InstallTarget = {description: string;};+/**+ * Validates a non-interactive custom MCP config path (same rules as the install wizard).+ * Returns the trimmed absolute path on success.+ */+export function validateCustomConfigPathInput(+ raw: string,+): { ok: true; path: string } | { ok: false; message: string } {+ const trimmed = raw.trim();+ if (trimmed.length === 0) {+ return { ok: false, message: "Path is required" };+ }+ if (!path.isAbsolute(trimmed)) {+ return { ok: false, message: "Path must be absolute" };+ }+ if (!trimmed.toLowerCase().endsWith(".json")) {+ return { ok: false, message: "Path must end with .json" };+ }+ return { ok: true, path: trimmed };+}+export const INSTALL_TARGETS: readonly InstallTarget[] = [{id: "cursor-user",diff --git a/apps/mcp/src/install/wizard.ts b/apps/mcp/src/install/wizard.tsindex c2bd182e4..0c16328f5 100644--- a/apps/mcp/src/install/wizard.ts+++ b/apps/mcp/src/install/wizard.ts@@ -1,6 +1,9 @@-import path from "node:path";import prompts from "prompts";-import { INSTALL_TARGETS, type InstallTargetId } from "./targets.js";+import {+ INSTALL_TARGETS,+ type InstallTargetId,+ validateCustomConfigPathInput,+} from "./targets.js";function onCancel(): void {console.log("\nCancelled.");@@ -46,17 +49,8 @@ export async function promptCustomConfigPath(): Promise<string> {if (typeof v !== "string") {return "Path is required";}- const trimmed = v.trim();- if (trimmed.length === 0) {- return "Path is required";- }- if (!path.isAbsolute(trimmed)) {- return "Path must be absolute";- }- if (!trimmed.toLowerCase().endsWith(".json")) {- return "Path must end with .json";- }- return true;+ const result = validateCustomConfigPathInput(v);+ return result.ok ? true : result.message;},},{ onCancel },