@mcp-native/core 0.0.3 → 0.2.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 +90 -21
- package/dist/index.d.ts +187 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +309 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
[](https://www.npmjs.com/package/@mcp-native/core)
|
|
9
9
|
[](https://github.com/pablospaniard/mcp-native/blob/main/LICENSE)
|
|
10
10
|
|
|
11
|
-
[GitHub](https://github.com/pablospaniard/mcp-native) · [Architecture](https://github.com/pablospaniard/mcp-native/blob/main/docs/RFC-0001-architecture.md) · [Security](https://github.com/pablospaniard/mcp-native/blob/main/SECURITY.md)
|
|
11
|
+
[GitHub](https://github.com/pablospaniard/mcp-native) · [Architecture](https://github.com/pablospaniard/mcp-native/blob/main/docs/RFC-0001-architecture.md) · [Standards status](https://github.com/pablospaniard/mcp-native/blob/main/docs/standards-compatibility.md) · [Security](https://github.com/pablospaniard/mcp-native/blob/main/SECURITY.md)
|
|
12
12
|
|
|
13
13
|
</div>
|
|
14
14
|
|
|
@@ -29,29 +29,38 @@ The package is ESM-only and includes TypeScript declarations.
|
|
|
29
29
|
Adapt any MCP client to the `McpClient` interface, then use `McpNativeRuntime` to coordinate operations:
|
|
30
30
|
|
|
31
31
|
```ts
|
|
32
|
-
import { McpNativeRuntime, type McpClient } from "@mcp-native/core";
|
|
32
|
+
import { McpNativeRuntime, createAllowlistActionPolicy, type McpClient } from "@mcp-native/core";
|
|
33
33
|
|
|
34
34
|
const client: McpClient = {
|
|
35
35
|
async listTools() {
|
|
36
|
-
return
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
return {
|
|
37
|
+
tools: [
|
|
38
|
+
{
|
|
39
|
+
name: "save_profile",
|
|
40
|
+
description: "Save profile details",
|
|
41
|
+
inputSchema: { type: "object" },
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
};
|
|
43
45
|
},
|
|
44
46
|
async callTool(name, arguments_) {
|
|
45
47
|
return {
|
|
46
|
-
content: [{ type: "
|
|
48
|
+
content: [{ type: "text", text: `Called ${name}` }],
|
|
49
|
+
structuredContent: { name, arguments: arguments_ },
|
|
47
50
|
};
|
|
48
51
|
},
|
|
49
52
|
async readResource(uri) {
|
|
50
|
-
return {
|
|
53
|
+
return {
|
|
54
|
+
contents: [{ uri, mimeType: "text/plain", text: "Hello from MCP" }],
|
|
55
|
+
};
|
|
51
56
|
},
|
|
52
57
|
};
|
|
53
58
|
|
|
54
|
-
const runtime = new McpNativeRuntime(client
|
|
59
|
+
const runtime = new McpNativeRuntime(client, {
|
|
60
|
+
actionPolicy: createAllowlistActionPolicy([
|
|
61
|
+
{ name: "save_profile", arguments: { displayName: "Ada" } },
|
|
62
|
+
]),
|
|
63
|
+
});
|
|
55
64
|
|
|
56
65
|
await runtime.dispatch({
|
|
57
66
|
type: "tool",
|
|
@@ -62,28 +71,88 @@ await runtime.dispatch({
|
|
|
62
71
|
|
|
63
72
|
## Public API
|
|
64
73
|
|
|
65
|
-
| Export
|
|
66
|
-
|
|
|
67
|
-
| `McpNativeRuntime`
|
|
68
|
-
| `McpClient`
|
|
69
|
-
| `McpTool`, `McpResource`, `McpToolCallResult` | Transport-neutral MCP data contracts used by the runtime. |
|
|
70
|
-
| `
|
|
71
|
-
| `
|
|
74
|
+
| Export | Purpose |
|
|
75
|
+
| -------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
|
|
76
|
+
| `McpNativeRuntime` | Delegates tool listing, tool calls, resource reads, and declared actions to an `McpClient`. |
|
|
77
|
+
| `McpClient` | Minimal interface implemented by an SDK- or transport-specific adapter. |
|
|
78
|
+
| `McpTool`, `McpListToolsResult`, `McpResource`, `McpReadResourceResult`, `McpToolCallResult` | Transport-neutral MCP data contracts used by the runtime. |
|
|
79
|
+
| `McpContent` and its discriminated content interfaces | Exact text, image, audio, resource-link, and embedded-resource shapes. |
|
|
80
|
+
| `McpAnnotations`, `McpToolAnnotations`, `McpIcon`, `McpCacheScope` | Official metadata, presentation hints, and response-cache contracts. |
|
|
81
|
+
| `ToolAction`, `McpNativeAction` | Declarative actions that can be dispatched through the runtime. |
|
|
82
|
+
| `McpNativeRuntimeOptions`, `McpNativeActionPolicy` | Host policy controlling which validated surface actions `dispatch()` may execute. |
|
|
83
|
+
| `createAllowlistActionPolicy`, `McpNativeToolAllowlistEntry` | Fail-closed helper that authorizes tools by name and exact or predicated arguments. |
|
|
84
|
+
| `McpNativeActionDeniedError` | Fail-closed error for actions not explicitly allowed by the host. |
|
|
85
|
+
| `parseMcpNativeAction`, `parseJsonObject`, `parseJsonValue` | Strict validators that return safely reconstructed untrusted data. |
|
|
86
|
+
| `JSON_MAX_DEPTH`, `JSON_MAX_VALUES`, `JSON_MAX_STRING_LENGTH` | Fixed complexity limits applied by the public JSON validators. |
|
|
87
|
+
| `JsonValidationError` | Error for non-JSON, circular, non-plain, or non-finite input. |
|
|
88
|
+
| `JsonPrimitive`, `JsonValue`, `JsonObject` | JSON-safe value types for untrusted protocol data. |
|
|
89
|
+
| `McpExtensionSettings`, `McpExtensionNegotiation` | Validated extension maps and explicit negotiation outcomes. |
|
|
90
|
+
| `parseMcpExtensionSettings`, `isMcpExtensionIdentifier` | Fail-closed validation for prefixed extension declarations. |
|
|
91
|
+
| `negotiateMcpExtension` | Computes mutual support from client and server declarations only. |
|
|
92
|
+
|
|
93
|
+
## Extension negotiation
|
|
94
|
+
|
|
95
|
+
Extension settings are JSON objects keyed by mandatorily prefixed identifiers. Core preserves this capability data without depending on an extension implementation:
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
import { negotiateMcpExtension } from "@mcp-native/core";
|
|
99
|
+
|
|
100
|
+
const result = negotiateMcpExtension(
|
|
101
|
+
"com.example/native-ui",
|
|
102
|
+
{ "com.example/native-ui": { version: "1" } },
|
|
103
|
+
{ "com.example/native-ui": { version: "1" } },
|
|
104
|
+
);
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Only the two explicit maps participate. Metadata, MIME types, and tool results cannot grant support. `McpNativeRuntime.negotiateExtension()` reads both maps from the optional `McpClient.getClientExtensionSettings()` and `getServerExtensionSettings()` boundary, so callers cannot substitute an unadvertised client map, and returns a typed fallback result when either side is absent.
|
|
108
|
+
|
|
109
|
+
## Pre-1.0 MCP result migration
|
|
110
|
+
|
|
111
|
+
The initial `0.0.x` proof of concept returned one `McpResource` directly from `readResource`. The official SDK returns a content collection, so implementations now return `McpReadResourceResult`:
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
// Before
|
|
115
|
+
return { uri, text: "Hello" };
|
|
116
|
+
|
|
117
|
+
// Current RFC-0001 contract
|
|
118
|
+
return { contents: [{ uri, text: "Hello" }] };
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Preserving the collection avoids silently discarding valid resource items.
|
|
122
|
+
|
|
123
|
+
Tool listings likewise preserve result metadata and cache hints, so `listTools()` now returns an object:
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
// Before
|
|
127
|
+
return [{ name: "save", inputSchema: { type: "object" } }];
|
|
128
|
+
|
|
129
|
+
// Current RFC-0001 contract
|
|
130
|
+
return { tools: [{ name: "save", inputSchema: { type: "object" } }] };
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Content blocks now use MCP's official discriminated fields. Replace `{ type: "text", data: { text } }` with `{ type: "text", text }`; resource links similarly expose `name`, `uri`, and `mimeType` directly.
|
|
72
134
|
|
|
73
135
|
## Design boundaries
|
|
74
136
|
|
|
75
137
|
- No React Native dependency.
|
|
76
138
|
- No A2UI or WebView dependency.
|
|
77
|
-
- No transport or official MCP SDK dependency
|
|
139
|
+
- No transport or official MCP SDK dependency.
|
|
78
140
|
- No remote code loading or execution.
|
|
141
|
+
- Surface-driven `dispatch()` is denied unless the host's action policy explicitly allows it.
|
|
142
|
+
- Direct `callTool()` is a lower-level API for trusted host code. It validates JSON arguments but does not apply the surface action policy.
|
|
143
|
+
- Prefer `createAllowlistActionPolicy()` so surface authorization covers tool arguments, not only tool names.
|
|
144
|
+
- Untrusted JSON is reconstructed without prototype mutation and rejects cycles, non-plain objects, non-finite numbers, excessive depth, excessive value counts, and oversized strings or object keys.
|
|
145
|
+
- Declared actions reject fields outside the exact `{ type, name, arguments? }` contract.
|
|
146
|
+
- Extension declarations require prefixed identifiers and JSON-object settings; server metadata never activates an extension.
|
|
79
147
|
- Host applications remain responsible for authentication, permissions, transport security, and user approval.
|
|
80
148
|
|
|
81
149
|
## Related packages
|
|
82
150
|
|
|
83
151
|
- [`@mcp-native/a2ui`](https://www.npmjs.com/package/@mcp-native/a2ui) validates declarative surfaces and actions.
|
|
152
|
+
- [`@mcp-native/mcp`](https://github.com/pablospaniard/mcp-native/tree/main/packages/mcp) adapts connected official SDK clients to this package's contracts.
|
|
84
153
|
- [`@mcp-native/react-native`](https://www.npmjs.com/package/@mcp-native/react-native) converts validated surfaces into trusted native render plans.
|
|
85
154
|
- [`@mcp-native/webview`](https://www.npmjs.com/package/@mcp-native/webview) defines the HTML compatibility policy boundary.
|
|
86
|
-
- [`mcp-native`](https://www.npmjs.com/package/mcp-native) re-exports the
|
|
155
|
+
- [`mcp-native`](https://www.npmjs.com/package/mcp-native) re-exports the runtime and UI APIs.
|
|
87
156
|
|
|
88
157
|
## License
|
|
89
158
|
|
package/dist/index.d.ts
CHANGED
|
@@ -3,33 +3,165 @@ export type JsonValue = JsonPrimitive | JsonObject | readonly JsonValue[];
|
|
|
3
3
|
export interface JsonObject {
|
|
4
4
|
readonly [key: string]: JsonValue;
|
|
5
5
|
}
|
|
6
|
+
/** Maximum nesting depth accepted by the public JSON validators (root is depth 0). */
|
|
7
|
+
export declare const JSON_MAX_DEPTH = 64;
|
|
8
|
+
/** Maximum number of values accepted in one JSON graph. */
|
|
9
|
+
export declare const JSON_MAX_VALUES = 10000;
|
|
10
|
+
/** Maximum UTF-16 code units accepted in one JSON string. */
|
|
11
|
+
export declare const JSON_MAX_STRING_LENGTH = 65536;
|
|
12
|
+
/** Thrown when an untrusted value cannot be represented as JSON data. */
|
|
13
|
+
export declare class JsonValidationError extends TypeError {
|
|
14
|
+
constructor(message: string);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Validates and safely reconstructs an untrusted JSON object.
|
|
18
|
+
*
|
|
19
|
+
* The returned object keeps keys such as `__proto__` as ordinary own data
|
|
20
|
+
* properties instead of invoking legacy prototype setters.
|
|
21
|
+
*/
|
|
22
|
+
export declare function parseJsonObject(value: unknown, path?: string): JsonObject;
|
|
23
|
+
/** Validates and safely reconstructs an untrusted JSON value. */
|
|
24
|
+
export declare function parseJsonValue(value: unknown, path?: string): JsonValue;
|
|
25
|
+
export type McpRole = "assistant" | "user";
|
|
26
|
+
export interface McpAnnotations {
|
|
27
|
+
readonly audience?: readonly McpRole[];
|
|
28
|
+
readonly priority?: number;
|
|
29
|
+
readonly lastModified?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface McpIcon {
|
|
32
|
+
readonly src: string;
|
|
33
|
+
readonly mimeType?: string;
|
|
34
|
+
readonly sizes?: readonly string[];
|
|
35
|
+
readonly theme?: "dark" | "light";
|
|
36
|
+
}
|
|
37
|
+
export interface McpToolAnnotations {
|
|
38
|
+
readonly title?: string;
|
|
39
|
+
readonly readOnlyHint?: boolean;
|
|
40
|
+
readonly destructiveHint?: boolean;
|
|
41
|
+
readonly idempotentHint?: boolean;
|
|
42
|
+
readonly openWorldHint?: boolean;
|
|
43
|
+
}
|
|
6
44
|
export interface McpTool {
|
|
45
|
+
readonly icons?: readonly McpIcon[];
|
|
7
46
|
readonly name: string;
|
|
47
|
+
readonly title?: string;
|
|
8
48
|
readonly description?: string;
|
|
9
49
|
readonly inputSchema: JsonObject;
|
|
50
|
+
readonly outputSchema?: JsonObject;
|
|
51
|
+
readonly annotations?: McpToolAnnotations;
|
|
52
|
+
readonly _meta?: JsonObject;
|
|
53
|
+
}
|
|
54
|
+
export interface McpTextContent {
|
|
55
|
+
readonly type: "text";
|
|
56
|
+
readonly text: string;
|
|
57
|
+
readonly annotations?: McpAnnotations;
|
|
58
|
+
readonly _meta?: JsonObject;
|
|
59
|
+
}
|
|
60
|
+
export interface McpImageContent {
|
|
61
|
+
readonly type: "image";
|
|
62
|
+
readonly data: string;
|
|
63
|
+
readonly mimeType: string;
|
|
64
|
+
readonly annotations?: McpAnnotations;
|
|
65
|
+
readonly _meta?: JsonObject;
|
|
10
66
|
}
|
|
11
|
-
export interface
|
|
12
|
-
readonly type:
|
|
13
|
-
readonly data:
|
|
67
|
+
export interface McpAudioContent {
|
|
68
|
+
readonly type: "audio";
|
|
69
|
+
readonly data: string;
|
|
70
|
+
readonly mimeType: string;
|
|
71
|
+
readonly annotations?: McpAnnotations;
|
|
72
|
+
readonly _meta?: JsonObject;
|
|
73
|
+
}
|
|
74
|
+
export interface McpResourceLink {
|
|
75
|
+
readonly type: "resource_link";
|
|
76
|
+
readonly icons?: readonly McpIcon[];
|
|
77
|
+
readonly name: string;
|
|
78
|
+
readonly title?: string;
|
|
79
|
+
readonly uri: string;
|
|
80
|
+
readonly description?: string;
|
|
81
|
+
readonly mimeType?: string;
|
|
82
|
+
readonly annotations?: McpAnnotations;
|
|
83
|
+
readonly size?: number;
|
|
84
|
+
readonly _meta?: JsonObject;
|
|
85
|
+
}
|
|
86
|
+
interface McpResourceContentsBase {
|
|
87
|
+
readonly uri: string;
|
|
88
|
+
readonly mimeType?: string;
|
|
89
|
+
readonly _meta?: JsonObject;
|
|
14
90
|
}
|
|
91
|
+
export interface McpTextResourceContents extends McpResourceContentsBase {
|
|
92
|
+
readonly text: string;
|
|
93
|
+
readonly blob?: never;
|
|
94
|
+
}
|
|
95
|
+
export interface McpBlobResourceContents extends McpResourceContentsBase {
|
|
96
|
+
readonly blob: string;
|
|
97
|
+
readonly text?: never;
|
|
98
|
+
}
|
|
99
|
+
export type McpResource = McpTextResourceContents | McpBlobResourceContents;
|
|
100
|
+
export interface McpEmbeddedResource {
|
|
101
|
+
readonly type: "resource";
|
|
102
|
+
readonly resource: McpResource;
|
|
103
|
+
readonly annotations?: McpAnnotations;
|
|
104
|
+
readonly _meta?: JsonObject;
|
|
105
|
+
}
|
|
106
|
+
export type McpContent = McpAudioContent | McpEmbeddedResource | McpImageContent | McpResourceLink | McpTextContent;
|
|
15
107
|
export interface McpToolCallResult {
|
|
16
108
|
readonly content: readonly McpContent[];
|
|
17
109
|
readonly isError?: boolean;
|
|
110
|
+
readonly structuredContent?: JsonValue;
|
|
111
|
+
readonly _meta?: JsonObject;
|
|
18
112
|
}
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
readonly
|
|
22
|
-
readonly
|
|
23
|
-
readonly
|
|
113
|
+
export type McpCacheScope = "private" | "public";
|
|
114
|
+
export interface McpListToolsResult {
|
|
115
|
+
readonly tools: readonly McpTool[];
|
|
116
|
+
readonly nextCursor?: string;
|
|
117
|
+
readonly ttlMs?: number;
|
|
118
|
+
readonly cacheScope?: McpCacheScope;
|
|
119
|
+
readonly _meta?: JsonObject;
|
|
120
|
+
}
|
|
121
|
+
export interface McpReadResourceResult {
|
|
122
|
+
readonly contents: readonly McpResource[];
|
|
123
|
+
readonly ttlMs?: number;
|
|
124
|
+
readonly cacheScope?: McpCacheScope;
|
|
125
|
+
readonly _meta?: JsonObject;
|
|
24
126
|
}
|
|
127
|
+
/** Per-extension settings advertised through MCP capability declarations. */
|
|
128
|
+
export interface McpExtensionSettings {
|
|
129
|
+
readonly [identifier: string]: JsonObject;
|
|
130
|
+
}
|
|
131
|
+
export type McpExtensionNegotiation = {
|
|
132
|
+
readonly kind: "fallback";
|
|
133
|
+
readonly identifier: string;
|
|
134
|
+
readonly reason: "client-unsupported" | "server-unsupported";
|
|
135
|
+
} | {
|
|
136
|
+
readonly kind: "negotiated";
|
|
137
|
+
readonly identifier: string;
|
|
138
|
+
readonly clientSettings: JsonObject;
|
|
139
|
+
readonly serverSettings: JsonObject;
|
|
140
|
+
};
|
|
141
|
+
/** Returns whether a value is a valid, mandatorily prefixed MCP extension identifier. */
|
|
142
|
+
export declare function isMcpExtensionIdentifier(value: unknown): value is string;
|
|
143
|
+
/** Validates and safely reconstructs an MCP extension capability map. */
|
|
144
|
+
export declare function parseMcpExtensionSettings(value: unknown, path?: string): McpExtensionSettings;
|
|
145
|
+
/**
|
|
146
|
+
* Negotiates one extension from explicit client and server capability maps.
|
|
147
|
+
* Metadata and MIME types are deliberately not considered capability grants.
|
|
148
|
+
*/
|
|
149
|
+
export declare function negotiateMcpExtension(identifier: string, clientExtensions: unknown, serverExtensions: unknown): McpExtensionNegotiation;
|
|
25
150
|
/**
|
|
26
151
|
* The small client boundary consumed by the runtime. SDK-specific clients can
|
|
27
152
|
* implement this interface without coupling the core package to a transport.
|
|
28
153
|
*/
|
|
29
154
|
export interface McpClient {
|
|
30
|
-
listTools(): Promise<
|
|
155
|
+
listTools(): Promise<McpListToolsResult>;
|
|
31
156
|
callTool(name: string, arguments_: JsonObject): Promise<McpToolCallResult>;
|
|
32
|
-
readResource(uri: string): Promise<
|
|
157
|
+
readResource(uri: string): Promise<McpReadResourceResult>;
|
|
158
|
+
/**
|
|
159
|
+
* Optional snapshot of extensions this client actually advertised.
|
|
160
|
+
* Omission means the client advertised none.
|
|
161
|
+
*/
|
|
162
|
+
getClientExtensionSettings?(): McpExtensionSettings;
|
|
163
|
+
/** Optional server capability snapshot; omission means no extension support. */
|
|
164
|
+
getServerExtensionSettings?(): McpExtensionSettings;
|
|
33
165
|
}
|
|
34
166
|
export interface ToolAction {
|
|
35
167
|
readonly type: "tool";
|
|
@@ -37,6 +169,42 @@ export interface ToolAction {
|
|
|
37
169
|
readonly arguments?: JsonObject;
|
|
38
170
|
}
|
|
39
171
|
export type McpNativeAction = ToolAction;
|
|
172
|
+
/** Validates and safely reconstructs a surface-declared native action. */
|
|
173
|
+
export declare function parseMcpNativeAction(value: unknown, path?: string): McpNativeAction;
|
|
174
|
+
/** A host-owned policy deciding which validated tool actions may execute. */
|
|
175
|
+
export type McpNativeActionPolicy = (action: McpNativeAction) => boolean | Promise<boolean>;
|
|
176
|
+
/**
|
|
177
|
+
* An allowlist entry that authorizes a tool by name and either exact arguments
|
|
178
|
+
* or a host-provided argument predicate. Name-only allowlists are intentionally
|
|
179
|
+
* unsupported — omit `arguments` to require empty/missing arguments, or supply
|
|
180
|
+
* `authorizeArguments` for dynamic checks.
|
|
181
|
+
*
|
|
182
|
+
* `authorizeArguments` may be sync or async, but must resolve to a boolean.
|
|
183
|
+
* Only an explicit `true` authorizes; thenables are awaited so a denied async
|
|
184
|
+
* predicate cannot be treated as a truthy Promise object.
|
|
185
|
+
*/
|
|
186
|
+
export type McpNativeToolAllowlistEntry = {
|
|
187
|
+
readonly name: string;
|
|
188
|
+
/** Exact JSON arguments required. Omit to allow only empty/missing arguments. */
|
|
189
|
+
readonly arguments?: JsonObject;
|
|
190
|
+
} | {
|
|
191
|
+
readonly name: string;
|
|
192
|
+
readonly authorizeArguments: (arguments_?: JsonObject) => boolean | Promise<boolean>;
|
|
193
|
+
};
|
|
194
|
+
/** Builds a fail-closed action policy from an explicit tool/argument allowlist. */
|
|
195
|
+
export declare function createAllowlistActionPolicy(allowlist: readonly McpNativeToolAllowlistEntry[]): McpNativeActionPolicy;
|
|
196
|
+
export interface McpNativeRuntimeOptions {
|
|
197
|
+
/**
|
|
198
|
+
* Authorizes surface-driven actions through `dispatch()` only. When omitted,
|
|
199
|
+
* `dispatch()` denies every action. Trusted host code can continue to use
|
|
200
|
+
* `callTool()` directly after JSON argument validation.
|
|
201
|
+
*/
|
|
202
|
+
readonly actionPolicy?: McpNativeActionPolicy;
|
|
203
|
+
}
|
|
204
|
+
export declare class McpNativeActionDeniedError extends Error {
|
|
205
|
+
readonly toolName: string;
|
|
206
|
+
constructor(toolName: string);
|
|
207
|
+
}
|
|
40
208
|
/**
|
|
41
209
|
* Coordinates MCP operations without knowing about A2UI, React Native, or any
|
|
42
210
|
* other renderer. It deliberately routes declared actions instead of loading
|
|
@@ -44,10 +212,16 @@ export type McpNativeAction = ToolAction;
|
|
|
44
212
|
*/
|
|
45
213
|
export declare class McpNativeRuntime {
|
|
46
214
|
#private;
|
|
47
|
-
constructor(client: McpClient);
|
|
48
|
-
listTools(): Promise<
|
|
215
|
+
constructor(client: McpClient, options?: McpNativeRuntimeOptions);
|
|
216
|
+
listTools(): Promise<McpListToolsResult>;
|
|
49
217
|
callTool(name: string, arguments_?: JsonObject): Promise<McpToolCallResult>;
|
|
50
|
-
readResource(uri: string): Promise<
|
|
218
|
+
readResource(uri: string): Promise<McpReadResourceResult>;
|
|
219
|
+
/**
|
|
220
|
+
* Negotiates one extension from the client's advertised map and the server's
|
|
221
|
+
* validated map. Callers cannot substitute an unadvertised client map.
|
|
222
|
+
*/
|
|
223
|
+
negotiateExtension(identifier: string): McpExtensionNegotiation;
|
|
51
224
|
dispatch(action: McpNativeAction): Promise<McpToolCallResult>;
|
|
52
225
|
}
|
|
226
|
+
export {};
|
|
53
227
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC;AAE7D,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,UAAU,GAAG,SAAS,SAAS,EAAE,CAAC;AAE1E,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;CACnC;AAED,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,WAAW,EAA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CAAC,CAOpF;IAED,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAExD;IAED;;;OAGG;IACH,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,uBAAuB,CAI9D;IAEK,QAAQ,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAUlE;CACF"}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,154 @@
|
|
|
1
|
+
/** Maximum nesting depth accepted by the public JSON validators (root is depth 0). */
|
|
2
|
+
export const JSON_MAX_DEPTH = 64;
|
|
3
|
+
/** Maximum number of values accepted in one JSON graph. */
|
|
4
|
+
export const JSON_MAX_VALUES = 10_000;
|
|
5
|
+
/** Maximum UTF-16 code units accepted in one JSON string. */
|
|
6
|
+
export const JSON_MAX_STRING_LENGTH = 65_536;
|
|
7
|
+
/** Thrown when an untrusted value cannot be represented as JSON data. */
|
|
8
|
+
export class JsonValidationError extends TypeError {
|
|
9
|
+
constructor(message) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = "JsonValidationError";
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Validates and safely reconstructs an untrusted JSON object.
|
|
16
|
+
*
|
|
17
|
+
* The returned object keeps keys such as `__proto__` as ordinary own data
|
|
18
|
+
* properties instead of invoking legacy prototype setters.
|
|
19
|
+
*/
|
|
20
|
+
export function parseJsonObject(value, path = "value") {
|
|
21
|
+
return parseJsonObjectWithState(value, path, createJsonValidationState(), 0);
|
|
22
|
+
}
|
|
23
|
+
/** Validates and safely reconstructs an untrusted JSON value. */
|
|
24
|
+
export function parseJsonValue(value, path = "value") {
|
|
25
|
+
return parseJsonValueWithState(value, path, createJsonValidationState(), 0);
|
|
26
|
+
}
|
|
27
|
+
/** Returns whether a value is a valid, mandatorily prefixed MCP extension identifier. */
|
|
28
|
+
export function isMcpExtensionIdentifier(value) {
|
|
29
|
+
if (typeof value !== "string" || value.length === 0 || value.length > JSON_MAX_STRING_LENGTH) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
const slash = value.indexOf("/");
|
|
33
|
+
if (slash <= 0 || slash !== value.lastIndexOf("/")) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
const prefix = value.slice(0, slash);
|
|
37
|
+
const name = value.slice(slash + 1);
|
|
38
|
+
const labelPattern = /^[A-Za-z](?:[A-Za-z0-9-]*[A-Za-z0-9])?$/;
|
|
39
|
+
const namePattern = /^[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?$/;
|
|
40
|
+
return namePattern.test(name) && prefix.split(".").every((label) => labelPattern.test(label));
|
|
41
|
+
}
|
|
42
|
+
/** Validates and safely reconstructs an MCP extension capability map. */
|
|
43
|
+
export function parseMcpExtensionSettings(value, path = "extensions") {
|
|
44
|
+
const parsed = parseJsonObject(value, path);
|
|
45
|
+
const extensions = {};
|
|
46
|
+
for (const [identifier, settings] of Object.entries(parsed)) {
|
|
47
|
+
if (!isMcpExtensionIdentifier(identifier)) {
|
|
48
|
+
throw new JsonValidationError(`Invalid MCP extension identifier ${JSON.stringify(identifier)} at ${path}`);
|
|
49
|
+
}
|
|
50
|
+
if (settings === null || typeof settings !== "object" || Array.isArray(settings)) {
|
|
51
|
+
throw new JsonValidationError(`Expected an object at ${path}.${identifier}`);
|
|
52
|
+
}
|
|
53
|
+
defineJsonProperty(extensions, identifier, settings);
|
|
54
|
+
}
|
|
55
|
+
return extensions;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Negotiates one extension from explicit client and server capability maps.
|
|
59
|
+
* Metadata and MIME types are deliberately not considered capability grants.
|
|
60
|
+
*/
|
|
61
|
+
export function negotiateMcpExtension(identifier, clientExtensions, serverExtensions) {
|
|
62
|
+
if (!isMcpExtensionIdentifier(identifier)) {
|
|
63
|
+
throw new JsonValidationError(`Invalid MCP extension identifier ${JSON.stringify(identifier)}`);
|
|
64
|
+
}
|
|
65
|
+
const client = parseMcpExtensionSettings(clientExtensions, "clientExtensions");
|
|
66
|
+
const server = parseMcpExtensionSettings(serverExtensions, "serverExtensions");
|
|
67
|
+
const clientSettings = client[identifier];
|
|
68
|
+
if (clientSettings === undefined) {
|
|
69
|
+
return { kind: "fallback", identifier, reason: "client-unsupported" };
|
|
70
|
+
}
|
|
71
|
+
const serverSettings = server[identifier];
|
|
72
|
+
if (serverSettings === undefined) {
|
|
73
|
+
return { kind: "fallback", identifier, reason: "server-unsupported" };
|
|
74
|
+
}
|
|
75
|
+
return { kind: "negotiated", identifier, clientSettings, serverSettings };
|
|
76
|
+
}
|
|
77
|
+
/** Validates and safely reconstructs a surface-declared native action. */
|
|
78
|
+
export function parseMcpNativeAction(value, path = "action") {
|
|
79
|
+
const action = expectPlainObject(value, path);
|
|
80
|
+
expectOnlyKeys(action, ["arguments", "name", "type"], path);
|
|
81
|
+
if (action.type !== "tool") {
|
|
82
|
+
throw new JsonValidationError(`Expected the string "tool" at ${path}.type`);
|
|
83
|
+
}
|
|
84
|
+
if (typeof action.name !== "string") {
|
|
85
|
+
throw new JsonValidationError(`Expected a string at ${path}.name`);
|
|
86
|
+
}
|
|
87
|
+
if (action.name.length === 0) {
|
|
88
|
+
throw new JsonValidationError(`Expected a non-empty string at ${path}.name`);
|
|
89
|
+
}
|
|
90
|
+
if (action.name.length > JSON_MAX_STRING_LENGTH) {
|
|
91
|
+
throw new JsonValidationError(`String at ${path}.name exceeds maximum length of ${JSON_MAX_STRING_LENGTH}`);
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
type: "tool",
|
|
95
|
+
name: action.name,
|
|
96
|
+
...(action.arguments === undefined
|
|
97
|
+
? {}
|
|
98
|
+
: { arguments: parseJsonObject(action.arguments, `${path}.arguments`) }),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/** Builds a fail-closed action policy from an explicit tool/argument allowlist. */
|
|
102
|
+
export function createAllowlistActionPolicy(allowlist) {
|
|
103
|
+
const entries = allowlist.map((entry) => {
|
|
104
|
+
if (typeof entry.name !== "string" || entry.name.length === 0) {
|
|
105
|
+
throw new JsonValidationError("Expected a non-empty allowlist tool name");
|
|
106
|
+
}
|
|
107
|
+
if ("authorizeArguments" in entry) {
|
|
108
|
+
if (typeof entry.authorizeArguments !== "function") {
|
|
109
|
+
throw new JsonValidationError(`Expected authorizeArguments to be a function for tool ${entry.name}`);
|
|
110
|
+
}
|
|
111
|
+
return entry;
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
name: entry.name,
|
|
115
|
+
arguments: entry.arguments === undefined
|
|
116
|
+
? undefined
|
|
117
|
+
: parseJsonObject(entry.arguments, `allowlist.${entry.name}.arguments`),
|
|
118
|
+
};
|
|
119
|
+
});
|
|
120
|
+
return async (action) => {
|
|
121
|
+
for (const entry of entries) {
|
|
122
|
+
if (entry.name !== action.name) {
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if ("authorizeArguments" in entry) {
|
|
126
|
+
// Predicates must run sequentially so a denied match does not race later entries.
|
|
127
|
+
// eslint-disable-next-line no-await-in-loop -- intentional fail-closed short-circuit
|
|
128
|
+
const allowed = await entry.authorizeArguments(action.arguments);
|
|
129
|
+
if (allowed === true) {
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
if (allowed !== false) {
|
|
133
|
+
throw new JsonValidationError(`authorizeArguments for tool ${entry.name} must return a boolean`);
|
|
134
|
+
}
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (jsonArgumentsMatch(entry.arguments, action.arguments)) {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return false;
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
export class McpNativeActionDeniedError extends Error {
|
|
145
|
+
toolName;
|
|
146
|
+
constructor(toolName) {
|
|
147
|
+
super(`MCP native action denied by host policy: ${toolName}`);
|
|
148
|
+
this.name = "McpNativeActionDeniedError";
|
|
149
|
+
this.toolName = toolName;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
1
152
|
/**
|
|
2
153
|
* Coordinates MCP operations without knowing about A2UI, React Native, or any
|
|
3
154
|
* other renderer. It deliberately routes declared actions instead of loading
|
|
@@ -5,20 +156,173 @@
|
|
|
5
156
|
*/
|
|
6
157
|
export class McpNativeRuntime {
|
|
7
158
|
#client;
|
|
8
|
-
|
|
159
|
+
#actionPolicy;
|
|
160
|
+
constructor(client, options = {}) {
|
|
9
161
|
this.#client = client;
|
|
162
|
+
this.#actionPolicy = options.actionPolicy;
|
|
10
163
|
}
|
|
11
164
|
listTools() {
|
|
12
165
|
return this.#client.listTools();
|
|
13
166
|
}
|
|
14
|
-
callTool(name, arguments_ = {}) {
|
|
15
|
-
|
|
167
|
+
async callTool(name, arguments_ = {}) {
|
|
168
|
+
const validatedAction = parseMcpNativeAction({
|
|
169
|
+
type: "tool",
|
|
170
|
+
name,
|
|
171
|
+
arguments: arguments_,
|
|
172
|
+
});
|
|
173
|
+
return this.#client.callTool(validatedAction.name, validatedAction.arguments ?? {});
|
|
16
174
|
}
|
|
17
175
|
readResource(uri) {
|
|
18
176
|
return this.#client.readResource(uri);
|
|
19
177
|
}
|
|
20
|
-
|
|
21
|
-
|
|
178
|
+
/**
|
|
179
|
+
* Negotiates one extension from the client's advertised map and the server's
|
|
180
|
+
* validated map. Callers cannot substitute an unadvertised client map.
|
|
181
|
+
*/
|
|
182
|
+
negotiateExtension(identifier) {
|
|
183
|
+
const clientExtensions = this.#client.getClientExtensionSettings?.() ?? {};
|
|
184
|
+
const serverExtensions = this.#client.getServerExtensionSettings?.() ?? {};
|
|
185
|
+
return negotiateMcpExtension(identifier, clientExtensions, serverExtensions);
|
|
186
|
+
}
|
|
187
|
+
async dispatch(action) {
|
|
188
|
+
const validatedAction = parseMcpNativeAction(action);
|
|
189
|
+
if (this.#actionPolicy === undefined) {
|
|
190
|
+
throw new McpNativeActionDeniedError(validatedAction.name);
|
|
191
|
+
}
|
|
192
|
+
const allowed = await this.#actionPolicy(validatedAction);
|
|
193
|
+
if (allowed !== true) {
|
|
194
|
+
throw new McpNativeActionDeniedError(validatedAction.name);
|
|
195
|
+
}
|
|
196
|
+
return this.#client.callTool(validatedAction.name, validatedAction.arguments ?? {});
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function jsonArgumentsMatch(expected, actual) {
|
|
200
|
+
if (expected === undefined) {
|
|
201
|
+
return actual === undefined || Object.keys(actual).length === 0;
|
|
22
202
|
}
|
|
203
|
+
if (actual === undefined) {
|
|
204
|
+
return Object.keys(expected).length === 0;
|
|
205
|
+
}
|
|
206
|
+
return jsonValuesEqual(expected, actual);
|
|
207
|
+
}
|
|
208
|
+
function jsonValuesEqual(left, right) {
|
|
209
|
+
if (left === right) {
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
if (left === null || right === null || typeof left !== typeof right) {
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
if (typeof left !== "object" || typeof right !== "object") {
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
if (Array.isArray(left)) {
|
|
219
|
+
if (!Array.isArray(right) || left.length !== right.length) {
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
return left.every((value, index) => jsonValuesEqual(value, right[index]));
|
|
223
|
+
}
|
|
224
|
+
if (Array.isArray(right)) {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
const leftObject = left;
|
|
228
|
+
const rightObject = right;
|
|
229
|
+
const leftKeys = Object.keys(leftObject);
|
|
230
|
+
const rightKeys = Object.keys(rightObject);
|
|
231
|
+
if (leftKeys.length !== rightKeys.length) {
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
return leftKeys.every((key) => Object.hasOwn(rightObject, key) && jsonValuesEqual(leftObject[key], rightObject[key]));
|
|
235
|
+
}
|
|
236
|
+
function expectPlainObject(value, path) {
|
|
237
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
238
|
+
throw new JsonValidationError(`Expected an object at ${path}`);
|
|
239
|
+
}
|
|
240
|
+
const prototype = Object.getPrototypeOf(value);
|
|
241
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
242
|
+
throw new JsonValidationError(`Expected a plain object at ${path}`);
|
|
243
|
+
}
|
|
244
|
+
return value;
|
|
245
|
+
}
|
|
246
|
+
function createJsonValidationState() {
|
|
247
|
+
return { ancestors: new Set(), values: 0 };
|
|
248
|
+
}
|
|
249
|
+
function parseJsonObjectWithState(value, path, state, depth) {
|
|
250
|
+
consumeJsonBudget(state, path, depth);
|
|
251
|
+
const object = expectPlainObject(value, path);
|
|
252
|
+
if (state.ancestors.has(object)) {
|
|
253
|
+
throw new JsonValidationError(`Circular JSON value at ${path}`);
|
|
254
|
+
}
|
|
255
|
+
state.ancestors.add(object);
|
|
256
|
+
const result = {};
|
|
257
|
+
for (const [key, child] of Object.entries(object)) {
|
|
258
|
+
if (key.length > JSON_MAX_STRING_LENGTH) {
|
|
259
|
+
throw new JsonValidationError(`JSON object key at ${path} exceeds maximum length of ${JSON_MAX_STRING_LENGTH}`);
|
|
260
|
+
}
|
|
261
|
+
defineJsonProperty(result, key, parseJsonValueWithState(child, `${path}.${key}`, state, depth + 1));
|
|
262
|
+
}
|
|
263
|
+
state.ancestors.delete(object);
|
|
264
|
+
return result;
|
|
265
|
+
}
|
|
266
|
+
function parseJsonValueWithState(value, path, state, depth) {
|
|
267
|
+
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
268
|
+
return parseJsonObjectWithState(value, path, state, depth);
|
|
269
|
+
}
|
|
270
|
+
consumeJsonBudget(state, path, depth);
|
|
271
|
+
if (value === null || typeof value === "boolean") {
|
|
272
|
+
return value;
|
|
273
|
+
}
|
|
274
|
+
if (typeof value === "string") {
|
|
275
|
+
if (value.length > JSON_MAX_STRING_LENGTH) {
|
|
276
|
+
throw new JsonValidationError(`String at ${path} exceeds maximum length of ${JSON_MAX_STRING_LENGTH}`);
|
|
277
|
+
}
|
|
278
|
+
return value;
|
|
279
|
+
}
|
|
280
|
+
if (typeof value === "number") {
|
|
281
|
+
if (!Number.isFinite(value)) {
|
|
282
|
+
throw new JsonValidationError(`Expected a finite number at ${path}`);
|
|
283
|
+
}
|
|
284
|
+
return value;
|
|
285
|
+
}
|
|
286
|
+
if (Array.isArray(value)) {
|
|
287
|
+
if (state.ancestors.has(value)) {
|
|
288
|
+
throw new JsonValidationError(`Circular JSON value at ${path}`);
|
|
289
|
+
}
|
|
290
|
+
state.ancestors.add(value);
|
|
291
|
+
const result = [];
|
|
292
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
293
|
+
if (!Object.hasOwn(value, index)) {
|
|
294
|
+
throw new JsonValidationError(`Sparse JSON array item at ${path}[${index}]`);
|
|
295
|
+
}
|
|
296
|
+
result.push(parseJsonValueWithState(value[index], `${path}[${index}]`, state, depth + 1));
|
|
297
|
+
}
|
|
298
|
+
state.ancestors.delete(value);
|
|
299
|
+
return result;
|
|
300
|
+
}
|
|
301
|
+
throw new JsonValidationError(`Expected a JSON value at ${path}`);
|
|
302
|
+
}
|
|
303
|
+
function consumeJsonBudget(state, path, depth) {
|
|
304
|
+
if (depth > JSON_MAX_DEPTH) {
|
|
305
|
+
throw new JsonValidationError(`JSON value exceeds maximum depth of ${JSON_MAX_DEPTH} at ${path}`);
|
|
306
|
+
}
|
|
307
|
+
state.values += 1;
|
|
308
|
+
if (state.values > JSON_MAX_VALUES) {
|
|
309
|
+
throw new JsonValidationError(`JSON value exceeds maximum of ${JSON_MAX_VALUES} values`);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
function expectOnlyKeys(object, allowedKeys, path) {
|
|
313
|
+
const allowed = new Set(allowedKeys);
|
|
314
|
+
for (const key of Object.keys(object)) {
|
|
315
|
+
if (!allowed.has(key)) {
|
|
316
|
+
throw new JsonValidationError(`Unsupported field ${JSON.stringify(key)} at ${path}`);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
function defineJsonProperty(object, key, value) {
|
|
321
|
+
Object.defineProperty(object, key, {
|
|
322
|
+
value,
|
|
323
|
+
enumerable: true,
|
|
324
|
+
configurable: true,
|
|
325
|
+
writable: true,
|
|
326
|
+
});
|
|
23
327
|
}
|
|
24
328
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAiDA;;;;GAIG;AACH,MAAM,OAAO,gBAAgB;IAClB,OAAO,CAAY;IAE5B,YAAY,MAAiB;QAC3B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;IAClC,CAAC;IAED,QAAQ,CAAC,IAAY,EAAE,UAAU,GAAe,EAAE;QAChD,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IACjD,CAAC;IAED,YAAY,CAAC,GAAW;QACtB,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;IACxC,CAAC;IAED,QAAQ,CAAC,MAAuB;QAC9B,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC;IAC5D,CAAC;CACF"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,sFAAsF;AACtF,MAAM,CAAC,MAAM,cAAc,GAAG,EAAE,CAAC;AACjC,2DAA2D;AAC3D,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC;AACtC,6DAA6D;AAC7D,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC;AAE7C,yEAAyE;AACzE,MAAM,OAAO,mBAAoB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