Skip to content

Commit e578ece

Browse files
committed
fix tests
1 parent 4db78ca commit e578ece

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed

src/tools/mongodb/metadata/connect.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,18 @@ export class ConnectTool extends MongoDBToolBase {
3434

3535
protected async execute({ options: optionsArr }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
3636
const options = optionsArr?.[0];
37+
let connectionString: string;
3738
if (!options && !config.connectionString) {
3839
return {
3940
content: [
4041
{ type: "text", text: "No connection details provided." },
4142
{ type: "text", text: "Please provide either a connection string or a cluster name" },
42-
{
43-
type: "text",
44-
text: "Alternatively, you can use the default deployment at mongodb://localhost:27017",
45-
},
4643
],
4744
};
4845
}
4946

50-
let connectionString: string;
51-
5247
if (!options) {
48+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
5349
connectionString = config.connectionString!;
5450
} else if ("connectionString" in options) {
5551
connectionString = options.connectionString;

tests/integration/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export function setupIntegrationTest(): {
148148
connectMcpClient: async () => {
149149
await getMcpClient().callTool({
150150
name: "connect",
151-
arguments: { connectionStringOrClusterName: getConnectionString() },
151+
arguments: { options: [{ connectionString: getConnectionString() }] },
152152
});
153153
},
154154
randomDbName: () => randomDbName,

tests/integration/tools/mongodb/metadata/connect.test.ts

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ describe("Connect tool", () => {
1313

1414
validateParameters(connectTool, [
1515
{
16-
name: "connectionStringOrClusterName",
17-
description: "MongoDB connection string (in the mongodb:// or mongodb+srv:// format) or cluster name",
18-
type: "string",
16+
name: "options",
17+
description:
18+
"Options for connecting to MongoDB. If not provided, the connection string from the config://connection-string resource will be used. If the user hasn't specified Atlas cluster name or a connection string explicitly and the `config://connection-string` resource is present, always invoke this with no arguments.",
19+
type: "array",
1920
required: false,
2021
},
2122
]);
@@ -27,15 +28,20 @@ describe("Connect tool", () => {
2728
const response = await integration.mcpClient().callTool({ name: "connect", arguments: {} });
2829
const content = getResponseContent(response.content);
2930
expect(content).toContain("No connection details provided");
30-
expect(content).toContain("mongodb://localhost:27017");
3131
});
3232
});
3333

3434
describe("with connection string", () => {
3535
it("connects to the database", async () => {
3636
const response = await integration.mcpClient().callTool({
3737
name: "connect",
38-
arguments: { connectionStringOrClusterName: integration.connectionString() },
38+
arguments: {
39+
options: [
40+
{
41+
connectionString: integration.connectionString(),
42+
},
43+
],
44+
},
3945
});
4046
const content = getResponseContent(response.content);
4147
expect(content).toContain("Successfully connected");
@@ -47,7 +53,7 @@ describe("Connect tool", () => {
4753
it("returns error message", async () => {
4854
const response = await integration.mcpClient().callTool({
4955
name: "connect",
50-
arguments: { connectionStringOrClusterName: "mongodb://localhost:12345" },
56+
arguments: { options: [{ connectionString: "mongodb://localhost:12345" }] },
5157
});
5258
const content = getResponseContent(response.content);
5359
expect(content).toContain("Error running connect");
@@ -74,7 +80,13 @@ describe("Connect tool", () => {
7480
const newConnectionString = `${integration.connectionString()}?appName=foo-bar`;
7581
const response = await integration.mcpClient().callTool({
7682
name: "connect",
77-
arguments: { connectionStringOrClusterName: newConnectionString },
83+
arguments: {
84+
options: [
85+
{
86+
connectionString: newConnectionString,
87+
},
88+
],
89+
},
7890
});
7991
const content = getResponseContent(response.content);
8092
expect(content).toContain("Successfully connected");
@@ -85,7 +97,13 @@ describe("Connect tool", () => {
8597
it("suggests the config connection string if set", async () => {
8698
const response = await integration.mcpClient().callTool({
8799
name: "connect",
88-
arguments: { connectionStringOrClusterName: "mongodb://localhost:12345" },
100+
arguments: {
101+
options: [
102+
{
103+
connectionString: "mongodb://localhost:12345",
104+
},
105+
],
106+
},
89107
});
90108
const content = getResponseContent(response.content);
91109
expect(content).toContain("Failed to connect to MongoDB at 'mongodb://localhost:12345'");
@@ -98,7 +116,13 @@ describe("Connect tool", () => {
98116
config.connectionString = "mongodb://localhost:12345";
99117
const response = await integration.mcpClient().callTool({
100118
name: "connect",
101-
arguments: { connectionStringOrClusterName: "mongodb://localhost:12345" },
119+
arguments: {
120+
options: [
121+
{
122+
connectionString: "mongodb://localhost:12345",
123+
},
124+
],
125+
},
102126
});
103127

104128
const content = getResponseContent(response.content);

0 commit comments

Comments
 (0)