|
1 | | -import { describeWithMongoDB } from "../mongodbHelpers.js"; |
| 1 | +import { defaultTestSuiteConfig, describeWithMongoDB } from "../mongodbHelpers.js"; |
2 | 2 | import { |
3 | 3 | defaultDriverOptions, |
4 | 4 | getResponseContent, |
5 | 5 | getResponseElements, |
6 | 6 | validateThrowsForInvalidArguments, |
7 | 7 | validateToolMetadata, |
8 | 8 | } from "../../../helpers.js"; |
9 | | -import { config } from "../../../../../src/common/config.js"; |
10 | 9 | import { defaultTestConfig, setupIntegrationTest } from "../../../helpers.js"; |
11 | 10 | import { beforeEach, describe, expect, it } from "vitest"; |
12 | 11 |
|
@@ -82,66 +81,65 @@ describeWithMongoDB( |
82 | 81 | }); |
83 | 82 | }); |
84 | 83 | }, |
85 | | - (mdbIntegration) => ({ |
86 | | - ...config, |
87 | | - connectionString: mdbIntegration.connectionString(), |
88 | | - }) |
| 84 | + { |
| 85 | + ...defaultTestSuiteConfig, |
| 86 | + getUserConfig: (mdbIntegration) => ({ |
| 87 | + ...defaultTestConfig, |
| 88 | + connectionString: mdbIntegration.connectionString(), |
| 89 | + }), |
| 90 | + } |
89 | 91 | ); |
90 | 92 |
|
91 | | -describeWithMongoDB( |
92 | | - "Connect tool", |
93 | | - (integration) => { |
94 | | - validateToolMetadata( |
95 | | - integration, |
96 | | - "connect", |
97 | | - "Connect to a MongoDB instance. The config resource captures if the server is already connected to a MongoDB cluster. If the user has configured a connection string or has previously called the connect tool, a connection is already established and there's no need to call this tool unless the user has explicitly requested to switch to a new MongoDB cluster.", |
98 | | - [ |
99 | | - { |
100 | | - name: "connectionString", |
101 | | - description: "MongoDB connection string (in the mongodb:// or mongodb+srv:// format)", |
102 | | - type: "string", |
103 | | - required: true, |
104 | | - }, |
105 | | - ] |
106 | | - ); |
| 93 | +describeWithMongoDB("Connect tool", (integration) => { |
| 94 | + validateToolMetadata( |
| 95 | + integration, |
| 96 | + "connect", |
| 97 | + "Connect to a MongoDB instance. The config resource captures if the server is already connected to a MongoDB cluster. If the user has configured a connection string or has previously called the connect tool, a connection is already established and there's no need to call this tool unless the user has explicitly requested to switch to a new MongoDB cluster.", |
| 98 | + [ |
| 99 | + { |
| 100 | + name: "connectionString", |
| 101 | + description: "MongoDB connection string (in the mongodb:// or mongodb+srv:// format)", |
| 102 | + type: "string", |
| 103 | + required: true, |
| 104 | + }, |
| 105 | + ] |
| 106 | + ); |
107 | 107 |
|
108 | | - validateThrowsForInvalidArguments(integration, "connect", [{}, { connectionString: 123 }]); |
| 108 | + validateThrowsForInvalidArguments(integration, "connect", [{}, { connectionString: 123 }]); |
109 | 109 |
|
110 | | - it("doesn't have the switch-connection tool registered", async () => { |
111 | | - const { tools } = await integration.mcpClient().listTools(); |
112 | | - const tool = tools.find((tool) => tool.name === "switch-connection"); |
113 | | - expect(tool).toBeUndefined(); |
114 | | - }); |
| 110 | + it("doesn't have the switch-connection tool registered", async () => { |
| 111 | + const { tools } = await integration.mcpClient().listTools(); |
| 112 | + const tool = tools.find((tool) => tool.name === "switch-connection"); |
| 113 | + expect(tool).toBeUndefined(); |
| 114 | + }); |
115 | 115 |
|
116 | | - describe("with connection string", () => { |
117 | | - it("connects to the database", async () => { |
118 | | - const response = await integration.mcpClient().callTool({ |
119 | | - name: "connect", |
120 | | - arguments: { |
121 | | - connectionString: integration.connectionString(), |
122 | | - }, |
123 | | - }); |
124 | | - const content = getResponseContent(response.content); |
125 | | - expect(content).toContain("Successfully connected"); |
| 116 | + describe("with connection string", () => { |
| 117 | + it("connects to the database", async () => { |
| 118 | + const response = await integration.mcpClient().callTool({ |
| 119 | + name: "connect", |
| 120 | + arguments: { |
| 121 | + connectionString: integration.connectionString(), |
| 122 | + }, |
126 | 123 | }); |
| 124 | + const content = getResponseContent(response.content); |
| 125 | + expect(content).toContain("Successfully connected"); |
127 | 126 | }); |
| 127 | + }); |
128 | 128 |
|
129 | | - describe("with invalid connection string", () => { |
130 | | - it("returns error message", async () => { |
131 | | - const response = await integration.mcpClient().callTool({ |
132 | | - name: "connect", |
133 | | - arguments: { connectionString: "mangodb://localhost:12345" }, |
134 | | - }); |
135 | | - const content = getResponseContent(response.content); |
136 | | - expect(content).toContain("The configured connection string is not valid."); |
137 | | - |
138 | | - // Should not suggest using the config connection string (because we don't have one) |
139 | | - expect(content).not.toContain("Your config lists a different connection string"); |
| 129 | + describe("with invalid connection string", () => { |
| 130 | + it("returns error message", async () => { |
| 131 | + const response = await integration.mcpClient().callTool({ |
| 132 | + name: "connect", |
| 133 | + arguments: { connectionString: "mangodb://localhost:12345" }, |
140 | 134 | }); |
| 135 | + const content = getResponseContent(response.content); |
| 136 | + expect(content).toContain("The configured connection string is not valid."); |
| 137 | + |
| 138 | + // Should not suggest using the config connection string (because we don't have one) |
| 139 | + expect(content).not.toContain("Your config lists a different connection string"); |
141 | 140 | }); |
142 | | - }, |
143 | | - () => config |
144 | | -); |
| 141 | + }); |
| 142 | +}); |
145 | 143 |
|
146 | 144 | describe("Connect tool when disabled", () => { |
147 | 145 | const integration = setupIntegrationTest( |
|
0 commit comments