mcp-use 1.5.1-canary.0 → 1.5.1-canary.2
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/.tsbuildinfo +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/src/server/index.cjs +165 -64
- package/dist/src/server/index.js +165 -64
- package/dist/src/server/logging.d.ts +6 -0
- package/dist/src/server/logging.d.ts.map +1 -1
- package/dist/src/server/mcp-server.d.ts.map +1 -1
- package/dist/src/server/types/common.d.ts +31 -0
- package/dist/src/server/types/common.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/src/server/index.js
CHANGED
|
@@ -263,15 +263,46 @@ async function adaptConnectMiddleware(connectMiddleware, middlewarePath) {
|
|
|
263
263
|
__name(adaptConnectMiddleware, "adaptConnectMiddleware");
|
|
264
264
|
|
|
265
265
|
// src/server/logging.ts
|
|
266
|
+
var isDeno = typeof globalThis.Deno !== "undefined";
|
|
267
|
+
function getEnv(key) {
|
|
268
|
+
if (isDeno) {
|
|
269
|
+
return globalThis.Deno.env.get(key);
|
|
270
|
+
}
|
|
271
|
+
return typeof process !== "undefined" && process.env ? process.env[key] : void 0;
|
|
272
|
+
}
|
|
273
|
+
__name(getEnv, "getEnv");
|
|
274
|
+
function isDebugMode() {
|
|
275
|
+
const debugEnv = getEnv("DEBUG");
|
|
276
|
+
return debugEnv !== void 0 && debugEnv !== "" && debugEnv !== "0" && debugEnv.toLowerCase() !== "false";
|
|
277
|
+
}
|
|
278
|
+
__name(isDebugMode, "isDebugMode");
|
|
279
|
+
function formatForLogging(obj) {
|
|
280
|
+
try {
|
|
281
|
+
return JSON.stringify(obj, null, 2);
|
|
282
|
+
} catch {
|
|
283
|
+
return String(obj);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
__name(formatForLogging, "formatForLogging");
|
|
266
287
|
async function requestLogger(c, next) {
|
|
267
288
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString().substring(11, 23);
|
|
268
289
|
const method = c.req.method;
|
|
269
290
|
const url = c.req.url;
|
|
270
|
-
|
|
271
|
-
|
|
291
|
+
const debugMode = isDebugMode();
|
|
292
|
+
let requestBody = null;
|
|
293
|
+
let requestHeaders = {};
|
|
294
|
+
if (debugMode) {
|
|
295
|
+
const allHeaders = c.req.header();
|
|
296
|
+
if (allHeaders) {
|
|
297
|
+
requestHeaders = allHeaders;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
if (method !== "GET" && method !== "HEAD") {
|
|
272
301
|
try {
|
|
273
302
|
const clonedRequest = c.req.raw.clone();
|
|
274
|
-
|
|
303
|
+
requestBody = await clonedRequest.json().catch(() => {
|
|
304
|
+
return clonedRequest.text().catch(() => null);
|
|
305
|
+
});
|
|
275
306
|
} catch {
|
|
276
307
|
}
|
|
277
308
|
}
|
|
@@ -288,11 +319,70 @@ async function requestLogger(c, next) {
|
|
|
288
319
|
statusColor = "\x1B[35m";
|
|
289
320
|
}
|
|
290
321
|
let logMessage = `[${timestamp}] ${method} \x1B[1m${new URL(url).pathname}\x1B[0m`;
|
|
291
|
-
if (method === "POST" && url.includes("/mcp") &&
|
|
292
|
-
logMessage += ` \x1B[1m[${
|
|
322
|
+
if (method === "POST" && url.includes("/mcp") && requestBody?.method) {
|
|
323
|
+
logMessage += ` \x1B[1m[${requestBody.method}]\x1B[0m`;
|
|
293
324
|
}
|
|
294
325
|
logMessage += ` ${statusColor}${statusCode}\x1B[0m`;
|
|
295
326
|
console.log(logMessage);
|
|
327
|
+
if (debugMode) {
|
|
328
|
+
console.log("\n\x1B[36m" + "=".repeat(80) + "\x1B[0m");
|
|
329
|
+
console.log("\x1B[1m\x1B[36m[DEBUG] Request Details\x1B[0m");
|
|
330
|
+
console.log("\x1B[36m" + "-".repeat(80) + "\x1B[0m");
|
|
331
|
+
if (Object.keys(requestHeaders).length > 0) {
|
|
332
|
+
console.log("\x1B[33mRequest Headers:\x1B[0m");
|
|
333
|
+
console.log(formatForLogging(requestHeaders));
|
|
334
|
+
}
|
|
335
|
+
if (requestBody !== null) {
|
|
336
|
+
console.log("\x1B[33mRequest Body:\x1B[0m");
|
|
337
|
+
if (typeof requestBody === "string") {
|
|
338
|
+
console.log(requestBody);
|
|
339
|
+
} else {
|
|
340
|
+
console.log(formatForLogging(requestBody));
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
const responseHeaders = {};
|
|
344
|
+
c.res.headers.forEach((value, key) => {
|
|
345
|
+
responseHeaders[key] = value;
|
|
346
|
+
});
|
|
347
|
+
if (Object.keys(responseHeaders).length > 0) {
|
|
348
|
+
console.log("\x1B[33mResponse Headers:\x1B[0m");
|
|
349
|
+
console.log(formatForLogging(responseHeaders));
|
|
350
|
+
}
|
|
351
|
+
try {
|
|
352
|
+
if (c.res.body !== null && c.res.body !== void 0) {
|
|
353
|
+
try {
|
|
354
|
+
const clonedResponse = c.res.clone();
|
|
355
|
+
const responseBody = await clonedResponse.text().catch(() => null);
|
|
356
|
+
if (responseBody !== null && responseBody.length > 0) {
|
|
357
|
+
console.log("\x1B[33mResponse Body:\x1B[0m");
|
|
358
|
+
try {
|
|
359
|
+
const jsonBody = JSON.parse(responseBody);
|
|
360
|
+
console.log(formatForLogging(jsonBody));
|
|
361
|
+
} catch {
|
|
362
|
+
const maxLength = 1e4;
|
|
363
|
+
if (responseBody.length > maxLength) {
|
|
364
|
+
console.log(
|
|
365
|
+
responseBody.substring(0, maxLength) + `
|
|
366
|
+
... (truncated, ${responseBody.length - maxLength} more characters)`
|
|
367
|
+
);
|
|
368
|
+
} else {
|
|
369
|
+
console.log(responseBody);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
} else {
|
|
373
|
+
console.log("\x1B[33mResponse Body:\x1B[0m (empty)");
|
|
374
|
+
}
|
|
375
|
+
} catch (cloneError) {
|
|
376
|
+
console.log("\x1B[33mResponse Body:\x1B[0m (unable to clone/read)");
|
|
377
|
+
}
|
|
378
|
+
} else {
|
|
379
|
+
console.log("\x1B[33mResponse Body:\x1B[0m (no body)");
|
|
380
|
+
}
|
|
381
|
+
} catch (error) {
|
|
382
|
+
console.log("\x1B[33mResponse Body:\x1B[0m (unable to read)");
|
|
383
|
+
}
|
|
384
|
+
console.log("\x1B[36m" + "=".repeat(80) + "\x1B[0m\n");
|
|
385
|
+
}
|
|
296
386
|
}
|
|
297
387
|
__name(requestLogger, "requestLogger");
|
|
298
388
|
|
|
@@ -302,16 +392,16 @@ function generateUUID() {
|
|
|
302
392
|
}
|
|
303
393
|
__name(generateUUID, "generateUUID");
|
|
304
394
|
var TMP_MCP_USE_DIR = ".mcp-use";
|
|
305
|
-
var
|
|
306
|
-
function
|
|
307
|
-
if (
|
|
395
|
+
var isDeno2 = typeof globalThis.Deno !== "undefined";
|
|
396
|
+
function getEnv2(key) {
|
|
397
|
+
if (isDeno2) {
|
|
308
398
|
return globalThis.Deno.env.get(key);
|
|
309
399
|
}
|
|
310
400
|
return process.env[key];
|
|
311
401
|
}
|
|
312
|
-
__name(
|
|
402
|
+
__name(getEnv2, "getEnv");
|
|
313
403
|
function getCwd() {
|
|
314
|
-
if (
|
|
404
|
+
if (isDeno2) {
|
|
315
405
|
return globalThis.Deno.cwd();
|
|
316
406
|
}
|
|
317
407
|
return process.cwd();
|
|
@@ -319,7 +409,7 @@ function getCwd() {
|
|
|
319
409
|
__name(getCwd, "getCwd");
|
|
320
410
|
var fsHelpers = {
|
|
321
411
|
async readFileSync(path, encoding = "utf8") {
|
|
322
|
-
if (
|
|
412
|
+
if (isDeno2) {
|
|
323
413
|
return await globalThis.Deno.readTextFile(path);
|
|
324
414
|
}
|
|
325
415
|
const { readFileSync } = await import("fs");
|
|
@@ -327,7 +417,7 @@ var fsHelpers = {
|
|
|
327
417
|
return typeof result === "string" ? result : result.toString(encoding);
|
|
328
418
|
},
|
|
329
419
|
async readFile(path) {
|
|
330
|
-
if (
|
|
420
|
+
if (isDeno2) {
|
|
331
421
|
const data = await globalThis.Deno.readFile(path);
|
|
332
422
|
return data.buffer;
|
|
333
423
|
}
|
|
@@ -339,7 +429,7 @@ var fsHelpers = {
|
|
|
339
429
|
);
|
|
340
430
|
},
|
|
341
431
|
async existsSync(path) {
|
|
342
|
-
if (
|
|
432
|
+
if (isDeno2) {
|
|
343
433
|
try {
|
|
344
434
|
await globalThis.Deno.stat(path);
|
|
345
435
|
return true;
|
|
@@ -351,7 +441,7 @@ var fsHelpers = {
|
|
|
351
441
|
return existsSync(path);
|
|
352
442
|
},
|
|
353
443
|
async readdirSync(path) {
|
|
354
|
-
if (
|
|
444
|
+
if (isDeno2) {
|
|
355
445
|
const entries = [];
|
|
356
446
|
for await (const entry of globalThis.Deno.readDir(path)) {
|
|
357
447
|
entries.push(entry.name);
|
|
@@ -364,7 +454,7 @@ var fsHelpers = {
|
|
|
364
454
|
};
|
|
365
455
|
var pathHelpers = {
|
|
366
456
|
join(...paths) {
|
|
367
|
-
if (
|
|
457
|
+
if (isDeno2) {
|
|
368
458
|
return paths.join("/").replace(/\/+/g, "/");
|
|
369
459
|
}
|
|
370
460
|
return paths.join("/").replace(/\/+/g, "/");
|
|
@@ -496,7 +586,7 @@ var McpServer = class {
|
|
|
496
586
|
if (this.serverBaseUrl) {
|
|
497
587
|
return this.serverBaseUrl;
|
|
498
588
|
}
|
|
499
|
-
const mcpUrl =
|
|
589
|
+
const mcpUrl = getEnv2("MCP_URL");
|
|
500
590
|
if (mcpUrl) {
|
|
501
591
|
return mcpUrl;
|
|
502
592
|
}
|
|
@@ -1118,7 +1208,7 @@ var McpServer = class {
|
|
|
1118
1208
|
* @returns true if in production mode, false otherwise
|
|
1119
1209
|
*/
|
|
1120
1210
|
isProductionMode() {
|
|
1121
|
-
return
|
|
1211
|
+
return getEnv2("NODE_ENV") === "production";
|
|
1122
1212
|
}
|
|
1123
1213
|
/**
|
|
1124
1214
|
* Read build manifest file
|
|
@@ -1129,7 +1219,7 @@ var McpServer = class {
|
|
|
1129
1219
|
async readBuildManifest() {
|
|
1130
1220
|
try {
|
|
1131
1221
|
const manifestPath = pathHelpers.join(
|
|
1132
|
-
|
|
1222
|
+
isDeno2 ? "." : getCwd(),
|
|
1133
1223
|
"dist",
|
|
1134
1224
|
"mcp-use.json"
|
|
1135
1225
|
);
|
|
@@ -1151,7 +1241,7 @@ var McpServer = class {
|
|
|
1151
1241
|
* @returns Promise that resolves when all widgets are mounted
|
|
1152
1242
|
*/
|
|
1153
1243
|
async mountWidgets(options) {
|
|
1154
|
-
if (this.isProductionMode() ||
|
|
1244
|
+
if (this.isProductionMode() || isDeno2) {
|
|
1155
1245
|
console.log("[WIDGETS] Mounting widgets in production mode");
|
|
1156
1246
|
await this.mountWidgetsProduction(options);
|
|
1157
1247
|
} else {
|
|
@@ -1571,7 +1661,7 @@ if (container && Component) {
|
|
|
1571
1661
|
async mountWidgetsProduction(options) {
|
|
1572
1662
|
const baseRoute = options?.baseRoute || "/mcp-use/widgets";
|
|
1573
1663
|
const widgetsDir = pathHelpers.join(
|
|
1574
|
-
|
|
1664
|
+
isDeno2 ? "." : getCwd(),
|
|
1575
1665
|
"dist",
|
|
1576
1666
|
"resources",
|
|
1577
1667
|
"widgets"
|
|
@@ -1778,47 +1868,50 @@ if (container && Component) {
|
|
|
1778
1868
|
if (this.mcpMounted) return;
|
|
1779
1869
|
const { StreamableHTTPServerTransport } = await import("@modelcontextprotocol/sdk/server/streamableHttp.js");
|
|
1780
1870
|
const idleTimeoutMs = this.config.sessionIdleTimeoutMs ?? 3e5;
|
|
1781
|
-
const
|
|
1782
|
-
if (
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
} catch (error) {
|
|
1787
|
-
}
|
|
1788
|
-
this.sessions.delete(sessionId);
|
|
1871
|
+
const createNewTransport = /* @__PURE__ */ __name(async (closeOldSessionId) => {
|
|
1872
|
+
if (closeOldSessionId && this.sessions.has(closeOldSessionId)) {
|
|
1873
|
+
try {
|
|
1874
|
+
this.sessions.get(closeOldSessionId).transport.close();
|
|
1875
|
+
} catch (error) {
|
|
1789
1876
|
}
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
allowedOrigins = void 0;
|
|
1799
|
-
enableDnsRebindingProtection = false;
|
|
1877
|
+
this.sessions.delete(closeOldSessionId);
|
|
1878
|
+
}
|
|
1879
|
+
const isProduction = this.isProductionMode();
|
|
1880
|
+
let allowedOrigins = this.config.allowedOrigins;
|
|
1881
|
+
let enableDnsRebindingProtection = false;
|
|
1882
|
+
if (isProduction) {
|
|
1883
|
+
if (allowedOrigins !== void 0) {
|
|
1884
|
+
enableDnsRebindingProtection = allowedOrigins.length > 0;
|
|
1800
1885
|
}
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1886
|
+
} else {
|
|
1887
|
+
allowedOrigins = void 0;
|
|
1888
|
+
enableDnsRebindingProtection = false;
|
|
1889
|
+
}
|
|
1890
|
+
const transport = new StreamableHTTPServerTransport({
|
|
1891
|
+
sessionIdGenerator: /* @__PURE__ */ __name(() => generateUUID(), "sessionIdGenerator"),
|
|
1892
|
+
enableJsonResponse: true,
|
|
1893
|
+
allowedOrigins,
|
|
1894
|
+
enableDnsRebindingProtection,
|
|
1895
|
+
onsessioninitialized: /* @__PURE__ */ __name((id) => {
|
|
1896
|
+
if (id) {
|
|
1897
|
+
this.sessions.set(id, {
|
|
1898
|
+
transport,
|
|
1899
|
+
lastAccessedAt: Date.now()
|
|
1900
|
+
});
|
|
1901
|
+
}
|
|
1902
|
+
}, "onsessioninitialized"),
|
|
1903
|
+
onsessionclosed: /* @__PURE__ */ __name((id) => {
|
|
1904
|
+
if (id) {
|
|
1905
|
+
this.sessions.delete(id);
|
|
1906
|
+
}
|
|
1907
|
+
}, "onsessionclosed")
|
|
1908
|
+
});
|
|
1909
|
+
await this.server.connect(transport);
|
|
1910
|
+
return transport;
|
|
1911
|
+
}, "createNewTransport");
|
|
1912
|
+
const getOrCreateTransport = /* @__PURE__ */ __name(async (sessionId, isInit = false) => {
|
|
1913
|
+
if (isInit) {
|
|
1914
|
+
return await createNewTransport(sessionId);
|
|
1822
1915
|
}
|
|
1823
1916
|
if (sessionId && this.sessions.has(sessionId)) {
|
|
1824
1917
|
const session = this.sessions.get(sessionId);
|
|
@@ -1826,7 +1919,15 @@ if (container && Component) {
|
|
|
1826
1919
|
return session.transport;
|
|
1827
1920
|
}
|
|
1828
1921
|
if (sessionId) {
|
|
1829
|
-
|
|
1922
|
+
const autoCreate = this.config.autoCreateSessionOnInvalidId ?? true;
|
|
1923
|
+
if (autoCreate) {
|
|
1924
|
+
console.warn(
|
|
1925
|
+
`[MCP] Session ${sessionId} not found (expired or invalid), auto-creating new session for seamless reconnection`
|
|
1926
|
+
);
|
|
1927
|
+
return await createNewTransport(sessionId);
|
|
1928
|
+
} else {
|
|
1929
|
+
return null;
|
|
1930
|
+
}
|
|
1830
1931
|
}
|
|
1831
1932
|
return null;
|
|
1832
1933
|
}, "getOrCreateTransport");
|
|
@@ -1935,7 +2036,7 @@ if (container && Component) {
|
|
|
1935
2036
|
getResponse: /* @__PURE__ */ __name(() => {
|
|
1936
2037
|
if (ended) {
|
|
1937
2038
|
if (responseBody.length > 0) {
|
|
1938
|
-
const body =
|
|
2039
|
+
const body = isDeno2 ? Buffer.concat(responseBody) : Buffer.concat(responseBody);
|
|
1939
2040
|
return new Response(body, {
|
|
1940
2041
|
status: statusCode,
|
|
1941
2042
|
headers
|
|
@@ -2243,9 +2344,9 @@ if (container && Component) {
|
|
|
2243
2344
|
console.log("");
|
|
2244
2345
|
}
|
|
2245
2346
|
async listen(port) {
|
|
2246
|
-
const portEnv =
|
|
2347
|
+
const portEnv = getEnv2("PORT");
|
|
2247
2348
|
this.serverPort = port || (portEnv ? parseInt(portEnv, 10) : 3001);
|
|
2248
|
-
const hostEnv =
|
|
2349
|
+
const hostEnv = getEnv2("HOST");
|
|
2249
2350
|
if (hostEnv) {
|
|
2250
2351
|
this.serverHost = hostEnv;
|
|
2251
2352
|
}
|
|
@@ -2256,7 +2357,7 @@ if (container && Component) {
|
|
|
2256
2357
|
await this.mountMcp();
|
|
2257
2358
|
await this.mountInspector();
|
|
2258
2359
|
this.logRegisteredItems();
|
|
2259
|
-
if (
|
|
2360
|
+
if (isDeno2) {
|
|
2260
2361
|
const corsHeaders = {
|
|
2261
2362
|
"Access-Control-Allow-Origin": "*",
|
|
2262
2363
|
"Access-Control-Allow-Headers": "authorization, x-client-info, apikey, content-type"
|
|
@@ -8,6 +8,12 @@ import type { Context, Next } from "hono";
|
|
|
8
8
|
* - MCP method name in brackets for POST requests to /mcp
|
|
9
9
|
* - Color-coded status codes (green 2xx, yellow 3xx, red 4xx, magenta 5xx)
|
|
10
10
|
*
|
|
11
|
+
* When DEBUG environment variable is set, also logs:
|
|
12
|
+
* - Request headers
|
|
13
|
+
* - Full request payload/body
|
|
14
|
+
* - Response headers
|
|
15
|
+
* - Response body
|
|
16
|
+
*
|
|
11
17
|
* @param c - Hono context object
|
|
12
18
|
* @param next - Hono next function
|
|
13
19
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logging.d.ts","sourceRoot":"","sources":["../../../src/server/logging.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"logging.d.ts","sourceRoot":"","sources":["../../../src/server/logging.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MA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CAAC,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,IAAI,CAAC;IAkCxD;;;;;;;;;;;;;;;;;;;;;OAqBG;YACW,cAAc;IAwC5B;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,OAAO,CAAC,iBAAiB;IAoLzB;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,iBAAiB;IAWzB;;;;;;;;;;;;;;;;;;OAkBG;IACH,OAAO,CAAC,kBAAkB;IA+C1B;;;;;;;;;;;;;;;;;;OAkBG;IACH,OAAO,CAAC,sBAAsB;IAqC9B;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,qBAAqB;IAK7B;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,gBAAgB;CA4BzB;AAED,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,SAAS,EAAE,MAAM,QAAQ,CAAC,GAC7D,QAAQ,GAAG;IACT,UAAU,EAAE,CAAC,OAAO,CAAC,EAAE;QACrB,QAAQ,CAAC,EAAE,UAAU,GAAG,YAAY,GAAG,aAAa,CAAC;KACtD,KAAK,OAAO,CAAC,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;CACpD,CAAC;AAEJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,OAAO,CAAC,YAAY,CAAM,GACjC,iBAAiB,CAWnB"}
|
|
@@ -35,6 +35,37 @@ export interface ServerConfig {
|
|
|
35
35
|
*/
|
|
36
36
|
allowedOrigins?: string[];
|
|
37
37
|
sessionIdleTimeoutMs?: number;
|
|
38
|
+
/**
|
|
39
|
+
* Automatically create a new session when a request is received with an invalid/expired session ID.
|
|
40
|
+
*
|
|
41
|
+
* **Default: true** (enables compatibility with non-compliant clients like ChatGPT)
|
|
42
|
+
*
|
|
43
|
+
* When set to `true` (default), the server will automatically create a new session when it receives
|
|
44
|
+
* a request with an invalid or expired session ID. This allows clients to seamlessly
|
|
45
|
+
* reconnect after server restarts without needing to send a new `initialize` request.
|
|
46
|
+
*
|
|
47
|
+
* **Note**: According to the [MCP protocol specification](https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#session-management),
|
|
48
|
+
* clients **MUST** start a new session by sending a new `InitializeRequest` when they receive
|
|
49
|
+
* HTTP 404 in response to a request containing an `MCP-Session-Id`. However, some clients (like
|
|
50
|
+
* ChatGPT) don't properly handle this and fail to reconnect. Setting this to `true` enables
|
|
51
|
+
* compatibility with these non-compliant clients.
|
|
52
|
+
*
|
|
53
|
+
* When set to `false`, the server follows the MCP protocol specification strictly:
|
|
54
|
+
* it returns HTTP 404 Not Found for requests with invalid session IDs, requiring
|
|
55
|
+
* clients to explicitly send a new `initialize` request.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* // Default behavior (compatible with ChatGPT and other non-compliant clients)
|
|
60
|
+
* const server = createMCPServer('my-server');
|
|
61
|
+
*
|
|
62
|
+
* // Use strict MCP spec behavior (requires compliant clients)
|
|
63
|
+
* const server = createMCPServer('my-server', {
|
|
64
|
+
* autoCreateSessionOnInvalidId: false
|
|
65
|
+
* });
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
autoCreateSessionOnInvalidId?: boolean;
|
|
38
69
|
}
|
|
39
70
|
export interface InputDefinition {
|
|
40
71
|
name: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../../src/server/types/common.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,oBAAoB,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../../src/server/types/common.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,4BAA4B,CAAC,EAAE,OAAO,CAAC;CACxC;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAC;IAC3D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,CAAC,MAAM,GAAG,WAAW,CAAC,EAAE,CAAC;IACpC,kEAAkE;IAClE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wDAAwD;IACxD,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-use",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.5.1-canary.
|
|
4
|
+
"version": "1.5.1-canary.2",
|
|
5
5
|
"description": "Opinionated MCP Framework for TypeScript (@modelcontextprotocol/sdk compatible) - Build MCP Agents and Clients + MCP Servers with support for MCP-UI.",
|
|
6
6
|
"author": "mcp-use, Inc.",
|
|
7
7
|
"license": "MIT",
|
|
@@ -115,8 +115,8 @@
|
|
|
115
115
|
"ws": "^8.18.2",
|
|
116
116
|
"zod": "^3.25.48",
|
|
117
117
|
"zod-to-json-schema": "^3.24.6",
|
|
118
|
-
"@mcp-use/cli": "2.3.1-canary.
|
|
119
|
-
"@mcp-use/inspector": "0.7.1-canary.
|
|
118
|
+
"@mcp-use/cli": "2.3.1-canary.2",
|
|
119
|
+
"@mcp-use/inspector": "0.7.1-canary.2"
|
|
120
120
|
},
|
|
121
121
|
"optionalDependencies": {
|
|
122
122
|
"@tailwindcss/vite": "^4.1.15",
|