fastmcp 4.9.1 → 4.10.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/README.md +42 -0
- package/dist/FastMCP.cjs +4 -2
- package/dist/FastMCP.cjs.map +1 -1
- package/dist/FastMCP.d.cts +68 -2
- package/dist/FastMCP.d.ts +68 -2
- package/dist/FastMCP.js +4 -2
- package/dist/{chunk-MJCWKCHZ.cjs → chunk-GF4ORBWZ.cjs} +140 -61
- package/dist/chunk-GF4ORBWZ.cjs.map +1 -0
- package/dist/{chunk-2PFUZL7I.js → chunk-MGP2FVUH.js} +96 -17
- package/dist/chunk-MGP2FVUH.js.map +1 -0
- package/dist/examples/custom-routes.cjs +2 -2
- package/dist/examples/custom-routes.js +1 -1
- package/package.json +11 -1
- package/dist/chunk-2PFUZL7I.js.map +0 -1
- package/dist/chunk-MJCWKCHZ.cjs.map +0 -1
|
@@ -114,6 +114,73 @@ var DiscoveryDocumentCache = class {
|
|
|
114
114
|
}
|
|
115
115
|
};
|
|
116
116
|
|
|
117
|
+
// src/jsonSchemaAdapter.ts
|
|
118
|
+
function jsonSchemaAdapter(schema) {
|
|
119
|
+
let compiled;
|
|
120
|
+
const getValidator = () => {
|
|
121
|
+
compiled ??= compileSchema(schema).catch((error) => {
|
|
122
|
+
compiled = void 0;
|
|
123
|
+
throw error;
|
|
124
|
+
});
|
|
125
|
+
return compiled;
|
|
126
|
+
};
|
|
127
|
+
return {
|
|
128
|
+
"~standard": {
|
|
129
|
+
jsonSchema: {
|
|
130
|
+
input: () => schema,
|
|
131
|
+
output: () => schema
|
|
132
|
+
},
|
|
133
|
+
validate: async (data) => {
|
|
134
|
+
const validate = await getValidator();
|
|
135
|
+
if (validate(data)) {
|
|
136
|
+
return { value: data };
|
|
137
|
+
}
|
|
138
|
+
return { issues: (_nullishCoalesce(validate.errors, () => ( []))).map(toIssue) };
|
|
139
|
+
},
|
|
140
|
+
vendor: "json-schema",
|
|
141
|
+
version: 1
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
async function compileSchema(schema) {
|
|
146
|
+
let ajvModule;
|
|
147
|
+
try {
|
|
148
|
+
ajvModule = await Promise.resolve().then(() => _interopRequireWildcard(require("ajv")));
|
|
149
|
+
} catch (e2) {
|
|
150
|
+
throw new Error(
|
|
151
|
+
'The "ajv" package is required to validate JSON Schema tool parameters. Install it with: npm install ajv'
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
const Ajv = unwrapDefault(unwrapDefault(ajvModule));
|
|
155
|
+
const ajv = new Ajv({ allErrors: true, strict: false });
|
|
156
|
+
try {
|
|
157
|
+
const formatsModule = await Promise.resolve().then(() => _interopRequireWildcard(require("ajv-formats")));
|
|
158
|
+
const addFormats = unwrapDefault(
|
|
159
|
+
unwrapDefault(formatsModule)
|
|
160
|
+
);
|
|
161
|
+
addFormats(ajv);
|
|
162
|
+
} catch (e3) {
|
|
163
|
+
}
|
|
164
|
+
return ajv.compile(schema);
|
|
165
|
+
}
|
|
166
|
+
function toIssue(error) {
|
|
167
|
+
const path = error.instancePath.split("/").filter(Boolean).map((segment) => segment.replaceAll("~1", "/").replaceAll("~0", "~")).map((segment) => {
|
|
168
|
+
const index = Number(segment);
|
|
169
|
+
return Number.isInteger(index) && segment !== "" ? index : segment;
|
|
170
|
+
});
|
|
171
|
+
const missingProperty = _optionalChain([error, 'access', _2 => _2.params, 'optionalAccess', _3 => _3.missingProperty]);
|
|
172
|
+
if (error.keyword === "required" && typeof missingProperty === "string") {
|
|
173
|
+
path.push(missingProperty);
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
message: error.message || "Validation error",
|
|
177
|
+
path
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function unwrapDefault(value) {
|
|
181
|
+
return typeof value === "object" && value !== null && "default" in value ? value.default : value;
|
|
182
|
+
}
|
|
183
|
+
|
|
117
184
|
// src/FastMCP.ts
|
|
118
185
|
var imageContent = async (input) => {
|
|
119
186
|
let rawData;
|
|
@@ -151,13 +218,13 @@ var imageContent = async (input) => {
|
|
|
151
218
|
const mimeType = await fileTypeFromBuffer(rawData);
|
|
152
219
|
if (!mimeType || !mimeType.mime.startsWith("image/")) {
|
|
153
220
|
console.warn(
|
|
154
|
-
`Warning: Content may not be a valid image. Detected MIME: ${_optionalChain([mimeType, 'optionalAccess',
|
|
221
|
+
`Warning: Content may not be a valid image. Detected MIME: ${_optionalChain([mimeType, 'optionalAccess', _4 => _4.mime]) || "unknown"}`
|
|
155
222
|
);
|
|
156
223
|
}
|
|
157
224
|
const base64Data = rawData.toString("base64");
|
|
158
225
|
return {
|
|
159
226
|
data: base64Data,
|
|
160
|
-
mimeType: _nullishCoalesce(_optionalChain([mimeType, 'optionalAccess',
|
|
227
|
+
mimeType: _nullishCoalesce(_optionalChain([mimeType, 'optionalAccess', _5 => _5.mime]), () => ( "image/png")),
|
|
161
228
|
type: "image"
|
|
162
229
|
};
|
|
163
230
|
} catch (error) {
|
|
@@ -204,13 +271,13 @@ var audioContent = async (input) => {
|
|
|
204
271
|
const mimeType = await fileTypeFromBuffer(rawData);
|
|
205
272
|
if (!mimeType || !mimeType.mime.startsWith("audio/")) {
|
|
206
273
|
console.warn(
|
|
207
|
-
`Warning: Content may not be a valid audio file. Detected MIME: ${_optionalChain([mimeType, 'optionalAccess',
|
|
274
|
+
`Warning: Content may not be a valid audio file. Detected MIME: ${_optionalChain([mimeType, 'optionalAccess', _6 => _6.mime]) || "unknown"}`
|
|
208
275
|
);
|
|
209
276
|
}
|
|
210
277
|
const base64Data = rawData.toString("base64");
|
|
211
278
|
return {
|
|
212
279
|
data: base64Data,
|
|
213
|
-
mimeType: _nullishCoalesce(_optionalChain([mimeType, 'optionalAccess',
|
|
280
|
+
mimeType: _nullishCoalesce(_optionalChain([mimeType, 'optionalAccess', _7 => _7.mime]), () => ( "audio/mpeg")),
|
|
214
281
|
type: "audio"
|
|
215
282
|
};
|
|
216
283
|
} catch (error) {
|
|
@@ -359,6 +426,12 @@ var FastMCPSession = class extends FastMCPSessionEventEmitter {
|
|
|
359
426
|
* Used to track per-session state across multiple requests.
|
|
360
427
|
*/
|
|
361
428
|
#sessionId;
|
|
429
|
+
/**
|
|
430
|
+
* Whether this session serves a single stateless HTTP request. The client
|
|
431
|
+
* handshake belongs to a different session — potentially on a different
|
|
432
|
+
* instance — so capabilities can never be inferred here.
|
|
433
|
+
*/
|
|
434
|
+
#stateless;
|
|
362
435
|
/**
|
|
363
436
|
* Resource URIs the connected client has subscribed to via
|
|
364
437
|
* `resources/subscribe`. Used to scope `notifications/resources/updated`
|
|
@@ -378,6 +451,7 @@ var FastMCPSession = class extends FastMCPSessionEventEmitter {
|
|
|
378
451
|
resourcesTemplates,
|
|
379
452
|
roots,
|
|
380
453
|
sessionId,
|
|
454
|
+
stateless = false,
|
|
381
455
|
tools,
|
|
382
456
|
transportType,
|
|
383
457
|
utils,
|
|
@@ -390,6 +464,7 @@ var FastMCPSession = class extends FastMCPSessionEventEmitter {
|
|
|
390
464
|
this.#pingConfig = ping;
|
|
391
465
|
this.#rootsConfig = roots;
|
|
392
466
|
this.#sessionId = sessionId;
|
|
467
|
+
this.#stateless = stateless;
|
|
393
468
|
this.#needsEventLoopFlush = transportType === "httpStream";
|
|
394
469
|
if (tools.length) {
|
|
395
470
|
this.#capabilities.tools = {};
|
|
@@ -458,26 +533,28 @@ var FastMCPSession = class extends FastMCPSessionEventEmitter {
|
|
|
458
533
|
this.#sessionId = transportWithSessionId.sessionId;
|
|
459
534
|
}
|
|
460
535
|
}
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
536
|
+
if (!this.#stateless) {
|
|
537
|
+
let attempt = 0;
|
|
538
|
+
const maxAttempts = 10;
|
|
539
|
+
const retryDelay = 100;
|
|
540
|
+
while (attempt++ < maxAttempts) {
|
|
541
|
+
const capabilities = this.#server.getClientCapabilities();
|
|
542
|
+
if (capabilities) {
|
|
543
|
+
this.#clientCapabilities = capabilities;
|
|
544
|
+
break;
|
|
545
|
+
}
|
|
546
|
+
await _promises3.setTimeout.call(void 0, retryDelay);
|
|
547
|
+
}
|
|
548
|
+
if (!this.#clientCapabilities) {
|
|
549
|
+
this.#logger.warn(
|
|
550
|
+
`[FastMCP warning] could not infer client capabilities after ${maxAttempts} attempts. Connection may be unstable.`
|
|
551
|
+
);
|
|
469
552
|
}
|
|
470
|
-
await _promises3.setTimeout.call(void 0, retryDelay);
|
|
471
|
-
}
|
|
472
|
-
if (!this.#clientCapabilities) {
|
|
473
|
-
this.#logger.warn(
|
|
474
|
-
`[FastMCP warning] could not infer client capabilities after ${maxAttempts} attempts. Connection may be unstable.`
|
|
475
|
-
);
|
|
476
553
|
}
|
|
477
|
-
if (_optionalChain([this, 'access',
|
|
554
|
+
if (_optionalChain([this, 'access', _8 => _8.#rootsConfig, 'optionalAccess', _9 => _9.enabled]) !== false && _optionalChain([this, 'access', _10 => _10.#clientCapabilities, 'optionalAccess', _11 => _11.roots, 'optionalAccess', _12 => _12.listChanged]) && typeof this.#server.listRoots === "function") {
|
|
478
555
|
try {
|
|
479
556
|
const roots = await this.#server.listRoots();
|
|
480
|
-
this.#roots = _optionalChain([roots, 'optionalAccess',
|
|
557
|
+
this.#roots = _optionalChain([roots, 'optionalAccess', _13 => _13.roots]) || [];
|
|
481
558
|
} catch (e) {
|
|
482
559
|
if (e instanceof _typesjs.McpError && e.code === _typesjs.ErrorCode.MethodNotFound) {
|
|
483
560
|
this.#logger.debug(
|
|
@@ -498,7 +575,7 @@ ${e instanceof Error ? e.stack : JSON.stringify(e)}`
|
|
|
498
575
|
this.#pingInterval = setInterval(async () => {
|
|
499
576
|
try {
|
|
500
577
|
await this.#server.ping();
|
|
501
|
-
} catch (
|
|
578
|
+
} catch (e4) {
|
|
502
579
|
const logLevel = pingConfig.logLevel;
|
|
503
580
|
if (logLevel === "debug") {
|
|
504
581
|
this.#logger.debug("[FastMCP debug] server ping failed");
|
|
@@ -650,7 +727,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
650
727
|
},
|
|
651
728
|
elicit: (params, options) => this.#server.elicitInput(params, options),
|
|
652
729
|
log: this.#createLog(),
|
|
653
|
-
requestId: typeof _optionalChain([meta, 'optionalAccess',
|
|
730
|
+
requestId: typeof _optionalChain([meta, 'optionalAccess', _14 => _14.requestId]) === "string" ? meta.requestId : void 0,
|
|
654
731
|
session: this.#auth,
|
|
655
732
|
sessionId: this.#sessionId
|
|
656
733
|
};
|
|
@@ -696,8 +773,8 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
696
773
|
};
|
|
697
774
|
}
|
|
698
775
|
#formatSchemaIssues(issues) {
|
|
699
|
-
return _optionalChain([this, 'access',
|
|
700
|
-
const path = _optionalChain([issue, 'access',
|
|
776
|
+
return _optionalChain([this, 'access', _15 => _15.#utils, 'optionalAccess', _16 => _16.formatInvalidParamsErrorMessage]) ? this.#utils.formatInvalidParamsErrorMessage(issues) : issues.map((issue) => {
|
|
777
|
+
const path = _optionalChain([issue, 'access', _17 => _17.path, 'optionalAccess', _18 => _18.join, 'call', _19 => _19(".")]) || "root";
|
|
701
778
|
return `${path}: ${issue.message}`;
|
|
702
779
|
}).join(", ");
|
|
703
780
|
}
|
|
@@ -909,7 +986,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
909
986
|
result = await prompt.load(
|
|
910
987
|
args,
|
|
911
988
|
this.#auth,
|
|
912
|
-
this.#createLoadContext(_optionalChain([request, 'access',
|
|
989
|
+
this.#createLoadContext(_optionalChain([request, 'access', _20 => _20.params, 'optionalAccess', _21 => _21._meta]))
|
|
913
990
|
);
|
|
914
991
|
} catch (error) {
|
|
915
992
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
@@ -974,7 +1051,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
974
1051
|
const result = await resourceTemplate.load(
|
|
975
1052
|
match,
|
|
976
1053
|
this.#auth,
|
|
977
|
-
this.#createLoadContext(_optionalChain([request, 'access',
|
|
1054
|
+
this.#createLoadContext(_optionalChain([request, 'access', _22 => _22.params, 'optionalAccess', _23 => _23._meta]))
|
|
978
1055
|
);
|
|
979
1056
|
const resources = Array.isArray(result) ? result : [result];
|
|
980
1057
|
return {
|
|
@@ -999,7 +1076,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
999
1076
|
try {
|
|
1000
1077
|
maybeArrayResult = await resource.load(
|
|
1001
1078
|
this.#auth,
|
|
1002
|
-
this.#createLoadContext(_optionalChain([request, 'access',
|
|
1079
|
+
this.#createLoadContext(_optionalChain([request, 'access', _24 => _24.params, 'optionalAccess', _25 => _25._meta]))
|
|
1003
1080
|
);
|
|
1004
1081
|
} catch (error) {
|
|
1005
1082
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
@@ -1062,7 +1139,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1062
1139
|
);
|
|
1063
1140
|
}
|
|
1064
1141
|
setupRootsHandlers() {
|
|
1065
|
-
if (_optionalChain([this, 'access',
|
|
1142
|
+
if (_optionalChain([this, 'access', _26 => _26.#rootsConfig, 'optionalAccess', _27 => _27.enabled]) === false) {
|
|
1066
1143
|
this.#logger.debug(
|
|
1067
1144
|
"[FastMCP debug] roots capability explicitly disabled via config"
|
|
1068
1145
|
);
|
|
@@ -1154,7 +1231,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1154
1231
|
}
|
|
1155
1232
|
args = parsed.value;
|
|
1156
1233
|
}
|
|
1157
|
-
const progressToken = _optionalChain([request, 'access',
|
|
1234
|
+
const progressToken = _optionalChain([request, 'access', _28 => _28.params, 'optionalAccess', _29 => _29._meta, 'optionalAccess', _30 => _30.progressToken]);
|
|
1158
1235
|
let result;
|
|
1159
1236
|
try {
|
|
1160
1237
|
const reportProgress = async (progress) => {
|
|
@@ -1213,7 +1290,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1213
1290
|
elicit: (params, options) => this.#server.elicitInput(params, options),
|
|
1214
1291
|
log,
|
|
1215
1292
|
reportProgress,
|
|
1216
|
-
requestId: typeof _optionalChain([request, 'access',
|
|
1293
|
+
requestId: typeof _optionalChain([request, 'access', _31 => _31.params, 'optionalAccess', _32 => _32._meta, 'optionalAccess', _33 => _33.requestId]) === "string" ? request.params._meta.requestId : void 0,
|
|
1217
1294
|
session: this.#auth,
|
|
1218
1295
|
sessionId: this.#sessionId,
|
|
1219
1296
|
streamContent
|
|
@@ -1323,14 +1400,14 @@ function normalizePath(path) {
|
|
|
1323
1400
|
return path.startsWith("/") ? path : `/${path}`;
|
|
1324
1401
|
}
|
|
1325
1402
|
function parseBasicAuthHeader(authHeader) {
|
|
1326
|
-
const basicMatch = _optionalChain([authHeader, 'optionalAccess',
|
|
1403
|
+
const basicMatch = _optionalChain([authHeader, 'optionalAccess', _34 => _34.match, 'call', _35 => _35(/^Basic\s+(.+)$/)]);
|
|
1327
1404
|
if (!basicMatch) return null;
|
|
1328
1405
|
try {
|
|
1329
1406
|
const credentials = Buffer.from(basicMatch[1], "base64").toString("utf-8");
|
|
1330
1407
|
const credMatch = credentials.match(/^([^:]+):(.*)$/);
|
|
1331
1408
|
if (!credMatch) return null;
|
|
1332
1409
|
return { clientId: credMatch[1], clientSecret: credMatch[2] };
|
|
1333
|
-
} catch (
|
|
1410
|
+
} catch (e5) {
|
|
1334
1411
|
return null;
|
|
1335
1412
|
}
|
|
1336
1413
|
}
|
|
@@ -1752,12 +1829,12 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
1752
1829
|
}
|
|
1753
1830
|
}
|
|
1754
1831
|
const sessionId = Array.isArray(request.headers["mcp-session-id"]) ? request.headers["mcp-session-id"][0] : request.headers["mcp-session-id"];
|
|
1755
|
-
return this.#createSession(auth, sessionId);
|
|
1832
|
+
return this.#createSession(auth, sessionId, true);
|
|
1756
1833
|
},
|
|
1757
1834
|
enableJsonResponse: httpConfig.enableJsonResponse,
|
|
1758
1835
|
eventStore: httpConfig.eventStore,
|
|
1759
1836
|
host: httpConfig.host,
|
|
1760
|
-
..._optionalChain([this, 'access',
|
|
1837
|
+
..._optionalChain([this, 'access', _36 => _36.#options, 'access', _37 => _37.oauth, 'optionalAccess', _38 => _38.enabled]) && _optionalChain([this, 'access', _39 => _39.#options, 'access', _40 => _40.oauth, 'access', _41 => _41.protectedResource, 'optionalAccess', _42 => _42.resource]) ? {
|
|
1761
1838
|
oauth: {
|
|
1762
1839
|
protectedResource: {
|
|
1763
1840
|
resource: this.#options.oauth.protectedResource.resource
|
|
@@ -1804,7 +1881,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
1804
1881
|
enableJsonResponse: httpConfig.enableJsonResponse,
|
|
1805
1882
|
eventStore: httpConfig.eventStore,
|
|
1806
1883
|
host: httpConfig.host,
|
|
1807
|
-
..._optionalChain([this, 'access',
|
|
1884
|
+
..._optionalChain([this, 'access', _43 => _43.#options, 'access', _44 => _44.oauth, 'optionalAccess', _45 => _45.enabled]) && _optionalChain([this, 'access', _46 => _46.#options, 'access', _47 => _47.oauth, 'access', _48 => _48.protectedResource, 'optionalAccess', _49 => _49.resource]) ? {
|
|
1808
1885
|
oauth: {
|
|
1809
1886
|
protectedResource: {
|
|
1810
1887
|
resource: this.#options.oauth.protectedResource.resource
|
|
@@ -1864,7 +1941,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
1864
1941
|
* Creates a new FastMCPSession instance with the current configuration.
|
|
1865
1942
|
* Used both for regular sessions and stateless requests.
|
|
1866
1943
|
*/
|
|
1867
|
-
#createSession(auth, sessionId) {
|
|
1944
|
+
#createSession(auth, sessionId, stateless = false) {
|
|
1868
1945
|
if (auth && typeof auth === "object" && "authenticated" in auth && !auth.authenticated) {
|
|
1869
1946
|
const errorMessage = "error" in auth && typeof auth.error === "string" ? auth.error : "Authentication failed";
|
|
1870
1947
|
throw this.#createUnauthorizedResponse(errorMessage);
|
|
@@ -1884,6 +1961,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
1884
1961
|
resourcesTemplates: this.#resourcesTemplates,
|
|
1885
1962
|
roots: this.#options.roots,
|
|
1886
1963
|
sessionId,
|
|
1964
|
+
stateless,
|
|
1887
1965
|
tools: allowedTools,
|
|
1888
1966
|
transportType: "httpStream",
|
|
1889
1967
|
utils: this.#options.utils,
|
|
@@ -1905,7 +1983,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
1905
1983
|
*/
|
|
1906
1984
|
#createUnauthorizedResponse(message) {
|
|
1907
1985
|
const oauth = this.#options.oauth;
|
|
1908
|
-
const resource = _optionalChain([oauth, 'optionalAccess',
|
|
1986
|
+
const resource = _optionalChain([oauth, 'optionalAccess', _50 => _50.enabled]) ? _optionalChain([oauth, 'access', _51 => _51.protectedResource, 'optionalAccess', _52 => _52.resource]) : void 0;
|
|
1909
1987
|
const wwwAuthenticateParts = [
|
|
1910
1988
|
'error="invalid_token"',
|
|
1911
1989
|
`error_description="${message.replace(/"/g, '\\"')}"`
|
|
@@ -2017,7 +2095,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2017
2095
|
}
|
|
2018
2096
|
}
|
|
2019
2097
|
const oauthConfig = this.#options.oauth;
|
|
2020
|
-
if (_optionalChain([oauthConfig, 'optionalAccess',
|
|
2098
|
+
if (_optionalChain([oauthConfig, 'optionalAccess', _53 => _53.enabled]) && req.method === "GET") {
|
|
2021
2099
|
const url2 = new URL(req.url || "", `http://${host}`);
|
|
2022
2100
|
const authorizationServerMetadataPath = joinPaths(
|
|
2023
2101
|
"",
|
|
@@ -2051,8 +2129,8 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2051
2129
|
}
|
|
2052
2130
|
}
|
|
2053
2131
|
}
|
|
2054
|
-
const oauthProxy = _optionalChain([oauthConfig, 'optionalAccess',
|
|
2055
|
-
if (oauthProxy && _optionalChain([oauthConfig, 'optionalAccess',
|
|
2132
|
+
const oauthProxy = _optionalChain([oauthConfig, 'optionalAccess', _54 => _54.proxy]);
|
|
2133
|
+
if (oauthProxy && _optionalChain([oauthConfig, 'optionalAccess', _55 => _55.enabled])) {
|
|
2056
2134
|
const url2 = new URL(req.url || "", `http://${host}`);
|
|
2057
2135
|
const oauthPath = basePathRelativePath;
|
|
2058
2136
|
try {
|
|
@@ -2069,7 +2147,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2069
2147
|
const statusCode = error.statusCode || 400;
|
|
2070
2148
|
res.writeHead(statusCode, { "Content-Type": "application/json" }).end(
|
|
2071
2149
|
JSON.stringify(
|
|
2072
|
-
_optionalChain([error, 'access',
|
|
2150
|
+
_optionalChain([error, 'access', _56 => _56.toJSON, 'optionalCall', _57 => _57()]) || {
|
|
2073
2151
|
error: "invalid_request"
|
|
2074
2152
|
}
|
|
2075
2153
|
)
|
|
@@ -2096,7 +2174,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2096
2174
|
} catch (error) {
|
|
2097
2175
|
res.writeHead(400, { "Content-Type": "application/json" }).end(
|
|
2098
2176
|
JSON.stringify(
|
|
2099
|
-
_optionalChain([error, 'access',
|
|
2177
|
+
_optionalChain([error, 'access', _58 => _58.toJSON, 'optionalCall', _59 => _59()]) || {
|
|
2100
2178
|
error: "invalid_request"
|
|
2101
2179
|
}
|
|
2102
2180
|
)
|
|
@@ -2118,7 +2196,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2118
2196
|
} catch (error) {
|
|
2119
2197
|
res.writeHead(400, { "Content-Type": "application/json" }).end(
|
|
2120
2198
|
JSON.stringify(
|
|
2121
|
-
_optionalChain([error, 'access',
|
|
2199
|
+
_optionalChain([error, 'access', _60 => _60.toJSON, 'optionalCall', _61 => _61()]) || {
|
|
2122
2200
|
error: "server_error"
|
|
2123
2201
|
}
|
|
2124
2202
|
)
|
|
@@ -2153,7 +2231,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2153
2231
|
} catch (error) {
|
|
2154
2232
|
res.writeHead(400, { "Content-Type": "application/json" }).end(
|
|
2155
2233
|
JSON.stringify(
|
|
2156
|
-
_optionalChain([error, 'access',
|
|
2234
|
+
_optionalChain([error, 'access', _62 => _62.toJSON, 'optionalCall', _63 => _63()]) || {
|
|
2157
2235
|
error: "server_error"
|
|
2158
2236
|
}
|
|
2159
2237
|
)
|
|
@@ -2175,8 +2253,8 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2175
2253
|
const basicAuth = parseBasicAuthHeader(
|
|
2176
2254
|
req.headers.authorization
|
|
2177
2255
|
);
|
|
2178
|
-
const clientId = _optionalChain([basicAuth, 'optionalAccess',
|
|
2179
|
-
const clientSecret = _nullishCoalesce(_nullishCoalesce(_optionalChain([basicAuth, 'optionalAccess',
|
|
2256
|
+
const clientId = _optionalChain([basicAuth, 'optionalAccess', _64 => _64.clientId]) || params.get("client_id") || "";
|
|
2257
|
+
const clientSecret = _nullishCoalesce(_nullishCoalesce(_optionalChain([basicAuth, 'optionalAccess', _65 => _65.clientSecret]), () => ( params.get("client_secret"))), () => ( void 0));
|
|
2180
2258
|
let response;
|
|
2181
2259
|
if (grantType === "authorization_code") {
|
|
2182
2260
|
response = await oauthProxy.exchangeAuthorizationCode({
|
|
@@ -2206,7 +2284,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2206
2284
|
const statusCode = error.statusCode || 400;
|
|
2207
2285
|
res.writeHead(statusCode, { "Content-Type": "application/json" }).end(
|
|
2208
2286
|
JSON.stringify(
|
|
2209
|
-
_optionalChain([error, 'access',
|
|
2287
|
+
_optionalChain([error, 'access', _66 => _66.toJSON, 'optionalCall', _67 => _67()]) || {
|
|
2210
2288
|
error: "invalid_request"
|
|
2211
2289
|
}
|
|
2212
2290
|
)
|
|
@@ -2277,23 +2355,23 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2277
2355
|
const envBasePath = process.env.FASTMCP_BASE_PATH;
|
|
2278
2356
|
const envStateless = process.env.FASTMCP_STATELESS;
|
|
2279
2357
|
const envHost = process.env.FASTMCP_HOST;
|
|
2280
|
-
const transportType = _optionalChain([overrides, 'optionalAccess',
|
|
2358
|
+
const transportType = _optionalChain([overrides, 'optionalAccess', _68 => _68.transportType]) || (transportArg === "http-stream" ? "httpStream" : transportArg) || envTransport || "stdio";
|
|
2281
2359
|
if (transportType === "httpStream") {
|
|
2282
2360
|
const port = parseInt(
|
|
2283
|
-
_optionalChain([overrides, 'optionalAccess',
|
|
2361
|
+
_optionalChain([overrides, 'optionalAccess', _69 => _69.httpStream, 'optionalAccess', _70 => _70.port, 'optionalAccess', _71 => _71.toString, 'call', _72 => _72()]) || portArg || envPort || "8080"
|
|
2284
2362
|
);
|
|
2285
|
-
const host = _optionalChain([overrides, 'optionalAccess',
|
|
2286
|
-
const endpoint = _optionalChain([overrides, 'optionalAccess',
|
|
2363
|
+
const host = _optionalChain([overrides, 'optionalAccess', _73 => _73.httpStream, 'optionalAccess', _74 => _74.host]) || hostArg || envHost || "localhost";
|
|
2364
|
+
const endpoint = _optionalChain([overrides, 'optionalAccess', _75 => _75.httpStream, 'optionalAccess', _76 => _76.endpoint]) || endpointArg || envEndpoint || "/mcp";
|
|
2287
2365
|
const basePath = normalizeBasePath(
|
|
2288
|
-
_optionalChain([overrides, 'optionalAccess',
|
|
2366
|
+
_optionalChain([overrides, 'optionalAccess', _77 => _77.httpStream, 'optionalAccess', _78 => _78.basePath]) || basePathArg || envBasePath
|
|
2289
2367
|
);
|
|
2290
|
-
const enableJsonResponse = _optionalChain([overrides, 'optionalAccess',
|
|
2291
|
-
const stateless = _optionalChain([overrides, 'optionalAccess',
|
|
2292
|
-
const cors = _optionalChain([overrides, 'optionalAccess',
|
|
2293
|
-
const eventStore = _optionalChain([overrides, 'optionalAccess',
|
|
2294
|
-
const sslCa = _optionalChain([overrides, 'optionalAccess',
|
|
2295
|
-
const sslCert = _optionalChain([overrides, 'optionalAccess',
|
|
2296
|
-
const sslKey = _optionalChain([overrides, 'optionalAccess',
|
|
2368
|
+
const enableJsonResponse = _optionalChain([overrides, 'optionalAccess', _79 => _79.httpStream, 'optionalAccess', _80 => _80.enableJsonResponse]) || false;
|
|
2369
|
+
const stateless = _optionalChain([overrides, 'optionalAccess', _81 => _81.httpStream, 'optionalAccess', _82 => _82.stateless]) || statelessArg === "true" || envStateless === "true" || false;
|
|
2370
|
+
const cors = _optionalChain([overrides, 'optionalAccess', _83 => _83.httpStream, 'optionalAccess', _84 => _84.cors]);
|
|
2371
|
+
const eventStore = _optionalChain([overrides, 'optionalAccess', _85 => _85.httpStream, 'optionalAccess', _86 => _86.eventStore]);
|
|
2372
|
+
const sslCa = _optionalChain([overrides, 'optionalAccess', _87 => _87.httpStream, 'optionalAccess', _88 => _88.sslCa]);
|
|
2373
|
+
const sslCert = _optionalChain([overrides, 'optionalAccess', _89 => _89.httpStream, 'optionalAccess', _90 => _90.sslCert]);
|
|
2374
|
+
const sslKey = _optionalChain([overrides, 'optionalAccess', _91 => _91.httpStream, 'optionalAccess', _92 => _92.sslKey]);
|
|
2297
2375
|
return {
|
|
2298
2376
|
httpStream: {
|
|
2299
2377
|
basePath,
|
|
@@ -2365,5 +2443,6 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2365
2443
|
|
|
2366
2444
|
|
|
2367
2445
|
|
|
2368
|
-
|
|
2369
|
-
|
|
2446
|
+
|
|
2447
|
+
exports.DiscoveryDocumentCache = DiscoveryDocumentCache; exports.jsonSchemaAdapter = jsonSchemaAdapter; exports.imageContent = imageContent; exports.audioContent = audioContent; exports.UnexpectedStateError = UnexpectedStateError; exports.UserError = UserError; exports.ServerState = ServerState; exports.FastMCPSession = FastMCPSession; exports.FastMCP = FastMCP;
|
|
2448
|
+
//# sourceMappingURL=chunk-GF4ORBWZ.cjs.map
|