@novorb/mcp-core 2.1.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +82 -161
- package/bin/mcp-core-jest.mjs +112 -0
- package/dist/auth.d.ts +57 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +74 -0
- package/dist/auth.js.map +1 -0
- package/dist/bootstrap.d.ts +129 -0
- package/dist/bootstrap.d.ts.map +1 -0
- package/dist/bootstrap.js +206 -0
- package/dist/bootstrap.js.map +1 -0
- package/dist/client-input.d.ts +72 -0
- package/dist/client-input.d.ts.map +1 -0
- package/dist/client-input.js +109 -0
- package/dist/client-input.js.map +1 -0
- package/dist/credential-checks.d.ts +80 -0
- package/dist/credential-checks.d.ts.map +1 -0
- package/dist/credential-checks.js +189 -0
- package/dist/credential-checks.js.map +1 -0
- package/dist/credential-health.d.ts +12 -0
- package/dist/credential-health.d.ts.map +1 -0
- package/dist/credential-health.js +12 -0
- package/dist/credential-health.js.map +1 -0
- package/dist/credential-report.d.ts +46 -0
- package/dist/credential-report.d.ts.map +1 -0
- package/dist/credential-report.js +135 -0
- package/dist/credential-report.js.map +1 -0
- package/dist/credential-status-tool.d.ts +20 -0
- package/dist/credential-status-tool.d.ts.map +1 -0
- package/dist/credential-status-tool.js +33 -0
- package/dist/credential-status-tool.js.map +1 -0
- package/dist/credentials.d.ts +288 -0
- package/dist/credentials.d.ts.map +1 -0
- package/dist/credentials.js +652 -0
- package/dist/credentials.js.map +1 -0
- package/dist/express-peers.d.ts +29 -0
- package/dist/express-peers.d.ts.map +1 -0
- package/dist/express-peers.js +36 -0
- package/dist/express-peers.js.map +1 -0
- package/dist/express.d.ts +74 -0
- package/dist/express.d.ts.map +1 -0
- package/dist/express.js +164 -0
- package/dist/express.js.map +1 -0
- package/dist/http-client.d.ts +278 -43
- package/dist/http-client.d.ts.map +1 -1
- package/dist/http-client.js +620 -182
- package/dist/http-client.js.map +1 -1
- package/dist/index.d.ts +27 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +49 -10
- package/dist/index.js.map +1 -1
- package/dist/limits.d.ts +28 -0
- package/dist/limits.d.ts.map +1 -0
- package/dist/limits.js +37 -0
- package/dist/limits.js.map +1 -0
- package/dist/list-pagination.d.ts +41 -0
- package/dist/list-pagination.d.ts.map +1 -0
- package/dist/list-pagination.js +104 -0
- package/dist/list-pagination.js.map +1 -0
- package/dist/net.d.ts +112 -0
- package/dist/net.d.ts.map +1 -0
- package/dist/net.js +490 -0
- package/dist/net.js.map +1 -0
- package/dist/notifications.d.ts +78 -0
- package/dist/notifications.d.ts.map +1 -0
- package/dist/notifications.js +173 -0
- package/dist/notifications.js.map +1 -0
- package/dist/pagination.d.ts +236 -5
- package/dist/pagination.d.ts.map +1 -1
- package/dist/pagination.js +393 -6
- package/dist/pagination.js.map +1 -1
- package/dist/prompts.d.ts +70 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +109 -0
- package/dist/prompts.js.map +1 -0
- package/dist/protocol-errors.d.ts +15 -0
- package/dist/protocol-errors.d.ts.map +1 -0
- package/dist/protocol-errors.js +28 -0
- package/dist/protocol-errors.js.map +1 -0
- package/dist/protocol-logging.d.ts +37 -0
- package/dist/protocol-logging.d.ts.map +1 -0
- package/dist/protocol-logging.js +77 -0
- package/dist/protocol-logging.js.map +1 -0
- package/dist/rate-limiter.d.ts +36 -0
- package/dist/rate-limiter.d.ts.map +1 -0
- package/dist/rate-limiter.js +79 -0
- package/dist/rate-limiter.js.map +1 -0
- package/dist/request-state.d.ts +74 -0
- package/dist/request-state.d.ts.map +1 -0
- package/dist/request-state.js +190 -0
- package/dist/request-state.js.map +1 -0
- package/dist/resources.d.ts +181 -0
- package/dist/resources.d.ts.map +1 -0
- package/dist/resources.js +302 -0
- package/dist/resources.js.map +1 -0
- package/dist/result-limits.d.ts +80 -0
- package/dist/result-limits.d.ts.map +1 -0
- package/dist/result-limits.js +248 -0
- package/dist/result-limits.js.map +1 -0
- package/dist/retry.d.ts +79 -23
- package/dist/retry.d.ts.map +1 -1
- package/dist/retry.js +170 -57
- package/dist/retry.js.map +1 -1
- package/dist/sdk/client-stdio.d.ts +6 -0
- package/dist/sdk/client-stdio.d.ts.map +1 -0
- package/dist/sdk/client-stdio.js +6 -0
- package/dist/sdk/client-stdio.js.map +1 -0
- package/dist/sdk/client.d.ts +6 -0
- package/dist/sdk/client.d.ts.map +1 -0
- package/dist/sdk/client.js +6 -0
- package/dist/sdk/client.js.map +1 -0
- package/dist/sdk/express.d.ts +3 -0
- package/dist/sdk/express.d.ts.map +1 -0
- package/dist/sdk/express.js +11 -0
- package/dist/sdk/express.js.map +1 -0
- package/dist/sdk/node.d.ts +6 -0
- package/dist/sdk/node.d.ts.map +1 -0
- package/dist/sdk/node.js +6 -0
- package/dist/sdk/node.js.map +1 -0
- package/dist/sdk/server-stdio.d.ts +6 -0
- package/dist/sdk/server-stdio.d.ts.map +1 -0
- package/dist/sdk/server-stdio.js +6 -0
- package/dist/sdk/server-stdio.js.map +1 -0
- package/dist/sdk/server.d.ts +6 -0
- package/dist/sdk/server.d.ts.map +1 -0
- package/dist/sdk/server.js +6 -0
- package/dist/sdk/server.js.map +1 -0
- package/dist/server.d.ts +88 -36
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +98 -44
- package/dist/server.js.map +1 -1
- package/dist/task-request.d.ts +20 -0
- package/dist/task-request.d.ts.map +1 -0
- package/dist/task-request.js +43 -0
- package/dist/task-request.js.map +1 -0
- package/dist/task-store.d.ts +230 -0
- package/dist/task-store.d.ts.map +1 -0
- package/dist/task-store.js +459 -0
- package/dist/task-store.js.map +1 -0
- package/dist/task-tools.d.ts +115 -0
- package/dist/task-tools.d.ts.map +1 -0
- package/dist/task-tools.js +397 -0
- package/dist/task-tools.js.map +1 -0
- package/dist/testing/client.d.ts +25 -0
- package/dist/testing/client.d.ts.map +1 -0
- package/dist/testing/client.js +11 -0
- package/dist/testing/client.js.map +1 -0
- package/dist/testing/in-memory.d.ts +26 -0
- package/dist/testing/in-memory.d.ts.map +1 -0
- package/dist/testing/in-memory.js +41 -0
- package/dist/testing/in-memory.js.map +1 -0
- package/dist/testing/index.d.ts +20 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +20 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/isolated-dirs.d.ts +27 -0
- package/dist/testing/isolated-dirs.d.ts.map +1 -0
- package/dist/testing/isolated-dirs.js +67 -0
- package/dist/testing/isolated-dirs.js.map +1 -0
- package/dist/testing/logs.d.ts +61 -0
- package/dist/testing/logs.d.ts.map +1 -0
- package/dist/testing/logs.js +113 -0
- package/dist/testing/logs.js.map +1 -0
- package/dist/testing/raw-http.d.ts +25 -0
- package/dist/testing/raw-http.d.ts.map +1 -0
- package/dist/testing/raw-http.js +41 -0
- package/dist/testing/raw-http.js.map +1 -0
- package/dist/testing/raw-peer.d.ts +43 -0
- package/dist/testing/raw-peer.d.ts.map +1 -0
- package/dist/testing/raw-peer.js +101 -0
- package/dist/testing/raw-peer.js.map +1 -0
- package/dist/testing/recording-server.d.ts +38 -0
- package/dist/testing/recording-server.d.ts.map +1 -0
- package/dist/testing/recording-server.js +38 -0
- package/dist/testing/recording-server.js.map +1 -0
- package/dist/testing/server-process.d.ts +76 -0
- package/dist/testing/server-process.d.ts.map +1 -0
- package/dist/testing/server-process.js +241 -0
- package/dist/testing/server-process.js.map +1 -0
- package/dist/testing/tools.d.ts +53 -0
- package/dist/testing/tools.d.ts.map +1 -0
- package/dist/testing/tools.js +98 -0
- package/dist/testing/tools.js.map +1 -0
- package/dist/testing/unit.d.ts +52 -0
- package/dist/testing/unit.d.ts.map +1 -0
- package/dist/testing/unit.js +95 -0
- package/dist/testing/unit.js.map +1 -0
- package/dist/tools.d.ts +205 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +370 -0
- package/dist/tools.js.map +1 -0
- package/dist/transport.d.ts +144 -53
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +305 -122
- package/dist/transport.js.map +1 -1
- package/dist/url-path.d.ts +49 -0
- package/dist/url-path.d.ts.map +1 -0
- package/dist/url-path.js +165 -0
- package/dist/url-path.js.map +1 -0
- package/dist/utils/dataStore.d.ts +143 -0
- package/dist/utils/dataStore.d.ts.map +1 -0
- package/dist/utils/dataStore.js +429 -0
- package/dist/utils/dataStore.js.map +1 -0
- package/dist/utils/envLoader.d.ts +129 -0
- package/dist/utils/envLoader.d.ts.map +1 -0
- package/dist/utils/envLoader.js +399 -0
- package/dist/utils/envLoader.js.map +1 -0
- package/dist/utils/logger.d.ts +181 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +664 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/redact.d.ts +50 -0
- package/dist/utils/redact.d.ts.map +1 -0
- package/dist/utils/redact.js +318 -0
- package/dist/utils/redact.js.map +1 -0
- package/docs/api-reference.md +29 -0
- package/docs/building-a-server.md +63 -0
- package/docs/credentials.md +131 -0
- package/docs/data-store.md +37 -0
- package/docs/env.md +38 -0
- package/docs/features.md +28 -0
- package/docs/http-client.md +116 -0
- package/docs/logger.md +100 -0
- package/docs/migrating-to-v3.md +45 -0
- package/docs/outbound-urls.md +104 -0
- package/docs/pagination.md +45 -0
- package/docs/protocol-features.md +62 -0
- package/docs/resources-prompts-tasks.md +95 -0
- package/docs/sdk.md +33 -0
- package/docs/server.md +68 -0
- package/docs/testing-harness.md +139 -0
- package/docs/testing.md +151 -0
- package/docs/tools.md +88 -0
- package/docs/transport.md +85 -0
- package/examples/testing/tools.integration.test.example.ts +312 -0
- package/examples/testing/tools.unit.test.example.ts +149 -0
- package/package.json +140 -18
- package/dist/logger.d.ts +0 -80
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js +0 -236
- package/dist/logger.js.map +0 -1
package/dist/server.js
CHANGED
|
@@ -1,47 +1,42 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @novorb/mcp-core
|
|
2
|
+
* @novorb/mcp-core - Server
|
|
3
3
|
*
|
|
4
|
-
* Re-exports and base patterns for building MCP servers
|
|
5
|
-
* Import from here instead of the SDK directly
|
|
6
|
-
* server-building
|
|
4
|
+
* Re-exports and base patterns for building MCP servers on `@modelcontextprotocol/server` (SDK v2).
|
|
5
|
+
* Import from here instead of the SDK directly: one centralised import point for every
|
|
6
|
+
* server-building primitive, high-level (`McpServer`) and low-level (`Server`) alike.
|
|
7
7
|
*
|
|
8
8
|
* Usage:
|
|
9
9
|
* import { createMcpServer, TOOL_ANNOTATIONS, completable } from '@novorb/mcp-core/server';
|
|
10
|
-
* import
|
|
10
|
+
* import * as z from 'zod/v4';
|
|
11
11
|
*
|
|
12
|
-
*
|
|
12
|
+
* export function buildServer(): McpServer {
|
|
13
|
+
* const server = createMcpServer('my-mcp', '1.0.0');
|
|
14
|
+
* server.registerTool('lookup', {
|
|
15
|
+
* description: 'Look up data by key',
|
|
16
|
+
* inputSchema: z.object({ key: z.string() }),
|
|
17
|
+
* annotations: TOOL_ANNOTATIONS.readOnly,
|
|
18
|
+
* }, async ({ key }) => ({ content: [{ type: 'text', text: await lookup(key) }] }));
|
|
19
|
+
* server.registerPrompt('find', {
|
|
20
|
+
* argsSchema: z.object({ key: completable(z.string(), (v) => ['foo', 'bar'].filter((k) => k.startsWith(v))) }),
|
|
21
|
+
* }, ({ key }) => ({ messages: [{ role: 'user', content: { type: 'text', text: `Find ${key}` } }] }));
|
|
22
|
+
* return server;
|
|
23
|
+
* }
|
|
13
24
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* inputSchema: { key: z.string() },
|
|
17
|
-
* outputSchema: { value: z.string(), found: z.boolean() },
|
|
18
|
-
* annotations: TOOL_ANNOTATIONS.readOnly,
|
|
19
|
-
* }, async ({ key }) => {
|
|
20
|
-
* const value = await lookup(key);
|
|
21
|
-
* return {
|
|
22
|
-
* content: [{ type: 'text', text: value ?? 'not found' }],
|
|
23
|
-
* structuredContent: { value: value ?? '', found: value !== null },
|
|
24
|
-
* };
|
|
25
|
-
* });
|
|
26
|
-
*
|
|
27
|
-
* server.registerPrompt('find-and-summarise', {
|
|
28
|
-
* title: 'Find and summarise',
|
|
29
|
-
* description: 'Look up a key and summarise the value',
|
|
30
|
-
* argsSchema: { key: completable(z.string(), val => ['foo', 'bar'].filter(k => k.startsWith(val))) },
|
|
31
|
-
* }, ({ key }) => ({
|
|
32
|
-
* messages: [{ role: 'user', content: { type: 'text', text: `Look up "${key}" and summarise the result.` } }],
|
|
33
|
-
* }));
|
|
25
|
+
* An optional completable argument is written `completable(z.string(), cb).optional()`; the inverse
|
|
26
|
+
* nesting `completable(z.string().optional(), cb)` silently yields no completions in SDK v2.
|
|
34
27
|
*/
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
28
|
+
import { McpServer, } from '@modelcontextprotocol/server';
|
|
29
|
+
import { resolveLimits } from './limits.js';
|
|
30
|
+
import { paginateLists } from './list-pagination.js';
|
|
31
|
+
import { enableProtocolLogging, protocolLoggingEnabled } from './protocol-logging.js';
|
|
32
|
+
import { captureTaskAugmentation } from './task-request.js';
|
|
33
|
+
import { getLogger } from './utils/logger.js';
|
|
34
|
+
export { acceptedContent, completable, createRequestStateCodec, fromJsonSchema, inputRequired, inputResponse, McpServer, OAuthError, OAuthErrorCode, ProtocolError, ProtocolErrorCode, ResourceNotFoundError, ResourceTemplate, requireScopes, Server, UrlElicitationRequiredError, } from '@modelcontextprotocol/server';
|
|
40
35
|
/**
|
|
41
36
|
* Standard tool annotation presets.
|
|
42
37
|
*
|
|
43
38
|
* Pass one of these (or a spread of multiple) to `annotations` in `registerTool`.
|
|
44
|
-
* These are HINTS
|
|
39
|
+
* These are HINTS; clients may or may not act on them.
|
|
45
40
|
*
|
|
46
41
|
* @example
|
|
47
42
|
* annotations: TOOL_ANNOTATIONS.readOnly
|
|
@@ -56,18 +51,77 @@ export const TOOL_ANNOTATIONS = {
|
|
|
56
51
|
mutableWrite: { readOnlyHint: false, idempotentHint: false },
|
|
57
52
|
/** Destructive / irreversible (delete, overwrite). */
|
|
58
53
|
destructive: { readOnlyHint: false, destructiveHint: true, idempotentHint: false },
|
|
54
|
+
// The `*OpenWorld` variants add `openWorldHint: true`: use them for every tool that reaches an external
|
|
55
|
+
// API or open system, so all servers declare it the same way.
|
|
56
|
+
/** `readOnly` + `openWorldHint` (lookups against an external API). */
|
|
57
|
+
readOnlyOpenWorld: { readOnlyHint: true, idempotentHint: true, openWorldHint: true },
|
|
58
|
+
/** `idempotentWrite` + `openWorldHint`. */
|
|
59
|
+
idempotentWriteOpenWorld: {
|
|
60
|
+
readOnlyHint: false,
|
|
61
|
+
idempotentHint: true,
|
|
62
|
+
openWorldHint: true,
|
|
63
|
+
},
|
|
64
|
+
/** `mutableWrite` + `openWorldHint`. */
|
|
65
|
+
mutableWriteOpenWorld: { readOnlyHint: false, idempotentHint: false, openWorldHint: true },
|
|
66
|
+
/** `destructive` + `openWorldHint`. */
|
|
67
|
+
destructiveOpenWorld: {
|
|
68
|
+
readOnlyHint: false,
|
|
69
|
+
destructiveHint: true,
|
|
70
|
+
idempotentHint: false,
|
|
71
|
+
openWorldHint: true,
|
|
72
|
+
},
|
|
59
73
|
};
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
export function createMcpServer(
|
|
71
|
-
|
|
74
|
+
/** mcp-core's default cache hints: tool lists are static per process, private while they may vary by caller. */
|
|
75
|
+
export const DEFAULT_CACHE_HINTS = {
|
|
76
|
+
'tools/list': { ttlMs: 300_000, cacheScope: 'private' },
|
|
77
|
+
};
|
|
78
|
+
const CODEC = Symbol.for('@novorb/mcp-core/requestStateCodec');
|
|
79
|
+
/** The requestState codec `createMcpServer` installed on `server`, if any. */
|
|
80
|
+
export function requestStateCodecOf(server) {
|
|
81
|
+
return server[CODEC];
|
|
82
|
+
}
|
|
83
|
+
const LIST_CAPABILITIES = ['tools', 'prompts', 'resources'];
|
|
84
|
+
export function createMcpServer(infoOrName, versionOrOptions, maybeOptions) {
|
|
85
|
+
const info = typeof infoOrName === 'string' ? { name: infoOrName, version: String(versionOrOptions) } : infoOrName;
|
|
86
|
+
const options = (typeof infoOrName === 'string' ? maybeOptions : versionOrOptions) ?? {};
|
|
87
|
+
const { listPageSize, protocolLogging, capabilities, requestStateCodec, ...sdkOptions } = options;
|
|
88
|
+
if (requestStateCodec && sdkOptions.requestState?.verify) {
|
|
89
|
+
throw new Error('createMcpServer: pass requestStateCodec or requestState.verify, not both');
|
|
90
|
+
}
|
|
91
|
+
const limits = resolveLimits(listPageSize !== undefined ? { listPageSize } : {});
|
|
92
|
+
const logging = protocolLoggingEnabled(protocolLogging);
|
|
93
|
+
const constructorCaps = { ...capabilities };
|
|
94
|
+
const listCaps = {};
|
|
95
|
+
for (const key of LIST_CAPABILITIES) {
|
|
96
|
+
if (constructorCaps[key] !== undefined) {
|
|
97
|
+
Object.assign(listCaps, { [key]: constructorCaps[key] });
|
|
98
|
+
delete constructorCaps[key];
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (logging)
|
|
102
|
+
constructorCaps.logging = {};
|
|
103
|
+
const server = new McpServer(info, {
|
|
104
|
+
...sdkOptions,
|
|
105
|
+
...(Object.keys(constructorCaps).length > 0 ? { capabilities: constructorCaps } : {}),
|
|
106
|
+
cacheHints: { ...DEFAULT_CACHE_HINTS, ...sdkOptions.cacheHints },
|
|
107
|
+
maxToolInputElements: sdkOptions.maxToolInputElements ?? limits.maxToolInputElements,
|
|
108
|
+
...(requestStateCodec ? { requestState: { verify: requestStateCodec.verify } } : {}),
|
|
109
|
+
});
|
|
110
|
+
if (requestStateCodec) {
|
|
111
|
+
Object.defineProperty(server, CODEC, { value: requestStateCodec });
|
|
112
|
+
// The SDK reports a refused requestState (the reason) to onerror only; keep it in the server log.
|
|
113
|
+
const previous = server.server.onerror;
|
|
114
|
+
server.server.onerror = (error) => {
|
|
115
|
+
getLogger().warn(`protocol error: ${error.message}`, 'Server');
|
|
116
|
+
previous?.(error);
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
paginateLists(server.server, limits.listPageSize);
|
|
120
|
+
captureTaskAugmentation(server.server);
|
|
121
|
+
if (Object.keys(listCaps).length > 0)
|
|
122
|
+
server.server.registerCapabilities(listCaps);
|
|
123
|
+
if (logging)
|
|
124
|
+
enableProtocolLogging();
|
|
125
|
+
return server;
|
|
72
126
|
}
|
|
73
127
|
//# sourceMappingURL=server.js.map
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAEL,SAAS,GAKV,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AACtF,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAyB9C,OAAO,EACL,eAAe,EACf,WAAW,EACX,uBAAuB,EACvB,cAAc,EACd,aAAa,EACb,aAAa,EACb,SAAS,EACT,UAAU,EACV,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,qBAAqB,EACrB,gBAAgB,EAChB,aAAa,EACb,MAAM,EACN,2BAA2B,GAC5B,MAAM,8BAA8B,CAAC;AAEtC;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;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C;QAAE,MAAM,CAAC,MAAM,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IACnF,IAAI,OAAO;QAAE,qBAAqB,EAAE,CAAC;IACrC,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @novorb/mcp-core - The `tools/call` request's task augmentation (internal)
|
|
3
|
+
*
|
|
4
|
+
* A 2025-11-25 client asks for task execution with `params.task` on `tools/call`; McpServer hands a
|
|
5
|
+
* tool callback only the validated arguments and the context, not the params. mcp-core decorates the
|
|
6
|
+
* instance's public `Server.setRequestHandler` (the same documented low-level hook list pagination
|
|
7
|
+
* uses) so the installed `tools/call` handler runs inside an AsyncLocalStorage scope that carries
|
|
8
|
+
* `params.task`; task tools read it with `currentTaskAugmentation()`.
|
|
9
|
+
*/
|
|
10
|
+
import type { Server } from '@modelcontextprotocol/server';
|
|
11
|
+
/** The 2025-11-25 `params.task` of a task-augmented request. */
|
|
12
|
+
export interface TaskAugmentation {
|
|
13
|
+
/** Requested retention in ms. */
|
|
14
|
+
ttl?: number;
|
|
15
|
+
}
|
|
16
|
+
/** Decorate `server` so the `tools/call` handler installed from now on sees `params.task`. Idempotent. */
|
|
17
|
+
export declare function captureTaskAugmentation(server: Server): void;
|
|
18
|
+
/** The current `tools/call`'s task augmentation (2025-11-25), or undefined when it has none. */
|
|
19
|
+
export declare function currentTaskAugmentation(): TaskAugmentation | undefined;
|
|
20
|
+
//# sourceMappingURL=task-request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task-request.d.ts","sourceRoot":"","sources":["../src/task-request.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAE3D,gEAAgE;AAChE,MAAM,WAAW,gBAAgB;IAC/B,iCAAiC;IACjC,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAaD,0GAA0G;AAC1G,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAmB5D;AAED,gGAAgG;AAChG,wBAAgB,uBAAuB,IAAI,gBAAgB,GAAG,SAAS,CAEtE"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @novorb/mcp-core - The `tools/call` request's task augmentation (internal)
|
|
3
|
+
*
|
|
4
|
+
* A 2025-11-25 client asks for task execution with `params.task` on `tools/call`; McpServer hands a
|
|
5
|
+
* tool callback only the validated arguments and the context, not the params. mcp-core decorates the
|
|
6
|
+
* instance's public `Server.setRequestHandler` (the same documented low-level hook list pagination
|
|
7
|
+
* uses) so the installed `tools/call` handler runs inside an AsyncLocalStorage scope that carries
|
|
8
|
+
* `params.task`; task tools read it with `currentTaskAugmentation()`.
|
|
9
|
+
*/
|
|
10
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
11
|
+
const scope = new AsyncLocalStorage();
|
|
12
|
+
const CAPTURED = Symbol.for('@novorb/mcp-core/taskAugmentation');
|
|
13
|
+
function augmentation(value) {
|
|
14
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
15
|
+
return undefined;
|
|
16
|
+
const ttl = value.ttl;
|
|
17
|
+
return typeof ttl === 'number' && Number.isFinite(ttl) && ttl >= 0 ? { ttl } : {};
|
|
18
|
+
}
|
|
19
|
+
/** Decorate `server` so the `tools/call` handler installed from now on sees `params.task`. Idempotent. */
|
|
20
|
+
export function captureTaskAugmentation(server) {
|
|
21
|
+
const target = server;
|
|
22
|
+
if (target[CAPTURED])
|
|
23
|
+
return;
|
|
24
|
+
target[CAPTURED] = true;
|
|
25
|
+
const original = target.setRequestHandler.bind(server);
|
|
26
|
+
target.setRequestHandler = (method, ...rest) => {
|
|
27
|
+
const handler = rest[0];
|
|
28
|
+
if (method === 'tools/call' && rest.length === 1 && typeof handler === 'function') {
|
|
29
|
+
const wrapped = (request, ctx) => {
|
|
30
|
+
const task = augmentation(request.params?.task);
|
|
31
|
+
return scope.run(task ? { task } : {}, () => handler(request, ctx));
|
|
32
|
+
};
|
|
33
|
+
original(method, wrapped);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
original(method, ...rest);
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** The current `tools/call`'s task augmentation (2025-11-25), or undefined when it has none. */
|
|
40
|
+
export function currentTaskAugmentation() {
|
|
41
|
+
return scope.getStore()?.task;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=task-request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task-request.js","sourceRoot":"","sources":["../src/task-request.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AASrD,MAAM,KAAK,GAAG,IAAI,iBAAiB,EAA+B,CAAC;AACnE,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;AAIjE,SAAS,YAAY,CAAC,KAAc;IAClC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAC1F,MAAM,GAAG,GAAI,KAA2B,CAAC,GAAG,CAAC;IAC7C,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AACpF,CAAC;AAED,0GAA0G;AAC1G,MAAM,UAAU,uBAAuB,CAAC,MAAc;IACpD,MAAM,MAAM,GAAG,MAEd,CAAC;IACF,IAAI,MAAM,CAAC,QAAQ,CAAC;QAAE,OAAO;IAC7B,MAAM,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC;IACxB,MAAM,QAAQ,GAAG,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAiD,CAAC;IACvG,MAAM,CAAC,iBAAiB,GAAG,CAAC,MAAc,EAAE,GAAG,IAAe,EAAQ,EAAE;QACtE,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACxB,IAAI,MAAM,KAAK,YAAY,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE,CAAC;YAClF,MAAM,OAAO,GAAoB,CAAC,OAAO,EAAE,GAAG,EAAE,EAAE;gBAChD,MAAM,IAAI,GAAG,YAAY,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;gBAChD,OAAO,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,GAAG,EAAE,CAAE,OAA2B,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;YAC3F,CAAC,CAAC;YACF,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YAC1B,OAAO;QACT,CAAC;QACD,QAAQ,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;IAC5B,CAAC,CAAC;AACJ,CAAC;AAED,gGAAgG;AAChG,MAAM,UAAU,uBAAuB;IACrC,OAAO,KAAK,CAAC,QAAQ,EAAE,EAAE,IAAI,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @novorb/mcp-core - Task stores (server side of MCP Tasks)
|
|
3
|
+
*
|
|
4
|
+
* The task wire types and the `TaskStore` contract mirror the open SDK PR
|
|
5
|
+
* modelcontextprotocol/typescript-sdk#2782 (`@modelcontextprotocol/server/ext/tasks`: `TaskStore`,
|
|
6
|
+
* `CreateTaskParams`, `TaskAccess`, `InMemoryTaskStore` with its writer `TaskHandle`) field for field,
|
|
7
|
+
* so a consumer can move to the SDK module when it ships. What mcp-core adds lives on
|
|
8
|
+
* `ManagedTaskStore`, a superset the PR does not define: `list` (the 2025-11-25 `tasks/list`), `watch`
|
|
9
|
+
* (status notifications and the blocking 2025 `tasks/result`), `updateContext` and `close`.
|
|
10
|
+
*
|
|
11
|
+
* - `InMemoryTaskStore`: records in a Map, TTL purge on a timer (the PR's reference store).
|
|
12
|
+
* - `FileTaskStore`: one JSON file per task under the data store (`tasks/<id>.json`, atomic writes), so
|
|
13
|
+
* tasks survive a restart and several processes on one host share them; cancellation written by
|
|
14
|
+
* another process reaches the running work through a status poll. `createTaskStore` falls back to
|
|
15
|
+
* memory when DATA_STORAGE=false.
|
|
16
|
+
*
|
|
17
|
+
* Isolation: a task created by an authenticated request carries the caller's `clientId` as
|
|
18
|
+
* `principal`; every read or write from another principal behaves exactly like an unknown task (no
|
|
19
|
+
* existence leak). A task created without a principal (stdio) is visible to every caller of the store.
|
|
20
|
+
*/
|
|
21
|
+
import type { CallToolResult, InputRequests, InputResponses } from '@modelcontextprotocol/server';
|
|
22
|
+
import type { DataStore } from './utils/dataStore.js';
|
|
23
|
+
/** The MCP Tasks extension identifier (2026-07-28). */
|
|
24
|
+
export declare const TASKS_EXTENSION_ID = "io.modelcontextprotocol/tasks";
|
|
25
|
+
/** All task statuses, in lifecycle order (terminal states last). */
|
|
26
|
+
export declare const TASK_STATUSES: readonly ["working", "input_required", "completed", "failed", "cancelled"];
|
|
27
|
+
export type TaskStatus = (typeof TASK_STATUSES)[number];
|
|
28
|
+
/** Data associated with a task (2026-07-28 / PR #2782 shape; the 2025 wire maps ttlMs -> ttl). */
|
|
29
|
+
export interface Task {
|
|
30
|
+
taskId: string;
|
|
31
|
+
status: TaskStatus;
|
|
32
|
+
statusMessage?: string;
|
|
33
|
+
/** ISO 8601. */
|
|
34
|
+
createdAt: string;
|
|
35
|
+
/** ISO 8601. */
|
|
36
|
+
lastUpdatedAt: string;
|
|
37
|
+
/** Retention from creation in ms; null = unlimited. */
|
|
38
|
+
ttlMs: number | null;
|
|
39
|
+
/** Suggested polling interval in ms. */
|
|
40
|
+
pollIntervalMs?: number;
|
|
41
|
+
}
|
|
42
|
+
export interface WorkingTask extends Task {
|
|
43
|
+
status: 'working';
|
|
44
|
+
}
|
|
45
|
+
export interface InputRequiredTask extends Task {
|
|
46
|
+
status: 'input_required';
|
|
47
|
+
inputRequests: InputRequests;
|
|
48
|
+
}
|
|
49
|
+
export interface CompletedTask extends Task {
|
|
50
|
+
status: 'completed';
|
|
51
|
+
result: {
|
|
52
|
+
[key: string]: unknown;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export interface FailedTask extends Task {
|
|
56
|
+
status: 'failed';
|
|
57
|
+
error: {
|
|
58
|
+
[key: string]: unknown;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export interface CancelledTask extends Task {
|
|
62
|
+
status: 'cancelled';
|
|
63
|
+
}
|
|
64
|
+
/** A task with status-specific fields inlined (`tasks/get`). */
|
|
65
|
+
export type DetailedTask = WorkingTask | InputRequiredTask | CompletedTask | FailedTask | CancelledTask;
|
|
66
|
+
/** What a store is asked to create (PR #2782 `CreateTaskParams`). */
|
|
67
|
+
export interface CreateTaskParams {
|
|
68
|
+
ttlMs: number | null;
|
|
69
|
+
pollIntervalMs?: number;
|
|
70
|
+
/** The creating caller; access from another principal is refused as "not found". */
|
|
71
|
+
principal?: string;
|
|
72
|
+
/** Store-defined context (the tool name, a job id). */
|
|
73
|
+
context?: Record<string, unknown>;
|
|
74
|
+
}
|
|
75
|
+
/** The caller identity presented on a `tasks/*` request (PR #2782 `TaskAccess`). */
|
|
76
|
+
export interface TaskAccess {
|
|
77
|
+
principal?: string;
|
|
78
|
+
}
|
|
79
|
+
/** The store contract of PR #2782, unchanged. */
|
|
80
|
+
export interface TaskStore {
|
|
81
|
+
create(params: CreateTaskParams): Promise<Task>;
|
|
82
|
+
get(taskId: string, access?: TaskAccess): Promise<DetailedTask | undefined>;
|
|
83
|
+
update(taskId: string, inputResponses: InputResponses, access?: TaskAccess): Promise<boolean>;
|
|
84
|
+
cancel(taskId: string, access?: TaskAccess): Promise<boolean>;
|
|
85
|
+
}
|
|
86
|
+
/** The writer side of a task, for the code that does the work (PR #2782 `TaskHandle`). */
|
|
87
|
+
export interface TaskHandle {
|
|
88
|
+
readonly taskId: string;
|
|
89
|
+
/** Aborted when the task is cancelled (or purged). */
|
|
90
|
+
readonly signal: AbortSignal;
|
|
91
|
+
status(message: string): Promise<void>;
|
|
92
|
+
requireInput(requests: InputRequests): Promise<InputResponses>;
|
|
93
|
+
complete(result: CallToolResult): Promise<void>;
|
|
94
|
+
fail(error: {
|
|
95
|
+
code: number;
|
|
96
|
+
message: string;
|
|
97
|
+
data?: unknown;
|
|
98
|
+
}): Promise<void>;
|
|
99
|
+
}
|
|
100
|
+
export interface TaskListPage {
|
|
101
|
+
tasks: Task[];
|
|
102
|
+
nextCursor?: string;
|
|
103
|
+
}
|
|
104
|
+
/** mcp-core's superset of `TaskStore` (not in PR #2782). */
|
|
105
|
+
export interface ManagedTaskStore extends TaskStore {
|
|
106
|
+
/** The caller's tasks, newest first, paged with an opaque cursor. */
|
|
107
|
+
list(access?: TaskAccess, options?: {
|
|
108
|
+
cursor?: string;
|
|
109
|
+
limit?: number;
|
|
110
|
+
}): Promise<TaskListPage>;
|
|
111
|
+
/** The writer handle (throws for an unknown task). */
|
|
112
|
+
handle(taskId: string): TaskHandle;
|
|
113
|
+
/** The context recorded at creation. */
|
|
114
|
+
context(taskId: string): Promise<Record<string, unknown> | undefined>;
|
|
115
|
+
/**
|
|
116
|
+
* Merge `patch` into the context (writer side, like `handle`: no caller check): for what the work learns
|
|
117
|
+
* after creation, such as the id an upstream assigned. False for an unknown task.
|
|
118
|
+
*/
|
|
119
|
+
updateContext(taskId: string, patch: Record<string, unknown>): Promise<boolean>;
|
|
120
|
+
/** Observe one task's changes (this process's writes); returns unsubscribe. */
|
|
121
|
+
watch(taskId: string, listener: (task: DetailedTask) => void): () => void;
|
|
122
|
+
/** Stop timers, abort running work, release resources. */
|
|
123
|
+
close(): void;
|
|
124
|
+
}
|
|
125
|
+
export interface TaskStoreOptions {
|
|
126
|
+
/** Task id factory (default `crypto.randomUUID()`). */
|
|
127
|
+
createTaskId?: () => string;
|
|
128
|
+
/** Clock (default `Date.now`). */
|
|
129
|
+
now?: () => number;
|
|
130
|
+
}
|
|
131
|
+
/** Whether `status` is terminal (completed, failed, cancelled). */
|
|
132
|
+
export declare function isTerminalStatus(status: TaskStatus): boolean;
|
|
133
|
+
interface TaskRecord {
|
|
134
|
+
taskId: string;
|
|
135
|
+
principal?: string;
|
|
136
|
+
context?: Record<string, unknown>;
|
|
137
|
+
status: TaskStatus;
|
|
138
|
+
statusMessage?: string;
|
|
139
|
+
createdAt: number;
|
|
140
|
+
lastUpdatedAt: number;
|
|
141
|
+
ttlMs: number | null;
|
|
142
|
+
pollIntervalMs?: number;
|
|
143
|
+
result?: CallToolResult;
|
|
144
|
+
error?: {
|
|
145
|
+
code: number;
|
|
146
|
+
message: string;
|
|
147
|
+
data?: unknown;
|
|
148
|
+
};
|
|
149
|
+
inputRequests?: InputRequests;
|
|
150
|
+
/** The answers so far; kept once complete (status back to working) until the waiter takes them. */
|
|
151
|
+
inputResponses?: InputResponses;
|
|
152
|
+
/** Identifies one requireInput call, so a waiter never takes the answers of an earlier round. */
|
|
153
|
+
inputRound?: string;
|
|
154
|
+
}
|
|
155
|
+
/** Shared bookkeeping for both stores: listeners, abort controllers, input waiters. */
|
|
156
|
+
declare abstract class BaseTaskStore implements ManagedTaskStore {
|
|
157
|
+
protected readonly createTaskId: () => string;
|
|
158
|
+
protected readonly now: () => number;
|
|
159
|
+
protected readonly aborts: Map<string, AbortController>;
|
|
160
|
+
protected readonly listeners: Map<string, Set<(task: DetailedTask) => void>>;
|
|
161
|
+
private readonly waiters;
|
|
162
|
+
constructor(options?: TaskStoreOptions);
|
|
163
|
+
protected abstract read(taskId: string): Promise<TaskRecord | undefined>;
|
|
164
|
+
protected abstract write(record: TaskRecord): Promise<void>;
|
|
165
|
+
protected abstract all(): Promise<TaskRecord[]>;
|
|
166
|
+
protected abstract forget(taskId: string): Promise<void>;
|
|
167
|
+
abstract close(): void;
|
|
168
|
+
protected abortController(taskId: string): AbortController;
|
|
169
|
+
protected emit(record: TaskRecord): void;
|
|
170
|
+
protected save(record: TaskRecord): Promise<void>;
|
|
171
|
+
protected expired(record: TaskRecord): boolean;
|
|
172
|
+
protected live(taskId: string): Promise<TaskRecord | undefined>;
|
|
173
|
+
/**
|
|
174
|
+
* Hand a completed round of answers to this process's waiting `requireInput`. The answers may have
|
|
175
|
+
* been written by another process sharing the store (the file store calls this from its poll).
|
|
176
|
+
*/
|
|
177
|
+
protected settleInput(record: TaskRecord): void;
|
|
178
|
+
protected purge(taskId: string): Promise<void>;
|
|
179
|
+
create(params: CreateTaskParams): Promise<Task>;
|
|
180
|
+
/** Hook: the in-memory store arms its TTL timer here. */
|
|
181
|
+
protected scheduled(_record: TaskRecord): void;
|
|
182
|
+
get(taskId: string, access?: TaskAccess): Promise<DetailedTask | undefined>;
|
|
183
|
+
update(taskId: string, inputResponses: InputResponses, access?: TaskAccess): Promise<boolean>;
|
|
184
|
+
cancel(taskId: string, access?: TaskAccess): Promise<boolean>;
|
|
185
|
+
list(access?: TaskAccess, options?: {
|
|
186
|
+
cursor?: string;
|
|
187
|
+
limit?: number;
|
|
188
|
+
}): Promise<TaskListPage>;
|
|
189
|
+
context(taskId: string): Promise<Record<string, unknown> | undefined>;
|
|
190
|
+
updateContext(taskId: string, patch: Record<string, unknown>): Promise<boolean>;
|
|
191
|
+
watch(taskId: string, listener: (task: DetailedTask) => void): () => void;
|
|
192
|
+
handle(taskId: string): TaskHandle;
|
|
193
|
+
}
|
|
194
|
+
/** The in-process reference store (PR #2782 `InMemoryTaskStore`, plus the `ManagedTaskStore` extras). */
|
|
195
|
+
export declare class InMemoryTaskStore extends BaseTaskStore {
|
|
196
|
+
private readonly tasks;
|
|
197
|
+
private readonly timers;
|
|
198
|
+
protected read(taskId: string): Promise<TaskRecord | undefined>;
|
|
199
|
+
protected write(record: TaskRecord): Promise<void>;
|
|
200
|
+
protected all(): Promise<TaskRecord[]>;
|
|
201
|
+
protected forget(taskId: string): Promise<void>;
|
|
202
|
+
protected scheduled(record: TaskRecord): void;
|
|
203
|
+
close(): void;
|
|
204
|
+
}
|
|
205
|
+
export interface FileTaskStoreOptions extends TaskStoreOptions {
|
|
206
|
+
/** How often running work re-reads its task file to see a cancellation from another process (ms, default 1000). */
|
|
207
|
+
cancelPollMs?: number;
|
|
208
|
+
/** How often expired task files are swept (ms, default 60000). */
|
|
209
|
+
sweepMs?: number;
|
|
210
|
+
}
|
|
211
|
+
/** A store of JSON files under the data store (`<DATA_PATH>/tasks/<taskId>.json`). */
|
|
212
|
+
export declare class FileTaskStore extends BaseTaskStore {
|
|
213
|
+
private readonly data;
|
|
214
|
+
private readonly pollers;
|
|
215
|
+
private readonly sweeper;
|
|
216
|
+
private readonly cancelPollMs;
|
|
217
|
+
constructor(data: DataStore, options?: FileTaskStoreOptions);
|
|
218
|
+
private file;
|
|
219
|
+
protected read(taskId: string): Promise<TaskRecord | undefined>;
|
|
220
|
+
protected write(record: TaskRecord): Promise<void>;
|
|
221
|
+
protected all(): Promise<TaskRecord[]>;
|
|
222
|
+
protected forget(taskId: string): Promise<void>;
|
|
223
|
+
private stopPolling;
|
|
224
|
+
handle(taskId: string): TaskHandle;
|
|
225
|
+
close(): void;
|
|
226
|
+
}
|
|
227
|
+
/** A file store when the data store is enabled, otherwise the in-memory store. */
|
|
228
|
+
export declare function createTaskStore(data: DataStore | undefined, options?: FileTaskStoreOptions): ManagedTaskStore;
|
|
229
|
+
export {};
|
|
230
|
+
//# sourceMappingURL=task-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task-store.d.ts","sourceRoot":"","sources":["../src/task-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG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