{"record":{"id":"5695b672841e0b79","repo":"can1357/oh-my-pi","slug":"server-name-not-found-in-filepath","errorCode":null,"errorMessage":"Server \"${name}\" not found in ${filePath}","messagePattern":"Server \"(.+?)\" not found in (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/mcp/config-writer.ts","lineNumber":190,"sourceCode":"\t\t\t\t[name]: config,\n\t\t\t},\n\t\t};\n\t\tawait writeMCPConfigFile(filePath, updated);\n\t});\n}\n\n/**\n * Remove an MCP server from a config file.\n *\n * @throws Error if server doesn't exist\n */\nexport async function removeMCPServer(filePath: string, name: string): Promise<void> {\n\t// Serialize the read-modify-write (see addMCPServer).\n\tawait withConfigLock(filePath, async () => {\n\t\tconst existing = await readMCPConfigFile(filePath);\n\n\t\tif (!existing.mcpServers?.[name]) {\n\t\t\tthrow new Error(`Server \"${name}\" not found in ${filePath}`);\n\t\t}\n\n\t\tconst { [name]: _removed, ...remaining } = existing.mcpServers;\n\t\tconst updated: MCPConfigFile = {\n\t\t\t...existing,\n\t\t\tmcpServers: remaining,\n\t\t};\n\t\tawait writeMCPConfigFile(filePath, updated);\n\t});\n}\n\n/**\n * Get a specific server config from a file.\n * Returns undefined if server doesn't exist.\n */\nexport async function getMCPServer(filePath: string, name: string): Promise<MCPServerConfig | undefined> {\n\tconst config = await readMCPConfigFile(filePath);\n\treturn config.mcpServers?.[name];","sourceCodeStart":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/mcp/config-writer.ts#L172-L208","documentation":"removeMCPServer() throws when the named server does not exist in the target config file. Inside the config lock it reads the config and throws if existing.mcpServers[name] is absent, so callers get a clear message naming both the server and the file instead of a silent no-op.","triggerScenarios":"Calling removeMCPServer(filePath, name) (or #handleRemove / handleRemoveCommand) when the config file has no mcpServers entry under that exact name — wrong name, wrong file, or the entry lives in a different config source (project vs global config).","commonSituations":"Server was already removed (double delete or rerun script); name mismatch (case sensitivity, whitespace, missing namespace prefix like \"plugin:server\"); the server is defined in project .omp/mcp.json but you are editing the global file; config was regenerated and lost the entry.","solutions":["Check the exact name in the config file at filePath (grep for the name).","Confirm you are editing the file the server is actually defined in (global vs project config).","Trim/copy the name exactly as it appears, including any namespace prefix and colon.","Make cleanup scripts idempotent: check existence before removing and treat absence as success.","If it may not exist, use readMCPConfigFile first: if (!cfg.mcpServers?.[name]) skip the remove call."],"exampleFix":"// before\nawait removeMCPServer(cfgPath, name); // throws if absent\n// after\nconst cfg = await readMCPConfigFile(cfgPath);\nif (cfg.mcpServers?.[name]) {\n  await removeMCPServer(cfgPath, name);\n}","handlingStrategy":"validation","validationCode":"import { readMCPConfigFile } from \"@oh-my-pi/pi-coding-agent/mcp/config\";\nconst cfg = await readMCPConfigFile(filePath);\nif (!cfg.mcpServers?.[name]) return; // nothing to remove; skip\ncopyExactNameFromConfig(name);","typeGuard":"function isKnownServer(cfg: { mcpServers?: Record<string, unknown> }, name: string): boolean {\n  return Object.prototype.hasOwnProperty.call(cfg.mcpServers ?? {}, name);\n}","tryCatchPattern":"try {\n  await removeMCPServer(cfgPath, name);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('not found in')) {\n    return; // idempotent delete: already gone\n  }\n  throw e;\n}","preventionTips":["Check existence in the target file before removing.","Copy server names exactly (case, whitespace, namespace prefix) from the config.","Confirm which file (global vs project) defines the server.","Make delete/cleanup flows idempotent so re-runs don't fail."],"tags":["mcp","config","not-found"],"backgroundTag":"config-entry-not-found","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}