Skip to content

Commit 86f4b88

Browse files
committed
chore: make sure prompts about connectivity are exclusive
We were concerned that with the previous prompt configuration we could mislead the LLM. With this change, OIDC messages are exclusiver and won't be added with the connectivity suggestions.
1 parent 816aefe commit 86f4b88

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/tools/mongodb/mongodbTool.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,20 @@ export abstract class MongoDBToolBase extends ToolBase {
6969

7070
const connectToolsNames = connectTools?.map((t) => `"${t.name}"`).join(", ");
7171
const connectionStatus = this.session.connectionManager.currentConnectionState;
72-
const additionalPromptForOidc: { type: "text"; text: string }[] = [];
72+
const additionalPromptForConnectivity: { type: "text"; text: string }[] = [];
7373

74-
if (connectionStatus.tag === "connecting" && connectionStatus.oidcConnectionType === "oidc-device-flow") {
75-
additionalPromptForOidc.push({
74+
if (connectionStatus.tag === "connecting" && connectionStatus.oidcConnectionType) {
75+
additionalPromptForConnectivity.push({
7676
type: "text",
7777
text: `The user needs to finish their OIDC connection by opening '${connectionStatus.oidcLoginUrl}' in the browser and use the following user code: '${connectionStatus.oidcUserCode}'`,
7878
});
79+
} else {
80+
additionalPromptForConnectivity.push({
81+
type: "text",
82+
text: connectToolsNames
83+
? `Please use one of the following tools: ${connectToolsNames} to connect to a MongoDB instance or update the MCP server configuration to include a connection string. ${llmConnectHint}`
84+
: "There are no tools available to connect. Please update the configuration to include a connection string and restart the server.",
85+
});
7986
}
8087

8188
switch (error.code) {
@@ -86,13 +93,7 @@ export abstract class MongoDBToolBase extends ToolBase {
8693
type: "text",
8794
text: "You need to connect to a MongoDB instance before you can access its data.",
8895
},
89-
...additionalPromptForOidc,
90-
{
91-
type: "text",
92-
text: connectToolsNames
93-
? `Please use one of the following tools: ${connectToolsNames} to connect to a MongoDB instance or update the MCP server configuration to include a connection string. ${llmConnectHint}`
94-
: "There are no tools available to connect. Please update the configuration to include a connection string and restart the server.",
95-
},
96+
...additionalPromptForConnectivity,
9697
],
9798
isError: true,
9899
};

tests/integration/common/connectionManager.oidc.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ describe.skipIf(process.platform !== "linux")("ConnectionManager OIDC Tests", as
231231
expect(response).toContain("The user needs to finish their OIDC connection by opening");
232232
expect(response).toContain(state.oidcLoginUrl);
233233
expect(response).toContain(state.oidcUserCode);
234+
expect(response).not.toContain("Please use one of the following tools");
235+
expect(response).not.toContain("There are no tools available to connect.");
234236

235237
await waitUntil<ConnectionStateConnected>(
236238
"connected",

0 commit comments

Comments
 (0)