File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed
tests/integration/tools/mongodb/metadata Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import { mongoLogId } from "mongodb-log-writer";
8
8
import { ObjectId } from "mongodb" ;
9
9
import { Telemetry } from "./telemetry/telemetry.js" ;
10
10
import { UserConfig } from "./config.js" ;
11
+ import { CallToolRequestSchema , CallToolResult } from "@modelcontextprotocol/sdk/types.js" ;
11
12
12
13
export interface ServerOptions {
13
14
session : Session ;
@@ -33,6 +34,15 @@ export class Server {
33
34
this . registerTools ( ) ;
34
35
this . registerResources ( ) ;
35
36
37
+ const existingHandler = this . mcpServer . server [ "_requestHandlers" ] . get ( CallToolRequestSchema . shape . method . value ) ;
38
+ this . mcpServer . server . setRequestHandler ( CallToolRequestSchema , ( request , extra ) : Promise < CallToolResult > => {
39
+ if ( ! request . params . arguments ) {
40
+ request . params . arguments = { } ;
41
+ }
42
+
43
+ return existingHandler ( request , extra ) ;
44
+ } ) ;
45
+
36
46
await initializeLogger ( this . mcpServer , this . userConfig . logPath ) ;
37
47
38
48
await this . mcpServer . connect ( transport ) ;
Original file line number Diff line number Diff line change @@ -15,6 +15,23 @@ describeWithMongoDB("Connect tool", (integration) => {
15
15
} ,
16
16
] ) ;
17
17
18
+ describe ( "without arguments" , ( ) => {
19
+ it ( "prompts for connection string if not set" , async ( ) => {
20
+ const response = await integration . mcpClient ( ) . callTool ( { name : "connect" } ) ;
21
+ const content = getResponseContent ( response . content ) ;
22
+ expect ( content ) . toContain ( "No connection details provided" ) ;
23
+ } ) ;
24
+
25
+ it ( "connects to the database if connection string is set" , async ( ) => {
26
+ config . connectionString = integration . connectionString ( ) ;
27
+
28
+ const response = await integration . mcpClient ( ) . callTool ( { name : "connect" } ) ;
29
+ const content = getResponseContent ( response . content ) ;
30
+ expect ( content ) . toContain ( "Successfully connected" ) ;
31
+ expect ( content ) . toContain ( integration . connectionString ( ) ) ;
32
+ } ) ;
33
+ } ) ;
34
+
18
35
describe ( "with default config" , ( ) => {
19
36
describe ( "without connection string" , ( ) => {
20
37
it ( "prompts for connection string" , async ( ) => {
You can’t perform that action at this time.
0 commit comments