mcp-use 1.10.6 → 1.11.0-canary.10
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 +1 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/{chunk-JH3ZOGLI.js → chunk-3GB7G5X7.js} +2 -2
- package/dist/{chunk-EEUJZMOP.js → chunk-5QAXQTDL.js} +1 -1
- package/dist/{chunk-44DFBJUL.js → chunk-BEGEDH6P.js} +196 -496
- package/dist/{chunk-FDKY2O5P.js → chunk-BLGIG2QD.js} +443 -969
- package/dist/{chunk-BLWPCOUZ.js → chunk-CBJTHTR4.js} +3 -8
- package/dist/{chunk-34R6SIER.js → chunk-FRUZDWXH.js} +1 -1
- package/dist/chunk-GUB5GQDD.js +101 -0
- package/dist/chunk-GXNAXUDI.js +0 -0
- package/dist/{chunk-CPG2WZUL.js → chunk-JRGQRPTN.js} +1 -1
- package/dist/chunk-MFSO5PUW.js +1049 -0
- package/dist/{chunk-D5WOXLJ2.js → chunk-NXFHUS7A.js} +171 -11
- package/dist/chunk-ULFNVP5Z.js +12 -0
- package/dist/chunk-UWWLWLS2.js +62 -0
- package/dist/chunk-VTEYN43V.js +1055 -0
- package/dist/{chunk-KIWNNI6F.js → chunk-XPTKLSBC.js} +16 -2
- package/dist/index.cjs +5065 -4608
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +53 -1068
- package/dist/{langfuse-N5Y5BSXK.js → langfuse-74RGPTAH.js} +2 -2
- package/dist/notifications-FLGIFS56.js +9 -0
- package/dist/src/adapters/base.d.ts +44 -0
- package/dist/src/adapters/base.d.ts.map +1 -1
- package/dist/src/adapters/index.cjs +1346 -0
- package/dist/src/adapters/index.js +11 -0
- package/dist/src/adapters/langchain_adapter.d.ts +12 -1
- package/dist/src/adapters/langchain_adapter.d.ts.map +1 -1
- package/dist/src/agents/index.cjs +3141 -159
- package/dist/src/agents/index.d.ts +2 -0
- package/dist/src/agents/index.d.ts.map +1 -1
- package/dist/src/agents/index.js +10 -6
- package/dist/src/agents/mcp_agent.d.ts +59 -37
- package/dist/src/agents/mcp_agent.d.ts.map +1 -1
- package/dist/src/agents/remote.d.ts +25 -0
- package/dist/src/agents/remote.d.ts.map +1 -1
- package/dist/src/agents/types.d.ts +76 -0
- package/dist/src/agents/types.d.ts.map +1 -1
- package/dist/src/agents/utils/index.d.ts +1 -0
- package/dist/src/agents/utils/index.d.ts.map +1 -1
- package/dist/src/agents/utils/llm_provider.d.ts +53 -0
- package/dist/src/agents/utils/llm_provider.d.ts.map +1 -0
- package/dist/src/browser.cjs +1856 -423
- package/dist/src/browser.d.ts +1 -2
- package/dist/src/browser.d.ts.map +1 -1
- package/dist/src/browser.js +26 -15
- package/dist/src/client/base.d.ts +1 -0
- package/dist/src/client/base.d.ts.map +1 -1
- package/dist/src/client/browser.d.ts +2 -2
- package/dist/src/client/browser.d.ts.map +1 -1
- package/dist/src/client/prompts.cjs +1 -1
- package/dist/src/client/prompts.js +5 -4
- package/dist/src/client.cjs +3787 -0
- package/dist/src/client.js +20 -0
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/connectors/base.d.ts +8 -0
- package/dist/src/connectors/base.d.ts.map +1 -1
- package/dist/src/connectors/index.d.ts +0 -1
- package/dist/src/connectors/index.d.ts.map +1 -1
- package/dist/src/managers/server_manager.d.ts.map +1 -1
- package/dist/src/managers/tools/connect_mcp_server.d.ts.map +1 -1
- package/dist/src/react/index.cjs +259 -298
- package/dist/src/react/index.js +6 -5
- package/dist/src/react/types.d.ts +42 -4
- package/dist/src/react/types.d.ts.map +1 -1
- package/dist/src/react/useMcp.d.ts.map +1 -1
- package/dist/src/react/useWidget.d.ts +11 -7
- package/dist/src/react/useWidget.d.ts.map +1 -1
- package/dist/src/react/widget-types.d.ts +6 -2
- package/dist/src/react/widget-types.d.ts.map +1 -1
- package/dist/src/server/endpoints/mount-mcp.d.ts.map +1 -1
- package/dist/src/server/index.cjs +1288 -140
- package/dist/src/server/index.d.ts +2 -0
- package/dist/src/server/index.d.ts.map +1 -1
- package/dist/src/server/index.js +1183 -102
- package/dist/src/server/mcp-server.d.ts +5 -1
- package/dist/src/server/mcp-server.d.ts.map +1 -1
- package/dist/src/server/notifications/index.d.ts +1 -1
- package/dist/src/server/notifications/index.d.ts.map +1 -1
- package/dist/src/server/notifications/notification-registration.d.ts +51 -0
- package/dist/src/server/notifications/notification-registration.d.ts.map +1 -1
- package/dist/src/server/sessions/index.d.ts +3 -1
- package/dist/src/server/sessions/index.d.ts.map +1 -1
- package/dist/src/server/sessions/session-manager.d.ts +36 -19
- package/dist/src/server/sessions/session-manager.d.ts.map +1 -1
- package/dist/src/server/sessions/stores/filesystem.d.ts +121 -0
- package/dist/src/server/sessions/stores/filesystem.d.ts.map +1 -0
- package/dist/src/server/sessions/stores/index.d.ts +94 -0
- package/dist/src/server/sessions/stores/index.d.ts.map +1 -0
- package/dist/src/server/sessions/stores/memory.d.ts +82 -0
- package/dist/src/server/sessions/stores/memory.d.ts.map +1 -0
- package/dist/src/server/sessions/stores/redis.d.ts +164 -0
- package/dist/src/server/sessions/stores/redis.d.ts.map +1 -0
- package/dist/src/server/sessions/streams/index.d.ts +77 -0
- package/dist/src/server/sessions/streams/index.d.ts.map +1 -0
- package/dist/src/server/sessions/streams/memory.d.ts +76 -0
- package/dist/src/server/sessions/streams/memory.d.ts.map +1 -0
- package/dist/src/server/sessions/streams/redis.d.ts +146 -0
- package/dist/src/server/sessions/streams/redis.d.ts.map +1 -0
- package/dist/src/server/types/common.d.ts +105 -28
- package/dist/src/server/types/common.d.ts.map +1 -1
- package/dist/src/server/types/resource.d.ts +16 -0
- package/dist/src/server/types/resource.d.ts.map +1 -1
- package/dist/src/server/types/widget.d.ts +21 -2
- package/dist/src/server/types/widget.d.ts.map +1 -1
- package/dist/src/server/utils/response-helpers.d.ts +12 -6
- package/dist/src/server/utils/response-helpers.d.ts.map +1 -1
- package/dist/src/server/widgets/index.d.ts +1 -1
- package/dist/src/server/widgets/index.d.ts.map +1 -1
- package/dist/src/server/widgets/mount-widgets-dev.d.ts.map +1 -1
- package/dist/src/server/widgets/setup-widget-routes.d.ts.map +1 -1
- package/dist/src/server/widgets/ui-resource-registration.d.ts.map +1 -1
- package/dist/src/server/widgets/widget-helpers.d.ts +22 -0
- package/dist/src/server/widgets/widget-helpers.d.ts.map +1 -1
- package/dist/src/server/widgets/widget-types.d.ts +2 -0
- package/dist/src/server/widgets/widget-types.d.ts.map +1 -1
- package/dist/src/session.d.ts +16 -2
- package/dist/src/session.d.ts.map +1 -1
- package/dist/src/task_managers/index.d.ts +10 -1
- package/dist/src/task_managers/index.d.ts.map +1 -1
- package/dist/src/task_managers/sse.d.ts +34 -1
- package/dist/src/task_managers/sse.d.ts.map +1 -1
- package/dist/src/task_managers/streamable_http.d.ts +8 -2
- package/dist/src/task_managers/streamable_http.d.ts.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.d.ts.map +1 -1
- package/dist/{tool-execution-helpers-4X6A63AS.js → tool-execution-helpers-N7R7YGAW.js} +3 -3
- package/dist/tsup.config.d.ts.map +1 -1
- package/package.json +47 -14
- package/dist/src/connectors/websocket.d.ts +0 -38
- package/dist/src/connectors/websocket.d.ts.map +0 -1
- package/dist/src/task_managers/websocket.d.ts +0 -18
- package/dist/src/task_managers/websocket.d.ts.map +0 -1
- /package/dist/{chunk-EW4MJSHA.js → chunk-LGDFGYRL.js} +0 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Redis Session Store
|
|
3
|
+
*
|
|
4
|
+
* Production-ready session storage using Redis for persistence across restarts
|
|
5
|
+
* and distributed deployments.
|
|
6
|
+
*
|
|
7
|
+
* **Note:** Redis is an optional dependency. Install it with:
|
|
8
|
+
* ```bash
|
|
9
|
+
* npm install redis
|
|
10
|
+
* # or
|
|
11
|
+
* pnpm add redis
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* If Redis is not installed, importing this module will throw an error at runtime
|
|
15
|
+
* when attempting to use RedisSessionStore. Use dynamic imports with error handling
|
|
16
|
+
* if you want to gracefully fall back when Redis is not available.
|
|
17
|
+
*
|
|
18
|
+
* Supports:
|
|
19
|
+
* - Session persistence across server restarts
|
|
20
|
+
* - Distributed session sharing (load balancing)
|
|
21
|
+
* - Automatic TTL-based expiration
|
|
22
|
+
* - Connection pooling and error handling
|
|
23
|
+
*/
|
|
24
|
+
import type { SessionStore } from "./index.js";
|
|
25
|
+
import type { SessionMetadata } from "../session-manager.js";
|
|
26
|
+
/**
|
|
27
|
+
* Check if Redis is available as an optional dependency
|
|
28
|
+
* @returns true if Redis can be imported, false otherwise
|
|
29
|
+
*/
|
|
30
|
+
export declare function isRedisAvailable(): Promise<boolean>;
|
|
31
|
+
/**
|
|
32
|
+
* Redis client interface - compatible with node-redis v5+ and ioredis
|
|
33
|
+
*/
|
|
34
|
+
export interface RedisClient {
|
|
35
|
+
get(key: string): Promise<string | null>;
|
|
36
|
+
set(key: string, value: string, options?: any): Promise<string | null>;
|
|
37
|
+
setEx?(key: string, seconds: number, value: string): Promise<string | null>;
|
|
38
|
+
setex?(key: string, seconds: number, value: string): Promise<string | null>;
|
|
39
|
+
del(key: string | string[]): Promise<number>;
|
|
40
|
+
exists(key: string | string[]): Promise<number>;
|
|
41
|
+
keys(pattern: string): Promise<string[]>;
|
|
42
|
+
expire?(key: string, seconds: number): Promise<boolean | number>;
|
|
43
|
+
sAdd?(key: string, ...members: string[]): Promise<number>;
|
|
44
|
+
sRem?(key: string, ...members: string[]): Promise<number>;
|
|
45
|
+
sMembers?(key: string): Promise<string[]>;
|
|
46
|
+
publish?(channel: string, message: string): Promise<number>;
|
|
47
|
+
subscribe?(channel: string, callback: (message: string) => void): Promise<number | void>;
|
|
48
|
+
unsubscribe?(channel: string): Promise<number | void>;
|
|
49
|
+
quit(): Promise<string | "OK">;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Configuration for Redis session store
|
|
53
|
+
*/
|
|
54
|
+
export interface RedisSessionStoreConfig {
|
|
55
|
+
/**
|
|
56
|
+
* Redis client instance (node-redis or ioredis)
|
|
57
|
+
* Must be already connected
|
|
58
|
+
*/
|
|
59
|
+
client: RedisClient;
|
|
60
|
+
/**
|
|
61
|
+
* Key prefix for session storage (default: "mcp:session:")
|
|
62
|
+
*/
|
|
63
|
+
prefix?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Default TTL in seconds for sessions (default: 3600 = 1 hour)
|
|
66
|
+
*/
|
|
67
|
+
defaultTTL?: number;
|
|
68
|
+
/**
|
|
69
|
+
* Whether to serialize/deserialize session data (default: true)
|
|
70
|
+
*/
|
|
71
|
+
serialize?: boolean;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Redis-backed session metadata storage
|
|
75
|
+
*
|
|
76
|
+
* Stores ONLY serializable metadata (client capabilities, log level, timestamps).
|
|
77
|
+
* For managing active SSE streams, use RedisStreamManager.
|
|
78
|
+
*
|
|
79
|
+
* Suitable for:
|
|
80
|
+
* - Production deployments requiring session persistence
|
|
81
|
+
* - Distributed/clustered applications
|
|
82
|
+
* - Load-balanced environments
|
|
83
|
+
* - Horizontal scaling scenarios
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* import { MCPServer, RedisSessionStore, RedisStreamManager } from 'mcp-use/server';
|
|
88
|
+
* import { createClient } from 'redis';
|
|
89
|
+
*
|
|
90
|
+
* // Create Redis clients (two needed for Pub/Sub)
|
|
91
|
+
* const redis = createClient({ url: process.env.REDIS_URL });
|
|
92
|
+
* const pubSubRedis = redis.duplicate();
|
|
93
|
+
*
|
|
94
|
+
* await redis.connect();
|
|
95
|
+
* await pubSubRedis.connect();
|
|
96
|
+
*
|
|
97
|
+
* // Create stores
|
|
98
|
+
* const sessionStore = new RedisSessionStore({ client: redis });
|
|
99
|
+
* const streamManager = new RedisStreamManager({
|
|
100
|
+
* client: redis,
|
|
101
|
+
* pubSubClient: pubSubRedis
|
|
102
|
+
* });
|
|
103
|
+
*
|
|
104
|
+
* // Use with MCP server
|
|
105
|
+
* const server = new MCPServer({
|
|
106
|
+
* name: 'my-server',
|
|
107
|
+
* version: '1.0.0',
|
|
108
|
+
* sessionStore,
|
|
109
|
+
* streamManager
|
|
110
|
+
* });
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export declare class RedisSessionStore implements SessionStore {
|
|
114
|
+
private client;
|
|
115
|
+
private prefix;
|
|
116
|
+
private defaultTTL;
|
|
117
|
+
constructor(config: RedisSessionStoreConfig);
|
|
118
|
+
/**
|
|
119
|
+
* Get full Redis key for a session ID
|
|
120
|
+
*/
|
|
121
|
+
private getKey;
|
|
122
|
+
/**
|
|
123
|
+
* Retrieve session metadata by ID
|
|
124
|
+
*/
|
|
125
|
+
get(sessionId: string): Promise<SessionMetadata | null>;
|
|
126
|
+
/**
|
|
127
|
+
* Store or update session metadata
|
|
128
|
+
*/
|
|
129
|
+
set(sessionId: string, data: SessionMetadata): Promise<void>;
|
|
130
|
+
/**
|
|
131
|
+
* Delete a session
|
|
132
|
+
*/
|
|
133
|
+
delete(sessionId: string): Promise<void>;
|
|
134
|
+
/**
|
|
135
|
+
* Check if a session exists
|
|
136
|
+
*/
|
|
137
|
+
has(sessionId: string): Promise<boolean>;
|
|
138
|
+
/**
|
|
139
|
+
* List all session IDs
|
|
140
|
+
*
|
|
141
|
+
* WARNING: Uses KEYS command which blocks Redis. For production systems with
|
|
142
|
+
* many sessions, consider using SCAN instead or maintaining a separate SET of
|
|
143
|
+
* active session IDs.
|
|
144
|
+
*/
|
|
145
|
+
keys(): Promise<string[]>;
|
|
146
|
+
/**
|
|
147
|
+
* Store session metadata with custom TTL (time-to-live)
|
|
148
|
+
*/
|
|
149
|
+
setWithTTL(sessionId: string, data: SessionMetadata, ttlMs: number): Promise<void>;
|
|
150
|
+
/**
|
|
151
|
+
* Close Redis connection
|
|
152
|
+
* Should be called when shutting down the server
|
|
153
|
+
*/
|
|
154
|
+
close(): Promise<void>;
|
|
155
|
+
/**
|
|
156
|
+
* Clear all sessions (useful for testing)
|
|
157
|
+
* WARNING: This will delete all sessions with the configured prefix
|
|
158
|
+
*
|
|
159
|
+
* NOTE: Uses KEYS command which blocks Redis. This is acceptable for testing
|
|
160
|
+
* but should be avoided in production with large datasets.
|
|
161
|
+
*/
|
|
162
|
+
clear(): Promise<void>;
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=redis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redis.d.ts","sourceRoot":"","sources":["../../../../../src/server/sessions/stores/redis.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D;;;GAGG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,OAAO,CAAC,CAOzD;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACzC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACvE,KAAK,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC5E,KAAK,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC5E,GAAG,CAAC,GAAG,EAAE,MAAM,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,CAAC;IAEpB;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,qBAAa,iBAAkB,YAAW,YAAY;IACpD,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,UAAU,CAAS;gBAEf,MAAM,EAAE,uBAAuB;IAM3C;;OAEG;IACH,OAAO,CAAC,MAAM;IAId;;OAEG;IACG,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IAmB7D;;OAEG;IACG,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAuBlE;;OAEG;IACG,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAa9C;;OAEG;IACG,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAc9C;;;;;;OAMG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAa/B;;OAEG;IACG,UAAU,CACd,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,eAAe,EACrB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC;IAuBhB;;;OAGG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAY5B;;;;;;OAMG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAa7B"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stream Manager Interface
|
|
3
|
+
*
|
|
4
|
+
* Handles active SSE/streaming connections separately from session metadata storage.
|
|
5
|
+
* This separation enables notifications, sampling, and resource subscriptions to work
|
|
6
|
+
* across distributed servers when using external storage (Redis, Postgres).
|
|
7
|
+
*
|
|
8
|
+
* Inspired by tmcp's split architecture between StreamSessionManager and InfoSessionManager.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Abstract interface for managing active SSE stream connections
|
|
12
|
+
*
|
|
13
|
+
* Unlike SessionStore (which stores serializable metadata), StreamManager handles
|
|
14
|
+
* ACTIVE connections that cannot be serialized (ReadableStreamDefaultController, WebSockets).
|
|
15
|
+
*
|
|
16
|
+
* Key responsibilities:
|
|
17
|
+
* - Manage active SSE stream controllers
|
|
18
|
+
* - Enable server-to-client push (notifications, sampling responses)
|
|
19
|
+
* - Support distributed notifications via message bus (Redis Pub/Sub, Postgres NOTIFY)
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* // Redis-backed stream manager for distributed deployments
|
|
24
|
+
* const streamManager = new RedisStreamManager({
|
|
25
|
+
* url: process.env.REDIS_URL,
|
|
26
|
+
* password: process.env.REDIS_PASSWORD
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // When SSE connection is established
|
|
30
|
+
* await streamManager.create(sessionId, controller);
|
|
31
|
+
*
|
|
32
|
+
* // From any server instance - send notification to client
|
|
33
|
+
* await streamManager.send([sessionId], 'event: message\ndata: {...}\n\n');
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export interface StreamManager {
|
|
37
|
+
/**
|
|
38
|
+
* Register an active SSE stream controller for a session
|
|
39
|
+
*
|
|
40
|
+
* @param sessionId - The unique session identifier
|
|
41
|
+
* @param controller - ReadableStreamDefaultController for the SSE connection
|
|
42
|
+
*/
|
|
43
|
+
create(sessionId: string, controller: ReadableStreamDefaultController): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Send data to one or more active SSE streams
|
|
46
|
+
*
|
|
47
|
+
* In distributed deployments:
|
|
48
|
+
* - Local implementation: directly enqueues to in-memory controller
|
|
49
|
+
* - Redis implementation: publishes to Pub/Sub channel, any server with this session receives it
|
|
50
|
+
* - Postgres implementation: uses NOTIFY/LISTEN for cross-server messaging
|
|
51
|
+
*
|
|
52
|
+
* @param sessionIds - Array of session IDs to send to, or undefined for broadcast to all
|
|
53
|
+
* @param data - SSE-formatted data (e.g., 'event: message\ndata: {...}\n\n')
|
|
54
|
+
*/
|
|
55
|
+
send(sessionIds: string[] | undefined, data: string): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Remove an active SSE stream
|
|
58
|
+
*
|
|
59
|
+
* @param sessionId - The unique session identifier
|
|
60
|
+
*/
|
|
61
|
+
delete(sessionId: string): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Check if an active SSE stream exists for a session
|
|
64
|
+
*
|
|
65
|
+
* @param sessionId - The unique session identifier
|
|
66
|
+
* @returns True if stream exists, false otherwise
|
|
67
|
+
*/
|
|
68
|
+
has(sessionId: string): Promise<boolean>;
|
|
69
|
+
/**
|
|
70
|
+
* Close all connections and cleanup resources
|
|
71
|
+
* Should be called on server shutdown
|
|
72
|
+
*/
|
|
73
|
+
close?(): Promise<void>;
|
|
74
|
+
}
|
|
75
|
+
export * from "./memory.js";
|
|
76
|
+
export * from "./redis.js";
|
|
77
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/server/sessions/streams/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;;OAKG;IACH,MAAM,CACJ,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,+BAA+B,GAC1C,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjB;;;;;;;;;;OAUG;IACH,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpE;;;;OAIG;IACH,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzC;;;;;OAKG;IACH,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEzC;;;OAGG;IACH,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB;AAED,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-Memory Stream Manager
|
|
3
|
+
*
|
|
4
|
+
* Default implementation for managing active SSE connections in a single server instance.
|
|
5
|
+
* Streams are stored in memory and lost on server restart.
|
|
6
|
+
*
|
|
7
|
+
* For distributed deployments, use RedisStreamManager or PostgresStreamManager.
|
|
8
|
+
*/
|
|
9
|
+
import type { StreamManager } from "./index.js";
|
|
10
|
+
/**
|
|
11
|
+
* In-memory stream management for SSE connections
|
|
12
|
+
*
|
|
13
|
+
* Stores active ReadableStreamDefaultController instances for pushing
|
|
14
|
+
* server-initiated messages (notifications, sampling responses) to clients.
|
|
15
|
+
*
|
|
16
|
+
* Suitable for:
|
|
17
|
+
* - Single-instance deployments
|
|
18
|
+
* - Development environments
|
|
19
|
+
* - Non-distributed architectures
|
|
20
|
+
*
|
|
21
|
+
* Not suitable for:
|
|
22
|
+
* - Load-balanced deployments (streams on different servers)
|
|
23
|
+
* - Horizontal scaling
|
|
24
|
+
* - Session persistence requirements
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import { MCPServer, InMemoryStreamManager } from 'mcp-use/server';
|
|
29
|
+
*
|
|
30
|
+
* const server = new MCPServer({
|
|
31
|
+
* name: 'my-server',
|
|
32
|
+
* version: '1.0.0',
|
|
33
|
+
* streamManager: new InMemoryStreamManager()
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare class InMemoryStreamManager implements StreamManager {
|
|
38
|
+
/**
|
|
39
|
+
* Map of active SSE stream controllers
|
|
40
|
+
* Key: sessionId, Value: ReadableStreamDefaultController
|
|
41
|
+
*/
|
|
42
|
+
private streams;
|
|
43
|
+
/**
|
|
44
|
+
* Text encoder for converting strings to Uint8Array
|
|
45
|
+
*/
|
|
46
|
+
private textEncoder;
|
|
47
|
+
/**
|
|
48
|
+
* Register an active SSE stream controller
|
|
49
|
+
*/
|
|
50
|
+
create(sessionId: string, controller: ReadableStreamDefaultController): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Send data to active SSE streams
|
|
53
|
+
*
|
|
54
|
+
* Directly enqueues data to in-memory controllers.
|
|
55
|
+
* For distributed deployments, use RedisStreamManager instead.
|
|
56
|
+
*/
|
|
57
|
+
send(sessionIds: string[] | undefined, data: string): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Remove an active SSE stream
|
|
60
|
+
*/
|
|
61
|
+
delete(sessionId: string): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Check if an active stream exists
|
|
64
|
+
*/
|
|
65
|
+
has(sessionId: string): Promise<boolean>;
|
|
66
|
+
/**
|
|
67
|
+
* Close all active streams
|
|
68
|
+
*/
|
|
69
|
+
close(): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Get the number of active streams
|
|
72
|
+
* Useful for monitoring
|
|
73
|
+
*/
|
|
74
|
+
get size(): number;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../../../src/server/sessions/streams/memory.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,qBAAsB,YAAW,aAAa;IACzD;;;OAGG;IACH,OAAO,CAAC,OAAO,CAAsD;IAErE;;OAEG;IACH,OAAO,CAAC,WAAW,CAAqB;IAExC;;OAEG;IACG,MAAM,CACV,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,+BAA+B,GAC1C,OAAO,CAAC,IAAI,CAAC;IAIhB;;;;;OAKG;IACG,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiCzE;;OAEG;IACG,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAe9C;;OAEG;IACG,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAI9C;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAc5B;;;OAGG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;CACF"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Redis Stream Manager
|
|
3
|
+
*
|
|
4
|
+
* Manages active SSE connections using Redis Pub/Sub for distributed notifications.
|
|
5
|
+
* Enables server-to-client push notifications across multiple server instances.
|
|
6
|
+
*
|
|
7
|
+
* **Note:** Redis is an optional dependency. Install it with:
|
|
8
|
+
* ```bash
|
|
9
|
+
* npm install redis
|
|
10
|
+
* # or
|
|
11
|
+
* pnpm add redis
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* If Redis is not installed, importing this module will throw an error at runtime
|
|
15
|
+
* when attempting to use RedisStreamManager. Use dynamic imports with error handling
|
|
16
|
+
* if you want to gracefully fall back when Redis is not available.
|
|
17
|
+
*/
|
|
18
|
+
import type { StreamManager } from "./index.js";
|
|
19
|
+
import type { RedisClient } from "../stores/redis.js";
|
|
20
|
+
/**
|
|
21
|
+
* Check if Redis is available as an optional dependency
|
|
22
|
+
* @returns true if Redis can be imported, false otherwise
|
|
23
|
+
*/
|
|
24
|
+
export declare function isRedisAvailable(): Promise<boolean>;
|
|
25
|
+
/**
|
|
26
|
+
* Configuration for Redis stream manager
|
|
27
|
+
*/
|
|
28
|
+
export interface RedisStreamManagerConfig {
|
|
29
|
+
/**
|
|
30
|
+
* Redis client for Pub/Sub subscriptions
|
|
31
|
+
* Should be a separate client from the main Redis client
|
|
32
|
+
*/
|
|
33
|
+
pubSubClient: RedisClient;
|
|
34
|
+
/**
|
|
35
|
+
* Redis client for checking session availability
|
|
36
|
+
* Can be shared with SessionStore
|
|
37
|
+
*/
|
|
38
|
+
client: RedisClient;
|
|
39
|
+
/**
|
|
40
|
+
* Channel prefix for Pub/Sub (default: "mcp:stream:")
|
|
41
|
+
*/
|
|
42
|
+
prefix?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Heartbeat interval in seconds to keep sessions alive (default: 10)
|
|
45
|
+
* Redis keys expire after this interval * 2
|
|
46
|
+
*/
|
|
47
|
+
heartbeatInterval?: number;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Redis-backed stream management for distributed SSE connections
|
|
51
|
+
*
|
|
52
|
+
* Enables notifications, sampling, and resource subscriptions to work across
|
|
53
|
+
* multiple server instances using Redis Pub/Sub.
|
|
54
|
+
*
|
|
55
|
+
* Architecture:
|
|
56
|
+
* 1. Client connects to Server A → creates SSE stream
|
|
57
|
+
* 2. Server A subscribes to Redis channel `mcp:stream:{sessionId}`
|
|
58
|
+
* 3. Client makes request → Load balancer routes to Server B
|
|
59
|
+
* 4. Server B sends notification → publishes to Redis channel
|
|
60
|
+
* 5. Server A receives Redis message → pushes to SSE stream → Client gets notification
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* import { MCPServer, RedisStreamManager } from 'mcp-use/server';
|
|
65
|
+
* import { createClient } from 'redis';
|
|
66
|
+
*
|
|
67
|
+
* // Create two separate Redis clients (required for Pub/Sub)
|
|
68
|
+
* const redis = createClient({ url: process.env.REDIS_URL });
|
|
69
|
+
* const pubSubRedis = redis.duplicate();
|
|
70
|
+
*
|
|
71
|
+
* await redis.connect();
|
|
72
|
+
* await pubSubRedis.connect();
|
|
73
|
+
*
|
|
74
|
+
* const streamManager = new RedisStreamManager({
|
|
75
|
+
* client: redis,
|
|
76
|
+
* pubSubClient: pubSubRedis
|
|
77
|
+
* });
|
|
78
|
+
*
|
|
79
|
+
* const server = new MCPServer({
|
|
80
|
+
* name: 'my-server',
|
|
81
|
+
* version: '1.0.0',
|
|
82
|
+
* streamManager
|
|
83
|
+
* });
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export declare class RedisStreamManager implements StreamManager {
|
|
87
|
+
private pubSubClient;
|
|
88
|
+
private client;
|
|
89
|
+
private prefix;
|
|
90
|
+
private heartbeatInterval;
|
|
91
|
+
private textEncoder;
|
|
92
|
+
/**
|
|
93
|
+
* Map of local controllers (only on this server instance)
|
|
94
|
+
* Key: sessionId, Value: controller
|
|
95
|
+
*/
|
|
96
|
+
private localControllers;
|
|
97
|
+
/**
|
|
98
|
+
* Map of heartbeat intervals for keeping sessions alive
|
|
99
|
+
* Key: sessionId, Value: interval timer
|
|
100
|
+
*/
|
|
101
|
+
private heartbeats;
|
|
102
|
+
constructor(config: RedisStreamManagerConfig);
|
|
103
|
+
/**
|
|
104
|
+
* Get the Redis channel name for a session
|
|
105
|
+
*/
|
|
106
|
+
private getChannel;
|
|
107
|
+
/**
|
|
108
|
+
* Get the Redis key for tracking active sessions
|
|
109
|
+
*/
|
|
110
|
+
private getAvailableKey;
|
|
111
|
+
/**
|
|
112
|
+
* Get the Redis key for the active sessions SET
|
|
113
|
+
*/
|
|
114
|
+
private getActiveSessionsKey;
|
|
115
|
+
/**
|
|
116
|
+
* Register an active SSE stream and subscribe to Redis channel
|
|
117
|
+
*/
|
|
118
|
+
create(sessionId: string, controller: ReadableStreamDefaultController): Promise<void>;
|
|
119
|
+
/**
|
|
120
|
+
* Send data to sessions via Redis Pub/Sub
|
|
121
|
+
*
|
|
122
|
+
* This works across distributed servers - any server with an active
|
|
123
|
+
* SSE connection for the target session will receive and forward the message.
|
|
124
|
+
*
|
|
125
|
+
* Note: Uses the regular client (not pubSubClient) for publishing.
|
|
126
|
+
* In node-redis v5+, clients in subscriber mode cannot publish.
|
|
127
|
+
*/
|
|
128
|
+
send(sessionIds: string[] | undefined, data: string): Promise<void>;
|
|
129
|
+
/**
|
|
130
|
+
* Remove an active SSE stream
|
|
131
|
+
*/
|
|
132
|
+
delete(sessionId: string): Promise<void>;
|
|
133
|
+
/**
|
|
134
|
+
* Check if a session has an active stream (on ANY server)
|
|
135
|
+
*/
|
|
136
|
+
has(sessionId: string): Promise<boolean>;
|
|
137
|
+
/**
|
|
138
|
+
* Close all connections and cleanup
|
|
139
|
+
*/
|
|
140
|
+
close(): Promise<void>;
|
|
141
|
+
/**
|
|
142
|
+
* Get count of active local streams on this server instance
|
|
143
|
+
*/
|
|
144
|
+
get localSize(): number;
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=redis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redis.d.ts","sourceRoot":"","sources":["../../../../../src/server/sessions/streams/redis.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD;;;GAGG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,OAAO,CAAC,CAOzD;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC;;;OAGG;IACH,YAAY,EAAE,WAAW,CAAC;IAE1B;;;OAGG;IACH,MAAM,EAAE,WAAW,CAAC;IAEpB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,qBAAa,kBAAmB,YAAW,aAAa;IACtD,OAAO,CAAC,YAAY,CAAc;IAClC,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,iBAAiB,CAAS;IAClC,OAAO,CAAC,WAAW,CAAqB;IAExC;;;OAGG;IACH,OAAO,CAAC,gBAAgB,CAAsD;IAE9E;;;OAGG;IACH,OAAO,CAAC,UAAU,CAAqC;gBAE3C,MAAM,EAAE,wBAAwB;IAO5C;;OAEG;IACH,OAAO,CAAC,UAAU;IAIlB;;OAEG;IACH,OAAO,CAAC,eAAe;IAIvB;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAI5B;;OAEG;IACG,MAAM,CACV,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,+BAA+B,GAC1C,OAAO,CAAC,IAAI,CAAC;IAwFhB;;;;;;;;OAQG;IACG,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAoDzE;;OAEG;IACG,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA+D9C;;OAEG;IACG,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAc9C;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAwC5B;;OAEG;IACH,IAAI,SAAS,IAAI,MAAM,CAEtB;CACF"}
|
|
@@ -66,67 +66,121 @@ export interface ServerConfig {
|
|
|
66
66
|
allowedOrigins?: string[];
|
|
67
67
|
sessionIdleTimeoutMs?: number;
|
|
68
68
|
/**
|
|
69
|
-
*
|
|
69
|
+
* @deprecated This option is deprecated and will be removed in a future version.
|
|
70
70
|
*
|
|
71
|
-
*
|
|
71
|
+
* The MCP specification requires clients to send a new InitializeRequest when they receive
|
|
72
|
+
* a 404 response for a stale session. Modern MCP clients
|
|
73
|
+
* handle this correctly. The server now follows the spec strictly by returning 404 for invalid
|
|
74
|
+
* session IDs.
|
|
72
75
|
*
|
|
73
|
-
*
|
|
74
|
-
* a
|
|
75
|
-
* reconnect after server restarts without needing to send a new `initialize` request.
|
|
76
|
+
* If you need session persistence across server restarts, use the `sessionStore` option
|
|
77
|
+
* with a persistent storage backend (Redis, PostgreSQL, etc.) instead.
|
|
76
78
|
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
* @see {@link sessionStore} for persistent session storage
|
|
80
|
+
* @see https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#session-management
|
|
81
|
+
*/
|
|
82
|
+
autoCreateSessionOnInvalidId?: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Enable stateless mode (no session tracking)
|
|
85
|
+
* - Default: true for Deno (edge runtimes), false for Node.js
|
|
86
|
+
* - Set to true to force stateless mode
|
|
87
|
+
* - Set to false to force stateful mode (with sessions)
|
|
88
|
+
* - Auto-detected per-request based on client Accept header
|
|
89
|
+
*
|
|
90
|
+
* **Auto-detection (Node.js default):**
|
|
91
|
+
* - Client sends `Accept: application/json, text/event-stream` → Stateful mode
|
|
92
|
+
* - Client sends `Accept: application/json` only → Stateless mode
|
|
93
|
+
* - Explicit `stateless: true` → Always stateless (ignores Accept header)
|
|
82
94
|
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
95
|
+
* This enables compatibility with k6, curl, and other HTTP-only clients
|
|
96
|
+
* while maintaining full SSE support for capable clients.
|
|
97
|
+
*
|
|
98
|
+
* Stateless mode is required for edge functions where instances don't persist.
|
|
99
|
+
* Stateful mode supports sessions, resumability, and notifications.
|
|
86
100
|
*
|
|
87
101
|
* @example
|
|
88
102
|
* ```typescript
|
|
89
|
-
* //
|
|
103
|
+
* // Auto-detected (Deno = stateless, Node.js = stateful with Accept header detection)
|
|
90
104
|
* const server = new MCPServer({
|
|
91
105
|
* name: 'my-server',
|
|
92
106
|
* version: '1.0.0'
|
|
93
107
|
* });
|
|
94
108
|
*
|
|
95
|
-
* //
|
|
109
|
+
* // Force stateless mode (ignores Accept header)
|
|
96
110
|
* const server = new MCPServer({
|
|
97
111
|
* name: 'my-server',
|
|
98
112
|
* version: '1.0.0',
|
|
99
|
-
*
|
|
113
|
+
* stateless: true
|
|
100
114
|
* });
|
|
101
115
|
* ```
|
|
102
116
|
*/
|
|
103
|
-
|
|
117
|
+
stateless?: boolean;
|
|
104
118
|
/**
|
|
105
|
-
*
|
|
106
|
-
* - Default: true for Deno (edge runtimes), false for Node.js
|
|
107
|
-
* - Set to true to force stateless mode
|
|
108
|
-
* - Set to false to force stateful mode (with sessions)
|
|
119
|
+
* Custom session metadata storage backend (default: in-memory)
|
|
109
120
|
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
121
|
+
* Stores serializable session metadata (client capabilities, log level, timestamps).
|
|
122
|
+
* For active SSE stream management, use `streamManager`.
|
|
123
|
+
*
|
|
124
|
+
* Allows pluggable session persistence for scenarios requiring:
|
|
125
|
+
* - Session metadata survival across server restarts
|
|
126
|
+
* - Distributed/clustered deployments
|
|
127
|
+
* - Horizontal scaling with session sharing
|
|
128
|
+
*
|
|
129
|
+
* Default: InMemorySessionStore (metadata lost on restart)
|
|
112
130
|
*
|
|
113
131
|
* @example
|
|
114
132
|
* ```typescript
|
|
115
|
-
*
|
|
133
|
+
* import { MCPServer, RedisSessionStore } from 'mcp-use/server';
|
|
134
|
+
* import { createClient } from 'redis';
|
|
135
|
+
*
|
|
136
|
+
* const redis = createClient({ url: process.env.REDIS_URL });
|
|
137
|
+
* await redis.connect();
|
|
138
|
+
*
|
|
116
139
|
* const server = new MCPServer({
|
|
117
140
|
* name: 'my-server',
|
|
118
|
-
* version: '1.0.0'
|
|
141
|
+
* version: '1.0.0',
|
|
142
|
+
* sessionStore: new RedisSessionStore({ client: redis })
|
|
119
143
|
* });
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
sessionStore?: import("../sessions/stores/index.js").SessionStore;
|
|
147
|
+
/**
|
|
148
|
+
* Custom stream manager for active SSE connections (default: in-memory)
|
|
149
|
+
*
|
|
150
|
+
* Manages active SSE stream controllers for server-to-client push notifications.
|
|
151
|
+
* Separate from sessionStore to enable distributed notifications via Redis Pub/Sub.
|
|
152
|
+
*
|
|
153
|
+
* Default: InMemoryStreamManager (streams on this server only)
|
|
154
|
+
*
|
|
155
|
+
* For distributed deployments where notifications/sampling need to work across
|
|
156
|
+
* multiple server instances, use RedisStreamManager with Redis Pub/Sub.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* import { MCPServer, RedisStreamManager, RedisSessionStore } from 'mcp-use/server';
|
|
161
|
+
* import { createClient } from 'redis';
|
|
162
|
+
*
|
|
163
|
+
* // Create two Redis clients (Pub/Sub requires dedicated client)
|
|
164
|
+
* const redis = createClient({ url: process.env.REDIS_URL });
|
|
165
|
+
* const pubSubRedis = redis.duplicate();
|
|
166
|
+
*
|
|
167
|
+
* await redis.connect();
|
|
168
|
+
* await pubSubRedis.connect();
|
|
120
169
|
*
|
|
121
|
-
* // Force stateless mode (e.g., for Node.js edge functions)
|
|
122
170
|
* const server = new MCPServer({
|
|
123
171
|
* name: 'my-server',
|
|
124
172
|
* version: '1.0.0',
|
|
125
|
-
*
|
|
173
|
+
* sessionStore: new RedisSessionStore({ client: redis }),
|
|
174
|
+
* streamManager: new RedisStreamManager({
|
|
175
|
+
* client: redis,
|
|
176
|
+
* pubSubClient: pubSubRedis
|
|
177
|
+
* })
|
|
126
178
|
* });
|
|
179
|
+
*
|
|
180
|
+
* // Now notifications and sampling work across all server instances!
|
|
127
181
|
* ```
|
|
128
182
|
*/
|
|
129
|
-
|
|
183
|
+
streamManager?: import("../sessions/streams/index.js").StreamManager;
|
|
130
184
|
/**
|
|
131
185
|
* OAuth authentication configuration
|
|
132
186
|
*
|
|
@@ -179,6 +233,29 @@ export interface ServerConfig {
|
|
|
179
233
|
* ```
|
|
180
234
|
*/
|
|
181
235
|
oauth?: OAuthProvider;
|
|
236
|
+
/**
|
|
237
|
+
* Path to favicon file relative to public directory
|
|
238
|
+
*
|
|
239
|
+
* The favicon will be automatically included in all widget pages.
|
|
240
|
+
* Place your favicon file in the public/ directory and specify the relative path.
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```typescript
|
|
244
|
+
* const server = new MCPServer({
|
|
245
|
+
* name: 'my-server',
|
|
246
|
+
* version: '1.0.0',
|
|
247
|
+
* favicon: 'favicon.ico' // References public/favicon.ico
|
|
248
|
+
* });
|
|
249
|
+
*
|
|
250
|
+
* // For files in subdirectories
|
|
251
|
+
* const server = new MCPServer({
|
|
252
|
+
* name: 'my-server',
|
|
253
|
+
* version: '1.0.0',
|
|
254
|
+
* favicon: 'icons/app-icon.png' // References public/icons/app-icon.png
|
|
255
|
+
* });
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
favicon?: string;
|
|
182
259
|
}
|
|
183
260
|
export interface InputDefinition {
|
|
184
261
|
name: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../../src/server/types/common.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,0BAA0B,CAAC,CAAC,IAAI;KACzC,CAAC,IAAI,MAAM,CAAC,IAAI,SAAS,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,EAAE,OAAO,CAC5D,CAAC,CAAC,CAAC,CAAC,EACJ,SAAS,CACV;CACF,GAAG;KACD,CAAC,IAAI,MAAM,CAAC,IAAI,SAAS,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC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