{"record":{"id":"cf4ca5325b74deb9","repo":"rohitg00/ai-engineering-from-scratch","slug":"32601","errorCode":"-32601","errorMessage":"Method not found: ${message.method}","messagePattern":"Method not found: (.+?)","errorType":"error_code","errorClass":"RpcProblem","httpStatus":null,"severity":"error","filePath":"phases/13-tools-and-protocols/07-building-an-mcp-server/code/main.ts","lineNumber":359,"sourceCode":"\nconst HANDLERS: Record<string, (params: JsonObject) => JsonObject> = {\n  \"prompts/get\": handlePromptsGet,\n  \"prompts/list\": handlePromptsList,\n  \"resources/list\": handleResourcesList,\n  \"resources/read\": handleResourcesRead,\n  \"server/discover\": handleDiscover,\n  \"tools/call\": handleToolsCall,\n  \"tools/list\": handleToolsList,\n};\n\nfunction dispatch(message: JsonRpcRequest): JsonRpcResponse | null {\n  if (message.id === undefined) return null;\n  const id = message.id;\n  const errorId = isValidRequestId(id) ? id : null;\n  try {\n    validateRequest(message);\n    const handler = HANDLERS[message.method];\n    if (!handler) throw new RpcProblem(-32601, `Method not found: ${message.method}`);\n    return { jsonrpc: \"2.0\", id, result: handler(message.params ?? {}) };\n  } catch (error) {\n    if (error instanceof RpcProblem) return rpcError(errorId, error.code, error.message, error.data);\n    return rpcError(errorId, -32603, \"Internal error\", { detail: String(error) });\n  }\n}\n\nfunction serveStdio(): void {\n  const reader = createInterface({ input: process.stdin, terminal: false });\n  reader.on(\"line\", (line) => {\n    if (!line.trim()) return;\n    let response: JsonRpcResponse | null;\n    try {\n      const parsed = JSON.parse(line) as unknown;\n      response =\n        parsed !== null && typeof parsed === \"object\" && !Array.isArray(parsed)\n          ? dispatch(parsed as JsonRpcRequest)\n          : rpcError(null, -32600, \"Invalid Request\");","sourceCodeStart":341,"sourceCodeEnd":377,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/phases/13-tools-and-protocols/07-building-an-mcp-server/code/main.ts#L341-L377","documentation":"dispatch looked up message.method in the HANDLERS table and found no entry, so it returns JSON-RPC -32601 Method not found with the method name embedded in the message. This fires only after validateRequest passed, i.e. the envelope was fine.","triggerScenarios":"Calling methods like 'sampling/createMessage', 'roots/list', or any typo ('tools/lsit') that this teaching server does not register in HANDLERS.","commonSituations":"Clients using newer or optional MCP methods the server never implemented, or assuming auto-discovery of methods.","solutions":["Inspect the HANDLERS map in main.ts for the exact supported method names","Check spelling and casing of the method string","Gate optional feature calls behind the capabilities the server advertised at initialize"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const SUPPORTED = new Set(Object.keys(HANDLERS)); \nif (!SUPPORTED.has(method)) throw new Error('unsupported method');","typeGuard":null,"tryCatchPattern":"catch (e) { if (e instanceof RpcProblem && e.code === -32601) degradeGracefully(); }","preventionTips":["Read HANDLERS (or initialize capabilities) to learn supported methods","Treat -32601 as a capability signal: disable that feature path in the client"],"tags":["json-rpc","method-not-found","mcp"],"backgroundTag":"method-not-found","analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","schemaVersion":2},"datasetVersion":"2026-08-26T07:17:17.940Z"}