fastmcp 4.30.1 → 4.30.3
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-C2Z93xC5.d.cts → OAuthProvider-BuBMMpsX.d.cts} +18 -2
- package/dist/{OAuthProvider-C2Z93xC5.d.ts → OAuthProvider-BuBMMpsX.d.ts} +18 -2
- 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-CZGQ2WTQ.cjs → chunk-F7XD3S4L.cjs} +54 -7
- package/dist/chunk-F7XD3S4L.cjs.map +1 -0
- package/dist/{chunk-4JEDH2ON.cjs → chunk-M3SNOHIM.cjs} +156 -85
- package/dist/chunk-M3SNOHIM.cjs.map +1 -0
- package/dist/{chunk-FBDPX4H2.cjs → chunk-NYV5TK43.cjs} +125 -2
- package/dist/chunk-NYV5TK43.cjs.map +1 -0
- package/dist/{chunk-XPTUOWUT.js → chunk-P4ZFER5I.js} +50 -3
- package/dist/chunk-P4ZFER5I.js.map +1 -0
- package/dist/{chunk-5KA6SOWT.js → chunk-UEEX3RD5.js} +109 -38
- package/dist/chunk-UEEX3RD5.js.map +1 -0
- package/dist/{chunk-JCKJRUCE.js → chunk-YEXAT4PO.js} +125 -2
- package/dist/chunk-YEXAT4PO.js.map +1 -0
- package/dist/edge/index.cjs +4 -4
- package/dist/edge/index.js +1 -1
- package/dist/examples/custom-routes.cjs +4 -4
- package/dist/examples/custom-routes.js +3 -3
- package/dist/openapi/index.cjs +15 -12
- package/dist/openapi/index.cjs.map +1 -1
- package/dist/openapi/index.d.cts +4 -3
- package/dist/openapi/index.d.ts +4 -3
- package/dist/openapi/index.js +9 -6
- package/dist/openapi/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-4JEDH2ON.cjs.map +0 -1
- package/dist/chunk-5KA6SOWT.js.map +0 -1
- package/dist/chunk-CZGQ2WTQ.cjs.map +0 -1
- package/dist/chunk-FBDPX4H2.cjs.map +0 -1
- package/dist/chunk-JCKJRUCE.js.map +0 -1
- package/dist/chunk-XPTUOWUT.js.map +0 -1
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkF7XD3S4Lcjs = require('./chunk-F7XD3S4L.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
var _chunkNYV5TK43cjs = require('./chunk-NYV5TK43.cjs');
|
|
9
10
|
|
|
10
11
|
// src/FastMCP.ts
|
|
11
12
|
var _indexjs = require('@modelcontextprotocol/sdk/server/index.js');
|
|
@@ -141,7 +142,7 @@ var DiscoveryDocumentCache = class {
|
|
|
141
142
|
throw error;
|
|
142
143
|
}
|
|
143
144
|
if (!res.ok) {
|
|
144
|
-
await
|
|
145
|
+
await _chunkF7XD3S4Lcjs.cancelResponseBody.call(void 0, res);
|
|
145
146
|
throw new Error(
|
|
146
147
|
`Failed to fetch discovery document from ${url}: ${res.status} ${res.statusText}`
|
|
147
148
|
);
|
|
@@ -258,7 +259,7 @@ var imageContent = async (input) => {
|
|
|
258
259
|
signal: AbortSignal.timeout(timeoutMs)
|
|
259
260
|
});
|
|
260
261
|
if (!response.ok) {
|
|
261
|
-
await
|
|
262
|
+
await _chunkF7XD3S4Lcjs.cancelResponseBody.call(void 0, response);
|
|
262
263
|
throw new Error(
|
|
263
264
|
`Server responded with status: ${response.status} - ${response.statusText}`
|
|
264
265
|
);
|
|
@@ -340,7 +341,7 @@ var audioContent = async (input) => {
|
|
|
340
341
|
signal: AbortSignal.timeout(timeoutMs)
|
|
341
342
|
});
|
|
342
343
|
if (!response.ok) {
|
|
343
|
-
await
|
|
344
|
+
await _chunkF7XD3S4Lcjs.cancelResponseBody.call(void 0, response);
|
|
344
345
|
throw new Error(
|
|
345
346
|
`Server responded with status: ${response.status} - ${response.statusText}`
|
|
346
347
|
);
|
|
@@ -1029,7 +1030,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1029
1030
|
streamableHttp ? { timeout: 1e3 } : void 0
|
|
1030
1031
|
);
|
|
1031
1032
|
this.#roots = _optionalChain([roots, 'optionalAccess', _40 => _40.roots]) || [];
|
|
1032
|
-
if (streamableHttp) {
|
|
1033
|
+
if (streamableHttp || this.#connectionState === "ready") {
|
|
1033
1034
|
this.emit("rootsChanged", { roots: this.#roots });
|
|
1034
1035
|
}
|
|
1035
1036
|
return;
|
|
@@ -1101,6 +1102,28 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1101
1102
|
);
|
|
1102
1103
|
});
|
|
1103
1104
|
}
|
|
1105
|
+
/**
|
|
1106
|
+
* A gateway can start a stdio server long before any client connects and
|
|
1107
|
+
* forward the first initialize only then, after #setUpSession stopped
|
|
1108
|
+
* waiting for it. Finish the setup when that client initializes.
|
|
1109
|
+
*/
|
|
1110
|
+
#setUpLateClient(streamableHttp) {
|
|
1111
|
+
const finish = () => {
|
|
1112
|
+
const capabilities = this.#server.getClientCapabilities();
|
|
1113
|
+
if (!capabilities || this.#clientCapabilities || this.#connectionState === "closed") {
|
|
1114
|
+
return;
|
|
1115
|
+
}
|
|
1116
|
+
this.#clientCapabilities = capabilities;
|
|
1117
|
+
void this.#loadRoots(streamableHttp);
|
|
1118
|
+
this.#startPing();
|
|
1119
|
+
};
|
|
1120
|
+
const oninitialized = this.#server.oninitialized;
|
|
1121
|
+
this.#server.oninitialized = () => {
|
|
1122
|
+
_optionalChain([oninitialized, 'optionalCall', _43 => _43()]);
|
|
1123
|
+
finish();
|
|
1124
|
+
};
|
|
1125
|
+
finish();
|
|
1126
|
+
}
|
|
1104
1127
|
async #setUpSession(streamableHttp) {
|
|
1105
1128
|
if (!this.#stateless) {
|
|
1106
1129
|
let attempt = 0;
|
|
@@ -1135,38 +1158,44 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1135
1158
|
}
|
|
1136
1159
|
}
|
|
1137
1160
|
if (this.#clientCapabilities) {
|
|
1138
|
-
|
|
1139
|
-
if (pingConfig.enabled) {
|
|
1140
|
-
this.#pingInterval = setInterval(async () => {
|
|
1141
|
-
if (this.#pingInFlight) {
|
|
1142
|
-
return;
|
|
1143
|
-
}
|
|
1144
|
-
this.#pingInFlight = true;
|
|
1145
|
-
try {
|
|
1146
|
-
await this.#server.ping();
|
|
1147
|
-
} catch (e4) {
|
|
1148
|
-
const logLevel = pingConfig.logLevel;
|
|
1149
|
-
if (logLevel === "debug") {
|
|
1150
|
-
this.#logger.debug("[FastMCP debug] server ping failed");
|
|
1151
|
-
} else if (logLevel === "warning") {
|
|
1152
|
-
this.#logger.warn(
|
|
1153
|
-
"[FastMCP warning] server is not responding to ping"
|
|
1154
|
-
);
|
|
1155
|
-
} else if (logLevel === "error") {
|
|
1156
|
-
this.#logger.error(
|
|
1157
|
-
"[FastMCP error] server is not responding to ping"
|
|
1158
|
-
);
|
|
1159
|
-
} else {
|
|
1160
|
-
this.#logger.info("[FastMCP info] server ping failed");
|
|
1161
|
-
}
|
|
1162
|
-
} finally {
|
|
1163
|
-
this.#pingInFlight = false;
|
|
1164
|
-
}
|
|
1165
|
-
}, pingConfig.intervalMs);
|
|
1166
|
-
}
|
|
1161
|
+
this.#startPing();
|
|
1167
1162
|
}
|
|
1168
1163
|
this.#connectionState = "ready";
|
|
1169
1164
|
this.emit("ready");
|
|
1165
|
+
if (!this.#stateless && !this.#clientCapabilities) {
|
|
1166
|
+
this.#setUpLateClient(streamableHttp);
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
#startPing() {
|
|
1170
|
+
const pingConfig = this.#getPingConfig();
|
|
1171
|
+
if (pingConfig.enabled) {
|
|
1172
|
+
this.#pingInterval = setInterval(async () => {
|
|
1173
|
+
if (this.#pingInFlight) {
|
|
1174
|
+
return;
|
|
1175
|
+
}
|
|
1176
|
+
this.#pingInFlight = true;
|
|
1177
|
+
try {
|
|
1178
|
+
await this.#server.ping();
|
|
1179
|
+
} catch (e4) {
|
|
1180
|
+
const logLevel = pingConfig.logLevel;
|
|
1181
|
+
if (logLevel === "debug") {
|
|
1182
|
+
this.#logger.debug("[FastMCP debug] server ping failed");
|
|
1183
|
+
} else if (logLevel === "warning") {
|
|
1184
|
+
this.#logger.warn(
|
|
1185
|
+
"[FastMCP warning] server is not responding to ping"
|
|
1186
|
+
);
|
|
1187
|
+
} else if (logLevel === "error") {
|
|
1188
|
+
this.#logger.error(
|
|
1189
|
+
"[FastMCP error] server is not responding to ping"
|
|
1190
|
+
);
|
|
1191
|
+
} else {
|
|
1192
|
+
this.#logger.info("[FastMCP info] server ping failed");
|
|
1193
|
+
}
|
|
1194
|
+
} finally {
|
|
1195
|
+
this.#pingInFlight = false;
|
|
1196
|
+
}
|
|
1197
|
+
}, pingConfig.intervalMs);
|
|
1198
|
+
}
|
|
1170
1199
|
}
|
|
1171
1200
|
/**
|
|
1172
1201
|
* Periodically writes to the response stream of an in-flight tool call, so an
|
|
@@ -1187,7 +1216,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1187
1216
|
*/
|
|
1188
1217
|
#startStreamKeepalive(extra, toolName) {
|
|
1189
1218
|
const config = this.#streamKeepaliveConfig;
|
|
1190
|
-
if (!_optionalChain([config, 'optionalAccess',
|
|
1219
|
+
if (!_optionalChain([config, 'optionalAccess', _44 => _44.enabled]) || _optionalChain([extra, 'access', _45 => _45.signal, 'optionalAccess', _46 => _46.aborted])) {
|
|
1191
1220
|
return () => {
|
|
1192
1221
|
};
|
|
1193
1222
|
}
|
|
@@ -1207,12 +1236,12 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1207
1236
|
);
|
|
1208
1237
|
});
|
|
1209
1238
|
}, intervalMs);
|
|
1210
|
-
_optionalChain([timer, 'access',
|
|
1239
|
+
_optionalChain([timer, 'access', _47 => _47.unref, 'optionalCall', _48 => _48()]);
|
|
1211
1240
|
const stop = () => {
|
|
1212
1241
|
clearInterval(timer);
|
|
1213
|
-
_optionalChain([extra, 'access',
|
|
1242
|
+
_optionalChain([extra, 'access', _49 => _49.signal, 'optionalAccess', _50 => _50.removeEventListener, 'call', _51 => _51("abort", stop)]);
|
|
1214
1243
|
};
|
|
1215
|
-
_optionalChain([extra, 'access',
|
|
1244
|
+
_optionalChain([extra, 'access', _52 => _52.signal, 'optionalAccess', _53 => _53.addEventListener, 'call', _54 => _54("abort", stop, { once: true })]);
|
|
1216
1245
|
return stop;
|
|
1217
1246
|
}
|
|
1218
1247
|
async #validateStructuredContent(tool, value, toolName) {
|
|
@@ -1432,7 +1461,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1432
1461
|
_nullishCoalesce(args, () => ( {})),
|
|
1433
1462
|
this.#auth,
|
|
1434
1463
|
this.#createLoadContext(
|
|
1435
|
-
_optionalChain([request, 'access',
|
|
1464
|
+
_optionalChain([request, 'access', _55 => _55.params, 'optionalAccess', _56 => _56._meta]),
|
|
1436
1465
|
extra.sendNotification,
|
|
1437
1466
|
extra.requestId
|
|
1438
1467
|
)
|
|
@@ -1504,7 +1533,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1504
1533
|
match,
|
|
1505
1534
|
this.#auth,
|
|
1506
1535
|
this.#createLoadContext(
|
|
1507
|
-
_optionalChain([request, 'access',
|
|
1536
|
+
_optionalChain([request, 'access', _57 => _57.params, 'optionalAccess', _58 => _58._meta]),
|
|
1508
1537
|
extra.sendNotification,
|
|
1509
1538
|
extra.requestId
|
|
1510
1539
|
)
|
|
@@ -1536,7 +1565,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1536
1565
|
maybeArrayResult = await resource.load(
|
|
1537
1566
|
this.#auth,
|
|
1538
1567
|
this.#createLoadContext(
|
|
1539
|
-
_optionalChain([request, 'access',
|
|
1568
|
+
_optionalChain([request, 'access', _59 => _59.params, 'optionalAccess', _60 => _60._meta]),
|
|
1540
1569
|
extra.sendNotification,
|
|
1541
1570
|
extra.requestId
|
|
1542
1571
|
)
|
|
@@ -1605,7 +1634,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1605
1634
|
);
|
|
1606
1635
|
}
|
|
1607
1636
|
setupRootsHandlers() {
|
|
1608
|
-
if (_optionalChain([this, 'access',
|
|
1637
|
+
if (_optionalChain([this, 'access', _61 => _61.#rootsConfig, 'optionalAccess', _62 => _62.enabled]) === false) {
|
|
1609
1638
|
this.#logger.debug(
|
|
1610
1639
|
"[FastMCP debug] roots capability explicitly disabled via config"
|
|
1611
1640
|
);
|
|
@@ -1655,8 +1684,8 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1655
1684
|
tools.map(async (tool) => {
|
|
1656
1685
|
let inputSchema;
|
|
1657
1686
|
try {
|
|
1658
|
-
inputSchema = tool.parameters ?
|
|
1659
|
-
tool.parameters["~standard"].vendor === "zod" && "_zod" in tool.parameters ?
|
|
1687
|
+
inputSchema = tool.parameters ? _chunkNYV5TK43cjs.strictInputSchema.call(void 0,
|
|
1688
|
+
tool.parameters["~standard"].vendor === "zod" && "_zod" in tool.parameters ? _chunkNYV5TK43cjs.zodInputSchema.call(void 0, tool.parameters, "draft-7") : await _xsschema.toJsonSchema.call(void 0, tool.parameters)
|
|
1660
1689
|
) : {
|
|
1661
1690
|
additionalProperties: false,
|
|
1662
1691
|
properties: {},
|
|
@@ -1678,8 +1707,8 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1678
1707
|
let outputSchema;
|
|
1679
1708
|
if (tool.outputSchema) {
|
|
1680
1709
|
try {
|
|
1681
|
-
outputSchema =
|
|
1682
|
-
await _xsschema.toJsonSchema.call(void 0, tool.outputSchema)
|
|
1710
|
+
outputSchema = _chunkNYV5TK43cjs.objectRootSchema.call(void 0,
|
|
1711
|
+
tool.outputSchema["~standard"].vendor === "zod" && "_zod" in tool.outputSchema ? _chunkNYV5TK43cjs.zodOutputSchema.call(void 0, tool.outputSchema, "draft-7") : await _xsschema.toJsonSchema.call(void 0, tool.outputSchema)
|
|
1683
1712
|
);
|
|
1684
1713
|
} catch (error) {
|
|
1685
1714
|
this.#logger.warn(
|
|
@@ -1749,7 +1778,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1749
1778
|
}
|
|
1750
1779
|
args = parsed.value;
|
|
1751
1780
|
}
|
|
1752
|
-
const progressToken = _optionalChain([request, 'access',
|
|
1781
|
+
const progressToken = _optionalChain([request, 'access', _63 => _63.params, 'optionalAccess', _64 => _64._meta, 'optionalAccess', _65 => _65.progressToken]);
|
|
1753
1782
|
let result;
|
|
1754
1783
|
const timeoutAbort = new AbortController();
|
|
1755
1784
|
const sourceSignal = AbortSignal.any([
|
|
@@ -1840,7 +1869,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1840
1869
|
elicit: this.#createElicit(extra.requestId),
|
|
1841
1870
|
log,
|
|
1842
1871
|
reportProgress,
|
|
1843
|
-
requestId: typeof _optionalChain([request, 'access',
|
|
1872
|
+
requestId: typeof _optionalChain([request, 'access', _66 => _66.params, 'optionalAccess', _67 => _67._meta, 'optionalAccess', _68 => _68.requestId]) === "string" ? request.params._meta.requestId : void 0,
|
|
1844
1873
|
session: this.#auth,
|
|
1845
1874
|
sessionId: this.sessionId,
|
|
1846
1875
|
signal,
|
|
@@ -2053,7 +2082,7 @@ function normalizePath(path) {
|
|
|
2053
2082
|
return path.startsWith("/") ? path : `/${path}`;
|
|
2054
2083
|
}
|
|
2055
2084
|
function parseBasicAuthHeader(authHeader) {
|
|
2056
|
-
const basicMatch = _optionalChain([authHeader, 'optionalAccess',
|
|
2085
|
+
const basicMatch = _optionalChain([authHeader, 'optionalAccess', _69 => _69.match, 'call', _70 => _70(/^Basic\s+(.*)$/i)]);
|
|
2057
2086
|
if (!basicMatch) return null;
|
|
2058
2087
|
const credentials = Buffer.from(basicMatch[1].trim(), "base64").toString(
|
|
2059
2088
|
"utf-8"
|
|
@@ -2120,7 +2149,7 @@ var OAUTH_INVALID_CLIENT_RESPONSE_HEADERS = {
|
|
|
2120
2149
|
"WWW-Authenticate": 'Basic realm="oauth", charset="UTF-8"'
|
|
2121
2150
|
};
|
|
2122
2151
|
function grantedScopes(auth) {
|
|
2123
|
-
const scopes = _optionalChain([auth, 'optionalAccess',
|
|
2152
|
+
const scopes = _optionalChain([auth, 'optionalAccess', _71 => _71.scopes]);
|
|
2124
2153
|
const values = Array.isArray(scopes) ? scopes : scopes instanceof Set ? [...scopes] : [];
|
|
2125
2154
|
return values.filter((scope) => typeof scope === "string");
|
|
2126
2155
|
}
|
|
@@ -2199,7 +2228,7 @@ function toolAdmits(tool, auth, logger) {
|
|
|
2199
2228
|
if (typeof admitted === "boolean") {
|
|
2200
2229
|
return admitted;
|
|
2201
2230
|
}
|
|
2202
|
-
const isPromise = typeof _optionalChain([admitted, 'optionalAccess',
|
|
2231
|
+
const isPromise = typeof _optionalChain([admitted, 'optionalAccess', _72 => _72.then]) === "function";
|
|
2203
2232
|
if (isPromise) {
|
|
2204
2233
|
Promise.resolve(admitted).catch(() => {
|
|
2205
2234
|
});
|
|
@@ -2264,6 +2293,12 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2264
2293
|
#resources = [];
|
|
2265
2294
|
#resourcesTemplates = [];
|
|
2266
2295
|
#serverState = "stopped" /* Stopped */;
|
|
2296
|
+
/**
|
|
2297
|
+
* What each session was built from, until it is listed in `#sessions`. Only
|
|
2298
|
+
* listed sessions hear about a registration, so one made while a session is
|
|
2299
|
+
* still connecting is passed on when it is listed.
|
|
2300
|
+
*/
|
|
2301
|
+
#sessionRegistrations = /* @__PURE__ */ new WeakMap();
|
|
2267
2302
|
#sessions = [];
|
|
2268
2303
|
#stdioSessions = /* @__PURE__ */ new Set();
|
|
2269
2304
|
#tools = [];
|
|
@@ -2401,7 +2436,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2401
2436
|
(resource) => resource.uri === uri
|
|
2402
2437
|
);
|
|
2403
2438
|
if (directResource) {
|
|
2404
|
-
const result = await directResource.load(_optionalChain([context, 'optionalAccess',
|
|
2439
|
+
const result = await directResource.load(_optionalChain([context, 'optionalAccess', _73 => _73.session]), context);
|
|
2405
2440
|
const results = Array.isArray(result) ? result : [result];
|
|
2406
2441
|
const firstResult = results[0];
|
|
2407
2442
|
if (!firstResult) {
|
|
@@ -2430,7 +2465,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2430
2465
|
}
|
|
2431
2466
|
const result = await template.load(
|
|
2432
2467
|
params,
|
|
2433
|
-
_optionalChain([context, 'optionalAccess',
|
|
2468
|
+
_optionalChain([context, 'optionalAccess', _74 => _74.session]),
|
|
2434
2469
|
context
|
|
2435
2470
|
);
|
|
2436
2471
|
const results = Array.isArray(result) ? result : [result];
|
|
@@ -2617,6 +2652,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2617
2652
|
version: this.#options.version,
|
|
2618
2653
|
websiteUrl: this.#options.websiteUrl
|
|
2619
2654
|
});
|
|
2655
|
+
this.#sessionRegistrations.set(session, this.#registrations());
|
|
2620
2656
|
let stdinClosed = false;
|
|
2621
2657
|
const onStdinClose = () => {
|
|
2622
2658
|
if (stdinClosed) return;
|
|
@@ -2751,7 +2787,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2751
2787
|
});
|
|
2752
2788
|
},
|
|
2753
2789
|
onConnect: async (session) => {
|
|
2754
|
-
this.#
|
|
2790
|
+
this.#addSession(session);
|
|
2755
2791
|
this.#logger.info(`[FastMCP info] HTTP Stream session established`);
|
|
2756
2792
|
this.emit("connect", {
|
|
2757
2793
|
session
|
|
@@ -2799,6 +2835,31 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2799
2835
|
}
|
|
2800
2836
|
this.#serverState = "stopped" /* Stopped */;
|
|
2801
2837
|
}
|
|
2838
|
+
/**
|
|
2839
|
+
* Lists a connected session in `sessions`, first passing on whatever was
|
|
2840
|
+
* registered or removed since it was built.
|
|
2841
|
+
*/
|
|
2842
|
+
#addSession(session) {
|
|
2843
|
+
this.#sessions.push(session);
|
|
2844
|
+
const built = this.#sessionRegistrations.get(session);
|
|
2845
|
+
const current = this.#registrations();
|
|
2846
|
+
this.#sessionRegistrations.delete(session);
|
|
2847
|
+
if (!built) {
|
|
2848
|
+
return;
|
|
2849
|
+
}
|
|
2850
|
+
if (built.tools !== current.tools) {
|
|
2851
|
+
session.toolsListChanged(current.tools);
|
|
2852
|
+
}
|
|
2853
|
+
if (built.resources !== current.resources) {
|
|
2854
|
+
session.resourcesListChanged(current.resources);
|
|
2855
|
+
}
|
|
2856
|
+
if (built.resourcesTemplates !== current.resourcesTemplates) {
|
|
2857
|
+
session.resourceTemplatesListChanged(current.resourcesTemplates);
|
|
2858
|
+
}
|
|
2859
|
+
if (built.prompts !== current.prompts) {
|
|
2860
|
+
session.promptsListChanged(current.prompts);
|
|
2861
|
+
}
|
|
2862
|
+
}
|
|
2802
2863
|
/**
|
|
2803
2864
|
* mcp-proxy's `beforeDispatch`: answers a `tools/call` the session's token
|
|
2804
2865
|
* lacks scopes for with MCP's 403 scope challenge. It runs for every message
|
|
@@ -2826,15 +2887,15 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2826
2887
|
const originalOnClose = transport.onclose;
|
|
2827
2888
|
transport.onclose = () => {
|
|
2828
2889
|
closed = true;
|
|
2829
|
-
_optionalChain([onClose, 'optionalCall',
|
|
2890
|
+
_optionalChain([onClose, 'optionalCall', _75 => _75()]);
|
|
2830
2891
|
this.#removeSession(session);
|
|
2831
|
-
_optionalChain([originalOnClose, 'optionalCall',
|
|
2892
|
+
_optionalChain([originalOnClose, 'optionalCall', _76 => _76()]);
|
|
2832
2893
|
};
|
|
2833
2894
|
await session.connect(transport);
|
|
2834
2895
|
if (closed) {
|
|
2835
2896
|
return;
|
|
2836
2897
|
}
|
|
2837
|
-
this.#
|
|
2898
|
+
this.#addSession(session);
|
|
2838
2899
|
session.once("error", () => {
|
|
2839
2900
|
this.#removeSession(session);
|
|
2840
2901
|
});
|
|
@@ -2855,7 +2916,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2855
2916
|
*/
|
|
2856
2917
|
#createInsufficientScopeResponse(challenge, id) {
|
|
2857
2918
|
const oauth = this.#options.oauth;
|
|
2858
|
-
const resource = _optionalChain([oauth, 'optionalAccess',
|
|
2919
|
+
const resource = _optionalChain([oauth, 'optionalAccess', _77 => _77.enabled]) ? _optionalChain([oauth, 'access', _78 => _78.protectedResource, 'optionalAccess', _79 => _79.resource]) : void 0;
|
|
2859
2920
|
const wwwAuthenticateParts = [
|
|
2860
2921
|
'error="insufficient_scope"',
|
|
2861
2922
|
`scope="${challenge.scopes.filter((scope) => SCOPE_TOKEN.test(scope)).join(" ")}"`
|
|
@@ -2900,7 +2961,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2900
2961
|
throw this.#createUnauthorizedResponse(errorMessage);
|
|
2901
2962
|
}
|
|
2902
2963
|
const authRequired = this.#authenticate !== void 0;
|
|
2903
|
-
|
|
2964
|
+
const session = new FastMCPSession({
|
|
2904
2965
|
auth,
|
|
2905
2966
|
authRequired,
|
|
2906
2967
|
enableJsonResponse,
|
|
@@ -2925,6 +2986,8 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2925
2986
|
version: this.#options.version,
|
|
2926
2987
|
websiteUrl: this.#options.websiteUrl
|
|
2927
2988
|
});
|
|
2989
|
+
this.#sessionRegistrations.set(session, this.#registrations());
|
|
2990
|
+
return session;
|
|
2928
2991
|
}
|
|
2929
2992
|
/**
|
|
2930
2993
|
* Builds a 401 Unauthorized HTTP Response for authentication failures.
|
|
@@ -2941,7 +3004,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2941
3004
|
*/
|
|
2942
3005
|
#createUnauthorizedResponse(message) {
|
|
2943
3006
|
const oauth = this.#options.oauth;
|
|
2944
|
-
const resource = _optionalChain([oauth, 'optionalAccess',
|
|
3007
|
+
const resource = _optionalChain([oauth, 'optionalAccess', _80 => _80.enabled]) ? _optionalChain([oauth, 'access', _81 => _81.protectedResource, 'optionalAccess', _82 => _82.resource]) : void 0;
|
|
2945
3008
|
const wwwAuthenticateParts = [
|
|
2946
3009
|
'error="invalid_token"',
|
|
2947
3010
|
`error_description="${message.replace(/"/g, '\\"')}"`
|
|
@@ -3080,7 +3143,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
3080
3143
|
}
|
|
3081
3144
|
}
|
|
3082
3145
|
const oauthConfig = this.#options.oauth;
|
|
3083
|
-
if (_optionalChain([oauthConfig, 'optionalAccess',
|
|
3146
|
+
if (_optionalChain([oauthConfig, 'optionalAccess', _83 => _83.enabled]) && req.method === "GET") {
|
|
3084
3147
|
const url2 = new URL(req.url || "", `http://${host}`);
|
|
3085
3148
|
const authorizationServerMetadataPath = joinPaths(
|
|
3086
3149
|
"",
|
|
@@ -3114,8 +3177,8 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
3114
3177
|
}
|
|
3115
3178
|
}
|
|
3116
3179
|
}
|
|
3117
|
-
const oauthProxy = _optionalChain([oauthConfig, 'optionalAccess',
|
|
3118
|
-
if (oauthProxy && _optionalChain([oauthConfig, 'optionalAccess',
|
|
3180
|
+
const oauthProxy = _optionalChain([oauthConfig, 'optionalAccess', _84 => _84.proxy]);
|
|
3181
|
+
if (oauthProxy && _optionalChain([oauthConfig, 'optionalAccess', _85 => _85.enabled])) {
|
|
3119
3182
|
const url2 = new URL(req.url || "", `http://${host}`);
|
|
3120
3183
|
const oauthPath = basePathRelativePath;
|
|
3121
3184
|
try {
|
|
@@ -3168,7 +3231,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
3168
3231
|
const statusCode = error.statusCode || 400;
|
|
3169
3232
|
res.writeHead(statusCode, OAUTH_CREDENTIAL_RESPONSE_HEADERS).end(
|
|
3170
3233
|
JSON.stringify(
|
|
3171
|
-
_optionalChain([error, 'access',
|
|
3234
|
+
_optionalChain([error, 'access', _86 => _86.toJSON, 'optionalCall', _87 => _87()]) || {
|
|
3172
3235
|
error: "invalid_request"
|
|
3173
3236
|
}
|
|
3174
3237
|
)
|
|
@@ -3193,7 +3256,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
3193
3256
|
} catch (error) {
|
|
3194
3257
|
res.writeHead(400, { "Content-Type": "application/json" }).end(
|
|
3195
3258
|
JSON.stringify(
|
|
3196
|
-
_optionalChain([error, 'access',
|
|
3259
|
+
_optionalChain([error, 'access', _88 => _88.toJSON, 'optionalCall', _89 => _89()]) || {
|
|
3197
3260
|
error: "invalid_request"
|
|
3198
3261
|
}
|
|
3199
3262
|
)
|
|
@@ -3211,7 +3274,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
3211
3274
|
} catch (error) {
|
|
3212
3275
|
res.writeHead(400, { "Content-Type": "application/json" }).end(
|
|
3213
3276
|
JSON.stringify(
|
|
3214
|
-
_optionalChain([error, 'access',
|
|
3277
|
+
_optionalChain([error, 'access', _90 => _90.toJSON, 'optionalCall', _91 => _91()]) || {
|
|
3215
3278
|
error: "server_error"
|
|
3216
3279
|
}
|
|
3217
3280
|
)
|
|
@@ -3275,7 +3338,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
3275
3338
|
} catch (error) {
|
|
3276
3339
|
res.writeHead(400, { "Content-Type": "application/json" }).end(
|
|
3277
3340
|
JSON.stringify(
|
|
3278
|
-
_optionalChain([error, 'access',
|
|
3341
|
+
_optionalChain([error, 'access', _92 => _92.toJSON, 'optionalCall', _93 => _93()]) || {
|
|
3279
3342
|
error: "server_error"
|
|
3280
3343
|
}
|
|
3281
3344
|
)
|
|
@@ -3390,7 +3453,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
3390
3453
|
}
|
|
3391
3454
|
res.writeHead(200, OAUTH_CREDENTIAL_RESPONSE_HEADERS).end(JSON.stringify(response));
|
|
3392
3455
|
} catch (error) {
|
|
3393
|
-
const body = _optionalChain([error, 'access',
|
|
3456
|
+
const body = _optionalChain([error, 'access', _94 => _94.toJSON, 'optionalCall', _95 => _95()]) || {
|
|
3394
3457
|
error: "invalid_request"
|
|
3395
3458
|
};
|
|
3396
3459
|
if (body.error === "invalid_client") {
|
|
@@ -3420,7 +3483,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
3420
3483
|
* regardless (RFC 7235), so no config is needed just to get the header.
|
|
3421
3484
|
*/
|
|
3422
3485
|
#httpStreamOAuthConfig() {
|
|
3423
|
-
const resource = _optionalChain([this, 'access',
|
|
3486
|
+
const resource = _optionalChain([this, 'access', _96 => _96.#options, 'access', _97 => _97.oauth, 'optionalAccess', _98 => _98.enabled]) ? _optionalChain([this, 'access', _99 => _99.#options, 'access', _100 => _100.oauth, 'access', _101 => _101.protectedResource, 'optionalAccess', _102 => _102.resource]) : void 0;
|
|
3424
3487
|
if (!resource) {
|
|
3425
3488
|
return {};
|
|
3426
3489
|
}
|
|
@@ -3560,25 +3623,25 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
3560
3623
|
const envBasePath = process.env.FASTMCP_BASE_PATH;
|
|
3561
3624
|
const envStateless = process.env.FASTMCP_STATELESS;
|
|
3562
3625
|
const envHost = process.env.FASTMCP_HOST;
|
|
3563
|
-
const transportType = _optionalChain([overrides, 'optionalAccess',
|
|
3626
|
+
const transportType = _optionalChain([overrides, 'optionalAccess', _103 => _103.transportType]) || parseTransportSetting(transportArg, "--transport") || parseTransportSetting(envTransport, "FASTMCP_TRANSPORT") || "stdio";
|
|
3564
3627
|
if (transportType === "httpStream") {
|
|
3565
3628
|
const port = parseInt(
|
|
3566
|
-
_optionalChain([overrides, 'optionalAccess',
|
|
3629
|
+
_optionalChain([overrides, 'optionalAccess', _104 => _104.httpStream, 'optionalAccess', _105 => _105.port, 'optionalAccess', _106 => _106.toString, 'call', _107 => _107()]) || portArg || envPort || "8080"
|
|
3567
3630
|
);
|
|
3568
|
-
const host = _optionalChain([overrides, 'optionalAccess',
|
|
3569
|
-
const endpoint = _optionalChain([overrides, 'optionalAccess',
|
|
3631
|
+
const host = _optionalChain([overrides, 'optionalAccess', _108 => _108.httpStream, 'optionalAccess', _109 => _109.host]) || hostArg || envHost || "localhost";
|
|
3632
|
+
const endpoint = _optionalChain([overrides, 'optionalAccess', _110 => _110.httpStream, 'optionalAccess', _111 => _111.endpoint]) || endpointArg || envEndpoint || "/mcp";
|
|
3570
3633
|
const basePath = normalizeBasePath(
|
|
3571
|
-
_optionalChain([overrides, 'optionalAccess',
|
|
3634
|
+
_optionalChain([overrides, 'optionalAccess', _112 => _112.httpStream, 'optionalAccess', _113 => _113.basePath]) || basePathArg || envBasePath
|
|
3572
3635
|
);
|
|
3573
|
-
const enableJsonResponse = _optionalChain([overrides, 'optionalAccess',
|
|
3574
|
-
const stateless = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([overrides, 'optionalAccess',
|
|
3636
|
+
const enableJsonResponse = _optionalChain([overrides, 'optionalAccess', _114 => _114.httpStream, 'optionalAccess', _115 => _115.enableJsonResponse]) || false;
|
|
3637
|
+
const stateless = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([overrides, 'optionalAccess', _116 => _116.httpStream, 'optionalAccess', _117 => _117.stateless]), () => ( // A bare `--stateless` means `--stateless true`.
|
|
3575
3638
|
(statelessArg === "" ? true : parseBooleanSetting(statelessArg, "--stateless")))), () => ( parseBooleanSetting(envStateless, "FASTMCP_STATELESS"))), () => ( false));
|
|
3576
|
-
const cors = _optionalChain([overrides, 'optionalAccess',
|
|
3577
|
-
const eventStore = _optionalChain([overrides, 'optionalAccess',
|
|
3578
|
-
const sseEndpoint = _optionalChain([overrides, 'optionalAccess',
|
|
3579
|
-
const sslCa = _optionalChain([overrides, 'optionalAccess',
|
|
3580
|
-
const sslCert = _optionalChain([overrides, 'optionalAccess',
|
|
3581
|
-
const sslKey = _optionalChain([overrides, 'optionalAccess',
|
|
3639
|
+
const cors = _optionalChain([overrides, 'optionalAccess', _118 => _118.httpStream, 'optionalAccess', _119 => _119.cors]);
|
|
3640
|
+
const eventStore = _optionalChain([overrides, 'optionalAccess', _120 => _120.httpStream, 'optionalAccess', _121 => _121.eventStore]);
|
|
3641
|
+
const sseEndpoint = _optionalChain([overrides, 'optionalAccess', _122 => _122.httpStream, 'optionalAccess', _123 => _123.sseEndpoint]);
|
|
3642
|
+
const sslCa = _optionalChain([overrides, 'optionalAccess', _124 => _124.httpStream, 'optionalAccess', _125 => _125.sslCa]);
|
|
3643
|
+
const sslCert = _optionalChain([overrides, 'optionalAccess', _126 => _126.httpStream, 'optionalAccess', _127 => _127.sslCert]);
|
|
3644
|
+
const sslKey = _optionalChain([overrides, 'optionalAccess', _128 => _128.httpStream, 'optionalAccess', _129 => _129.sslKey]);
|
|
3582
3645
|
return {
|
|
3583
3646
|
httpStream: {
|
|
3584
3647
|
basePath,
|
|
@@ -3607,6 +3670,14 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
3607
3670
|
session.promptsListChanged(prompts);
|
|
3608
3671
|
}
|
|
3609
3672
|
}
|
|
3673
|
+
#registrations() {
|
|
3674
|
+
return {
|
|
3675
|
+
prompts: this.#prompts,
|
|
3676
|
+
resources: this.#resources,
|
|
3677
|
+
resourcesTemplates: this.#resourcesTemplates,
|
|
3678
|
+
tools: this.#tools
|
|
3679
|
+
};
|
|
3680
|
+
}
|
|
3610
3681
|
#removeSession(session) {
|
|
3611
3682
|
const sessionIndex = this.#sessions.indexOf(session);
|
|
3612
3683
|
if (sessionIndex !== -1) {
|
|
@@ -3670,7 +3741,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
3670
3741
|
*/
|
|
3671
3742
|
#useEndpointAsResource(endpoint) {
|
|
3672
3743
|
const oauth = this.#options.oauth;
|
|
3673
|
-
if (this.#providerResourceBase === void 0 || !_optionalChain([oauth, 'optionalAccess',
|
|
3744
|
+
if (this.#providerResourceBase === void 0 || !_optionalChain([oauth, 'optionalAccess', _130 => _130.protectedResource]))
|
|
3674
3745
|
return;
|
|
3675
3746
|
this.#options = {
|
|
3676
3747
|
...this.#options,
|
|
@@ -3699,4 +3770,4 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
3699
3770
|
|
|
3700
3771
|
|
|
3701
3772
|
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;
|
|
3702
|
-
//# sourceMappingURL=chunk-
|
|
3773
|
+
//# sourceMappingURL=chunk-M3SNOHIM.cjs.map
|