mcp-use 1.11.0-canary.8 → 1.11.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/dist/.tsbuildinfo +1 -1
- package/dist/{chunk-5RTMAOZ6.js → chunk-A4QJRN7Z.js} +5 -1041
- package/dist/{chunk-4LZSXUFM.js → chunk-B7AGEK7F.js} +1 -1
- package/dist/{chunk-TAEHPLGV.js → chunk-GN5HOAV3.js} +664 -136
- package/dist/chunk-QPIDKGV4.js +1246 -0
- package/dist/chunk-UWWLWLS2.js +62 -0
- package/dist/{chunk-ZFZPZ4GE.js → chunk-V77WS6CS.js} +9 -0
- package/dist/{chunk-EBSNALCB.js → chunk-VRHAF2WT.js} +10 -4
- package/dist/{chunk-X7JKFBPN.js → chunk-Y2HHHJQB.js} +159 -8
- package/dist/{chunk-JPKFN73V.js → chunk-ZLZOOXMJ.js} +96 -43
- package/dist/index.cjs +316 -53
- package/dist/index.js +22 -24
- package/dist/notifications-FLGIFS56.js +9 -0
- package/dist/src/agents/index.cjs +153 -47
- package/dist/src/agents/index.d.ts +1 -1
- package/dist/src/agents/index.d.ts.map +1 -1
- package/dist/src/agents/index.js +7 -10
- package/dist/src/agents/mcp_agent.d.ts.map +1 -1
- package/dist/src/{client/prompts.d.ts → agents/prompts/index.d.ts} +3 -3
- package/dist/src/agents/prompts/index.d.ts.map +1 -0
- package/dist/src/browser.cjs +160 -48
- package/dist/src/browser.js +10 -12
- package/dist/src/client/browser.d.ts.map +1 -1
- package/dist/src/client.cjs +3852 -0
- package/dist/src/client.d.ts +2 -0
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/client.js +21 -0
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/connectors/http.d.ts +2 -0
- package/dist/src/connectors/http.d.ts.map +1 -1
- package/dist/src/react/index.cjs +313 -52
- package/dist/src/react/index.js +7 -8
- package/dist/src/react/types.d.ts +41 -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/endpoints/mount-mcp.d.ts.map +1 -1
- package/dist/src/server/index.cjs +1339 -256
- 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 +1119 -156
- package/dist/src/server/mcp-server.d.ts +4 -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 +30 -16
- 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 +82 -28
- package/dist/src/server/types/common.d.ts.map +1 -1
- package/dist/src/server/types/widget.d.ts +2 -2
- package/dist/src/server/types/widget.d.ts.map +1 -1
- package/dist/src/server/utils/response-helpers.d.ts +4 -2
- package/dist/src/server/utils/response-helpers.d.ts.map +1 -1
- package/dist/src/server/widgets/mount-widgets-dev.d.ts.map +1 -1
- package/dist/src/server/widgets/ui-resource-registration.d.ts.map +1 -1
- package/dist/src/task_managers/index.d.ts +10 -0
- 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/telemetry/telemetry.d.ts +1 -0
- package/dist/src/telemetry/telemetry.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-EYAIJERC.js → tool-execution-helpers-ZUA5D5IO.js} +2 -2
- package/dist/tsup.config.d.ts.map +1 -1
- package/package.json +62 -52
- package/dist/chunk-GVU7C2ZD.js +0 -12
- package/dist/chunk-JZNXOM7C.js +0 -204
- package/dist/chunk-XKTBHYNM.js +0 -491
- package/dist/src/client/prompts.cjs +0 -407
- package/dist/src/client/prompts.d.ts.map +0 -1
- package/dist/src/client/prompts.js +0 -11
|
@@ -7,7 +7,7 @@ import type { ToolContext, SampleOptions, ElicitOptions, ElicitFormParams, Elici
|
|
|
7
7
|
export type { ToolContext, SampleOptions, ElicitOptions, ElicitFormParams, ElicitUrlParams, };
|
|
8
8
|
import { onRootsChanged, listRoots } from "./roots/index.js";
|
|
9
9
|
import type { SessionData } from "./sessions/index.js";
|
|
10
|
-
import { getActiveSessions, sendNotification, sendNotificationToSession } from "./notifications/index.js";
|
|
10
|
+
import { getActiveSessions, sendNotification, sendNotificationToSession, sendToolsListChanged, sendResourcesListChanged, sendPromptsListChanged } from "./notifications/index.js";
|
|
11
11
|
import type { ServerConfig } from "./types/index.js";
|
|
12
12
|
import { parseTemplateUri as parseTemplateUriHelper } from "./utils/index.js";
|
|
13
13
|
import type { OAuthProvider } from "./oauth/providers/types.js";
|
|
@@ -122,6 +122,9 @@ declare class MCPServerClass<HasOAuth extends boolean = false> {
|
|
|
122
122
|
getActiveSessions: typeof getActiveSessions;
|
|
123
123
|
sendNotification: typeof sendNotification;
|
|
124
124
|
sendNotificationToSession: typeof sendNotificationToSession;
|
|
125
|
+
sendToolsListChanged: typeof sendToolsListChanged;
|
|
126
|
+
sendResourcesListChanged: typeof sendResourcesListChanged;
|
|
127
|
+
sendPromptsListChanged: typeof sendPromptsListChanged;
|
|
125
128
|
/**
|
|
126
129
|
* Notify subscribed clients that a resource has been updated
|
|
127
130
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../../../src/server/mcp-server.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,IAAI,iBAAiB,EAE/B,MAAM,iDAAiD,CAAC;AACzD,OAAO,KAAK,EACV,oBAAoB,EACpB,mBAAmB,EACpB,MAAM,4CAA4C,CAAC;AAKpD,OAAO,KAAK,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAK7C,OAAO,EAAE,sBAAsB,EAAgB,MAAM,oBAAoB,CAAC;AAE1E,OAAO,EAEL,wBAAwB,EACxB,kBAAkB,EACnB,MAAM,kBAAkB,CAAC;AAS1B,OAAO,KAAK,EACV,WAAW,EACX,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,eAAe,EAChB,MAAM,yBAAyB,CAAC;AAEjC,YAAY,EACV,WAAW,EACX,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,eAAe,GAChB,CAAC;AAEF,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,yBAAyB,
|
|
1
|
+
{"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../../../src/server/mcp-server.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS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AO,CAAC,CAAC;CACpC;AAMD,eAAO,MAAM,SAAS,EAAE,oBAA4C,CAAC;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AAIH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG;IAAE,KAAK,EAAE,WAAW,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAA;CAAE,GAC5E,iBAAiB,CAAC,IAAI,CAAC,CAAC;AAI3B,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,GAC7B,iBAAiB,CAAC,KAAK,CAAC,CAAC"}
|
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This module provides functions for managing client notifications with the MCP server.
|
|
5
5
|
*/
|
|
6
|
-
export { getActiveSessions, sendNotification, sendNotificationToSession, type NotificationServerContext, } from "./notification-registration.js";
|
|
6
|
+
export { getActiveSessions, sendNotification, sendNotificationToSession, sendToolsListChanged, sendResourcesListChanged, sendPromptsListChanged, type NotificationServerContext, } from "./notification-registration.js";
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/server/notifications/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,yBAAyB,EACzB,KAAK,yBAAyB,GAC/B,MAAM,gCAAgC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/server/notifications/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,yBAAyB,EACzB,oBAAoB,EACpB,wBAAwB,EACxB,sBAAsB,EACtB,KAAK,yBAAyB,GAC/B,MAAM,gCAAgC,CAAC"}
|
|
@@ -79,4 +79,55 @@ export declare function sendNotification(this: NotificationServerContext, method
|
|
|
79
79
|
* ```
|
|
80
80
|
*/
|
|
81
81
|
export declare function sendNotificationToSession(this: NotificationServerContext, sessionId: string, method: string, params?: Record<string, unknown>): Promise<boolean>;
|
|
82
|
+
/**
|
|
83
|
+
* Notify all clients that the tools list has changed
|
|
84
|
+
*
|
|
85
|
+
* Convenience method that sends a `notifications/tools/list_changed` notification
|
|
86
|
+
* to all connected clients. Use this when dynamically adding or removing tools
|
|
87
|
+
* to prompt clients to refresh their tools cache.
|
|
88
|
+
*
|
|
89
|
+
* Note: This only works in stateful mode with active sessions.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* // After dynamically registering a new tool
|
|
94
|
+
* server.tool({ name: 'new_tool', ... }, async () => {...});
|
|
95
|
+
* await server.sendToolsListChanged();
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export declare function sendToolsListChanged(this: NotificationServerContext): Promise<void>;
|
|
99
|
+
/**
|
|
100
|
+
* Notify all clients that the resources list has changed
|
|
101
|
+
*
|
|
102
|
+
* Convenience method that sends a `notifications/resources/list_changed` notification
|
|
103
|
+
* to all connected clients. Use this when dynamically adding or removing resources
|
|
104
|
+
* to prompt clients to refresh their resources cache.
|
|
105
|
+
*
|
|
106
|
+
* Note: This only works in stateful mode with active sessions.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* // After dynamically registering a new resource
|
|
111
|
+
* server.resource({ name: 'new_resource', uri: 'app://new' }, async () => {...});
|
|
112
|
+
* await server.sendResourcesListChanged();
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export declare function sendResourcesListChanged(this: NotificationServerContext): Promise<void>;
|
|
116
|
+
/**
|
|
117
|
+
* Notify all clients that the prompts list has changed
|
|
118
|
+
*
|
|
119
|
+
* Convenience method that sends a `notifications/prompts/list_changed` notification
|
|
120
|
+
* to all connected clients. Use this when dynamically adding or removing prompts
|
|
121
|
+
* to prompt clients to refresh their prompts cache.
|
|
122
|
+
*
|
|
123
|
+
* Note: This only works in stateful mode with active sessions.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* // After dynamically registering a new prompt
|
|
128
|
+
* server.prompt({ name: 'new_prompt', ... }, async () => {...});
|
|
129
|
+
* await server.sendPromptsListChanged();
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
export declare function sendPromptsListChanged(this: NotificationServerContext): Promise<void>;
|
|
82
133
|
//# sourceMappingURL=notification-registration.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notification-registration.d.ts","sourceRoot":"","sources":["../../../../src/server/notifications/notification-registration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAMxD,MAAM,WAAW,yBAAyB;IACxC,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;CACpC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,yBAAyB,GAAG,MAAM,EAAE,CAE3E;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,yBAAyB,EAC/B,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,OAAO,CAAC,IAAI,CAAC,CAEf;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAsB,yBAAyB,CAC7C,IAAI,EAAE,yBAAyB,EAC/B,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,OAAO,CAAC,OAAO,CAAC,CAOlB"}
|
|
1
|
+
{"version":3,"file":"notification-registration.d.ts","sourceRoot":"","sources":["../../../../src/server/notifications/notification-registration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAMxD,MAAM,WAAW,yBAAyB;IACxC,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;CACpC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,yBAAyB,GAAG,MAAM,EAAE,CAE3E;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,yBAAyB,EAC/B,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,OAAO,CAAC,IAAI,CAAC,CAEf;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAsB,yBAAyB,CAC7C,IAAI,EAAE,yBAAyB,EAC/B,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,OAAO,CAAC,OAAO,CAAC,CAOlB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,yBAAyB,GAC9B,OAAO,CAAC,IAAI,CAAC,CAKf;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,wBAAwB,CAC5C,IAAI,EAAE,yBAAyB,GAC9B,OAAO,CAAC,IAAI,CAAC,CAKf;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,yBAAyB,GAC9B,OAAO,CAAC,IAAI,CAAC,CAKf"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Session Management Exports
|
|
3
3
|
*/
|
|
4
|
-
export { type SessionData, startIdleCleanup } from "./session-manager.js";
|
|
4
|
+
export { type SessionData, type SessionMetadata, startIdleCleanup, } from "./session-manager.js";
|
|
5
5
|
export { sendNotificationToAll, sendNotificationToSession, } from "./notifications.js";
|
|
6
|
+
export { type SessionStore, InMemorySessionStore, RedisSessionStore, type RedisClient, type RedisSessionStoreConfig, FileSystemSessionStore, type FileSystemSessionStoreConfig, } from "./stores/index.js";
|
|
7
|
+
export { type StreamManager, InMemoryStreamManager, RedisStreamManager, type RedisStreamManagerConfig, } from "./streams/index.js";
|
|
6
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/server/sessions/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/server/sessions/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,qBAAqB,EACrB,yBAAyB,GAC1B,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,KAAK,YAAY,EACjB,oBAAoB,EACpB,iBAAiB,EACjB,KAAK,WAAW,EAChB,KAAK,uBAAuB,EAC5B,sBAAsB,EACtB,KAAK,4BAA4B,GAClC,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,KAAK,aAAa,EAClB,qBAAqB,EACrB,kBAAkB,EAClB,KAAK,wBAAwB,GAC9B,MAAM,oBAAoB,CAAC"}
|
|
@@ -8,33 +8,47 @@ import type { Context } from "hono";
|
|
|
8
8
|
import type { Transport } from "@mcp-use/modelcontextprotocol-sdk/shared/transport.js";
|
|
9
9
|
import type { McpServer } from "@mcp-use/modelcontextprotocol-sdk/server/mcp.js";
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
* Serializable session metadata
|
|
12
|
+
*
|
|
13
|
+
* This is the data that can be stored in external stores (Redis, Postgres).
|
|
14
|
+
* It excludes runtime objects like transport and server instances.
|
|
13
15
|
*/
|
|
14
|
-
export interface
|
|
15
|
-
/** Reference to this session's transport instance */
|
|
16
|
-
transport: Transport;
|
|
17
|
-
/** Reference to this session's server instance */
|
|
18
|
-
server?: McpServer;
|
|
16
|
+
export interface SessionMetadata {
|
|
19
17
|
/** Timestamp of last activity for idle timeout tracking */
|
|
20
18
|
lastAccessedAt: number;
|
|
21
|
-
/**
|
|
22
|
-
|
|
19
|
+
/** Minimum log level for filtering log messages (RFC 5424 levels) */
|
|
20
|
+
logLevel?: string;
|
|
21
|
+
/** Client capabilities advertised during initialization */
|
|
22
|
+
clientCapabilities?: Record<string, unknown>;
|
|
23
|
+
/** Client info (name, version) */
|
|
24
|
+
clientInfo?: Record<string, unknown>;
|
|
25
|
+
/** Protocol version negotiated during initialization */
|
|
26
|
+
protocolVersion?: string;
|
|
23
27
|
/** Progress token for current tool call (if any) */
|
|
24
28
|
progressToken?: number;
|
|
25
|
-
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Complete session data including runtime instances
|
|
32
|
+
*
|
|
33
|
+
* This extends SessionMetadata with non-serializable runtime objects.
|
|
34
|
+
* The full SessionData is only available in memory on the server handling the session.
|
|
35
|
+
*/
|
|
36
|
+
export interface SessionData extends SessionMetadata {
|
|
37
|
+
/** Reference to this session's transport instance (not serializable) */
|
|
38
|
+
transport: Transport;
|
|
39
|
+
/** Reference to this session's server instance (not serializable) */
|
|
40
|
+
server?: McpServer;
|
|
41
|
+
/** Hono context for this session's current request (not serializable) */
|
|
42
|
+
context?: Context;
|
|
43
|
+
/** Function to send notifications to the client (not serializable) */
|
|
26
44
|
sendNotification?: (notification: {
|
|
27
45
|
method: string;
|
|
28
46
|
params: Record<string, unknown>;
|
|
29
47
|
}) => Promise<void>;
|
|
30
|
-
/** Express-like response object for notifications */
|
|
48
|
+
/** Express-like response object for notifications (not serializable) */
|
|
31
49
|
expressRes?: Response | Record<string, unknown>;
|
|
32
|
-
/** Hono context for direct response access */
|
|
50
|
+
/** Hono context for direct response access (not serializable) */
|
|
33
51
|
honoContext?: Context;
|
|
34
|
-
/** Minimum log level for filtering log messages (RFC 5424 levels) */
|
|
35
|
-
logLevel?: string;
|
|
36
|
-
/** Client capabilities advertised during initialization */
|
|
37
|
-
clientCapabilities?: Record<string, unknown>;
|
|
38
52
|
}
|
|
39
53
|
/**
|
|
40
54
|
* Start idle session cleanup interval
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-manager.d.ts","sourceRoot":"","sources":["../../../../src/server/sessions/session-manager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uDAAuD,CAAC;AACvF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iDAAiD,CAAC;AAEjF
|
|
1
|
+
{"version":3,"file":"session-manager.d.ts","sourceRoot":"","sources":["../../../../src/server/sessions/session-manager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uDAAuD,CAAC;AACvF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iDAAiD,CAAC;AAEjF;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,2DAA2D;IAC3D,cAAc,EAAE,MAAM,CAAC;IACvB,qEAAqE;IACrE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2DAA2D;IAC3D,kBAAkB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7C,kCAAkC;IAClC,UAAU,CA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sessions survive server hot reloads, eliminating the need for client re-initialization.
|
|
6
|
+
*
|
|
7
|
+
* Designed for:
|
|
8
|
+
* - Development environments with hot reload (tsx, nodemon, etc.)
|
|
9
|
+
* - Single-instance deployments requiring session persistence
|
|
10
|
+
* - Testing scenarios where session state needs to persist
|
|
11
|
+
*
|
|
12
|
+
* Not suitable for:
|
|
13
|
+
* - Production deployments (use InMemorySessionStore or RedisSessionStore)
|
|
14
|
+
* - Distributed/clustered deployments (use RedisSessionStore)
|
|
15
|
+
* - High-throughput scenarios (frequent disk I/O may impact performance)
|
|
16
|
+
*/
|
|
17
|
+
import type { SessionStore } from "./index.js";
|
|
18
|
+
import type { SessionMetadata } from "../session-manager.js";
|
|
19
|
+
/**
|
|
20
|
+
* Configuration for FileSystem session store
|
|
21
|
+
*/
|
|
22
|
+
export interface FileSystemSessionStoreConfig {
|
|
23
|
+
/**
|
|
24
|
+
* Path to the session file (default: .mcp-use/sessions.json in project root)
|
|
25
|
+
*/
|
|
26
|
+
path?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Debounce delay in milliseconds for write operations (default: 100)
|
|
29
|
+
* Reduces disk I/O by batching rapid consecutive writes
|
|
30
|
+
*/
|
|
31
|
+
debounceMs?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Maximum session age in milliseconds (default: 24 hours)
|
|
34
|
+
* Sessions older than this are cleaned up on load
|
|
35
|
+
*/
|
|
36
|
+
maxAgeMs?: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* FileSystem-based session storage (default for development mode)
|
|
40
|
+
*
|
|
41
|
+
* Persists session metadata to a JSON file on disk, enabling sessions to survive
|
|
42
|
+
* server restarts during hot reload. Uses atomic writes and debouncing for reliability.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* import { MCPServer, FileSystemSessionStore } from 'mcp-use/server';
|
|
47
|
+
*
|
|
48
|
+
* const server = new MCPServer({
|
|
49
|
+
* name: 'dev-server',
|
|
50
|
+
* version: '1.0.0',
|
|
51
|
+
* sessionStore: new FileSystemSessionStore({
|
|
52
|
+
* path: '.mcp-use/sessions.json'
|
|
53
|
+
* })
|
|
54
|
+
* });
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare class FileSystemSessionStore implements SessionStore {
|
|
58
|
+
private sessions;
|
|
59
|
+
private readonly filePath;
|
|
60
|
+
private readonly debounceMs;
|
|
61
|
+
private readonly maxAgeMs;
|
|
62
|
+
private saveTimer;
|
|
63
|
+
private saving;
|
|
64
|
+
private pendingSave;
|
|
65
|
+
constructor(config?: FileSystemSessionStoreConfig);
|
|
66
|
+
/**
|
|
67
|
+
* Load sessions from file synchronously during construction
|
|
68
|
+
* This ensures sessions are available immediately when the server starts
|
|
69
|
+
*/
|
|
70
|
+
private loadSessionsSync;
|
|
71
|
+
/**
|
|
72
|
+
* Retrieve session metadata by ID
|
|
73
|
+
*/
|
|
74
|
+
get(sessionId: string): Promise<SessionMetadata | null>;
|
|
75
|
+
/**
|
|
76
|
+
* Store or update session metadata
|
|
77
|
+
* Uses debouncing to batch rapid consecutive writes
|
|
78
|
+
*/
|
|
79
|
+
set(sessionId: string, data: SessionMetadata): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Delete session metadata
|
|
82
|
+
*/
|
|
83
|
+
delete(sessionId: string): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Check if session exists
|
|
86
|
+
*/
|
|
87
|
+
has(sessionId: string): Promise<boolean>;
|
|
88
|
+
/**
|
|
89
|
+
* List all session IDs
|
|
90
|
+
*/
|
|
91
|
+
keys(): Promise<string[]>;
|
|
92
|
+
/**
|
|
93
|
+
* Store session metadata with TTL
|
|
94
|
+
* Note: TTL is enforced on load, not with timers (simple implementation)
|
|
95
|
+
*/
|
|
96
|
+
setWithTTL(sessionId: string, data: SessionMetadata, ttlMs: number): Promise<void>;
|
|
97
|
+
/**
|
|
98
|
+
* Get the number of active sessions
|
|
99
|
+
*/
|
|
100
|
+
get size(): number;
|
|
101
|
+
/**
|
|
102
|
+
* Clear all sessions
|
|
103
|
+
*/
|
|
104
|
+
clear(): Promise<void>;
|
|
105
|
+
/**
|
|
106
|
+
* Schedule a save operation with debouncing
|
|
107
|
+
* Prevents excessive disk I/O from rapid consecutive writes
|
|
108
|
+
*/
|
|
109
|
+
private scheduleSave;
|
|
110
|
+
/**
|
|
111
|
+
* Perform the actual save operation with atomic writes
|
|
112
|
+
* Uses write-to-temp-then-rename pattern to prevent corruption
|
|
113
|
+
*/
|
|
114
|
+
private performSave;
|
|
115
|
+
/**
|
|
116
|
+
* Force an immediate save (bypasses debouncing)
|
|
117
|
+
* Useful for ensuring persistence before process exit
|
|
118
|
+
*/
|
|
119
|
+
flush(): Promise<void>;
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=filesystem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filesystem.d.ts","sourceRoot":"","sources":["../../../../../src/server/sessions/stores/filesystem.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,sBAAuB,YAAW,YAAY;IACzD,OAAO,CAAC,QAAQ,CAAsC;IACtD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,SAAS,CAA+B;IAChD,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,WAAW,CAAS;gBAEhB,MAAM,GAAE,4BAAiC;IAUrD;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAsDxB;;OAEG;IACG,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IAK7D;;;OAGG;IACG,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAKlE;;OAEG;IACG,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAK9C;;OAEG;IACG,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAI9C;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAI/B;;;OAGG;IACG,UAAU,CACd,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,eAAe,EACrB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC;IAgBhB;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAK5B;;;OAGG;YACW,YAAY;IAkB1B;;;OAGG;YACW,WAAW;IAiDzB;;;OAGG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAO7B"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session Storage Interface
|
|
3
|
+
*
|
|
4
|
+
* Pluggable session storage for MCP servers to support different persistence backends.
|
|
5
|
+
* Default implementation is in-memory (InMemorySessionStore).
|
|
6
|
+
*
|
|
7
|
+
* For persistent sessions across server restarts, implement custom stores:
|
|
8
|
+
* - RedisSessionStore (for distributed deployments)
|
|
9
|
+
* - PostgresSessionStore (for database-backed persistence)
|
|
10
|
+
* - FileSystemSessionStore (for simple file-based persistence)
|
|
11
|
+
*/
|
|
12
|
+
import type { SessionMetadata } from "../session-manager.js";
|
|
13
|
+
/**
|
|
14
|
+
* Abstract interface for session metadata storage
|
|
15
|
+
*
|
|
16
|
+
* Stores ONLY serializable session metadata (client capabilities, log level, timestamps).
|
|
17
|
+
* Does NOT store runtime objects (transport, server instances, controllers).
|
|
18
|
+
*
|
|
19
|
+
* For managing active SSE connections, use StreamManager.
|
|
20
|
+
*
|
|
21
|
+
* Inspired by tmcp's split architecture (InfoSessionManager + StreamSessionManager).
|
|
22
|
+
* All methods are async to support external storage backends (Redis, Postgres, etc.)
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* // Custom Redis implementation
|
|
27
|
+
* class RedisSessionStore implements SessionStore {
|
|
28
|
+
* constructor(private redis: RedisClient) {}
|
|
29
|
+
*
|
|
30
|
+
* async get(sessionId: string): Promise<SessionMetadata | null> {
|
|
31
|
+
* const data = await this.redis.get(`session:${sessionId}`);
|
|
32
|
+
* return data ? JSON.parse(data) : null;
|
|
33
|
+
* }
|
|
34
|
+
*
|
|
35
|
+
* async set(sessionId: string, data: SessionMetadata): Promise<void> {
|
|
36
|
+
* await this.redis.set(`session:${sessionId}`, JSON.stringify(data));
|
|
37
|
+
* }
|
|
38
|
+
*
|
|
39
|
+
* async delete(sessionId: string): Promise<void> {
|
|
40
|
+
* await this.redis.del(`session:${sessionId}`);
|
|
41
|
+
* }
|
|
42
|
+
*
|
|
43
|
+
* async has(sessionId: string): Promise<boolean> {
|
|
44
|
+
* return (await this.redis.exists(`session:${sessionId}`)) === 1;
|
|
45
|
+
* }
|
|
46
|
+
*
|
|
47
|
+
* async keys(): Promise<string[]> {
|
|
48
|
+
* return await this.redis.keys('session:*');
|
|
49
|
+
* }
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export interface SessionStore {
|
|
54
|
+
/**
|
|
55
|
+
* Retrieve session metadata by ID
|
|
56
|
+
* @param sessionId - The unique session identifier
|
|
57
|
+
* @returns Session metadata if found, null otherwise
|
|
58
|
+
*/
|
|
59
|
+
get(sessionId: string): Promise<SessionMetadata | null>;
|
|
60
|
+
/**
|
|
61
|
+
* Store or update session metadata
|
|
62
|
+
* @param sessionId - The unique session identifier
|
|
63
|
+
* @param data - Session metadata to store (serializable only)
|
|
64
|
+
*/
|
|
65
|
+
set(sessionId: string, data: SessionMetadata): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Delete session metadata
|
|
68
|
+
* @param sessionId - The unique session identifier
|
|
69
|
+
*/
|
|
70
|
+
delete(sessionId: string): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Check if session metadata exists
|
|
73
|
+
* @param sessionId - The unique session identifier
|
|
74
|
+
* @returns True if session exists, false otherwise
|
|
75
|
+
*/
|
|
76
|
+
has(sessionId: string): Promise<boolean>;
|
|
77
|
+
/**
|
|
78
|
+
* List all session IDs
|
|
79
|
+
* Used for cleanup operations and monitoring
|
|
80
|
+
* @returns Array of session IDs
|
|
81
|
+
*/
|
|
82
|
+
keys(): Promise<string[]>;
|
|
83
|
+
/**
|
|
84
|
+
* Optional: Store session metadata with automatic expiration (TTL)
|
|
85
|
+
* @param sessionId - The unique session identifier
|
|
86
|
+
* @param data - Session metadata to store
|
|
87
|
+
* @param ttlMs - Time to live in milliseconds
|
|
88
|
+
*/
|
|
89
|
+
setWithTTL?(sessionId: string, data: SessionMetadata, ttlMs: number): Promise<void>;
|
|
90
|
+
}
|
|
91
|
+
export * from "./memory.js";
|
|
92
|
+
export * from "./redis.js";
|
|
93
|
+
export * from "./filesystem.js";
|
|
94
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/server/sessions/stores/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;IAExD;;;;OAIG;IACH,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7D;;;OAGG;IACH,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzC;;;;OAIG;IACH,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEzC;;;;OAIG;IACH,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAE1B;;;;;OAKG;IACH,UAAU,CAAC,CACT,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,eAAe,EACrB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC,CAAC;CAClB;AAED,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-Memory Session Store
|
|
3
|
+
*
|
|
4
|
+
* Default session storage implementation using JavaScript Map.
|
|
5
|
+
* Sessions are stored in memory and lost on server restart.
|
|
6
|
+
*
|
|
7
|
+
* For production deployments requiring session persistence across restarts,
|
|
8
|
+
* consider implementing a custom SessionStore backed by Redis, PostgreSQL,
|
|
9
|
+
* or another persistent storage system.
|
|
10
|
+
*/
|
|
11
|
+
import type { SessionStore } from "./index.js";
|
|
12
|
+
import type { SessionMetadata } from "../session-manager.js";
|
|
13
|
+
/**
|
|
14
|
+
* In-memory session storage (default)
|
|
15
|
+
*
|
|
16
|
+
* Provides fast, local session management without external dependencies.
|
|
17
|
+
* Suitable for:
|
|
18
|
+
* - Development environments
|
|
19
|
+
* - Single-instance deployments
|
|
20
|
+
* - Stateful applications where session loss on restart is acceptable
|
|
21
|
+
*
|
|
22
|
+
* Not suitable for:
|
|
23
|
+
* - Distributed/clustered deployments
|
|
24
|
+
* - Applications requiring session persistence across restarts
|
|
25
|
+
* - Horizontal scaling scenarios
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* import { MCPServer, InMemorySessionStore } from 'mcp-use/server';
|
|
30
|
+
*
|
|
31
|
+
* const server = new MCPServer({
|
|
32
|
+
* name: 'my-server',
|
|
33
|
+
* version: '1.0.0',
|
|
34
|
+
* sessionStore: new InMemorySessionStore()
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare class InMemorySessionStore implements SessionStore {
|
|
39
|
+
/**
|
|
40
|
+
* Internal map storing session metadata
|
|
41
|
+
* Key: sessionId, Value: SessionMetadata
|
|
42
|
+
*/
|
|
43
|
+
private sessions;
|
|
44
|
+
/**
|
|
45
|
+
* Retrieve session metadata by ID
|
|
46
|
+
*/
|
|
47
|
+
get(sessionId: string): Promise<SessionMetadata | null>;
|
|
48
|
+
/**
|
|
49
|
+
* Store or update session metadata
|
|
50
|
+
*/
|
|
51
|
+
set(sessionId: string, data: SessionMetadata): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Delete session metadata
|
|
54
|
+
*/
|
|
55
|
+
delete(sessionId: string): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Check if session exists
|
|
58
|
+
*/
|
|
59
|
+
has(sessionId: string): Promise<boolean>;
|
|
60
|
+
/**
|
|
61
|
+
* List all session IDs
|
|
62
|
+
*/
|
|
63
|
+
keys(): Promise<string[]>;
|
|
64
|
+
/**
|
|
65
|
+
* Store session metadata with TTL (time-to-live)
|
|
66
|
+
*
|
|
67
|
+
* Note: In-memory implementation uses setTimeout for TTL.
|
|
68
|
+
* For production TTL support, use Redis or another store with native TTL.
|
|
69
|
+
*/
|
|
70
|
+
setWithTTL(sessionId: string, data: SessionMetadata, ttlMs: number): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Get the number of active sessions
|
|
73
|
+
* Useful for monitoring and debugging
|
|
74
|
+
*/
|
|
75
|
+
get size(): number;
|
|
76
|
+
/**
|
|
77
|
+
* Clear all sessions
|
|
78
|
+
* Useful for testing and manual cleanup
|
|
79
|
+
*/
|
|
80
|
+
clear(): Promise<void>;
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../../../src/server/sessions/stores/memory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,oBAAqB,YAAW,YAAY;IACvD;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAsC;IAEtD;;OAEG;IACG,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IAK7D;;OAEG;IACG,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlE;;OAEG;IACG,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI9C;;OAEG;IACG,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAI9C;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAI/B;;;;;OAKG;IACG,UAAU,CACd,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,eAAe,EACrB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC;IAUhB;;;OAGG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;;OAGG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
|