{"record":{"id":"2ed83df34626a6e7","repo":"CherryHQ/cherry-studio","slug":"failed-to-start-in-memory-server-error-message","errorCode":null,"errorMessage":"Failed to start in-memory server: ${error.message}","messagePattern":"Failed to start in-memory server: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/main/ai/mcp/McpRuntimeService.ts","lineNumber":503,"sourceCode":"                }\n              },\n              authProvider\n            }\n            getServerLogger(server).debug(`Using StreamableHTTPClientTransport for ${server.name}`)\n            return new StreamableHTTPClientTransport(new URL(httpUrl), options)\n          }\n\n          if (isInMemoryBuiltinMcpServer(server) && server.name !== BuiltinMcpServerNames.mcpAutoInstall) {\n            getServerLogger(server).debug(`Using in-memory transport`)\n            const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair()\n            // start the in-memory server with the given name and environment variables\n            const inMemoryServer = createInMemoryMcpServer(server.name, args, server.env || {})\n            try {\n              await inMemoryServer.connect(serverTransport)\n              getServerLogger(server).debug(`In-memory server started`)\n            } catch (error: any) {\n              getServerLogger(server).error(`Error starting in-memory server`, error as Error)\n              throw new Error(`Failed to start in-memory server: ${error.message}`)\n            }\n            // set the client transport to the client\n            return clientTransport\n          } else if (server.baseUrl) {\n            const urlBasedType: McpServerType = typeOverride ?? server.type ?? 'sse'\n            if (urlBasedType === 'streamableHttp') {\n              const options: StreamableHTTPClientTransportOptions = {\n                fetch: async (url, init) => {\n                  return net.fetch(typeof url === 'string' ? url : url.toString(), init)\n                },\n                requestInit: {\n                  headers: prepareHeaders()\n                },\n                authProvider\n              }\n              // redact headers before logging\n              getServerLogger(server).debug(`StreamableHTTPClientTransport options`, {\n                options: redactSensitive(options)","sourceCodeStart":485,"sourceCodeEnd":521,"githubUrl":"https://github.com/CherryHQ/cherry-studio/blob/726446b54cd69ffe51a276638672f6d95ca0768c/src/main/ai/mcp/McpRuntimeService.ts#L485-L521","documentation":"Thrown when an in-memory builtin MCP server fails to connect via `InMemoryTransport`. The runtime creates a linked pair of in-memory transports, instantiates the server via `createInMemoryMcpServer(name, args, env)`, and attempts `.connect(serverTransport)`. If connect throws, the error is wrapped with context. This applies to builtin in-memory servers except mcpAutoInstall.","triggerScenarios":"An in-memory server's `connect()` method throws due to an initialization failure — invalid arguments, a runtime error in the server's setup handler, SDK version incompatibility, or the server module failing to register its tools/resources.","commonSituations":"Builtin in-memory MCP server has a bug in its initialization; the server's args/env are invalid for the current platform; SDK version mismatch between the server implementation and the client; the server requires external resources that are unavailable.","solutions":["Check the detailed server logs (emitted via getServerLogger just before the throw) for the original error.message","Verify the in-memory server's constructor and connect handler don't throw on the given args/env","Update the MCP SDK to a compatible version if there's a protocol mismatch","If the server is a custom builtin, debug its setup logic in isolation using InMemoryTransport.createLinkedPair()"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isInMemoryServer(server: McpServer): boolean {\n  return isInMemoryBuiltinMcpServer(server) && server.name !== BuiltinMcpServerNames.mcpAutoInstall\n}","tryCatchPattern":"try {\n  await runtime.withClient(serverId, async (client, server) => {\n    // operation\n  })\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Failed to start in-memory server')) {\n    // Check server logs for the original error, likely a server implementation bug\n    logger.error('In-memory server startup failed', e)\n  }\n  throw e\n}","preventionTips":["Test in-memory MCP server initialization in isolation before integrating","Ensure the server's connect handler validates its args/env and fails early with clear messages","Keep the MCP SDK version aligned between the app and builtin server implementations"],"tags":["mcp","in-memory","builtin-server","connection"],"backgroundTag":null,"analyzedSha":"726446b54cd69ffe51a276638672f6d95ca0768c","analyzedAt":"2026-08-12T17:30:37.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}