fastmcp 4.12.3 → 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 +10 -5
- package/dist/FastMCP.cjs +4 -2
- package/dist/FastMCP.cjs.map +1 -1
- package/dist/FastMCP.d.cts +13 -10
- package/dist/FastMCP.d.ts +13 -10
- package/dist/FastMCP.js +3 -1
- package/dist/{chunk-5K4GLQMV.js → chunk-HIIPZVNY.js} +137 -12
- package/dist/chunk-HIIPZVNY.js.map +1 -0
- package/dist/{chunk-3O5ZKWCC.cjs → chunk-U36NARZG.cjs} +138 -13
- package/dist/chunk-U36NARZG.cjs.map +1 -0
- package/dist/examples/custom-routes.cjs +2 -2
- package/dist/examples/custom-routes.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-3O5ZKWCC.cjs.map +0 -1
- package/dist/chunk-5K4GLQMV.js.map +0 -1
package/README.md
CHANGED
|
@@ -848,6 +848,7 @@ server.addTool({
|
|
|
848
848
|
The `imageContent` function takes the following options:
|
|
849
849
|
|
|
850
850
|
- `url`: The URL of the image.
|
|
851
|
+
- `timeoutMs`: Optional timeout for a URL download in milliseconds (defaults to 30 seconds).
|
|
851
852
|
- `path`: The path to the image file.
|
|
852
853
|
- `buffer`: The image data as a buffer.
|
|
853
854
|
|
|
@@ -1025,6 +1026,7 @@ server.addTool({
|
|
|
1025
1026
|
The `audioContent` function takes the following options:
|
|
1026
1027
|
|
|
1027
1028
|
- `url`: The URL of the audio.
|
|
1029
|
+
- `timeoutMs`: Optional timeout for a URL download in milliseconds (defaults to 30 seconds).
|
|
1028
1030
|
- `path`: The path to the audio file.
|
|
1029
1031
|
- `buffer`: The audio data as a buffer.
|
|
1030
1032
|
|
|
@@ -2013,20 +2015,23 @@ For more control over OAuth behavior, you can use the `oauth` option directly:
|
|
|
2013
2015
|
import { FastMCP } from "fastmcp";
|
|
2014
2016
|
import { GoogleProvider } from "fastmcp/auth";
|
|
2015
2017
|
|
|
2016
|
-
const
|
|
2017
|
-
clientId: process.env.GOOGLE_CLIENT_ID,
|
|
2018
|
-
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
|
|
2018
|
+
const authProvider = new GoogleProvider({
|
|
2019
2019
|
baseUrl: "https://your-server.com",
|
|
2020
|
+
clientId: process.env.GOOGLE_CLIENT_ID!,
|
|
2021
|
+
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
|
|
2020
2022
|
scopes: ["openid", "profile", "email"],
|
|
2021
2023
|
});
|
|
2022
2024
|
|
|
2023
2025
|
const server = new FastMCP({
|
|
2024
2026
|
name: "My Server",
|
|
2025
2027
|
oauth: {
|
|
2028
|
+
authorizationServer: authProvider
|
|
2029
|
+
.getProxy()
|
|
2030
|
+
.getAuthorizationServerMetadata(),
|
|
2026
2031
|
enabled: true,
|
|
2027
|
-
|
|
2028
|
-
proxy: authProxy,
|
|
2032
|
+
proxy: authProvider.getProxy(),
|
|
2029
2033
|
},
|
|
2034
|
+
version: "1.0.0",
|
|
2030
2035
|
});
|
|
2031
2036
|
```
|
|
2032
2037
|
|
package/dist/FastMCP.cjs
CHANGED
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
|
|
14
|
+
var _chunkU36NARZGcjs = require('./chunk-U36NARZG.cjs');
|
|
14
15
|
|
|
15
16
|
|
|
16
17
|
|
|
@@ -47,5 +48,6 @@ var _chunkENMHHQJFcjs = require('./chunk-ENMHHQJF.cjs');
|
|
|
47
48
|
|
|
48
49
|
|
|
49
50
|
|
|
50
|
-
|
|
51
|
+
|
|
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;
|
|
51
53
|
//# sourceMappingURL=FastMCP.cjs.map
|
package/dist/FastMCP.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/fastmcp/fastmcp/dist/FastMCP.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/fastmcp/fastmcp/dist/FastMCP.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,0yCAAC","file":"/home/runner/work/fastmcp/fastmcp/dist/FastMCP.cjs"}
|
package/dist/FastMCP.d.cts
CHANGED
|
@@ -141,20 +141,23 @@ type FastMCPSessionEvents = {
|
|
|
141
141
|
roots: Root[];
|
|
142
142
|
}) => void;
|
|
143
143
|
};
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
144
|
+
/**
|
|
145
|
+
* Timeout for image/audio URL fetches (in milliseconds). The OAuth upstream
|
|
146
|
+
* fetches (#304) use 10s because they are short interactive exchanges; media
|
|
147
|
+
* downloads can be larger and slower, so 30s is the balance between hanging
|
|
148
|
+
* forever on an unresponsive server and false positives on slow connections.
|
|
149
|
+
*/
|
|
150
|
+
declare const MEDIA_FETCH_TIMEOUT_MS = 30000;
|
|
151
|
+
type MediaContentInput = {
|
|
152
152
|
buffer: Buffer;
|
|
153
153
|
} | {
|
|
154
154
|
path: string;
|
|
155
155
|
} | {
|
|
156
|
+
timeoutMs?: number;
|
|
156
157
|
url: string;
|
|
157
|
-
}
|
|
158
|
+
};
|
|
159
|
+
declare const imageContent: (input: MediaContentInput) => Promise<ImageContent>;
|
|
160
|
+
declare const audioContent: (input: MediaContentInput) => Promise<AudioContent>;
|
|
158
161
|
type Context<T extends FastMCPSessionAuth> = {
|
|
159
162
|
client: {
|
|
160
163
|
version: ReturnType<Server["getClientVersion"]>;
|
|
@@ -1054,4 +1057,4 @@ declare class FastMCP<T extends FastMCPSessionAuth = FastMCPSessionAuth> extends
|
|
|
1054
1057
|
stop(): Promise<void>;
|
|
1055
1058
|
}
|
|
1056
1059
|
|
|
1057
|
-
export { type AudioContent, AuthProvider, type Content, type ContentResult, type Context, DiscoveryDocumentCache, FastMCP, FastMCPError, type FastMCPEvents, type FastMCPRequest, type FastMCPResponse, FastMCPSession, type FastMCPSessionAuth, type FastMCPSessionEvents, type HTTPMethod, type ImageContent, type InputPrompt, type InputPromptArgument, type JsonSchemaObject, type JsonSchemaStandardSchema, type LoadContext, type Logger, type LoggingLevel, OAuthSession, type Progress, type Prompt, type PromptArgument, type Resource, type ResourceContent, type ResourceResult, type ResourceTemplate, type ResourceTemplateArgument, type RouteHandler, type RouteOptions, type SSEServer, type SerializableValue, type ServerOptions, ServerState, SessionError, type TextContent, type Tool, type ToolParameters, UnexpectedStateError, UserError, audioContent, imageContent, jsonSchemaAdapter };
|
|
1060
|
+
export { type AudioContent, AuthProvider, type Content, type ContentResult, type Context, DiscoveryDocumentCache, FastMCP, FastMCPError, type FastMCPEvents, type FastMCPRequest, type FastMCPResponse, FastMCPSession, type FastMCPSessionAuth, type FastMCPSessionEvents, type HTTPMethod, type ImageContent, type InputPrompt, type InputPromptArgument, type JsonSchemaObject, type JsonSchemaStandardSchema, type LoadContext, type Logger, type LoggingLevel, MEDIA_FETCH_TIMEOUT_MS, OAuthSession, type Progress, type Prompt, type PromptArgument, type Resource, type ResourceContent, type ResourceResult, type ResourceTemplate, type ResourceTemplateArgument, type RouteHandler, type RouteOptions, type SSEServer, type SerializableValue, type ServerOptions, ServerState, SessionError, type TextContent, type Tool, type ToolParameters, UnexpectedStateError, UserError, audioContent, imageContent, jsonSchemaAdapter };
|
package/dist/FastMCP.d.ts
CHANGED
|
@@ -141,20 +141,23 @@ type FastMCPSessionEvents = {
|
|
|
141
141
|
roots: Root[];
|
|
142
142
|
}) => void;
|
|
143
143
|
};
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
144
|
+
/**
|
|
145
|
+
* Timeout for image/audio URL fetches (in milliseconds). The OAuth upstream
|
|
146
|
+
* fetches (#304) use 10s because they are short interactive exchanges; media
|
|
147
|
+
* downloads can be larger and slower, so 30s is the balance between hanging
|
|
148
|
+
* forever on an unresponsive server and false positives on slow connections.
|
|
149
|
+
*/
|
|
150
|
+
declare const MEDIA_FETCH_TIMEOUT_MS = 30000;
|
|
151
|
+
type MediaContentInput = {
|
|
152
152
|
buffer: Buffer;
|
|
153
153
|
} | {
|
|
154
154
|
path: string;
|
|
155
155
|
} | {
|
|
156
|
+
timeoutMs?: number;
|
|
156
157
|
url: string;
|
|
157
|
-
}
|
|
158
|
+
};
|
|
159
|
+
declare const imageContent: (input: MediaContentInput) => Promise<ImageContent>;
|
|
160
|
+
declare const audioContent: (input: MediaContentInput) => Promise<AudioContent>;
|
|
158
161
|
type Context<T extends FastMCPSessionAuth> = {
|
|
159
162
|
client: {
|
|
160
163
|
version: ReturnType<Server["getClientVersion"]>;
|
|
@@ -1054,4 +1057,4 @@ declare class FastMCP<T extends FastMCPSessionAuth = FastMCPSessionAuth> extends
|
|
|
1054
1057
|
stop(): Promise<void>;
|
|
1055
1058
|
}
|
|
1056
1059
|
|
|
1057
|
-
export { type AudioContent, AuthProvider, type Content, type ContentResult, type Context, DiscoveryDocumentCache, FastMCP, FastMCPError, type FastMCPEvents, type FastMCPRequest, type FastMCPResponse, FastMCPSession, type FastMCPSessionAuth, type FastMCPSessionEvents, type HTTPMethod, type ImageContent, type InputPrompt, type InputPromptArgument, type JsonSchemaObject, type JsonSchemaStandardSchema, type LoadContext, type Logger, type LoggingLevel, OAuthSession, type Progress, type Prompt, type PromptArgument, type Resource, type ResourceContent, type ResourceResult, type ResourceTemplate, type ResourceTemplateArgument, type RouteHandler, type RouteOptions, type SSEServer, type SerializableValue, type ServerOptions, ServerState, SessionError, type TextContent, type Tool, type ToolParameters, UnexpectedStateError, UserError, audioContent, imageContent, jsonSchemaAdapter };
|
|
1060
|
+
export { type AudioContent, AuthProvider, type Content, type ContentResult, type Context, DiscoveryDocumentCache, FastMCP, FastMCPError, type FastMCPEvents, type FastMCPRequest, type FastMCPResponse, FastMCPSession, type FastMCPSessionAuth, type FastMCPSessionEvents, type HTTPMethod, type ImageContent, type InputPrompt, type InputPromptArgument, type JsonSchemaObject, type JsonSchemaStandardSchema, type LoadContext, type Logger, type LoggingLevel, MEDIA_FETCH_TIMEOUT_MS, OAuthSession, type Progress, type Prompt, type PromptArgument, type Resource, type ResourceContent, type ResourceResult, type ResourceTemplate, type ResourceTemplateArgument, type RouteHandler, type RouteOptions, type SSEServer, type SerializableValue, type ServerOptions, ServerState, SessionError, type TextContent, type Tool, type ToolParameters, UnexpectedStateError, UserError, audioContent, imageContent, jsonSchemaAdapter };
|
package/dist/FastMCP.js
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
FastMCP,
|
|
4
4
|
FastMCPError,
|
|
5
5
|
FastMCPSession,
|
|
6
|
+
MEDIA_FETCH_TIMEOUT_MS,
|
|
6
7
|
ServerState,
|
|
7
8
|
SessionError,
|
|
8
9
|
UnexpectedStateError,
|
|
@@ -10,7 +11,7 @@ import {
|
|
|
10
11
|
audioContent,
|
|
11
12
|
imageContent,
|
|
12
13
|
jsonSchemaAdapter
|
|
13
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-HIIPZVNY.js";
|
|
14
15
|
import {
|
|
15
16
|
AuthProvider,
|
|
16
17
|
AzureProvider,
|
|
@@ -33,6 +34,7 @@ export {
|
|
|
33
34
|
FastMCPSession,
|
|
34
35
|
GitHubProvider,
|
|
35
36
|
GoogleProvider,
|
|
37
|
+
MEDIA_FETCH_TIMEOUT_MS,
|
|
36
38
|
OAuthProvider,
|
|
37
39
|
ServerState,
|
|
38
40
|
SessionError,
|
|
@@ -197,12 +197,16 @@ function unwrapDefault(value) {
|
|
|
197
197
|
}
|
|
198
198
|
|
|
199
199
|
// src/FastMCP.ts
|
|
200
|
+
var MEDIA_FETCH_TIMEOUT_MS = 3e4;
|
|
200
201
|
var imageContent = async (input) => {
|
|
201
202
|
let rawData;
|
|
202
203
|
try {
|
|
203
204
|
if ("url" in input) {
|
|
205
|
+
const timeoutMs = input.timeoutMs ?? MEDIA_FETCH_TIMEOUT_MS;
|
|
204
206
|
try {
|
|
205
|
-
const response = await fetch2(input.url
|
|
207
|
+
const response = await fetch2(input.url, {
|
|
208
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
209
|
+
});
|
|
206
210
|
if (!response.ok) {
|
|
207
211
|
throw new Error(
|
|
208
212
|
`Server responded with status: ${response.status} - ${response.statusText}`
|
|
@@ -210,6 +214,11 @@ var imageContent = async (input) => {
|
|
|
210
214
|
}
|
|
211
215
|
rawData = Buffer.from(await response.arrayBuffer());
|
|
212
216
|
} catch (error) {
|
|
217
|
+
if (error instanceof Error && (error.name === "AbortError" || error.name === "TimeoutError")) {
|
|
218
|
+
throw new Error(
|
|
219
|
+
`Failed to fetch image from URL (${input.url}): timed out after ${timeoutMs}ms`
|
|
220
|
+
);
|
|
221
|
+
}
|
|
213
222
|
throw new Error(
|
|
214
223
|
`Failed to fetch image from URL (${input.url}): ${error instanceof Error ? error.message : String(error)}`
|
|
215
224
|
);
|
|
@@ -254,8 +263,11 @@ var audioContent = async (input) => {
|
|
|
254
263
|
let rawData;
|
|
255
264
|
try {
|
|
256
265
|
if ("url" in input) {
|
|
266
|
+
const timeoutMs = input.timeoutMs ?? MEDIA_FETCH_TIMEOUT_MS;
|
|
257
267
|
try {
|
|
258
|
-
const response = await fetch2(input.url
|
|
268
|
+
const response = await fetch2(input.url, {
|
|
269
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
270
|
+
});
|
|
259
271
|
if (!response.ok) {
|
|
260
272
|
throw new Error(
|
|
261
273
|
`Server responded with status: ${response.status} - ${response.statusText}`
|
|
@@ -263,6 +275,11 @@ var audioContent = async (input) => {
|
|
|
263
275
|
}
|
|
264
276
|
rawData = Buffer.from(await response.arrayBuffer());
|
|
265
277
|
} catch (error) {
|
|
278
|
+
if (error instanceof Error && (error.name === "AbortError" || error.name === "TimeoutError")) {
|
|
279
|
+
throw new Error(
|
|
280
|
+
`Failed to fetch audio from URL (${input.url}): timed out after ${timeoutMs}ms`
|
|
281
|
+
);
|
|
282
|
+
}
|
|
266
283
|
throw new Error(
|
|
267
284
|
`Failed to fetch audio from URL (${input.url}): ${error instanceof Error ? error.message : String(error)}`
|
|
268
285
|
);
|
|
@@ -1445,6 +1462,7 @@ function parseBasicAuthHeader(authHeader) {
|
|
|
1445
1462
|
return null;
|
|
1446
1463
|
}
|
|
1447
1464
|
}
|
|
1465
|
+
var OAUTH_PROXY_MAX_BODY_SIZE = 1024 * 1024;
|
|
1448
1466
|
function stripBasePath(path, basePath) {
|
|
1449
1467
|
if (!basePath) {
|
|
1450
1468
|
return path;
|
|
@@ -2219,11 +2237,47 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2219
2237
|
try {
|
|
2220
2238
|
if (req.method === "POST" && oauthPath === "/oauth/register") {
|
|
2221
2239
|
await new Promise((resolve) => {
|
|
2222
|
-
|
|
2223
|
-
|
|
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);
|
|
2224
2273
|
req.on("end", async () => {
|
|
2274
|
+
if (failed) {
|
|
2275
|
+
return;
|
|
2276
|
+
}
|
|
2225
2277
|
try {
|
|
2226
|
-
const request = JSON.parse(
|
|
2278
|
+
const request = JSON.parse(
|
|
2279
|
+
Buffer.concat(bodyChunks).toString("utf8")
|
|
2280
|
+
);
|
|
2227
2281
|
const response = await oauthProxy.registerClient(request);
|
|
2228
2282
|
res.writeHead(201, { "Content-Type": "application/json" }).end(JSON.stringify(response));
|
|
2229
2283
|
} catch (error) {
|
|
@@ -2289,14 +2343,48 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2289
2343
|
}
|
|
2290
2344
|
if (req.method === "POST" && oauthPath === "/oauth/consent") {
|
|
2291
2345
|
await new Promise((resolve) => {
|
|
2292
|
-
|
|
2293
|
-
|
|
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);
|
|
2294
2379
|
req.on("end", async () => {
|
|
2380
|
+
if (failed) {
|
|
2381
|
+
return;
|
|
2382
|
+
}
|
|
2295
2383
|
try {
|
|
2296
2384
|
const mockRequest = new Request(
|
|
2297
2385
|
`http://${host}${url2.pathname}${url2.search}`,
|
|
2298
2386
|
{
|
|
2299
|
-
body,
|
|
2387
|
+
body: Buffer.concat(bodyChunks).toString("utf8"),
|
|
2300
2388
|
headers: {
|
|
2301
2389
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
2302
2390
|
},
|
|
@@ -2327,11 +2415,47 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2327
2415
|
}
|
|
2328
2416
|
if (req.method === "POST" && oauthPath === "/oauth/token") {
|
|
2329
2417
|
await new Promise((resolve) => {
|
|
2330
|
-
|
|
2331
|
-
|
|
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);
|
|
2332
2451
|
req.on("end", async () => {
|
|
2452
|
+
if (failed) {
|
|
2453
|
+
return;
|
|
2454
|
+
}
|
|
2333
2455
|
try {
|
|
2334
|
-
const params = new URLSearchParams(
|
|
2456
|
+
const params = new URLSearchParams(
|
|
2457
|
+
Buffer.concat(bodyChunks).toString("utf8")
|
|
2458
|
+
);
|
|
2335
2459
|
const grantType = params.get("grant_type");
|
|
2336
2460
|
const basicAuth = parseBasicAuthHeader(
|
|
2337
2461
|
req.headers.authorization
|
|
@@ -2520,6 +2644,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2520
2644
|
export {
|
|
2521
2645
|
DiscoveryDocumentCache,
|
|
2522
2646
|
jsonSchemaAdapter,
|
|
2647
|
+
MEDIA_FETCH_TIMEOUT_MS,
|
|
2523
2648
|
imageContent,
|
|
2524
2649
|
audioContent,
|
|
2525
2650
|
FastMCPError,
|
|
@@ -2530,4 +2655,4 @@ export {
|
|
|
2530
2655
|
FastMCPSession,
|
|
2531
2656
|
FastMCP
|
|
2532
2657
|
};
|
|
2533
|
-
//# sourceMappingURL=chunk-
|
|
2658
|
+
//# sourceMappingURL=chunk-HIIPZVNY.js.map
|