@@ -2036,6 +2036,7 @@ export class FastMCP<
2036
2036
enableJsonResponse ?: boolean ;
2037
2037
endpoint ?: `/${string } `;
2038
2038
eventStore ?: EventStore ;
2039
+ host ?: string ;
2039
2040
port : number ;
2040
2041
stateless ?: boolean ;
2041
2042
} ;
@@ -2094,7 +2095,7 @@ export class FastMCP<
2094
2095
if ( httpConfig . stateless ) {
2095
2096
// Stateless mode - create new server instance for each request
2096
2097
this . #logger. info (
2097
- `[FastMCP info] Starting server in stateless mode on HTTP Stream at http://localhost :${ httpConfig . port } ${ httpConfig . endpoint } ` ,
2098
+ `[FastMCP info] Starting server in stateless mode on HTTP Stream at http://${ httpConfig . host } :${ httpConfig . port } ${ httpConfig . endpoint } ` ,
2098
2099
) ;
2099
2100
2100
2101
this . #httpStreamServer = await startHTTPServer < FastMCPSession < T > > ( {
@@ -2111,6 +2112,7 @@ export class FastMCP<
2111
2112
} ,
2112
2113
enableJsonResponse : httpConfig . enableJsonResponse ,
2113
2114
eventStore : httpConfig . eventStore ,
2115
+ host : httpConfig . host ,
2114
2116
// In stateless mode, we don't track sessions
2115
2117
onClose : async ( ) => {
2116
2118
// No session tracking in stateless mode
@@ -2122,7 +2124,7 @@ export class FastMCP<
2122
2124
) ;
2123
2125
} ,
2124
2126
onUnhandledRequest : async ( req , res ) => {
2125
- await this . #handleUnhandledRequest( req , res , true ) ;
2127
+ await this . #handleUnhandledRequest( req , res , true , httpConfig . host ) ;
2126
2128
} ,
2127
2129
port : httpConfig . port ,
2128
2130
stateless : true ,
@@ -2142,6 +2144,7 @@ export class FastMCP<
2142
2144
} ,
2143
2145
enableJsonResponse : httpConfig . enableJsonResponse ,
2144
2146
eventStore : httpConfig . eventStore ,
2147
+ host : httpConfig . host ,
2145
2148
onClose : async ( session ) => {
2146
2149
this . emit ( "disconnect" , {
2147
2150
session : session as FastMCPSession < FastMCPSessionAuth > ,
@@ -2158,14 +2161,19 @@ export class FastMCP<
2158
2161
} ,
2159
2162
2160
2163
onUnhandledRequest : async ( req , res ) => {
2161
- await this . #handleUnhandledRequest( req , res , false ) ;
2164
+ await this . #handleUnhandledRequest(
2165
+ req ,
2166
+ res ,
2167
+ false ,
2168
+ httpConfig . host ,
2169
+ ) ;
2162
2170
} ,
2163
2171
port : httpConfig . port ,
2164
2172
streamEndpoint : httpConfig . endpoint ,
2165
2173
} ) ;
2166
2174
2167
2175
this . #logger. info (
2168
- `[FastMCP info] server is running on HTTP Stream at http://localhost :${ httpConfig . port } ${ httpConfig . endpoint } ` ,
2176
+ `[FastMCP info] server is running on HTTP Stream at http://${ httpConfig . host } :${ httpConfig . port } ${ httpConfig . endpoint } ` ,
2169
2177
) ;
2170
2178
this . #logger. info (
2171
2179
`[FastMCP info] Transport type: httpStream (Streamable HTTP, not SSE)` ,
@@ -2218,6 +2226,7 @@ export class FastMCP<
2218
2226
req : http . IncomingMessage ,
2219
2227
res : http . ServerResponse ,
2220
2228
isStateless = false ,
2229
+ host : string ,
2221
2230
) => {
2222
2231
const healthConfig = this . #options. health ?? { } ;
2223
2232
@@ -2226,7 +2235,7 @@ export class FastMCP<
2226
2235
2227
2236
if ( enabled ) {
2228
2237
const path = healthConfig . path ?? "/health" ;
2229
- const url = new URL ( req . url || "" , " http://localhost" ) ;
2238
+ const url = new URL ( req . url || "" , ` http://${ host } ` ) ;
2230
2239
2231
2240
try {
2232
2241
if ( req . method === "GET" && url . pathname === path ) {
@@ -2290,7 +2299,7 @@ export class FastMCP<
2290
2299
// Handle OAuth well-known endpoints
2291
2300
const oauthConfig = this . #options. oauth ;
2292
2301
if ( oauthConfig ?. enabled && req . method === "GET" ) {
2293
- const url = new URL ( req . url || "" , " http://localhost" ) ;
2302
+ const url = new URL ( req . url || "" , ` http://${ host } ` ) ;
2294
2303
2295
2304
if (
2296
2305
url . pathname === "/.well-known/oauth-authorization-server" &&
@@ -2331,6 +2340,7 @@ export class FastMCP<
2331
2340
httpStream : {
2332
2341
enableJsonResponse ?: boolean ;
2333
2342
endpoint ?: `/${string } `;
2343
+ host ?: string ;
2334
2344
port : number ;
2335
2345
stateless ?: boolean ;
2336
2346
} ;
@@ -2342,6 +2352,7 @@ export class FastMCP<
2342
2352
enableJsonResponse ?: boolean ;
2343
2353
endpoint : `/${string } `;
2344
2354
eventStore ?: EventStore ;
2355
+ host : string ;
2345
2356
port : number ;
2346
2357
stateless ?: boolean ;
2347
2358
} ;
@@ -2361,12 +2372,13 @@ export class FastMCP<
2361
2372
const portArg = getArg ( "port" ) ;
2362
2373
const endpointArg = getArg ( "endpoint" ) ;
2363
2374
const statelessArg = getArg ( "stateless" ) ;
2375
+ const hostArg = getArg ( "host" ) ;
2364
2376
2365
2377
const envTransport = process . env . FASTMCP_TRANSPORT ;
2366
2378
const envPort = process . env . FASTMCP_PORT ;
2367
2379
const envEndpoint = process . env . FASTMCP_ENDPOINT ;
2368
2380
const envStateless = process . env . FASTMCP_STATELESS ;
2369
-
2381
+ const envHost = process . env . FASTMCP_HOST ;
2370
2382
// Overrides > CLI > env > defaults
2371
2383
const transportType =
2372
2384
overrides ?. transportType ||
@@ -2378,6 +2390,8 @@ export class FastMCP<
2378
2390
const port = parseInt (
2379
2391
overrides ?. httpStream ?. port ?. toString ( ) || portArg || envPort || "8080" ,
2380
2392
) ;
2393
+ const host =
2394
+ overrides ?. httpStream ?. host || hostArg || envHost || "localhost" ;
2381
2395
const endpoint =
2382
2396
overrides ?. httpStream ?. endpoint || endpointArg || envEndpoint || "/mcp" ;
2383
2397
const enableJsonResponse =
@@ -2392,6 +2406,7 @@ export class FastMCP<
2392
2406
httpStream : {
2393
2407
enableJsonResponse,
2394
2408
endpoint : endpoint as `/${string } `,
2409
+ host,
2395
2410
port,
2396
2411
stateless,
2397
2412
} ,
0 commit comments