@@ -2,21 +2,26 @@ import { StreamableHttpRunner } from "../../../src/transports/streamableHttp.js"
22import { Client } from "@modelcontextprotocol/sdk/client/index.js" ;
33import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js" ;
44import { describe , expect , it , afterEach , beforeEach } from "vitest" ;
5- import { defaultTestConfig } from "../helpers.js" ;
5+ import { defaultTestConfig , expectDefined } from "../helpers.js" ;
6+ import type { TransportRunnerConfig , UserConfig } from "../../../src/lib.js" ;
7+ import type { RequestContext } from "../../../src/transports/base.js" ;
68
79describe ( "Config Overrides via HTTP" , ( ) => {
810 let runner : StreamableHttpRunner ;
911 let client : Client ;
1012 let transport : StreamableHTTPClientTransport ;
1113
1214 // Helper function to setup and start runner with config
13- async function startRunner ( config : any , createSessionConfig ?: any ) {
15+ async function startRunner (
16+ config : UserConfig ,
17+ createSessionConfig ?: TransportRunnerConfig [ "createSessionConfig" ]
18+ ) : Promise < void > {
1419 runner = new StreamableHttpRunner ( { userConfig : config , createSessionConfig } ) ;
1520 await runner . start ( ) ;
1621 }
1722
1823 // Helper function to connect client with headers
19- async function connectClient ( headers : Record < string , string > = { } ) {
24+ async function connectClient ( headers : Record < string , string > = { } ) : Promise < void > {
2025 transport = new StreamableHTTPClientTransport ( new URL ( `${ runner . serverAddress } /mcp` ) , {
2126 requestInit : { headers } ,
2227 } ) ;
@@ -106,7 +111,8 @@ describe("Config Overrides via HTTP", () => {
106111 const insertTool = response . tools . find (
107112 ( tool ) => tool . name === "insert-many" || tool . name === "find" || tool . name === "aggregate"
108113 ) ;
109- expect ( response . tools ) . is . not . empty ;
114+
115+ expect ( response . tools ) . not . toHaveLength ( 0 ) ;
110116 expect ( insertTool ) . toBeUndefined ( ) ;
111117 } ) ;
112118 } ) ;
@@ -228,14 +234,15 @@ describe("Config Overrides via HTTP", () => {
228234
229235 // createSessionConfig receives the config after header overrides are applied
230236 // It can further modify it, but headers have already been applied
231- const createSessionConfig = async ( {
237+ const createSessionConfig : TransportRunnerConfig [ "createSessionConfig" ] = ( {
232238 userConfig : config ,
233239 request,
234240 } : {
235241 userConfig : typeof userConfig ;
236- request ?: any ;
237- } ) => {
238- expect ( request ) . toBeDefined ( ) ;
242+ request ?: RequestContext ;
243+ } ) : typeof userConfig => {
244+ expectDefined ( request ) ;
245+ expectDefined ( request . headers ) ;
239246 expect ( request . headers ) . toBeDefined ( ) ;
240247 config . readOnly = request . headers [ "x-mongodb-mcp-read-only" ] === "true" ;
241248 config . disabledTools = [ "count" ] ;
@@ -260,7 +267,7 @@ describe("Config Overrides via HTTP", () => {
260267 const countTool = response . tools . find ( ( tool ) => tool . name === "count" ) ;
261268 expect ( countTool ) . toBeUndefined ( ) ;
262269
263- expect ( response . tools ) . is . not . empty ;
270+ expect ( response . tools ) . not . toHaveLength ( 0 ) ;
264271 } ) ;
265272
266273 it ( "should pass request context to createSessionConfig" , async ( ) => {
@@ -269,10 +276,17 @@ describe("Config Overrides via HTTP", () => {
269276 httpPort : 0 ,
270277 } ;
271278
272- let capturedRequest : any ;
273- const createSessionConfig = async ( { request } : { userConfig : typeof userConfig ; request ?: any } ) => {
279+ let capturedRequest : RequestContext | undefined ;
280+ const createSessionConfig : TransportRunnerConfig [ "createSessionConfig" ] = ( {
281+ request,
282+ } : {
283+ userConfig : typeof userConfig ;
284+ request ?: RequestContext ;
285+ } ) : Promise < typeof userConfig > => {
286+ expectDefined ( request ) ;
287+ expectDefined ( request . headers ) ;
274288 capturedRequest = request ;
275- return userConfig ;
289+ return Promise . resolve ( userConfig ) ;
276290 } ;
277291
278292 await startRunner ( userConfig , createSessionConfig ) ;
@@ -282,7 +296,8 @@ describe("Config Overrides via HTTP", () => {
282296 } ) ;
283297
284298 // Verify that request context was passed
285- expect ( capturedRequest ) . toBeDefined ( ) ;
299+ expectDefined ( capturedRequest ) ;
300+ expectDefined ( capturedRequest . headers ) ;
286301 expect ( capturedRequest . headers [ "x-custom-header" ] ) . toBe ( "test-value" ) ;
287302 } ) ;
288303 } ) ;
0 commit comments