MCP 'Server is already initialized' Error Due to Double Connection Attempt #1021
fitchmultz
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Summary
When using MCP servers in ACP/Wire mode, kimi-cli attempts to initialize the same MCP server connection twice, causing a "Server is already initialized" error from servers that strictly follow the MCP protocol.
Environment
Configuration
{ "mcpServers": { "RepoPrompt": { "command": "/Users/user/RepoPrompt/repoprompt_cli" } } }Steps to Reproduce
~/.kimi/mcp.jsonkimi --print -c "Call the RepoPrompt MCP get_file_tree tool"Error running tool: Client failed to connect: Invalid Request: Server is already initializedEvidence
The error message:
Log analysis reveals double connection attempt:
Root Cause Analysis
In
/kimi_cli/soul/toolset.py, the MCP client context is entered twice:First initialization (line 249) - During server discovery in
load_mcp_tools():Second initialization (line 386) - During actual tool call in
MCPTool.__call__():The
fastmcp.Clientcontext manager sends aninitializerequest when entering the context. The secondasync withattempts another initialization on the same connection, which compliant MCP servers reject with:{"jsonrpc":"2.0","id":1,"error":{"code":-32600,"message":"Invalid Request: Server is already initialized"}}Verification
The
kimi mcp test RepoPromptcommand works correctly because it creates a fresh connection and properly closes it after the test.Suggested Fix
Either:
_connect_server()instead of usingasync with(keep the client connected for the session lifetime)initializerequest if already initializedAdditional Context
kimi mcp testworks fineAll reactions