fastmcp 4.20.0 → 4.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/FastMCP.cjs +2 -2
- package/dist/FastMCP.js +1 -1
- package/dist/{chunk-XJWV6G5Q.js → chunk-RGV6FTGL.js} +25 -15
- package/dist/{chunk-XJWV6G5Q.js.map → chunk-RGV6FTGL.js.map} +1 -1
- package/dist/{chunk-KGXPEC7J.cjs → chunk-TMDXVX4L.cjs} +48 -38
- package/dist/chunk-TMDXVX4L.cjs.map +1 -0
- package/dist/examples/custom-routes.cjs +2 -2
- package/dist/examples/custom-routes.js +1 -1
- package/dist/openapi/index.cjs +5 -5
- package/dist/openapi/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-KGXPEC7J.cjs.map +0 -1
|
@@ -2097,13 +2097,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2097
2097
|
enableJsonResponse: httpConfig.enableJsonResponse,
|
|
2098
2098
|
eventStore: httpConfig.eventStore,
|
|
2099
2099
|
host: httpConfig.host,
|
|
2100
|
-
...
|
|
2101
|
-
oauth: {
|
|
2102
|
-
protectedResource: {
|
|
2103
|
-
resource: this.#options.oauth.protectedResource.resource
|
|
2104
|
-
}
|
|
2105
|
-
}
|
|
2106
|
-
} : {},
|
|
2100
|
+
...this.#httpStreamOAuthConfig(),
|
|
2107
2101
|
// In stateless mode, we don't track sessions
|
|
2108
2102
|
onClose: async () => {
|
|
2109
2103
|
},
|
|
@@ -2145,13 +2139,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2145
2139
|
enableJsonResponse: httpConfig.enableJsonResponse,
|
|
2146
2140
|
eventStore: httpConfig.eventStore,
|
|
2147
2141
|
host: httpConfig.host,
|
|
2148
|
-
...
|
|
2149
|
-
oauth: {
|
|
2150
|
-
protectedResource: {
|
|
2151
|
-
resource: this.#options.oauth.protectedResource.resource
|
|
2152
|
-
}
|
|
2153
|
-
}
|
|
2154
|
-
} : {},
|
|
2142
|
+
...this.#httpStreamOAuthConfig(),
|
|
2155
2143
|
onClose: async (session) => {
|
|
2156
2144
|
const sessionIndex = this.#sessions.indexOf(session);
|
|
2157
2145
|
if (sessionIndex !== -1) this.#sessions.splice(sessionIndex, 1);
|
|
@@ -2251,7 +2239,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2251
2239
|
*/
|
|
2252
2240
|
#createUnauthorizedResponse(message) {
|
|
2253
2241
|
const oauth = this.#options.oauth;
|
|
2254
|
-
const resource = _optionalChain([oauth, 'optionalAccess',
|
|
2242
|
+
const resource = _optionalChain([oauth, 'optionalAccess', _46 => _46.enabled]) ? _optionalChain([oauth, 'access', _47 => _47.protectedResource, 'optionalAccess', _48 => _48.resource]) : void 0;
|
|
2255
2243
|
const wwwAuthenticateParts = [
|
|
2256
2244
|
'error="invalid_token"',
|
|
2257
2245
|
`error_description="${message.replace(/"/g, '\\"')}"`
|
|
@@ -2377,7 +2365,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2377
2365
|
}
|
|
2378
2366
|
}
|
|
2379
2367
|
const oauthConfig = this.#options.oauth;
|
|
2380
|
-
if (_optionalChain([oauthConfig, 'optionalAccess',
|
|
2368
|
+
if (_optionalChain([oauthConfig, 'optionalAccess', _49 => _49.enabled]) && req.method === "GET") {
|
|
2381
2369
|
const url2 = new URL(req.url || "", `http://${host}`);
|
|
2382
2370
|
const authorizationServerMetadataPath = joinPaths(
|
|
2383
2371
|
"",
|
|
@@ -2411,8 +2399,8 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2411
2399
|
}
|
|
2412
2400
|
}
|
|
2413
2401
|
}
|
|
2414
|
-
const oauthProxy = _optionalChain([oauthConfig, 'optionalAccess',
|
|
2415
|
-
if (oauthProxy && _optionalChain([oauthConfig, 'optionalAccess',
|
|
2402
|
+
const oauthProxy = _optionalChain([oauthConfig, 'optionalAccess', _50 => _50.proxy]);
|
|
2403
|
+
if (oauthProxy && _optionalChain([oauthConfig, 'optionalAccess', _51 => _51.enabled])) {
|
|
2416
2404
|
const url2 = new URL(req.url || "", `http://${host}`);
|
|
2417
2405
|
const oauthPath = basePathRelativePath;
|
|
2418
2406
|
try {
|
|
@@ -2465,7 +2453,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2465
2453
|
const statusCode = error.statusCode || 400;
|
|
2466
2454
|
res.writeHead(statusCode, OAUTH_CREDENTIAL_RESPONSE_HEADERS).end(
|
|
2467
2455
|
JSON.stringify(
|
|
2468
|
-
_optionalChain([error, 'access',
|
|
2456
|
+
_optionalChain([error, 'access', _52 => _52.toJSON, 'optionalCall', _53 => _53()]) || {
|
|
2469
2457
|
error: "invalid_request"
|
|
2470
2458
|
}
|
|
2471
2459
|
)
|
|
@@ -2492,7 +2480,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2492
2480
|
} catch (error) {
|
|
2493
2481
|
res.writeHead(400, { "Content-Type": "application/json" }).end(
|
|
2494
2482
|
JSON.stringify(
|
|
2495
|
-
_optionalChain([error, 'access',
|
|
2483
|
+
_optionalChain([error, 'access', _54 => _54.toJSON, 'optionalCall', _55 => _55()]) || {
|
|
2496
2484
|
error: "invalid_request"
|
|
2497
2485
|
}
|
|
2498
2486
|
)
|
|
@@ -2514,7 +2502,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2514
2502
|
} catch (error) {
|
|
2515
2503
|
res.writeHead(400, { "Content-Type": "application/json" }).end(
|
|
2516
2504
|
JSON.stringify(
|
|
2517
|
-
_optionalChain([error, 'access',
|
|
2505
|
+
_optionalChain([error, 'access', _56 => _56.toJSON, 'optionalCall', _57 => _57()]) || {
|
|
2518
2506
|
error: "server_error"
|
|
2519
2507
|
}
|
|
2520
2508
|
)
|
|
@@ -2583,7 +2571,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2583
2571
|
} catch (error) {
|
|
2584
2572
|
res.writeHead(400, { "Content-Type": "application/json" }).end(
|
|
2585
2573
|
JSON.stringify(
|
|
2586
|
-
_optionalChain([error, 'access',
|
|
2574
|
+
_optionalChain([error, 'access', _58 => _58.toJSON, 'optionalCall', _59 => _59()]) || {
|
|
2587
2575
|
error: "server_error"
|
|
2588
2576
|
}
|
|
2589
2577
|
)
|
|
@@ -2641,8 +2629,8 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2641
2629
|
const basicAuth = parseBasicAuthHeader(
|
|
2642
2630
|
req.headers.authorization
|
|
2643
2631
|
);
|
|
2644
|
-
const clientId = _optionalChain([basicAuth, 'optionalAccess',
|
|
2645
|
-
const clientSecret = _nullishCoalesce(_nullishCoalesce(_optionalChain([basicAuth, 'optionalAccess',
|
|
2632
|
+
const clientId = _optionalChain([basicAuth, 'optionalAccess', _60 => _60.clientId]) || params.get("client_id") || "";
|
|
2633
|
+
const clientSecret = _nullishCoalesce(_nullishCoalesce(_optionalChain([basicAuth, 'optionalAccess', _61 => _61.clientSecret]), () => ( params.get("client_secret"))), () => ( void 0));
|
|
2646
2634
|
let response;
|
|
2647
2635
|
if (grantType === "authorization_code") {
|
|
2648
2636
|
response = await oauthProxy.exchangeAuthorizationCode({
|
|
@@ -2672,7 +2660,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2672
2660
|
const statusCode = error.statusCode || 400;
|
|
2673
2661
|
res.writeHead(statusCode, OAUTH_CREDENTIAL_RESPONSE_HEADERS).end(
|
|
2674
2662
|
JSON.stringify(
|
|
2675
|
-
_optionalChain([error, 'access',
|
|
2663
|
+
_optionalChain([error, 'access', _62 => _62.toJSON, 'optionalCall', _63 => _63()]) || {
|
|
2676
2664
|
error: "invalid_request"
|
|
2677
2665
|
}
|
|
2678
2666
|
)
|
|
@@ -2690,6 +2678,28 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2690
2678
|
}
|
|
2691
2679
|
}
|
|
2692
2680
|
};
|
|
2681
|
+
/**
|
|
2682
|
+
* mcp-proxy only emits `WWW-Authenticate` on 401 when `oauth` is set.
|
|
2683
|
+
* Custom `authenticate()` still needs that challenge with no OAuth metadata
|
|
2684
|
+
* configured (RFC 7235). Pass an empty oauth object in that case so the
|
|
2685
|
+
* header is present without advertising a resource_metadata URL that 404s.
|
|
2686
|
+
*/
|
|
2687
|
+
#httpStreamOAuthConfig() {
|
|
2688
|
+
const resource = _optionalChain([this, 'access', _64 => _64.#options, 'access', _65 => _65.oauth, 'optionalAccess', _66 => _66.enabled]) ? _optionalChain([this, 'access', _67 => _67.#options, 'access', _68 => _68.oauth, 'access', _69 => _69.protectedResource, 'optionalAccess', _70 => _70.resource]) : void 0;
|
|
2689
|
+
if (resource) {
|
|
2690
|
+
return {
|
|
2691
|
+
oauth: {
|
|
2692
|
+
protectedResource: {
|
|
2693
|
+
resource
|
|
2694
|
+
}
|
|
2695
|
+
}
|
|
2696
|
+
};
|
|
2697
|
+
}
|
|
2698
|
+
if (this.#authenticate) {
|
|
2699
|
+
return { oauth: {} };
|
|
2700
|
+
}
|
|
2701
|
+
return {};
|
|
2702
|
+
}
|
|
2693
2703
|
/**
|
|
2694
2704
|
* On `httpStream`, `authenticate` is handed to both mcp-proxy (which calls it
|
|
2695
2705
|
* once per request to gate the 401) and this server's own `createServer`
|
|
@@ -2777,23 +2787,23 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2777
2787
|
const envBasePath = process.env.FASTMCP_BASE_PATH;
|
|
2778
2788
|
const envStateless = process.env.FASTMCP_STATELESS;
|
|
2779
2789
|
const envHost = process.env.FASTMCP_HOST;
|
|
2780
|
-
const transportType = _optionalChain([overrides, 'optionalAccess',
|
|
2790
|
+
const transportType = _optionalChain([overrides, 'optionalAccess', _71 => _71.transportType]) || (transportArg === "http-stream" ? "httpStream" : transportArg) || envTransport || "stdio";
|
|
2781
2791
|
if (transportType === "httpStream") {
|
|
2782
2792
|
const port = parseInt(
|
|
2783
|
-
_optionalChain([overrides, 'optionalAccess',
|
|
2793
|
+
_optionalChain([overrides, 'optionalAccess', _72 => _72.httpStream, 'optionalAccess', _73 => _73.port, 'optionalAccess', _74 => _74.toString, 'call', _75 => _75()]) || portArg || envPort || "8080"
|
|
2784
2794
|
);
|
|
2785
|
-
const host = _optionalChain([overrides, 'optionalAccess',
|
|
2786
|
-
const endpoint = _optionalChain([overrides, 'optionalAccess',
|
|
2795
|
+
const host = _optionalChain([overrides, 'optionalAccess', _76 => _76.httpStream, 'optionalAccess', _77 => _77.host]) || hostArg || envHost || "localhost";
|
|
2796
|
+
const endpoint = _optionalChain([overrides, 'optionalAccess', _78 => _78.httpStream, 'optionalAccess', _79 => _79.endpoint]) || endpointArg || envEndpoint || "/mcp";
|
|
2787
2797
|
const basePath = normalizeBasePath(
|
|
2788
|
-
_optionalChain([overrides, 'optionalAccess',
|
|
2798
|
+
_optionalChain([overrides, 'optionalAccess', _80 => _80.httpStream, 'optionalAccess', _81 => _81.basePath]) || basePathArg || envBasePath
|
|
2789
2799
|
);
|
|
2790
|
-
const enableJsonResponse = _optionalChain([overrides, 'optionalAccess',
|
|
2791
|
-
const stateless = _optionalChain([overrides, 'optionalAccess',
|
|
2792
|
-
const cors = _optionalChain([overrides, 'optionalAccess',
|
|
2793
|
-
const eventStore = _optionalChain([overrides, 'optionalAccess',
|
|
2794
|
-
const sslCa = _optionalChain([overrides, 'optionalAccess',
|
|
2795
|
-
const sslCert = _optionalChain([overrides, 'optionalAccess',
|
|
2796
|
-
const sslKey = _optionalChain([overrides, 'optionalAccess',
|
|
2800
|
+
const enableJsonResponse = _optionalChain([overrides, 'optionalAccess', _82 => _82.httpStream, 'optionalAccess', _83 => _83.enableJsonResponse]) || false;
|
|
2801
|
+
const stateless = _optionalChain([overrides, 'optionalAccess', _84 => _84.httpStream, 'optionalAccess', _85 => _85.stateless]) || statelessArg === "true" || envStateless === "true" || false;
|
|
2802
|
+
const cors = _optionalChain([overrides, 'optionalAccess', _86 => _86.httpStream, 'optionalAccess', _87 => _87.cors]);
|
|
2803
|
+
const eventStore = _optionalChain([overrides, 'optionalAccess', _88 => _88.httpStream, 'optionalAccess', _89 => _89.eventStore]);
|
|
2804
|
+
const sslCa = _optionalChain([overrides, 'optionalAccess', _90 => _90.httpStream, 'optionalAccess', _91 => _91.sslCa]);
|
|
2805
|
+
const sslCert = _optionalChain([overrides, 'optionalAccess', _92 => _92.httpStream, 'optionalAccess', _93 => _93.sslCert]);
|
|
2806
|
+
const sslKey = _optionalChain([overrides, 'optionalAccess', _94 => _94.httpStream, 'optionalAccess', _95 => _95.sslKey]);
|
|
2797
2807
|
return {
|
|
2798
2808
|
httpStream: {
|
|
2799
2809
|
basePath,
|
|
@@ -2892,4 +2902,4 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2892
2902
|
|
|
2893
2903
|
|
|
2894
2904
|
exports.DiscoveryDocumentCache = DiscoveryDocumentCache; exports.jsonSchemaAdapter = jsonSchemaAdapter; exports.MEDIA_FETCH_TIMEOUT_MS = MEDIA_FETCH_TIMEOUT_MS; exports.imageContent = imageContent; exports.audioContent = audioContent; exports.FastMCPError = FastMCPError; exports.SessionError = SessionError; exports.UnexpectedStateError = UnexpectedStateError; exports.UserError = UserError; exports.ServerState = ServerState; exports.FastMCPSession = FastMCPSession; exports.FastMCP = FastMCP;
|
|
2895
|
-
//# sourceMappingURL=chunk-
|
|
2905
|
+
//# sourceMappingURL=chunk-TMDXVX4L.cjs.map
|