fastmcp 4.12.4 → 4.12.5

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/README.md CHANGED
@@ -2015,20 +2015,23 @@ For more control over OAuth behavior, you can use the `oauth` option directly:
2015
2015
  import { FastMCP } from "fastmcp";
2016
2016
  import { GoogleProvider } from "fastmcp/auth";
2017
2017
 
2018
- const authProxy = new GoogleProvider({
2019
- clientId: process.env.GOOGLE_CLIENT_ID,
2020
- clientSecret: process.env.GOOGLE_CLIENT_SECRET,
2018
+ const authProvider = new GoogleProvider({
2021
2019
  baseUrl: "https://your-server.com",
2020
+ clientId: process.env.GOOGLE_CLIENT_ID!,
2021
+ clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
2022
2022
  scopes: ["openid", "profile", "email"],
2023
2023
  });
2024
2024
 
2025
2025
  const server = new FastMCP({
2026
2026
  name: "My Server",
2027
2027
  oauth: {
2028
+ authorizationServer: authProvider
2029
+ .getProxy()
2030
+ .getAuthorizationServerMetadata(),
2028
2031
  enabled: true,
2029
- authorizationServer: authProxy.getAuthorizationServerMetadata(),
2030
- proxy: authProxy,
2032
+ proxy: authProvider.getProxy(),
2031
2033
  },
2034
+ version: "1.0.0",
2032
2035
  });
2033
2036
  ```
2034
2037
 
package/dist/FastMCP.cjs CHANGED
@@ -11,7 +11,7 @@
11
11
 
12
12
 
13
13
 
14
- var _chunkDD63MJG7cjs = require('./chunk-DD63MJG7.cjs');
14
+ var _chunkU36NARZGcjs = require('./chunk-U36NARZG.cjs');
15
15
 
16
16
 
17
17
 
@@ -49,5 +49,5 @@ var _chunkENMHHQJFcjs = require('./chunk-ENMHHQJF.cjs');
49
49
 
50
50
 
51
51
 
52
- exports.AuthProvider = _chunkENMHHQJFcjs.AuthProvider; exports.AzureProvider = _chunkENMHHQJFcjs.AzureProvider; exports.DiscoveryDocumentCache = _chunkDD63MJG7cjs.DiscoveryDocumentCache; exports.FastMCP = _chunkDD63MJG7cjs.FastMCP; exports.FastMCPError = _chunkDD63MJG7cjs.FastMCPError; exports.FastMCPSession = _chunkDD63MJG7cjs.FastMCPSession; exports.GitHubProvider = _chunkENMHHQJFcjs.GitHubProvider; exports.GoogleProvider = _chunkENMHHQJFcjs.GoogleProvider; exports.MEDIA_FETCH_TIMEOUT_MS = _chunkDD63MJG7cjs.MEDIA_FETCH_TIMEOUT_MS; exports.OAuthProvider = _chunkENMHHQJFcjs.OAuthProvider; exports.ServerState = _chunkDD63MJG7cjs.ServerState; exports.SessionError = _chunkDD63MJG7cjs.SessionError; exports.UnexpectedStateError = _chunkDD63MJG7cjs.UnexpectedStateError; exports.UserError = _chunkDD63MJG7cjs.UserError; exports.audioContent = _chunkDD63MJG7cjs.audioContent; exports.getAuthSession = _chunkENMHHQJFcjs.getAuthSession; exports.imageContent = _chunkDD63MJG7cjs.imageContent; exports.jsonSchemaAdapter = _chunkDD63MJG7cjs.jsonSchemaAdapter; exports.requireAll = _chunkENMHHQJFcjs.requireAll; exports.requireAny = _chunkENMHHQJFcjs.requireAny; exports.requireAuth = _chunkENMHHQJFcjs.requireAuth; exports.requireRole = _chunkENMHHQJFcjs.requireRole; exports.requireScopes = _chunkENMHHQJFcjs.requireScopes;
52
+ exports.AuthProvider = _chunkENMHHQJFcjs.AuthProvider; exports.AzureProvider = _chunkENMHHQJFcjs.AzureProvider; exports.DiscoveryDocumentCache = _chunkU36NARZGcjs.DiscoveryDocumentCache; exports.FastMCP = _chunkU36NARZGcjs.FastMCP; exports.FastMCPError = _chunkU36NARZGcjs.FastMCPError; exports.FastMCPSession = _chunkU36NARZGcjs.FastMCPSession; exports.GitHubProvider = _chunkENMHHQJFcjs.GitHubProvider; exports.GoogleProvider = _chunkENMHHQJFcjs.GoogleProvider; exports.MEDIA_FETCH_TIMEOUT_MS = _chunkU36NARZGcjs.MEDIA_FETCH_TIMEOUT_MS; exports.OAuthProvider = _chunkENMHHQJFcjs.OAuthProvider; exports.ServerState = _chunkU36NARZGcjs.ServerState; exports.SessionError = _chunkU36NARZGcjs.SessionError; exports.UnexpectedStateError = _chunkU36NARZGcjs.UnexpectedStateError; exports.UserError = _chunkU36NARZGcjs.UserError; exports.audioContent = _chunkU36NARZGcjs.audioContent; exports.getAuthSession = _chunkENMHHQJFcjs.getAuthSession; exports.imageContent = _chunkU36NARZGcjs.imageContent; exports.jsonSchemaAdapter = _chunkU36NARZGcjs.jsonSchemaAdapter; exports.requireAll = _chunkENMHHQJFcjs.requireAll; exports.requireAny = _chunkENMHHQJFcjs.requireAny; exports.requireAuth = _chunkENMHHQJFcjs.requireAuth; exports.requireRole = _chunkENMHHQJFcjs.requireRole; exports.requireScopes = _chunkENMHHQJFcjs.requireScopes;
53
53
  //# sourceMappingURL=FastMCP.cjs.map
package/dist/FastMCP.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  audioContent,
12
12
  imageContent,
13
13
  jsonSchemaAdapter
14
- } from "./chunk-FKX5QBJV.js";
14
+ } from "./chunk-HIIPZVNY.js";
15
15
  import {
16
16
  AuthProvider,
17
17
  AzureProvider,
@@ -1462,6 +1462,7 @@ function parseBasicAuthHeader(authHeader) {
1462
1462
  return null;
1463
1463
  }
1464
1464
  }
1465
+ var OAUTH_PROXY_MAX_BODY_SIZE = 1024 * 1024;
1465
1466
  function stripBasePath(path, basePath) {
1466
1467
  if (!basePath) {
1467
1468
  return path;
@@ -2236,11 +2237,47 @@ var FastMCP = class extends FastMCPEventEmitter {
2236
2237
  try {
2237
2238
  if (req.method === "POST" && oauthPath === "/oauth/register") {
2238
2239
  await new Promise((resolve) => {
2239
- let body = "";
2240
- req.on("data", (chunk) => body += chunk);
2240
+ const bodyChunks = [];
2241
+ let bodySize = 0;
2242
+ let failed = false;
2243
+ const fail = () => {
2244
+ if (failed || res.headersSent) {
2245
+ resolve();
2246
+ return;
2247
+ }
2248
+ failed = true;
2249
+ res.writeHead(400, {
2250
+ Connection: "close",
2251
+ "Content-Type": "application/json"
2252
+ }).end(
2253
+ JSON.stringify({
2254
+ error: "invalid_request",
2255
+ error_description: "Request body exceeds 1 MiB"
2256
+ })
2257
+ );
2258
+ resolve();
2259
+ };
2260
+ req.on("data", (chunk) => {
2261
+ if (failed) {
2262
+ return;
2263
+ }
2264
+ bodySize += chunk.length;
2265
+ if (bodySize > OAUTH_PROXY_MAX_BODY_SIZE) {
2266
+ fail();
2267
+ return;
2268
+ }
2269
+ bodyChunks.push(chunk);
2270
+ });
2271
+ req.on("aborted", fail);
2272
+ req.on("error", fail);
2241
2273
  req.on("end", async () => {
2274
+ if (failed) {
2275
+ return;
2276
+ }
2242
2277
  try {
2243
- const request = JSON.parse(body);
2278
+ const request = JSON.parse(
2279
+ Buffer.concat(bodyChunks).toString("utf8")
2280
+ );
2244
2281
  const response = await oauthProxy.registerClient(request);
2245
2282
  res.writeHead(201, { "Content-Type": "application/json" }).end(JSON.stringify(response));
2246
2283
  } catch (error) {
@@ -2306,14 +2343,48 @@ var FastMCP = class extends FastMCPEventEmitter {
2306
2343
  }
2307
2344
  if (req.method === "POST" && oauthPath === "/oauth/consent") {
2308
2345
  await new Promise((resolve) => {
2309
- let body = "";
2310
- req.on("data", (chunk) => body += chunk);
2346
+ const bodyChunks = [];
2347
+ let bodySize = 0;
2348
+ let failed = false;
2349
+ const fail = () => {
2350
+ if (failed || res.headersSent) {
2351
+ resolve();
2352
+ return;
2353
+ }
2354
+ failed = true;
2355
+ res.writeHead(400, {
2356
+ Connection: "close",
2357
+ "Content-Type": "application/json"
2358
+ }).end(
2359
+ JSON.stringify({
2360
+ error: "invalid_request",
2361
+ error_description: "Request body exceeds 1 MiB"
2362
+ })
2363
+ );
2364
+ resolve();
2365
+ };
2366
+ req.on("data", (chunk) => {
2367
+ if (failed) {
2368
+ return;
2369
+ }
2370
+ bodySize += chunk.length;
2371
+ if (bodySize > OAUTH_PROXY_MAX_BODY_SIZE) {
2372
+ fail();
2373
+ return;
2374
+ }
2375
+ bodyChunks.push(chunk);
2376
+ });
2377
+ req.on("aborted", fail);
2378
+ req.on("error", fail);
2311
2379
  req.on("end", async () => {
2380
+ if (failed) {
2381
+ return;
2382
+ }
2312
2383
  try {
2313
2384
  const mockRequest = new Request(
2314
2385
  `http://${host}${url2.pathname}${url2.search}`,
2315
2386
  {
2316
- body,
2387
+ body: Buffer.concat(bodyChunks).toString("utf8"),
2317
2388
  headers: {
2318
2389
  "Content-Type": "application/x-www-form-urlencoded"
2319
2390
  },
@@ -2344,11 +2415,47 @@ var FastMCP = class extends FastMCPEventEmitter {
2344
2415
  }
2345
2416
  if (req.method === "POST" && oauthPath === "/oauth/token") {
2346
2417
  await new Promise((resolve) => {
2347
- let body = "";
2348
- req.on("data", (chunk) => body += chunk);
2418
+ const bodyChunks = [];
2419
+ let bodySize = 0;
2420
+ let failed = false;
2421
+ const fail = () => {
2422
+ if (failed || res.headersSent) {
2423
+ resolve();
2424
+ return;
2425
+ }
2426
+ failed = true;
2427
+ res.writeHead(400, {
2428
+ Connection: "close",
2429
+ "Content-Type": "application/json"
2430
+ }).end(
2431
+ JSON.stringify({
2432
+ error: "invalid_request",
2433
+ error_description: "Request body exceeds 1 MiB"
2434
+ })
2435
+ );
2436
+ resolve();
2437
+ };
2438
+ req.on("data", (chunk) => {
2439
+ if (failed) {
2440
+ return;
2441
+ }
2442
+ bodySize += chunk.length;
2443
+ if (bodySize > OAUTH_PROXY_MAX_BODY_SIZE) {
2444
+ fail();
2445
+ return;
2446
+ }
2447
+ bodyChunks.push(chunk);
2448
+ });
2449
+ req.on("aborted", fail);
2450
+ req.on("error", fail);
2349
2451
  req.on("end", async () => {
2452
+ if (failed) {
2453
+ return;
2454
+ }
2350
2455
  try {
2351
- const params = new URLSearchParams(body);
2456
+ const params = new URLSearchParams(
2457
+ Buffer.concat(bodyChunks).toString("utf8")
2458
+ );
2352
2459
  const grantType = params.get("grant_type");
2353
2460
  const basicAuth = parseBasicAuthHeader(
2354
2461
  req.headers.authorization
@@ -2548,4 +2655,4 @@ export {
2548
2655
  FastMCPSession,
2549
2656
  FastMCP
2550
2657
  };
2551
- //# sourceMappingURL=chunk-FKX5QBJV.js.map
2658
+ //# sourceMappingURL=chunk-HIIPZVNY.js.map