[Bug]: Switching Connection When Connection String Is Not Initially Specified
Closed this issue · 8 comments
Version
mongo-mcp:
type: stdio
command: npx
args:
- -y
- "mongodb-mcp-server"
App
- Cursor
- Windsurf
- VSCode
- VSCode Insiders
- Claude Desktop
- Other
Affected Models (if applicable)
- Claude 3.5 Sonnet
- Claude 3.7 Sonnet
- GPT-4a
- o4-mini
- Other
Bug Description
I am experiencing a problem when attempting to switch the connection if the connection string is not specified from the beginning. The server initializes correctly and is able to perform the first connection successfully. However, after that, it is not possible to change or switch the connection.
[mongo-mcp][connect] Tool call failed MCP error -32602: MCP error -32602: Tool connect not found
Hi @BrunoIzagu, thank you for your feedback! I wanted to understand a couple of things as we are potentially considering deprecating the switch-connection tool.
- Are you OK with pasting your connection string directly in your LLM chat? Are you passing connection string to local instances where you don't have sensitive credentials?
- Are there alternate/more secure ways where we could help you switch connection? One potential solution could be allowing you to define all your connection strings at the config level. This way you do not have to pass sensitive creds in your LLM chat.
Will let @nirinchev follow up here on debugging the issue you're experiencing!
Can you clarify how/why the model is trying to invoke the connect tool? Asking mostly because beyond the first connection, we update the connect tool name and description and send out a tool update notification, so it's kind of surprising that the model is trying to invoke connect at that point.
Hi @nirinchev and @GaurabAryal ,
Thank you very much for your quick response and for considering my feedback regarding the switch-connection tool.
Regarding your questions:
I would like to emphasize that I prefer to have a switch connection functionality because I am developing a model based on open source that does not have a desktop application. Therefore, the best case would be to have a UI (not chat-based) where users can input new connections and load them into an environment variable to perform switch connections. However, currently, such an environment variable does not exist, and the existing environment variable (MDB_MCP_CONNECTION_STRING) does not work properly for switching connections.
When switching connections via chat, the error I mentioned earlier occurs, which could be resolved by having a base environment variable defined. But since I want this to be a multi-user model, I do not want there to be a single default connection.
DEBUGG:
From my observation, the server initializes and allows a first successful connection, but subsequent attempts to switch connections appear to trigger the connect tool again unexpectedly. This is the info messages when I don´t specify any connection string at configuration level. First i send a string connection, and then i ask to switch connection with other string.
2025-07-12 18:00:33 info: [MCP][mongo-mcp] Capabilities: {"logging":{},"completions":{},"resources":{"listChanged":true},"tools":{"listChanged":true}}
2025-07-12 18:00:33 info: [MCP][mongo-mcp] Available tools: connect, list-collections, list-databases, collection-indexes, collection-schema, find, collection-storage-size, count, db-stats, aggregate, explain, mongodb-logs
][mongo-mcp] Connection successfully established
Tool call failed MCP error -32602: MCP error -32602: Tool connect not found
Tool Error "connect_mcp_mongo-mcp" tool call failed: MCP error -32602: MCP error -32602: Tool connect not found
Hey, does your model support tool change notifications - i.e. when the server emits it, do you re-list the available tools? Again, asking because the connect tool is updated after the first connection, and as such, would not be available for switching connections (which explains the error you're getting). The part that's missing for me is why the model is even attempting to call connect and my working theory is that it only fetches the available tools on startup and never updates the list.
Hi @nirinchev, when i ask the model again to give me the avialable tools, it fetches me the tools from the startup
Hm... not sure how complete those logs are, but assuming "Connection successfully established" is the log from the first successful connect, I would expect there would be a call to tools/list from the client in response to the notification we're emitting, but I don't see that in the logs.
Thanks for opening this issue. The ticket MCP-79 was created for internal tracking.
It seems the issue is from the fact that the agent is not reloading the list of tools. We would assume that any relatively modern agent could do this, as it's part of the MCP specification. Can you provide a bit more info on how you are working with the MCP Server? Are you building your own agent or using an IDE like Cursor, Windsurf...
Thanks!