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";
88import { ObjectId } from "mongodb" ;
99import { Telemetry } from "./telemetry/telemetry.js" ;
1010import { UserConfig } from "./config.js" ;
11+ import { CallToolRequestSchema , CallToolResult } from "@modelcontextprotocol/sdk/types.js" ;
1112
1213export interface ServerOptions {
1314 session : Session ;
@@ -33,6 +34,15 @@ export class Server {
3334 this . registerTools ( ) ;
3435 this . registerResources ( ) ;
3536
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+
3646 await initializeLogger ( this . mcpServer , this . userConfig . logPath ) ;
3747
3848 await this . mcpServer . connect ( transport ) ;
Original file line number Diff line number Diff line change @@ -15,6 +15,23 @@ describeWithMongoDB("Connect tool", (integration) => {
1515 } ,
1616 ] ) ;
1717
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+
1835 describe ( "with default config" , ( ) => {
1936 describe ( "without connection string" , ( ) => {
2037 it ( "prompts for connection string" , async ( ) => {
You can’t perform that action at this time.
0 commit comments