fastmcp 4.26.2 → 4.28.0
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 +4 -4
- package/dist/FastMCP.d.cts +2 -2
- package/dist/FastMCP.d.ts +2 -2
- package/dist/FastMCP.js +3 -3
- package/dist/{OAuthProvider-B7VDZGyx.d.cts → OAuthProvider-BnQsqcsL.d.cts} +13 -3
- package/dist/{OAuthProvider-B7VDZGyx.d.ts → OAuthProvider-BnQsqcsL.d.ts} +13 -3
- package/dist/auth/index.cjs +2 -2
- package/dist/auth/index.d.cts +2 -2
- package/dist/auth/index.d.ts +2 -2
- package/dist/auth/index.js +1 -1
- package/dist/chunk-2NZFMD6I.cjs +120 -0
- package/dist/chunk-2NZFMD6I.cjs.map +1 -0
- package/dist/{chunk-W6P57SNV.js → chunk-4ZSNKIR3.js} +37 -5
- package/dist/chunk-4ZSNKIR3.js.map +1 -0
- package/dist/{chunk-UULT6NOS.cjs → chunk-AAPHX5IG.cjs} +28 -13
- package/dist/chunk-AAPHX5IG.cjs.map +1 -0
- package/dist/chunk-AM3HVK4Z.js +120 -0
- package/dist/chunk-AM3HVK4Z.js.map +1 -0
- package/dist/{chunk-ASOZUCE2.js → chunk-EI3KPYSZ.js} +22 -7
- package/dist/chunk-EI3KPYSZ.js.map +1 -0
- package/dist/{chunk-HVKGDRTL.cjs → chunk-VVAKRLCY.cjs} +37 -5
- package/dist/chunk-VVAKRLCY.cjs.map +1 -0
- package/dist/edge/index.cjs +61 -43
- package/dist/edge/index.cjs.map +1 -1
- package/dist/edge/index.d.cts +0 -6
- package/dist/edge/index.d.ts +0 -6
- package/dist/edge/index.js +59 -41
- package/dist/edge/index.js.map +1 -1
- package/dist/examples/custom-routes.cjs +4 -4
- package/dist/examples/custom-routes.js +3 -3
- package/dist/openapi/index.cjs +98 -36
- package/dist/openapi/index.cjs.map +1 -1
- package/dist/openapi/index.d.cts +4 -4
- package/dist/openapi/index.d.ts +4 -4
- package/dist/openapi/index.js +88 -26
- package/dist/openapi/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-6TDYSPLC.cjs +0 -44
- package/dist/chunk-6TDYSPLC.cjs.map +0 -1
- package/dist/chunk-ASOZUCE2.js.map +0 -1
- package/dist/chunk-HVKGDRTL.cjs.map +0 -1
- package/dist/chunk-OKKFL2M4.js +0 -44
- package/dist/chunk-OKKFL2M4.js.map +0 -1
- package/dist/chunk-UULT6NOS.cjs.map +0 -1
- package/dist/chunk-W6P57SNV.js.map +0 -1
package/dist/edge/index.d.cts
CHANGED
|
@@ -169,12 +169,6 @@ declare class WebStreamableHTTPServerTransport implements Transport {
|
|
|
169
169
|
* Handles unsupported HTTP methods
|
|
170
170
|
*/
|
|
171
171
|
private handleUnsupportedRequest;
|
|
172
|
-
/**
|
|
173
|
-
* Read a request body as text, giving up once it exceeds
|
|
174
|
-
* `MAXIMUM_MESSAGE_SIZE`. Returns `null` when the cap is exceeded so the
|
|
175
|
-
* caller can answer 413 without ever holding the whole body.
|
|
176
|
-
*/
|
|
177
|
-
private readBodyWithLimit;
|
|
178
172
|
/**
|
|
179
173
|
* Settle the routing state of a request the client cancelled, which will
|
|
180
174
|
* therefore never produce a response: the same drain `send()` performs once
|
package/dist/edge/index.d.ts
CHANGED
|
@@ -169,12 +169,6 @@ declare class WebStreamableHTTPServerTransport implements Transport {
|
|
|
169
169
|
* Handles unsupported HTTP methods
|
|
170
170
|
*/
|
|
171
171
|
private handleUnsupportedRequest;
|
|
172
|
-
/**
|
|
173
|
-
* Read a request body as text, giving up once it exceeds
|
|
174
|
-
* `MAXIMUM_MESSAGE_SIZE`. Returns `null` when the cap is exceeded so the
|
|
175
|
-
* caller can answer 413 without ever holding the whole body.
|
|
176
|
-
*/
|
|
177
|
-
private readBodyWithLimit;
|
|
178
172
|
/**
|
|
179
173
|
* Settle the routing state of a request the client cancelled, which will
|
|
180
174
|
* therefore never produce a response: the same drain `send()` performs once
|
package/dist/edge/index.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
strictInputSchema,
|
|
3
3
|
zodInputSchema
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-AM3HVK4Z.js";
|
|
5
5
|
|
|
6
6
|
// src/edge/index.ts
|
|
7
7
|
import {
|
|
8
8
|
ErrorCode as ErrorCode2,
|
|
9
9
|
isInitializeRequest as isInitializeRequest2,
|
|
10
10
|
LATEST_PROTOCOL_VERSION,
|
|
11
|
+
McpError,
|
|
11
12
|
SUPPORTED_PROTOCOL_VERSIONS as SUPPORTED_PROTOCOL_VERSIONS2
|
|
12
13
|
} from "@modelcontextprotocol/sdk/types.js";
|
|
13
14
|
import { Hono } from "hono";
|
|
@@ -33,6 +34,37 @@ var unsupportedProtocolVersion = (request) => {
|
|
|
33
34
|
return `Bad Request: Unsupported protocol version: ${protocolVersion} (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`;
|
|
34
35
|
};
|
|
35
36
|
var MAXIMUM_MESSAGE_SIZE = 4 * 1024 * 1024;
|
|
37
|
+
var readBodyWithLimit = async (request) => {
|
|
38
|
+
if (!request.body) {
|
|
39
|
+
return "";
|
|
40
|
+
}
|
|
41
|
+
const reader = request.body.getReader();
|
|
42
|
+
const chunks = [];
|
|
43
|
+
let size = 0;
|
|
44
|
+
try {
|
|
45
|
+
for (; ; ) {
|
|
46
|
+
const { done, value } = await reader.read();
|
|
47
|
+
if (done) {
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
size += value.byteLength;
|
|
51
|
+
if (size > MAXIMUM_MESSAGE_SIZE) {
|
|
52
|
+
await reader.cancel();
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
chunks.push(value);
|
|
56
|
+
}
|
|
57
|
+
} finally {
|
|
58
|
+
reader.releaseLock();
|
|
59
|
+
}
|
|
60
|
+
const joined = new Uint8Array(size);
|
|
61
|
+
let offset = 0;
|
|
62
|
+
for (const chunk of chunks) {
|
|
63
|
+
joined.set(chunk, offset);
|
|
64
|
+
offset += chunk.byteLength;
|
|
65
|
+
}
|
|
66
|
+
return new TextDecoder().decode(joined);
|
|
67
|
+
};
|
|
36
68
|
var WebStreamableHTTPServerTransport = class {
|
|
37
69
|
onclose;
|
|
38
70
|
onerror;
|
|
@@ -365,7 +397,7 @@ var WebStreamableHTTPServerTransport = class {
|
|
|
365
397
|
if (parsedBody !== void 0 && parsedBody !== null) {
|
|
366
398
|
rawMessage = parsedBody;
|
|
367
399
|
} else {
|
|
368
|
-
const text = await
|
|
400
|
+
const text = await readBodyWithLimit(request);
|
|
369
401
|
if (text === null) {
|
|
370
402
|
return this.createErrorResponse(
|
|
371
403
|
413,
|
|
@@ -602,42 +634,6 @@ var WebStreamableHTTPServerTransport = class {
|
|
|
602
634
|
handleUnsupportedRequest() {
|
|
603
635
|
return this.createErrorResponse(405, -32e3, "Method not allowed");
|
|
604
636
|
}
|
|
605
|
-
/**
|
|
606
|
-
* Read a request body as text, giving up once it exceeds
|
|
607
|
-
* `MAXIMUM_MESSAGE_SIZE`. Returns `null` when the cap is exceeded so the
|
|
608
|
-
* caller can answer 413 without ever holding the whole body.
|
|
609
|
-
*/
|
|
610
|
-
async readBodyWithLimit(request) {
|
|
611
|
-
if (!request.body) {
|
|
612
|
-
return "";
|
|
613
|
-
}
|
|
614
|
-
const reader = request.body.getReader();
|
|
615
|
-
const chunks = [];
|
|
616
|
-
let size = 0;
|
|
617
|
-
try {
|
|
618
|
-
for (; ; ) {
|
|
619
|
-
const { done, value } = await reader.read();
|
|
620
|
-
if (done) {
|
|
621
|
-
break;
|
|
622
|
-
}
|
|
623
|
-
size += value.byteLength;
|
|
624
|
-
if (size > MAXIMUM_MESSAGE_SIZE) {
|
|
625
|
-
await reader.cancel();
|
|
626
|
-
return null;
|
|
627
|
-
}
|
|
628
|
-
chunks.push(value);
|
|
629
|
-
}
|
|
630
|
-
} finally {
|
|
631
|
-
reader.releaseLock();
|
|
632
|
-
}
|
|
633
|
-
const joined = new Uint8Array(size);
|
|
634
|
-
let offset = 0;
|
|
635
|
-
for (const chunk of chunks) {
|
|
636
|
-
joined.set(chunk, offset);
|
|
637
|
-
offset += chunk.byteLength;
|
|
638
|
-
}
|
|
639
|
-
return new TextDecoder().decode(joined);
|
|
640
|
-
}
|
|
641
637
|
/**
|
|
642
638
|
* Settle the routing state of a request the client cancelled, which will
|
|
643
639
|
* therefore never produce a response: the same drain `send()` performs once
|
|
@@ -976,9 +972,18 @@ var EdgeFastMCP = class {
|
|
|
976
972
|
"Unsupported Media Type: Content-Type must be application/json"
|
|
977
973
|
);
|
|
978
974
|
}
|
|
975
|
+
const tooLarge = `Request body too large. Maximum size is ${MAXIMUM_MESSAGE_SIZE} bytes`;
|
|
976
|
+
const contentLength = Number(request.headers.get("content-length") ?? "0");
|
|
977
|
+
if (contentLength > MAXIMUM_MESSAGE_SIZE) {
|
|
978
|
+
return this.#errorResponse(413, -32e3, tooLarge);
|
|
979
|
+
}
|
|
979
980
|
let body;
|
|
980
981
|
try {
|
|
981
|
-
|
|
982
|
+
const text = await readBodyWithLimit(request);
|
|
983
|
+
if (text === null) {
|
|
984
|
+
return this.#errorResponse(413, -32e3, tooLarge);
|
|
985
|
+
}
|
|
986
|
+
body = JSON.parse(text);
|
|
982
987
|
} catch {
|
|
983
988
|
return this.#errorResponse(400, -32700, "Parse error: Invalid JSON");
|
|
984
989
|
}
|
|
@@ -1098,6 +1103,13 @@ var EdgeFastMCP = class {
|
|
|
1098
1103
|
async #handlePromptsGet(id, params) {
|
|
1099
1104
|
const promptName = params?.name;
|
|
1100
1105
|
const promptArgs = params?.arguments;
|
|
1106
|
+
if (promptArgs !== void 0 && (promptArgs === null || typeof promptArgs !== "object" || Array.isArray(promptArgs) || Object.values(promptArgs).some((value) => typeof value !== "string"))) {
|
|
1107
|
+
return this.#rpcError(
|
|
1108
|
+
id,
|
|
1109
|
+
ErrorCode2.InvalidParams,
|
|
1110
|
+
"Prompt arguments must be an object with string values"
|
|
1111
|
+
);
|
|
1112
|
+
}
|
|
1101
1113
|
const prompt = this.#prompts.find((p) => p.name === promptName);
|
|
1102
1114
|
if (!prompt) {
|
|
1103
1115
|
return this.#rpcError(
|
|
@@ -1124,6 +1136,9 @@ var EdgeFastMCP = class {
|
|
|
1124
1136
|
result: { messages }
|
|
1125
1137
|
};
|
|
1126
1138
|
} catch (error) {
|
|
1139
|
+
if (error instanceof McpError) {
|
|
1140
|
+
return this.#rpcError(id, error.code, error.message, error.data);
|
|
1141
|
+
}
|
|
1127
1142
|
return this.#rpcError(
|
|
1128
1143
|
id,
|
|
1129
1144
|
ErrorCode2.InternalError,
|
|
@@ -1190,6 +1205,9 @@ var EdgeFastMCP = class {
|
|
|
1190
1205
|
result: { contents: [content] }
|
|
1191
1206
|
};
|
|
1192
1207
|
} catch (error) {
|
|
1208
|
+
if (error instanceof McpError) {
|
|
1209
|
+
return this.#rpcError(id, error.code, error.message, error.data);
|
|
1210
|
+
}
|
|
1193
1211
|
return this.#rpcError(
|
|
1194
1212
|
id,
|
|
1195
1213
|
ErrorCode2.InternalError,
|
|
@@ -1296,9 +1314,9 @@ var EdgeFastMCP = class {
|
|
|
1296
1314
|
/**
|
|
1297
1315
|
* Create an RPC error message
|
|
1298
1316
|
*/
|
|
1299
|
-
#rpcError(id, code, message) {
|
|
1317
|
+
#rpcError(id, code, message, data) {
|
|
1300
1318
|
return {
|
|
1301
|
-
error: { code, message },
|
|
1319
|
+
error: { code, ...data !== void 0 && { data }, message },
|
|
1302
1320
|
id,
|
|
1303
1321
|
jsonrpc: "2.0"
|
|
1304
1322
|
};
|