mcp-use 1.5.0 → 1.5.1-canary.1
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/{chunk-WERYJ6PF.js → chunk-2AOGMX4T.js} +1 -1
- package/dist/{chunk-DSBKVAWD.js → chunk-2JBWOW4S.js} +152 -0
- package/dist/{chunk-UT7O4SIJ.js → chunk-BWOTID2D.js} +209 -75
- package/dist/{chunk-GPAOZN2F.js → chunk-QRABML5H.js} +15 -3
- package/dist/index.cjs +395 -84
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +30 -10
- package/dist/src/agents/index.cjs +1 -0
- package/dist/src/agents/index.js +2 -2
- package/dist/src/browser.cjs +351 -72
- package/dist/src/browser.d.ts +2 -0
- package/dist/src/browser.d.ts.map +1 -1
- package/dist/src/browser.js +2 -2
- package/dist/src/client/browser.d.ts.map +1 -1
- package/dist/src/client/prompts.cjs +3 -0
- package/dist/src/client/prompts.js +2 -2
- package/dist/src/client.d.ts +8 -0
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/config.d.ts +2 -1
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/connectors/base.d.ts +79 -1
- package/dist/src/connectors/base.d.ts.map +1 -1
- package/dist/src/connectors/http.d.ts +1 -0
- package/dist/src/connectors/http.d.ts.map +1 -1
- package/dist/src/connectors/stdio.d.ts.map +1 -1
- package/dist/src/connectors/websocket.d.ts +6 -0
- package/dist/src/connectors/websocket.d.ts.map +1 -1
- package/dist/src/react/index.cjs +365 -73
- package/dist/src/react/index.d.ts +1 -0
- package/dist/src/react/index.d.ts.map +1 -1
- package/dist/src/react/index.js +3 -3
- package/dist/src/react/types.d.ts +9 -1
- package/dist/src/react/types.d.ts.map +1 -1
- package/dist/src/react/useMcp.d.ts.map +1 -1
- package/dist/src/server/adapters/mcp-ui-adapter.d.ts +1 -0
- package/dist/src/server/adapters/mcp-ui-adapter.d.ts.map +1 -1
- package/dist/src/server/index.cjs +730 -192
- package/dist/src/server/index.js +730 -192
- 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 +201 -10
- package/dist/src/server/mcp-server.d.ts.map +1 -1
- package/dist/src/server/types/common.d.ts +59 -0
- package/dist/src/server/types/common.d.ts.map +1 -1
- package/dist/src/session.d.ts +40 -1
- package/dist/src/session.d.ts.map +1 -1
- package/package.json +10 -4
|
@@ -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,MAAM,MAAM,CAAC;AAyC1C;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,aAAa,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAsIzE"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { CreateMessageRequest, CreateMessageResult } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
+
import type { RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
1
3
|
import { type Hono as HonoType } from "hono";
|
|
2
4
|
import type { PromptDefinition, ResourceDefinition, ResourceTemplateDefinition, ServerConfig, ToolDefinition, UIResourceDefinition } from "./types/index.js";
|
|
3
5
|
export declare class McpServer {
|
|
@@ -12,6 +14,9 @@ export declare class McpServer {
|
|
|
12
14
|
private registeredTools;
|
|
13
15
|
private registeredPrompts;
|
|
14
16
|
private registeredResources;
|
|
17
|
+
private buildId?;
|
|
18
|
+
private sessions;
|
|
19
|
+
private idleCleanupInterval?;
|
|
15
20
|
/**
|
|
16
21
|
* Creates a new MCP server instance with Hono integration
|
|
17
22
|
*
|
|
@@ -175,6 +180,43 @@ export declare class McpServer {
|
|
|
175
180
|
* ```
|
|
176
181
|
*/
|
|
177
182
|
prompt(promptDefinition: PromptDefinition): this;
|
|
183
|
+
/**
|
|
184
|
+
* Request LLM sampling from connected clients.
|
|
185
|
+
*
|
|
186
|
+
* This method allows server tools to request LLM completions from clients
|
|
187
|
+
* that support the sampling capability. The client will handle model selection,
|
|
188
|
+
* user approval (human-in-the-loop), and return the generated response.
|
|
189
|
+
*
|
|
190
|
+
* @param params - Sampling request parameters including messages, model preferences, etc.
|
|
191
|
+
* @param options - Optional request options (timeouts, cancellation, etc.)
|
|
192
|
+
* @returns Promise resolving to the generated message from the client's LLM
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* ```typescript
|
|
196
|
+
* // In a tool callback
|
|
197
|
+
* server.tool({
|
|
198
|
+
* name: 'analyze-sentiment',
|
|
199
|
+
* description: 'Analyze sentiment using LLM',
|
|
200
|
+
* inputs: [{ name: 'text', type: 'string', required: true }],
|
|
201
|
+
* cb: async (params, ctx) => {
|
|
202
|
+
* const result = await ctx.sample({
|
|
203
|
+
* messages: [{
|
|
204
|
+
* role: 'user',
|
|
205
|
+
* content: { type: 'text', text: `Analyze sentiment: ${params.text}` }
|
|
206
|
+
* }],
|
|
207
|
+
* modelPreferences: {
|
|
208
|
+
* intelligencePriority: 0.8,
|
|
209
|
+
* speedPriority: 0.5
|
|
210
|
+
* }
|
|
211
|
+
* });
|
|
212
|
+
* return {
|
|
213
|
+
* content: [{ type: 'text', text: result.content.text }]
|
|
214
|
+
* };
|
|
215
|
+
* }
|
|
216
|
+
* })
|
|
217
|
+
* ```
|
|
218
|
+
*/
|
|
219
|
+
createMessage(params: CreateMessageRequest["params"], options?: RequestOptions): Promise<CreateMessageResult>;
|
|
178
220
|
/**
|
|
179
221
|
* Register a UI widget as both a tool and a resource
|
|
180
222
|
*
|
|
@@ -256,6 +298,16 @@ export declare class McpServer {
|
|
|
256
298
|
* @returns UIResource object compatible with MCP-UI
|
|
257
299
|
*/
|
|
258
300
|
private createWidgetUIResource;
|
|
301
|
+
/**
|
|
302
|
+
* Generate a widget URI with optional build ID for cache busting
|
|
303
|
+
*
|
|
304
|
+
* @private
|
|
305
|
+
* @param widgetName - Widget name/identifier
|
|
306
|
+
* @param extension - Optional file extension (e.g., '.html')
|
|
307
|
+
* @param suffix - Optional suffix (e.g., random ID for dynamic URIs)
|
|
308
|
+
* @returns Widget URI with build ID if available
|
|
309
|
+
*/
|
|
310
|
+
private generateWidgetUri;
|
|
259
311
|
/**
|
|
260
312
|
* Build a complete URL for a widget including query parameters
|
|
261
313
|
*
|
|
@@ -358,12 +410,11 @@ export declare class McpServer {
|
|
|
358
410
|
*/
|
|
359
411
|
private waitForRequestComplete;
|
|
360
412
|
/**
|
|
361
|
-
* Mount MCP server endpoints at /mcp
|
|
413
|
+
* Mount MCP server endpoints at /mcp and /sse
|
|
362
414
|
*
|
|
363
415
|
* Sets up the HTTP transport layer for the MCP server, creating endpoints for
|
|
364
416
|
* Server-Sent Events (SSE) streaming, POST message handling, and DELETE session cleanup.
|
|
365
|
-
*
|
|
366
|
-
* concurrent client connections.
|
|
417
|
+
* Transports are reused per session ID to maintain state across requests.
|
|
367
418
|
*
|
|
368
419
|
* This method is called automatically when the server starts listening and ensures
|
|
369
420
|
* that MCP clients can communicate with the server over HTTP.
|
|
@@ -373,9 +424,9 @@ export declare class McpServer {
|
|
|
373
424
|
*
|
|
374
425
|
* @example
|
|
375
426
|
* Endpoints created:
|
|
376
|
-
* - GET /mcp - SSE streaming endpoint for real-time communication
|
|
377
|
-
* - POST /mcp - Message handling endpoint for MCP protocol messages
|
|
378
|
-
* - DELETE /mcp - Session cleanup endpoint
|
|
427
|
+
* - GET /mcp, GET /sse - SSE streaming endpoint for real-time communication
|
|
428
|
+
* - POST /mcp, POST /sse - Message handling endpoint for MCP protocol messages
|
|
429
|
+
* - DELETE /mcp, DELETE /sse - Session cleanup endpoint
|
|
379
430
|
*/
|
|
380
431
|
private mountMcp;
|
|
381
432
|
/**
|
|
@@ -385,7 +436,7 @@ export declare class McpServer {
|
|
|
385
436
|
* the inspector UI (if available), and starting the server to listen
|
|
386
437
|
* for incoming connections. This is the main entry point for running the server.
|
|
387
438
|
*
|
|
388
|
-
* The server will be accessible at the specified port with MCP endpoints at /mcp
|
|
439
|
+
* The server will be accessible at the specified port with MCP endpoints at /mcp and /sse
|
|
389
440
|
* and inspector UI at /inspector (if the inspector package is installed).
|
|
390
441
|
*
|
|
391
442
|
* @param port - Port number to listen on (defaults to 3001 if not specified)
|
|
@@ -395,7 +446,7 @@ export declare class McpServer {
|
|
|
395
446
|
* ```typescript
|
|
396
447
|
* await server.listen(8080)
|
|
397
448
|
* // Server now running at http://localhost:8080 (or configured host)
|
|
398
|
-
* // MCP endpoints: http://localhost:8080/mcp
|
|
449
|
+
* // MCP endpoints: http://localhost:8080/mcp and http://localhost:8080/sse
|
|
399
450
|
* // Inspector UI: http://localhost:8080/inspector
|
|
400
451
|
* ```
|
|
401
452
|
*/
|
|
@@ -440,6 +491,132 @@ export declare class McpServer {
|
|
|
440
491
|
getHandler(options?: {
|
|
441
492
|
provider?: "supabase" | "cloudflare" | "deno-deploy";
|
|
442
493
|
}): Promise<(req: Request) => Promise<Response>>;
|
|
494
|
+
/**
|
|
495
|
+
* Get array of active session IDs
|
|
496
|
+
*
|
|
497
|
+
* Returns an array of all currently active session IDs. This is useful for
|
|
498
|
+
* sending targeted notifications to specific clients or iterating over
|
|
499
|
+
* connected clients.
|
|
500
|
+
*
|
|
501
|
+
* Note: This only works in stateful mode. In stateless mode (edge environments),
|
|
502
|
+
* this will return an empty array.
|
|
503
|
+
*
|
|
504
|
+
* @returns Array of active session ID strings
|
|
505
|
+
*
|
|
506
|
+
* @example
|
|
507
|
+
* ```typescript
|
|
508
|
+
* const sessions = server.getActiveSessions();
|
|
509
|
+
* console.log(`${sessions.length} clients connected`);
|
|
510
|
+
*
|
|
511
|
+
* // Send notification to first connected client
|
|
512
|
+
* if (sessions.length > 0) {
|
|
513
|
+
* server.sendNotificationToSession(sessions[0], "custom/hello", { message: "Hi!" });
|
|
514
|
+
* }
|
|
515
|
+
* ```
|
|
516
|
+
*/
|
|
517
|
+
getActiveSessions(): string[];
|
|
518
|
+
/**
|
|
519
|
+
* Send a notification to all connected clients
|
|
520
|
+
*
|
|
521
|
+
* Broadcasts a JSON-RPC notification to all active sessions. Notifications are
|
|
522
|
+
* one-way messages that do not expect a response from the client.
|
|
523
|
+
*
|
|
524
|
+
* Note: This only works in stateful mode with active sessions. If no sessions
|
|
525
|
+
* are connected, the notification is silently discarded (per MCP spec: "server MAY send").
|
|
526
|
+
*
|
|
527
|
+
* @param method - The notification method name (e.g., "custom/my-notification")
|
|
528
|
+
* @param params - Optional parameters to include in the notification
|
|
529
|
+
*
|
|
530
|
+
* @example
|
|
531
|
+
* ```typescript
|
|
532
|
+
* // Send a simple notification to all clients
|
|
533
|
+
* server.sendNotification("custom/server-status", {
|
|
534
|
+
* status: "ready",
|
|
535
|
+
* timestamp: new Date().toISOString()
|
|
536
|
+
* });
|
|
537
|
+
*
|
|
538
|
+
* // Notify all clients that resources have changed
|
|
539
|
+
* server.sendNotification("notifications/resources/list_changed");
|
|
540
|
+
* ```
|
|
541
|
+
*/
|
|
542
|
+
sendNotification(method: string, params?: Record<string, unknown>): Promise<void>;
|
|
543
|
+
/**
|
|
544
|
+
* Send a notification to a specific client session
|
|
545
|
+
*
|
|
546
|
+
* Sends a JSON-RPC notification to a single client identified by their session ID.
|
|
547
|
+
* This allows sending customized notifications to individual clients.
|
|
548
|
+
*
|
|
549
|
+
* Note: This only works in stateful mode. If the session ID doesn't exist,
|
|
550
|
+
* the notification is silently discarded.
|
|
551
|
+
*
|
|
552
|
+
* @param sessionId - The target session ID (from getActiveSessions())
|
|
553
|
+
* @param method - The notification method name (e.g., "custom/my-notification")
|
|
554
|
+
* @param params - Optional parameters to include in the notification
|
|
555
|
+
* @returns true if the notification was sent, false if session not found
|
|
556
|
+
*
|
|
557
|
+
* @example
|
|
558
|
+
* ```typescript
|
|
559
|
+
* const sessions = server.getActiveSessions();
|
|
560
|
+
*
|
|
561
|
+
* // Send different messages to different clients
|
|
562
|
+
* sessions.forEach((sessionId, index) => {
|
|
563
|
+
* server.sendNotificationToSession(sessionId, "custom/welcome", {
|
|
564
|
+
* message: `Hello client #${index + 1}!`,
|
|
565
|
+
* clientNumber: index + 1
|
|
566
|
+
* });
|
|
567
|
+
* });
|
|
568
|
+
* ```
|
|
569
|
+
*/
|
|
570
|
+
sendNotificationToSession(sessionId: string, method: string, params?: Record<string, unknown>): Promise<boolean>;
|
|
571
|
+
private onRootsChangedCallback?;
|
|
572
|
+
/**
|
|
573
|
+
* Register a callback for when a client's roots change
|
|
574
|
+
*
|
|
575
|
+
* When a client sends a `notifications/roots/list_changed` notification,
|
|
576
|
+
* the server will automatically request the updated roots list and call
|
|
577
|
+
* this callback with the new roots.
|
|
578
|
+
*
|
|
579
|
+
* @param callback - Function called with the updated roots array
|
|
580
|
+
*
|
|
581
|
+
* @example
|
|
582
|
+
* ```typescript
|
|
583
|
+
* server.onRootsChanged(async (roots) => {
|
|
584
|
+
* console.log("Client roots updated:", roots);
|
|
585
|
+
* roots.forEach(root => {
|
|
586
|
+
* console.log(` - ${root.name || "unnamed"}: ${root.uri}`);
|
|
587
|
+
* });
|
|
588
|
+
* });
|
|
589
|
+
* ```
|
|
590
|
+
*/
|
|
591
|
+
onRootsChanged(callback: (roots: Array<{
|
|
592
|
+
uri: string;
|
|
593
|
+
name?: string;
|
|
594
|
+
}>) => void | Promise<void>): this;
|
|
595
|
+
/**
|
|
596
|
+
* Request the current roots list from a specific client session
|
|
597
|
+
*
|
|
598
|
+
* This sends a `roots/list` request to the client and returns
|
|
599
|
+
* the list of roots the client has configured.
|
|
600
|
+
*
|
|
601
|
+
* @param sessionId - The session ID of the client to query
|
|
602
|
+
* @returns Array of roots, or null if the session doesn't exist or request fails
|
|
603
|
+
*
|
|
604
|
+
* @example
|
|
605
|
+
* ```typescript
|
|
606
|
+
* const sessions = server.getActiveSessions();
|
|
607
|
+
* if (sessions.length > 0) {
|
|
608
|
+
* const roots = await server.listRoots(sessions[0]);
|
|
609
|
+
* if (roots) {
|
|
610
|
+
* console.log(`Client has ${roots.length} roots:`);
|
|
611
|
+
* roots.forEach(r => console.log(` - ${r.uri}`));
|
|
612
|
+
* }
|
|
613
|
+
* }
|
|
614
|
+
* ```
|
|
615
|
+
*/
|
|
616
|
+
listRoots(sessionId: string): Promise<Array<{
|
|
617
|
+
uri: string;
|
|
618
|
+
name?: string;
|
|
619
|
+
}> | null>;
|
|
443
620
|
/**
|
|
444
621
|
* Mount MCP Inspector UI at /inspector
|
|
445
622
|
*
|
|
@@ -456,7 +633,7 @@ export declare class McpServer {
|
|
|
456
633
|
* @example
|
|
457
634
|
* If @mcp-use/inspector is installed:
|
|
458
635
|
* - Inspector UI available at http://localhost:PORT/inspector
|
|
459
|
-
* - Automatically connects to http://localhost:PORT/mcp
|
|
636
|
+
* - Automatically connects to http://localhost:PORT/mcp (or /sse)
|
|
460
637
|
*
|
|
461
638
|
* If not installed:
|
|
462
639
|
* - Server continues to function normally
|
|
@@ -591,16 +768,30 @@ export type McpServerInstance = Omit<McpServer, keyof HonoType> & HonoType & {
|
|
|
591
768
|
* @param config.description - Server description
|
|
592
769
|
* @param config.host - Hostname for widget URLs and server endpoints (defaults to 'localhost')
|
|
593
770
|
* @param config.baseUrl - Full base URL (e.g., 'https://myserver.com') - overrides host:port for widget URLs
|
|
771
|
+
* @param config.allowedOrigins - Allowed origins for DNS rebinding protection
|
|
772
|
+
* - **Development mode** (NODE_ENV !== "production"): If not set, all origins are allowed
|
|
773
|
+
* - **Production mode** (NODE_ENV === "production"): Only uses explicitly configured origins
|
|
774
|
+
* - See {@link ServerConfig.allowedOrigins} for detailed documentation
|
|
775
|
+
* @param config.sessionIdleTimeoutMs - Idle timeout for sessions in milliseconds (default: 300000 = 5 minutes)
|
|
594
776
|
* @returns McpServerInstance with both MCP and Hono methods
|
|
595
777
|
*
|
|
596
778
|
* @example
|
|
597
779
|
* ```typescript
|
|
598
|
-
* // Basic usage
|
|
780
|
+
* // Basic usage (development mode - allows all origins)
|
|
599
781
|
* const server = createMCPServer('my-server', {
|
|
600
782
|
* version: '1.0.0',
|
|
601
783
|
* description: 'My MCP server'
|
|
602
784
|
* })
|
|
603
785
|
*
|
|
786
|
+
* // Production mode with explicit allowed origins
|
|
787
|
+
* const server = createMCPServer('my-server', {
|
|
788
|
+
* version: '1.0.0',
|
|
789
|
+
* allowedOrigins: [
|
|
790
|
+
* 'https://myapp.com',
|
|
791
|
+
* 'https://app.myapp.com'
|
|
792
|
+
* ]
|
|
793
|
+
* })
|
|
794
|
+
*
|
|
604
795
|
* // With custom host (e.g., for Docker or remote access)
|
|
605
796
|
* const server = createMCPServer('my-server', {
|
|
606
797
|
* version: '1.0.0',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../../../src/server/mcp-server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../../../src/server/mcp-server.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,oBAAoB,EACpB,mBAAm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;;;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"}
|
|
@@ -7,6 +7,65 @@ export interface ServerConfig {
|
|
|
7
7
|
description?: string;
|
|
8
8
|
host?: string;
|
|
9
9
|
baseUrl?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Allowed origins for DNS rebinding protection
|
|
12
|
+
*
|
|
13
|
+
* **Development mode** (NODE_ENV !== "production"):
|
|
14
|
+
* - If not set: All origins are allowed (DNS rebinding protection disabled)
|
|
15
|
+
* - This enables direct browser connections from any origin for easier development
|
|
16
|
+
*
|
|
17
|
+
* **Production mode** (NODE_ENV === "production"):
|
|
18
|
+
* - If not set: DNS rebinding protection is disabled (not recommended for production)
|
|
19
|
+
* - If set to empty array: DNS rebinding protection is disabled
|
|
20
|
+
* - If set with origins: DNS rebinding protection is enabled with those specific origins
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* // Development: No need to set (allows all origins)
|
|
25
|
+
* const server = createMCPServer('my-server');
|
|
26
|
+
*
|
|
27
|
+
* // Production: Explicitly set allowed origins
|
|
28
|
+
* const server = createMCPServer('my-server', {
|
|
29
|
+
* allowedOrigins: [
|
|
30
|
+
* 'https://myapp.com',
|
|
31
|
+
* 'https://app.myapp.com'
|
|
32
|
+
* ]
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
allowedOrigins?: string[];
|
|
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;
|
|
10
69
|
}
|
|
11
70
|
export interface InputDefinition {
|
|
12
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;
|
|
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/dist/src/session.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Notification, Root } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
+
import type { BaseConnector, NotificationHandler } from "./connectors/base.js";
|
|
2
3
|
export declare class MCPSession {
|
|
3
4
|
readonly connector: BaseConnector;
|
|
4
5
|
private autoConnect;
|
|
@@ -7,5 +8,43 @@ export declare class MCPSession {
|
|
|
7
8
|
disconnect(): Promise<void>;
|
|
8
9
|
initialize(): Promise<void>;
|
|
9
10
|
get isConnected(): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Register an event handler for session events
|
|
13
|
+
*
|
|
14
|
+
* @param event - The event type to listen for
|
|
15
|
+
* @param handler - The handler function to call when the event occurs
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* session.on("notification", async (notification) => {
|
|
20
|
+
* console.log(`Received: ${notification.method}`, notification.params);
|
|
21
|
+
*
|
|
22
|
+
* if (notification.method === "notifications/tools/list_changed") {
|
|
23
|
+
* // Refresh tools list
|
|
24
|
+
* }
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
on(event: "notification", handler: NotificationHandler): void;
|
|
29
|
+
/**
|
|
30
|
+
* Set roots and notify the server.
|
|
31
|
+
* Roots represent directories or files that the client has access to.
|
|
32
|
+
*
|
|
33
|
+
* @param roots - Array of Root objects with `uri` (must start with "file://") and optional `name`
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* await session.setRoots([
|
|
38
|
+
* { uri: "file:///home/user/project", name: "My Project" },
|
|
39
|
+
* { uri: "file:///home/user/data" }
|
|
40
|
+
* ]);
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
setRoots(roots: Root[]): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Get the current roots.
|
|
46
|
+
*/
|
|
47
|
+
getRoots(): Root[];
|
|
10
48
|
}
|
|
49
|
+
export type { Notification, Root };
|
|
11
50
|
//# sourceMappingURL=session.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,oCAAoC,CAAC;AAC7E,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE/E,qBAAa,UAAU;IACrB,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC;IAClC,OAAO,CAAC,WAAW,CAAU;gBAEjB,SAAS,EAAE,aAAa,EAAE,WAAW,UAAO;IAKlD,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAOjC,IAAI,WAAW,IAAI,OAAO,CAEzB;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,EAAE,CAAC,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,mBAAmB,GAAG,IAAI;IAM7D;;;;;;;;;;;;;OAaG;IACG,QAAQ,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5C;;OAEG;IACH,QAAQ,IAAI,IAAI,EAAE;CAGnB;AAGD,YAAY,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-use",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.5.
|
|
4
|
+
"version": "1.5.1-canary.1",
|
|
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.
|
|
119
|
-
"@mcp-use/inspector": "0.7.
|
|
118
|
+
"@mcp-use/cli": "2.3.1-canary.1",
|
|
119
|
+
"@mcp-use/inspector": "0.7.1-canary.1"
|
|
120
120
|
},
|
|
121
121
|
"optionalDependencies": {
|
|
122
122
|
"@tailwindcss/vite": "^4.1.15",
|
|
@@ -193,6 +193,12 @@
|
|
|
193
193
|
"example:structured": "tsx examples/client/structured_output.ts",
|
|
194
194
|
"example:observability": "tsx examples/client/observability.ts",
|
|
195
195
|
"example:code_mode": "tsx examples/client/code_mode_example.ts",
|
|
196
|
-
"example:code_mode_e2b": "source .env 2>/dev/null || true && tsx examples/client/code_mode_e2b_example.ts"
|
|
196
|
+
"example:code_mode_e2b": "source .env 2>/dev/null || true && tsx examples/client/code_mode_e2b_example.ts",
|
|
197
|
+
"example:server:notification": "tsx examples/server/notification-example/src/server.ts",
|
|
198
|
+
"example:client:notification": "tsx examples/client/notification-client.ts",
|
|
199
|
+
"example:notifications": "lsof -ti:3000 | xargs kill -9 2>/dev/null; tsx examples/server/notification-example/src/server.ts & sleep 3 && tsx examples/client/notification-client.ts",
|
|
200
|
+
"example:server:sampling": "tsx examples/server/sampling/src/server.ts",
|
|
201
|
+
"example:client:sampling": "tsx examples/client/sampling-client.ts",
|
|
202
|
+
"example:sampling": "lsof -ti:3001 | xargs kill -9 2>/dev/null; tsx examples/server/sampling/src/server.ts & sleep 3 && tsx examples/client/sampling-client.ts"
|
|
197
203
|
}
|
|
198
204
|
}
|