@@ -7,25 +7,22 @@ import {
77} from "../tool.js" ;
88import { CallToolResult } from "@modelcontextprotocol/sdk/types.js" ;
99import { Server } from "../../server.js" ;
10- import { Session } from "../../common/session.js" ;
11- import { UserConfig } from "../../common/config.js" ;
12- import { Telemetry } from "../../telemetry/telemetry.js" ;
1310import { packageInfo } from "../../common/packageInfo.js" ;
1411
1512export abstract class AssistantToolBase extends ToolBase {
1613 protected server ?: Server ;
1714 public category : ToolCategory = "assistant" ;
1815 protected baseUrl : URL ;
19- protected requiredHeaders : Record < string , string > ;
16+ protected requiredHeaders : Headers ;
2017
2118 constructor ( { session, config, telemetry, elicitation } : ToolConstructorParams ) {
2219 super ( { session, config, telemetry, elicitation } ) ;
2320 this . baseUrl = new URL ( config . assistantBaseUrl ) ;
2421 const serverVersion = packageInfo . version ;
25- this . requiredHeaders = {
22+ this . requiredHeaders = new Headers ( {
2623 "x-request-origin" : "mongodb-mcp-server" ,
2724 "user-agent" : serverVersion ? `mongodb-mcp-server/v${ serverVersion } ` : "mongodb-mcp-server" ,
28- } ;
25+ } ) ;
2926 }
3027
3128 public register ( server : Server ) : boolean {
@@ -39,10 +36,16 @@ export abstract class AssistantToolBase extends ToolBase {
3936 return { } ;
4037 }
4138
42- protected handleError (
43- error : unknown ,
44- args : ToolArgs < typeof this . argsShape >
45- ) : Promise < CallToolResult > | CallToolResult {
46- return super . handleError ( error , args ) ;
39+ protected async callAssistantApi ( args : { method : "GET" | "POST" ; endpoint : string ; body ?: unknown } ) {
40+ const endpoint = new URL ( args . endpoint , this . baseUrl ) ;
41+ const headers = new Headers ( this . requiredHeaders ) ;
42+ if ( args . method === "POST" ) {
43+ headers . set ( "Content-Type" , "application/json" ) ;
44+ }
45+ return await fetch ( endpoint , {
46+ method : args . method ,
47+ headers,
48+ body : JSON . stringify ( args . body ) ,
49+ } ) ;
4750 }
4851}
0 commit comments