Skip to content

Commit ba884f8

Browse files
committed
Adds hints to llm on which connect tool to use and fixes atlas test
1 parent 0c53f48 commit ba884f8

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/common/connectionErrorHandler.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,18 @@ export const connectionErrorHandler: ConnectionErrorHandler = (error, { availabl
2020
// Find the first Atlas connect tool if available and suggest to the LLM to use it.
2121
// Note: if we ever have multiple Atlas connect tools, we may want to refine this logic to select the most appropriate one.
2222
const atlasConnectTool = connectTools?.find((t) => t.category === "atlas");
23-
const llmConnectHint = atlasConnectTool
24-
? `Note to LLM: prefer using the "${atlasConnectTool.name}" tool to connect to an Atlas cluster over using a connection string. Make sure to ask the user to specify a cluster name they want to connect to or ask them if they want to use the "list-clusters" tool to list all their clusters. Do not invent cluster names or connection strings unless the user has explicitly specified them. If they've previously connected to MongoDB using MCP, you can ask them if they want to reconnect using the same cluster/connection.`
25-
: "Note to LLM: do not invent connection strings and explicitly ask the user to provide one. If they have previously connected to MongoDB using MCP, you can ask them if they want to reconnect using the same connection string.";
23+
const atlasLocalConnectTool = connectTools?.find((t) => t.category === "atlas-local");
24+
25+
let llmConnectHint: string;
26+
27+
if (atlasConnectTool) {
28+
llmConnectHint = `Note to LLM: prefer using the "${atlasConnectTool.name}" tool to connect to an Atlas cluster over using a connection string. Make sure to ask the user to specify a cluster name they want to connect to or ask them if they want to use the "list-clusters" tool to list all their clusters. Do not invent cluster names or connection strings unless the user has explicitly specified them. If they've previously connected to MongoDB using MCP, you can ask them if they want to reconnect using the same cluster/connection.`;
29+
} else if (atlasLocalConnectTool) {
30+
llmConnectHint = `Note to LLM: prefer using the "${atlasLocalConnectTool.name}" tool for connecting to local MongoDB deployments. Ask the user to specify a deployment name or use "atlas-local-list-deployments" to show available local deployments. Do not invent deployment names unless the user has explicitly specified them. If they've previously connected to a local MongoDB deployment using MCP, you can ask them if they want to reconnect using the same deployment.`;
31+
} else {
32+
llmConnectHint =
33+
"Note to LLM: do not invent connection strings and explicitly ask the user to provide one. If they have previously connected to MongoDB using MCP, you can ask them if they want to reconnect using the same connection string.";
34+
}
2635

2736
const connectToolsNames = connectTools?.map((t) => `"${t.name}"`).join(", ");
2837
const additionalPromptForConnectivity: { type: "text"; text: string }[] = [];

tests/integration/tools/atlas/clusters.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ describeWithAtlas("clusters", (integration) => {
239239
"You need to connect to a MongoDB instance before you can access its data."
240240
);
241241
expect(elements[1]?.text).toContain(
242-
'Please use one of the following tools: "atlas-connect-cluster", "connect" to connect to a MongoDB instance'
242+
'Please use one of the following tools: "atlas-connect-cluster", "atlas-local-connect-deployment", "connect" to connect to a MongoDB instance'
243243
);
244244
});
245245
});

0 commit comments

Comments
 (0)