{"record":{"id":"2fdfc9b21fb6951d","repo":"siyuan-note/siyuan","slug":"mcp-server-s-not-connected","errorCode":null,"errorMessage":"mcp server [%s] not connected","messagePattern":"mcp server \\[(.+?)\\] not connected","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/mcp/client/mcp.go","lineNumber":808,"sourceCode":"\treturn tools.CallToolResult{\n\t\tContent: []tools.ContentItem{{\n\t\t\tType: \"text\",\n\t\t\tText: \"mcp tool returned invalid content after execution; execution result may have side effects and must not be \" +\n\t\t\t\t\"retried automatically\",\n\t\t}},\n\t\tIsError:          true,\n\t\tExecutionUnknown: true,\n\t}\n}\n\nfunc trustedReadOnlyHint(server conf.MCPServer, tool *mcp.Tool) bool {\n\treturn server.TrustToolAnnotations && tool.Annotations != nil && tool.Annotations.ReadOnlyHint\n}\n\nfunc callMCPTool(parentCtx context.Context, serverName, toolName string, timeout time.Duration, args map[string]any) (*mcp.CallToolResult, error) {\n\tsession := getMCPSession(serverName)\n\tif session == nil {\n\t\treturn nil, fmt.Errorf(\"mcp server [%s] not connected\", serverName)\n\t}\n\n\tctx, cancel := context.WithTimeout(parentCtx, timeout)\n\tdefer cancel()\n\n\treturn session.CallTool(ctx, &mcp.CallToolParams{\n\t\tName:      toolName,\n\t\tArguments: args,\n\t})\n}\n\nfunc getMCPSession(serverName string) *mcp.ClientSession {\n\tmcpMu.Lock()\n\tdefer mcpMu.Unlock()\n\tfor _, conn := range mcpConns {\n\t\tif conn.ServerName == serverName {\n\t\t\treturn conn.Session\n\t\t}","sourceCodeStart":790,"sourceCodeEnd":826,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/mcp/client/mcp.go#L790-L826","documentation":"callMCPTool looks up a live MCP client session by server name via getMCPSession; if no connected session exists for that server, the tool call cannot proceed and this error is returned. It means the named MCP server has not completed a connection or its session was lost/disconnected.","triggerScenarios":"A tool invocation names a server with no entry in the session registry: the server was never connected, connection failed at startup, the session was disconnected, or the server name is misspelled.","commonSituations":"Calling a tool before the MCP server finished connecting; the remote server went offline and the session was dropped; the server was disabled or removed in settings; using a stale server name after renaming the entry.","solutions":["Open the MCP server settings and reconnect/enable the named server, then retry the tool call","Check the server's connection status and logs to see why the session dropped (auth failure, network error)","Verify the tool is invoked with the exact configured server name (case and spelling)","Restart the kernel or refresh MCP connections if the session registry is stale"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// guard before calling a tool\nif getMCPSession(serverName) == nil {\n    return fmt.Errorf(\"server %q not connected; reconnect first\", serverName)\n}","typeGuard":null,"tryCatchPattern":"res, err := callMCPTool(ctx, serverName, toolName, timeout, args)\nif err != nil && strings.Contains(err.Error(), \"not connected\") {\n    // re-establish the connection, then retry once\n    if cerr := reconnectMCPServer(serverName); cerr == nil {\n        res, err = callMCPTool(ctx, serverName, toolName, timeout, args)\n    }\n}","preventionTips":["Ensure MCP servers are connected/enabled before listing or invoking their tools","Handle server-rename/remove flows so stale names are not used","Detect dropped sessions and reconnect proactively","Log and surface connection state changes to the user"],"tags":["mcp","session","not-connected","tool-call"],"backgroundTag":"invalid-state-transition","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}