@qase/mcp-server 2.7.4 → 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/CHANGELOG.md +58 -0
- package/README.md +4 -4
- package/build/auth/mcp-guard.d.ts.map +1 -1
- package/build/auth/mcp-guard.js +1 -1
- package/build/auth/mcp-guard.js.map +1 -1
- package/build/cache/metrics.d.ts.map +1 -1
- package/build/cache/metrics.js +16 -1
- package/build/cache/metrics.js.map +1 -1
- package/build/index.js +27 -5
- package/build/index.js.map +1 -1
- package/build/operations-v2/composites/ci-report.js +3 -5
- package/build/operations-v2/composites/ci-report.js.map +1 -1
- package/build/operations-v2/composites/regression-run.js +2 -1
- package/build/operations-v2/composites/regression-run.js.map +1 -1
- package/build/operations-v2/composites/triage-defect.js +5 -7
- package/build/operations-v2/composites/triage-defect.js.map +1 -1
- package/build/operations-v2/escape/api.js +11 -4
- package/build/operations-v2/escape/api.js.map +1 -1
- package/build/operations-v2/index.d.ts +1 -0
- package/build/operations-v2/index.d.ts.map +1 -1
- package/build/operations-v2/index.js +1 -0
- package/build/operations-v2/index.js.map +1 -1
- package/build/operations-v2/meta/discover.d.ts +5 -4
- package/build/operations-v2/meta/discover.d.ts.map +1 -1
- package/build/operations-v2/meta/discover.js +13 -32
- package/build/operations-v2/meta/discover.js.map +1 -1
- package/build/operations-v2/meta/tool-help.d.ts +10 -0
- package/build/operations-v2/meta/tool-help.d.ts.map +1 -0
- package/build/operations-v2/meta/tool-help.js +42 -0
- package/build/operations-v2/meta/tool-help.js.map +1 -0
- package/build/operations-v2/qql/index.js +15 -9
- package/build/operations-v2/qql/index.js.map +1 -1
- package/build/operations-v2/read/get.js +2 -1
- package/build/operations-v2/read/get.js.map +1 -1
- package/build/operations-v2/read/project-context.js +9 -7
- package/build/operations-v2/read/project-context.js.map +1 -1
- package/build/operations-v2/write/attachments.js +25 -19
- package/build/operations-v2/write/attachments.js.map +1 -1
- package/build/operations-v2/write/case-fields.d.ts +26 -215
- package/build/operations-v2/write/case-fields.d.ts.map +1 -1
- package/build/operations-v2/write/case-fields.js +28 -24
- package/build/operations-v2/write/case-fields.js.map +1 -1
- package/build/operations-v2/write/cases-bulk.js +2 -1
- package/build/operations-v2/write/cases-bulk.js.map +1 -1
- package/build/operations-v2/write/cases.js +4 -3
- package/build/operations-v2/write/cases.js.map +1 -1
- package/build/operations-v2/write/custom-fields.js +13 -10
- package/build/operations-v2/write/custom-fields.js.map +1 -1
- package/build/operations-v2/write/defects.js +7 -9
- package/build/operations-v2/write/defects.js.map +1 -1
- package/build/operations-v2/write/environments.js +5 -5
- package/build/operations-v2/write/environments.js.map +1 -1
- package/build/operations-v2/write/external-issues.js +2 -2
- package/build/operations-v2/write/external-issues.js.map +1 -1
- package/build/operations-v2/write/milestones.js +6 -6
- package/build/operations-v2/write/milestones.js.map +1 -1
- package/build/operations-v2/write/plans.js +5 -5
- package/build/operations-v2/write/plans.js.map +1 -1
- package/build/operations-v2/write/projects.js +6 -6
- package/build/operations-v2/write/projects.js.map +1 -1
- package/build/operations-v2/write/results.js +7 -12
- package/build/operations-v2/write/results.js.map +1 -1
- package/build/operations-v2/write/reviews.js +18 -18
- package/build/operations-v2/write/reviews.js.map +1 -1
- package/build/operations-v2/write/runs.js +8 -6
- package/build/operations-v2/write/runs.js.map +1 -1
- package/build/operations-v2/write/shared-steps.js +5 -8
- package/build/operations-v2/write/shared-steps.js.map +1 -1
- package/build/operations-v2/write/suites.js +4 -3
- package/build/operations-v2/write/suites.js.map +1 -1
- package/build/server-instructions.d.ts +1 -1
- package/build/server-instructions.d.ts.map +1 -1
- package/build/server-instructions.js +4 -4
- package/build/server.d.ts.map +1 -1
- package/build/server.js +154 -104
- package/build/server.js.map +1 -1
- package/build/transports/body-limit.d.ts +13 -0
- package/build/transports/body-limit.d.ts.map +1 -0
- package/build/transports/body-limit.js +43 -0
- package/build/transports/body-limit.js.map +1 -0
- package/build/transports/json-parse-error.d.ts +10 -6
- package/build/transports/json-parse-error.d.ts.map +1 -1
- package/build/transports/json-parse-error.js +38 -14
- package/build/transports/json-parse-error.js.map +1 -1
- package/build/transports/rate-limit.d.ts +1 -1
- package/build/transports/rate-limit.js +1 -1
- package/build/transports/sse.d.ts.map +1 -1
- package/build/transports/sse.js +3 -2
- package/build/transports/sse.js.map +1 -1
- package/build/transports/streamableHttp.d.ts.map +1 -1
- package/build/transports/streamableHttp.js +84 -171
- package/build/transports/streamableHttp.js.map +1 -1
- package/build/utils/auth-context.d.ts +30 -0
- package/build/utils/auth-context.d.ts.map +1 -1
- package/build/utils/auth-context.js +33 -0
- package/build/utils/auth-context.js.map +1 -1
- package/build/utils/protocol-telemetry.d.ts +62 -0
- package/build/utils/protocol-telemetry.d.ts.map +1 -0
- package/build/utils/protocol-telemetry.js +123 -0
- package/build/utils/protocol-telemetry.js.map +1 -0
- package/build/utils/registry.d.ts +28 -34
- package/build/utils/registry.d.ts.map +1 -1
- package/build/utils/registry.js +107 -102
- package/build/utils/registry.js.map +1 -1
- package/build/utils/request-state.d.ts +71 -0
- package/build/utils/request-state.d.ts.map +1 -0
- package/build/utils/request-state.js +108 -0
- package/build/utils/request-state.js.map +1 -0
- package/build/utils/server-context.d.ts +53 -16
- package/build/utils/server-context.d.ts.map +1 -1
- package/build/utils/server-context.js +147 -39
- package/build/utils/server-context.js.map +1 -1
- package/build/utils/validation.d.ts +12 -25
- package/build/utils/validation.d.ts.map +1 -1
- package/build/utils/validation.js +2 -2
- package/build/utils/validation.js.map +1 -1
- package/build/version.d.ts +1 -1
- package/build/version.js +1 -1
- package/docs/self-run.md +40 -3
- package/docs/tools.md +54 -60
- package/docs/troubleshooting.md +29 -8
- package/package.json +8 -9
- package/server.json +2 -2
package/build/utils/registry.js
CHANGED
|
@@ -1,8 +1,37 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { z } from 'zod';
|
|
2
2
|
/**
|
|
3
3
|
* Tool definition for registration
|
|
4
4
|
* Contains all information needed to register a tool with the MCP server
|
|
5
5
|
*/
|
|
6
|
+
/**
|
|
7
|
+
* `Number.MAX_SAFE_INTEGER`, which zod emits as the bound of every integer.
|
|
8
|
+
*
|
|
9
|
+
* It is true — a JSON number above it loses precision in JavaScript — but it
|
|
10
|
+
* is true of every integer everywhere, so repeating it on all 55 integer
|
|
11
|
+
* fields spends bytes in every tool list to tell the model something that
|
|
12
|
+
* never changes and that no caller of ours is anywhere near. Our integers are
|
|
13
|
+
* record IDs and page sizes.
|
|
14
|
+
*/
|
|
15
|
+
const SAFE_INTEGER_BOUND = 9007199254740991;
|
|
16
|
+
/** Drop that bound wherever zod attached it, in place. */
|
|
17
|
+
function stripSafeIntegerBounds(node) {
|
|
18
|
+
if (Array.isArray(node)) {
|
|
19
|
+
for (const item of node)
|
|
20
|
+
stripSafeIntegerBounds(item);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (node === null || typeof node !== 'object')
|
|
24
|
+
return;
|
|
25
|
+
const record = node;
|
|
26
|
+
if (record.type === 'integer') {
|
|
27
|
+
if (record.maximum === SAFE_INTEGER_BOUND)
|
|
28
|
+
delete record.maximum;
|
|
29
|
+
if (record.minimum === -SAFE_INTEGER_BOUND)
|
|
30
|
+
delete record.minimum;
|
|
31
|
+
}
|
|
32
|
+
for (const value of Object.values(record))
|
|
33
|
+
stripSafeIntegerBounds(value);
|
|
34
|
+
}
|
|
6
35
|
/**
|
|
7
36
|
* Sort by `name`, comparing code units rather than by locale: ListTools and
|
|
8
37
|
* ListPrompts must come back in the same order on every host.
|
|
@@ -12,6 +41,35 @@ function byName(a, b) {
|
|
|
12
41
|
return -1;
|
|
13
42
|
return a.name > b.name ? 1 : 0;
|
|
14
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Annotation hints as the MCP spec defaults them when a tool says nothing.
|
|
46
|
+
* A hint equal to its default carries no information, so the wire projection
|
|
47
|
+
* leaves it out — the client reads exactly the same meaning either way.
|
|
48
|
+
*/
|
|
49
|
+
const SPEC_DEFAULT_HINTS = {
|
|
50
|
+
readOnlyHint: false,
|
|
51
|
+
destructiveHint: true,
|
|
52
|
+
idempotentHint: false,
|
|
53
|
+
openWorldHint: true,
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* The shape a tool takes on the wire, as opposed to the one the registry
|
|
57
|
+
* stores. Every byte of `tools/list` is sent to the model on every request:
|
|
58
|
+
*
|
|
59
|
+
* - hints equal to the spec defaults are dropped (see SPEC_DEFAULT_HINTS);
|
|
60
|
+
* - `outputSchema` is dropped: no client validates results against it, and
|
|
61
|
+
* its one job here — deciding whether to attach `structuredContent` — is
|
|
62
|
+
* now done for every object result (see server.ts).
|
|
63
|
+
*
|
|
64
|
+
* The stored definition keeps both, because handlers and tests read it.
|
|
65
|
+
*/
|
|
66
|
+
function toWire(tool) {
|
|
67
|
+
const { outputSchema: _omitted, annotations, ...rest } = tool;
|
|
68
|
+
if (!annotations)
|
|
69
|
+
return rest;
|
|
70
|
+
const kept = Object.fromEntries(Object.entries(annotations).filter(([k, v]) => SPEC_DEFAULT_HINTS[k] !== v));
|
|
71
|
+
return Object.keys(kept).length ? { ...rest, annotations: kept } : rest;
|
|
72
|
+
}
|
|
15
73
|
/**
|
|
16
74
|
* Tool Registry Class
|
|
17
75
|
* Manages the lifecycle of MCP tools with support for dynamic discovery
|
|
@@ -19,22 +77,11 @@ function byName(a, b) {
|
|
|
19
77
|
export class ToolRegistry {
|
|
20
78
|
tools = new Map();
|
|
21
79
|
handlers = new Map();
|
|
22
|
-
|
|
23
|
-
toolVisibility = new Map();
|
|
24
|
-
/**
|
|
25
|
-
* Listeners invoked when the active tool set changes (each wired to one
|
|
26
|
-
* Server's sendToolListChanged).
|
|
27
|
-
*
|
|
28
|
-
* A set rather than a single slot because the registry is a process-wide
|
|
29
|
-
* singleton while every HTTP session gets its own Server: with one slot each
|
|
30
|
-
* new session overwrote the previous one's callback, so only the newest
|
|
31
|
-
* session ever heard that discovery had activated a tool.
|
|
32
|
-
*/
|
|
33
|
-
toolsChangedListeners = new Set();
|
|
80
|
+
help = new Map();
|
|
34
81
|
/**
|
|
35
82
|
* Register a new tool with the registry
|
|
36
83
|
*
|
|
37
|
-
* @param definition - Tool definition including name, description, schema
|
|
84
|
+
* @param definition - Tool definition including name, description, schema and handler
|
|
38
85
|
*
|
|
39
86
|
* @example
|
|
40
87
|
* ```typescript
|
|
@@ -44,41 +91,34 @@ export class ToolRegistry {
|
|
|
44
91
|
* description: 'Get all projects',
|
|
45
92
|
* schema: z.object({ limit: z.number().optional() }),
|
|
46
93
|
* handler: async (args) => { ... },
|
|
47
|
-
* visibility: 'discoverable', // hidden until discovered
|
|
48
94
|
* });
|
|
49
95
|
* ```
|
|
50
96
|
*/
|
|
51
97
|
register(definition) {
|
|
52
|
-
const { name, title, description, schema, handler, annotations, outputSchema } = definition;
|
|
53
|
-
|
|
54
|
-
//
|
|
55
|
-
//
|
|
56
|
-
//
|
|
57
|
-
//
|
|
98
|
+
const { name, title, description, schema, handler, annotations, outputSchema, help } = definition;
|
|
99
|
+
// Convert the Zod schema to JSON Schema for the MCP protocol.
|
|
100
|
+
//
|
|
101
|
+
// `io: 'input'` is what the client is being described: a field with a
|
|
102
|
+
// default is optional on the way in, and a `z.preprocess` is advertised by
|
|
103
|
+
// what it accepts rather than by what it produces.
|
|
104
|
+
//
|
|
105
|
+
// zod emits `$defs` + `$ref` for a schema that refers to itself (the test
|
|
106
|
+
// step tree). That is the only way to express recursion in JSON Schema at
|
|
107
|
+
// all, and the pointers are same-document, which every JSON Schema
|
|
108
|
+
// implementation resolves.
|
|
109
|
+
//
|
|
110
|
+
// Cast through `unknown`: the conversion is value-level, and letting
|
|
111
|
+
// TypeScript infer it across our deepest schemas trips "excessively deep".
|
|
58
112
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const definitionKey = Object.keys(jsonSchema.definitions)[0];
|
|
69
|
-
inputSchema = jsonSchema.definitions[definitionKey];
|
|
70
|
-
}
|
|
71
|
-
else if (jsonSchema.type === 'object') {
|
|
72
|
-
// Use directly
|
|
73
|
-
inputSchema = jsonSchema;
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
// Fallback: create minimal object schema
|
|
77
|
-
inputSchema = {
|
|
78
|
-
type: 'object',
|
|
79
|
-
properties: {},
|
|
80
|
-
};
|
|
81
|
-
}
|
|
113
|
+
const converted = z.toJSONSchema(schema, { io: 'input' });
|
|
114
|
+
// `$schema` says which dialect the document is written in. The tool list
|
|
115
|
+
// repeats it in all 42 schemas and no client reads it, so it is dropped —
|
|
116
|
+
// the MCP spec already fixes the dialect for `inputSchema`.
|
|
117
|
+
const { $schema: _dialect, ...body } = converted;
|
|
118
|
+
stripSafeIntegerBounds(body);
|
|
119
|
+
const inputSchema = body.type === 'object'
|
|
120
|
+
? body
|
|
121
|
+
: { type: 'object', properties: {} };
|
|
82
122
|
// Store tool definition
|
|
83
123
|
this.tools.set(name, {
|
|
84
124
|
name,
|
|
@@ -90,28 +130,36 @@ export class ToolRegistry {
|
|
|
90
130
|
});
|
|
91
131
|
// Store handler function
|
|
92
132
|
this.handlers.set(name, handler);
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (visibility === 'core') {
|
|
96
|
-
this.activeTools.add(name);
|
|
97
|
-
}
|
|
133
|
+
if (help)
|
|
134
|
+
this.help.set(name, help);
|
|
98
135
|
// Log registration for debugging (to stderr)
|
|
99
|
-
console.error(`[Registry] Registered tool: ${name}
|
|
136
|
+
console.error(`[Registry] Registered tool: ${name}`);
|
|
100
137
|
}
|
|
101
138
|
/**
|
|
102
|
-
*
|
|
103
|
-
*
|
|
139
|
+
* Every tool, in the shape it takes on the wire. Nothing is hidden: the
|
|
140
|
+
* full list is what a client needs to call any of them, and a client cannot
|
|
141
|
+
* be told about a list that changed on a stateless connection anyway.
|
|
104
142
|
*/
|
|
105
143
|
getTools() {
|
|
106
|
-
return
|
|
107
|
-
|
|
108
|
-
|
|
144
|
+
return this.getDefinitions().map(toWire);
|
|
145
|
+
}
|
|
146
|
+
/** The long documentation of a tool, or undefined when it has none. */
|
|
147
|
+
getHelp(name) {
|
|
148
|
+
return this.help.get(name);
|
|
109
149
|
}
|
|
110
150
|
/**
|
|
111
|
-
*
|
|
112
|
-
*
|
|
151
|
+
* Every tool as it was registered, with nothing projected away.
|
|
152
|
+
*
|
|
153
|
+
* This is what code INSIDE the server reads — search, the category filter,
|
|
154
|
+
* the help index. `getTools()` is for the wire and drops annotation hints
|
|
155
|
+
* that match the spec's own defaults, and one of those defaults is
|
|
156
|
+
* `destructiveHint: true`. Reading the wire shape internally therefore said
|
|
157
|
+
* no tool was destructive: `qase_discover_tools` answered `category:
|
|
158
|
+
* "delete"` with nothing and reported `destructive: false` for every
|
|
159
|
+
* deletion it listed. The two shapes are kept apart by name so that cannot
|
|
160
|
+
* be reintroduced by reaching for whichever accessor is nearest.
|
|
113
161
|
*/
|
|
114
|
-
|
|
162
|
+
getDefinitions() {
|
|
115
163
|
return Array.from(this.tools.values()).sort(byName);
|
|
116
164
|
}
|
|
117
165
|
/**
|
|
@@ -126,49 +174,11 @@ export class ToolRegistry {
|
|
|
126
174
|
const words = query.toLowerCase().split(/\s+/).filter(Boolean);
|
|
127
175
|
if (words.length === 0)
|
|
128
176
|
return [];
|
|
129
|
-
return this.
|
|
177
|
+
return this.getDefinitions().filter((t) => {
|
|
130
178
|
const haystack = `${t.name} ${t.description ?? ''}`.toLowerCase();
|
|
131
179
|
return words.every((word) => haystack.includes(word));
|
|
132
180
|
});
|
|
133
181
|
}
|
|
134
|
-
/**
|
|
135
|
-
* Subscribe to active-tool-set changes. Returns an unsubscribe function the
|
|
136
|
-
* caller must invoke when its session ends, or the listener — and the Server
|
|
137
|
-
* it closes over — outlives the connection.
|
|
138
|
-
*/
|
|
139
|
-
subscribeToolsChanged(listener) {
|
|
140
|
-
this.toolsChangedListeners.add(listener);
|
|
141
|
-
return () => {
|
|
142
|
-
this.toolsChangedListeners.delete(listener);
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Activate tools by name, making them visible in getTools().
|
|
147
|
-
* Returns the list of newly activated tool names.
|
|
148
|
-
* Notifies every subscriber if any tools were activated.
|
|
149
|
-
*/
|
|
150
|
-
activateTools(names) {
|
|
151
|
-
const newlyActivated = [];
|
|
152
|
-
for (const name of names) {
|
|
153
|
-
if (this.tools.has(name) && !this.activeTools.has(name)) {
|
|
154
|
-
this.activeTools.add(name);
|
|
155
|
-
newlyActivated.push(name);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
if (newlyActivated.length > 0) {
|
|
159
|
-
for (const listener of this.toolsChangedListeners) {
|
|
160
|
-
// One dead session's transport must not swallow the notification for
|
|
161
|
-
// every session subscribed after it.
|
|
162
|
-
try {
|
|
163
|
-
listener();
|
|
164
|
-
}
|
|
165
|
-
catch (err) {
|
|
166
|
-
console.error('[Registry] Tool-list-changed listener failed:', err);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
return newlyActivated;
|
|
171
|
-
}
|
|
172
182
|
/**
|
|
173
183
|
* Get handler function for a specific tool
|
|
174
184
|
*
|
|
@@ -209,8 +219,6 @@ export class ToolRegistry {
|
|
|
209
219
|
unregister(name) {
|
|
210
220
|
const hadTool = this.tools.delete(name);
|
|
211
221
|
this.handlers.delete(name);
|
|
212
|
-
this.activeTools.delete(name);
|
|
213
|
-
this.toolVisibility.delete(name);
|
|
214
222
|
return hadTool;
|
|
215
223
|
}
|
|
216
224
|
/**
|
|
@@ -221,9 +229,6 @@ export class ToolRegistry {
|
|
|
221
229
|
clear() {
|
|
222
230
|
this.tools.clear();
|
|
223
231
|
this.handlers.clear();
|
|
224
|
-
this.activeTools.clear();
|
|
225
|
-
this.toolVisibility.clear();
|
|
226
|
-
this.toolsChangedListeners.clear();
|
|
227
232
|
}
|
|
228
233
|
}
|
|
229
234
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/utils/registry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/utils/registry.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AASxB;;;GAGG;AACH;;;;;;;;GAQG;AACH,MAAM,kBAAkB,GAAG,gBAAgB,CAAC;AAE5C,0DAA0D;AAC1D,SAAS,sBAAsB,CAAC,IAAa;IAC3C,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,KAAK,MAAM,IAAI,IAAI,IAAI;YAAE,sBAAsB,CAAC,IAAI,CAAC,CAAC;QACtD,OAAO;IACT,CAAC;IACD,IAAI,IAAI,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO;IAEtD,MAAM,MAAM,GAAG,IAA+B,CAAC;IAC/C,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC9B,IAAI,MAAM,CAAC,OAAO,KAAK,kBAAkB;YAAE,OAAO,MAAM,CAAC,OAAO,CAAC;QACjE,IAAI,MAAM,CAAC,OAAO,KAAK,CAAC,kBAAkB;YAAE,OAAO,MAAM,CAAC,OAAO,CAAC;IACpE,CAAC;IACD,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;QAAE,sBAAsB,CAAC,KAAK,CAAC,CAAC;AAC3E,CAAC;AAED;;;GAGG;AACH,SAAS,MAAM,CAAC,CAAmB,EAAE,CAAmB;IACtD,IAAI,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI;QAAE,OAAO,CAAC,CAAC,CAAC;IAC/B,OAAO,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CA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,CAAC;IAED;;;;;;OAMG;IACH,UAAU,CAAC,IAAY;QACrB,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACxC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC3B,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;;;OAIG;IACH,KAAK;QACH,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACnB,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,YAAY,EAAE,CAAC;AAE/C;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAoB;IAC7C,YAAY,EAAE,IAAI;IAClB,eAAe,EAAE,KAAK;IACtB,cAAc,EAAE,IAAI;IACpB,aAAa,EAAE,IAAI;CACpB,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAoB;IAC/C,YAAY,EAAE,KAAK;IACnB,eAAe,EAAE,KAAK;IACtB,cAAc,EAAE,KAAK;IACrB,aAAa,EAAE,IAAI;CACpB,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAoB;IAC/C,YAAY,EAAE,KAAK;IACnB,eAAe,EAAE,KAAK;IACtB,cAAc,EAAE,IAAI;IACpB,aAAa,EAAE,IAAI;CACpB,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAoB;IAC/C,YAAY,EAAE,KAAK;IACnB,eAAe,EAAE,IAAI;IACrB,cAAc,EAAE,IAAI;IACpB,aAAa,EAAE,IAAI;CACpB,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-round-trip request state.
|
|
3
|
+
*
|
|
4
|
+
* A destructive confirmation now spans two requests: the first returns an
|
|
5
|
+
* input-required result, the second carries the answer. Nothing on the server
|
|
6
|
+
* remembers the first one — the only thing that connects them is the opaque
|
|
7
|
+
* `requestState` string the client echoes back.
|
|
8
|
+
*/
|
|
9
|
+
import type { RequestStateCodec } from '@modelcontextprotocol/server';
|
|
10
|
+
/** What a pending destructive confirmation carries across the round trip. */
|
|
11
|
+
export interface ConfirmationState {
|
|
12
|
+
/** The tool the confirmation was issued for; an answer only counts for it. */
|
|
13
|
+
tool: string;
|
|
14
|
+
/**
|
|
15
|
+
* Digest of the arguments the human was shown.
|
|
16
|
+
*
|
|
17
|
+
* The tool name alone does not say WHAT was confirmed. Without this, an
|
|
18
|
+
* accepted `qase_case_delete {code:'TEST', id:1}` could be echoed back
|
|
19
|
+
* unchanged against `{code:'PROD', id:999}` for the whole lifetime of the
|
|
20
|
+
* state — same caller, same tool, valid signature — and the second case
|
|
21
|
+
* would be deleted with nobody asked. The client here is the agent, and
|
|
22
|
+
* stopping exactly that is what this gate is for.
|
|
23
|
+
*/
|
|
24
|
+
arguments: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* How long a confirmation stays answerable.
|
|
28
|
+
*
|
|
29
|
+
* This is a human's thinking time, not a protocol timeout: the prompt is in
|
|
30
|
+
* front of a person deciding whether to delete something. Ten minutes is long
|
|
31
|
+
* enough to read the arguments, check them elsewhere and come back, and short
|
|
32
|
+
* enough that an answer given before lunch is not still spendable after it.
|
|
33
|
+
* It is the SDK's own default, stated here because it is a policy decision
|
|
34
|
+
* rather than an implementation detail.
|
|
35
|
+
*/
|
|
36
|
+
export declare const CONFIRMATION_TTL_SECONDS = 600;
|
|
37
|
+
/**
|
|
38
|
+
* Digest of a call's arguments, for pinning a confirmation to the exact call
|
|
39
|
+
* the human saw.
|
|
40
|
+
*
|
|
41
|
+
* Canonical: keys are sorted at every depth, so `{a:1,b:2}` and `{b:2,a:1}`
|
|
42
|
+
* agree — the same call written two ways is the same call, and a client that
|
|
43
|
+
* re-serialises its arguments between rounds must not be told its answer no
|
|
44
|
+
* longer counts. Array order is preserved, because it is part of the value.
|
|
45
|
+
*/
|
|
46
|
+
export declare function digestArguments(args: Record<string, unknown>): string;
|
|
47
|
+
/**
|
|
48
|
+
* requestState round-trips through the client, so it comes back as
|
|
49
|
+
* attacker-controlled input and has to be integrity-checked. The SDK does not
|
|
50
|
+
* do that for us — this is the HMAC layer it expects.
|
|
51
|
+
*
|
|
52
|
+
* The key must be the same on every replica that might receive the echoed
|
|
53
|
+
* value. Without one we generate a random key and say so: a single replica
|
|
54
|
+
* keeps working, a multi-replica deployment would reject its own second round.
|
|
55
|
+
*
|
|
56
|
+
* `bind` ties a minted confirmation to the caller and the method, so a
|
|
57
|
+
* confirmation issued to one authenticated user cannot be replayed by another
|
|
58
|
+
* — the spec's user-binding requirement for state that gates authorization.
|
|
59
|
+
* The binding value never reaches the wire; the codec stores a keyed tag.
|
|
60
|
+
* The caller identity comes from `subjectFromContext` (auth-context.ts) — the
|
|
61
|
+
* same derivation tool activation uses — so a caller with no OAuth `sub` is
|
|
62
|
+
* bound by their per-request token digest rather than collapsing onto one
|
|
63
|
+
* shared, empty binding for everyone.
|
|
64
|
+
*/
|
|
65
|
+
export declare function createRequestStateCodecFromEnv(env?: typeof process.env): RequestStateCodec<ConfirmationState>;
|
|
66
|
+
/**
|
|
67
|
+
* Lazy for the same reason as the event bus and the activation store:
|
|
68
|
+
* importing the module must not build anything and must not write to stderr.
|
|
69
|
+
*/
|
|
70
|
+
export declare function getRequestStateCodec(): RequestStateCodec<ConfirmationState>;
|
|
71
|
+
//# sourceMappingURL=request-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-state.d.ts","sourceRoot":"","sources":["../../src/utils/request-state.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,8BAA8B,CAAC;AAGrF,6EAA6E;AAC7E,MAAM,WAAW,iBAAiB;IAChC,8EAA8E;IAC9E,IAAI,EAAE,MAAM,CAAC;IACb;;;;;;;;;OASG;IACH,SAAS,EAAE,MAAM,CAAC;CACnB;AAID;;;;;;;;;GASG;AACH,eAAO,MAAM,wBAAwB,MAAM,CAAC;AA4B5C;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAIrE;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,8BAA8B,CAC5C,GAAG,GAAE,OAAO,OAAO,CAAC,GAAiB,GACpC,iBAAiB,CAAC,iBAAiB,CAAC,CAmBtC;AAKD;;;GAGG;AACH,wBAAgB,oBAAoB,IAAI,iBAAiB,CAAC,iBAAiB,CAAC,CAG3E"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-round-trip request state.
|
|
3
|
+
*
|
|
4
|
+
* A destructive confirmation now spans two requests: the first returns an
|
|
5
|
+
* input-required result, the second carries the answer. Nothing on the server
|
|
6
|
+
* remembers the first one — the only thing that connects them is the opaque
|
|
7
|
+
* `requestState` string the client echoes back.
|
|
8
|
+
*/
|
|
9
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
10
|
+
import { createRequestStateCodec } from '@modelcontextprotocol/server';
|
|
11
|
+
import { subjectFromContext } from './auth-context.js';
|
|
12
|
+
const MIN_KEY_BYTES = 32;
|
|
13
|
+
/**
|
|
14
|
+
* How long a confirmation stays answerable.
|
|
15
|
+
*
|
|
16
|
+
* This is a human's thinking time, not a protocol timeout: the prompt is in
|
|
17
|
+
* front of a person deciding whether to delete something. Ten minutes is long
|
|
18
|
+
* enough to read the arguments, check them elsewhere and come back, and short
|
|
19
|
+
* enough that an answer given before lunch is not still spendable after it.
|
|
20
|
+
* It is the SDK's own default, stated here because it is a policy decision
|
|
21
|
+
* rather than an implementation detail.
|
|
22
|
+
*/
|
|
23
|
+
export const CONFIRMATION_TTL_SECONDS = 600;
|
|
24
|
+
/**
|
|
25
|
+
* Order two keys by code unit, NOT by `localeCompare`.
|
|
26
|
+
*
|
|
27
|
+
* This ordering feeds a digest that two replicas must agree on, and
|
|
28
|
+
* `localeCompare` depends on the runtime's locale data — it could order the
|
|
29
|
+
* same two keys differently on two machines and refuse a confirmation the
|
|
30
|
+
* user actually gave.
|
|
31
|
+
*/
|
|
32
|
+
function byCodeUnit(a, b) {
|
|
33
|
+
if (a < b)
|
|
34
|
+
return -1;
|
|
35
|
+
if (a > b)
|
|
36
|
+
return 1;
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
|
39
|
+
/** Recursively sort object keys so two spellings of one value serialise alike. */
|
|
40
|
+
function canonicalize(value) {
|
|
41
|
+
if (Array.isArray(value))
|
|
42
|
+
return value.map(canonicalize);
|
|
43
|
+
if (value === null || typeof value !== 'object')
|
|
44
|
+
return value;
|
|
45
|
+
const source = value;
|
|
46
|
+
return Object.fromEntries(Object.keys(source)
|
|
47
|
+
.sort(byCodeUnit)
|
|
48
|
+
.map((key) => [key, canonicalize(source[key])]));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Digest of a call's arguments, for pinning a confirmation to the exact call
|
|
52
|
+
* the human saw.
|
|
53
|
+
*
|
|
54
|
+
* Canonical: keys are sorted at every depth, so `{a:1,b:2}` and `{b:2,a:1}`
|
|
55
|
+
* agree — the same call written two ways is the same call, and a client that
|
|
56
|
+
* re-serialises its arguments between rounds must not be told its answer no
|
|
57
|
+
* longer counts. Array order is preserved, because it is part of the value.
|
|
58
|
+
*/
|
|
59
|
+
export function digestArguments(args) {
|
|
60
|
+
return createHash('sha256')
|
|
61
|
+
.update(JSON.stringify(canonicalize(args)))
|
|
62
|
+
.digest('hex');
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* requestState round-trips through the client, so it comes back as
|
|
66
|
+
* attacker-controlled input and has to be integrity-checked. The SDK does not
|
|
67
|
+
* do that for us — this is the HMAC layer it expects.
|
|
68
|
+
*
|
|
69
|
+
* The key must be the same on every replica that might receive the echoed
|
|
70
|
+
* value. Without one we generate a random key and say so: a single replica
|
|
71
|
+
* keeps working, a multi-replica deployment would reject its own second round.
|
|
72
|
+
*
|
|
73
|
+
* `bind` ties a minted confirmation to the caller and the method, so a
|
|
74
|
+
* confirmation issued to one authenticated user cannot be replayed by another
|
|
75
|
+
* — the spec's user-binding requirement for state that gates authorization.
|
|
76
|
+
* The binding value never reaches the wire; the codec stores a keyed tag.
|
|
77
|
+
* The caller identity comes from `subjectFromContext` (auth-context.ts) — the
|
|
78
|
+
* same derivation tool activation uses — so a caller with no OAuth `sub` is
|
|
79
|
+
* bound by their per-request token digest rather than collapsing onto one
|
|
80
|
+
* shared, empty binding for everyone.
|
|
81
|
+
*/
|
|
82
|
+
export function createRequestStateCodecFromEnv(env = process.env) {
|
|
83
|
+
const configured = env.QASE_MCP_REQUEST_STATE_KEY;
|
|
84
|
+
if (configured !== undefined && Buffer.byteLength(configured) < MIN_KEY_BYTES) {
|
|
85
|
+
throw new Error(`QASE_MCP_REQUEST_STATE_KEY must be at least ${MIN_KEY_BYTES} bytes; got ${Buffer.byteLength(configured)}.`);
|
|
86
|
+
}
|
|
87
|
+
if (!configured) {
|
|
88
|
+
console.error('[RequestState] QASE_MCP_REQUEST_STATE_KEY is not set — generating a per-process key. ' +
|
|
89
|
+
'Multi-round-trip confirmations will fail across replicas; set the variable to a shared ' +
|
|
90
|
+
'value of at least 32 bytes before running more than one.');
|
|
91
|
+
}
|
|
92
|
+
return createRequestStateCodec({
|
|
93
|
+
key: configured ?? randomBytes(MIN_KEY_BYTES),
|
|
94
|
+
ttlSeconds: CONFIRMATION_TTL_SECONDS,
|
|
95
|
+
bind: (ctx) => `${ctx.mcpReq.method}\0${subjectFromContext(ctx)}`,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
/** The one codec this process mints and verifies with, built on first use. */
|
|
99
|
+
let processCodec;
|
|
100
|
+
/**
|
|
101
|
+
* Lazy for the same reason as the event bus and the activation store:
|
|
102
|
+
* importing the module must not build anything and must not write to stderr.
|
|
103
|
+
*/
|
|
104
|
+
export function getRequestStateCodec() {
|
|
105
|
+
processCodec ??= createRequestStateCodecFromEnv();
|
|
106
|
+
return processCodec;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=request-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-state.js","sourceRoot":"","sources":["../../src/utils/request-state.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAEvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAmBvD,MAAM,aAAa,GAAG,EAAE,CAAC;AAEzB;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAE5C;;;;;;;GAOG;AACH,SAAS,UAAU,CAAC,CAAS,EAAE,CAAS;IACtC,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,CAAC,CAAC,CAAC;IACrB,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,CAAC,CAAC;IACpB,OAAO,CAAC,CAAC;AACX,CAAC;AAED,kFAAkF;AAClF,SAAS,YAAY,CAAC,KAAc;IAClC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IACzD,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC9D,MAAM,MAAM,GAAG,KAAgC,CAAC;IAChD,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;SAChB,IAAI,CAAC,UAAU,CAAC;SAChB,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,CA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
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Per-request context for code that sits too far below a request handler to be
|
|
5
|
+
* passed it, carried through AsyncLocalStorage the same way auth-context.ts
|
|
6
|
+
* carries the caller's subject.
|
|
6
7
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
8
|
+
* Two stores live here: the MCP `Server` instance (for server-level features)
|
|
9
|
+
* and the handler's own `ServerContext`, which is what the destructive-action
|
|
10
|
+
* gate needs — it reads the retry's answers, the verified request state, and
|
|
11
|
+
* the protocol era off it.
|
|
9
12
|
*/
|
|
10
13
|
import { AsyncLocalStorage } from 'async_hooks';
|
|
11
|
-
import type { Server,
|
|
14
|
+
import type { InputRequiredResult, Server, ServerContext } from '@modelcontextprotocol/server';
|
|
12
15
|
/**
|
|
13
16
|
* Per-request server storage.
|
|
14
17
|
* Holds the Server instance for the current request context.
|
|
@@ -19,14 +22,45 @@ export declare const serverStorage: AsyncLocalStorage<Server>;
|
|
|
19
22
|
* Returns undefined if called outside of a serverStorage.run() scope.
|
|
20
23
|
*/
|
|
21
24
|
export declare function getServer(): Server | undefined;
|
|
25
|
+
/** Per-request handler context, for code too far below the handler to be passed it. */
|
|
26
|
+
export declare const requestContextStorage: AsyncLocalStorage<ServerContext>;
|
|
27
|
+
/**
|
|
28
|
+
* Get the current request's handler context.
|
|
29
|
+
* Returns undefined if called outside of a requestContextStorage.run() scope.
|
|
30
|
+
*/
|
|
31
|
+
export declare function getRequestContext(): ServerContext | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Thrown by the destructive-action gate to hand an input-required result up to
|
|
34
|
+
* the `tools/call` handler.
|
|
35
|
+
*
|
|
36
|
+
* Multi-round-trip works by RETURNING the request, but the gate is called from
|
|
37
|
+
* inside plain tool handlers (`(args) => Promise<R>`) several frames below the
|
|
38
|
+
* handler that does the returning — see src/operations-v2/escape/api.ts. An
|
|
39
|
+
* exception is the only way up that does not change every handler's signature.
|
|
40
|
+
*/
|
|
41
|
+
export declare class InputRequiredSignal extends Error {
|
|
42
|
+
readonly result: InputRequiredResult;
|
|
43
|
+
constructor(result: InputRequiredResult);
|
|
44
|
+
}
|
|
22
45
|
/** Why a destructive action was refused. */
|
|
23
46
|
export type RefusalReason =
|
|
24
|
-
/** The client
|
|
47
|
+
/** The client speaks an era on which this server cannot ask at all. */
|
|
25
48
|
'unsupported'
|
|
26
|
-
/** The
|
|
49
|
+
/** The client speaks the right era but never said it can show a prompt. */
|
|
50
|
+
| 'incapable'
|
|
51
|
+
/** The prompt was sent but no usable answer came back for this action. */
|
|
27
52
|
| 'undeliverable'
|
|
28
53
|
/** The human saw the prompt and said no. */
|
|
29
|
-
| 'declined'
|
|
54
|
+
| 'declined'
|
|
55
|
+
/**
|
|
56
|
+
* The client dropped the prompt instead of answering it.
|
|
57
|
+
*
|
|
58
|
+
* Kept apart from `declined` deliberately. Reporting a cancel as a refusal
|
|
59
|
+
* tells somebody they said no to a question they were never shown — which
|
|
60
|
+
* is exactly how this reached us: a tester was told they had declined a run
|
|
61
|
+
* deletion they had never been asked about.
|
|
62
|
+
*/
|
|
63
|
+
| 'cancelled';
|
|
30
64
|
/** Outcome of the destructive-action gate. */
|
|
31
65
|
export type DestructiveConfirmation = {
|
|
32
66
|
allowed: true;
|
|
@@ -35,17 +69,20 @@ export type DestructiveConfirmation = {
|
|
|
35
69
|
reason: RefusalReason;
|
|
36
70
|
};
|
|
37
71
|
/**
|
|
38
|
-
* Ask the user to confirm a destructive action
|
|
72
|
+
* Ask the user to confirm a destructive action, across a round trip.
|
|
39
73
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
74
|
+
* On the first round there is no answer, so the gate signals an input-required
|
|
75
|
+
* result and the `tools/call` handler returns it; the client collects the
|
|
76
|
+
* answer and retries the same call carrying it. On the retry the answer is
|
|
77
|
+
* read straight off the request.
|
|
43
78
|
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
79
|
+
* Fail-closed: the action proceeds only on an explicit accept whose signed
|
|
80
|
+
* state names this very call — this tool, with these arguments. No request
|
|
81
|
+
* context, a client on a protocol revision this server cannot ask, a decline,
|
|
82
|
+
* a cancel, an answer belonging to some other confirmation — all refuse, and
|
|
83
|
+
* name the reason so the caller can say what happened.
|
|
47
84
|
*/
|
|
48
|
-
export declare function confirmDestructiveAction(toolName: string, args: Record<string, unknown
|
|
85
|
+
export declare function confirmDestructiveAction(toolName: string, args: Record<string, unknown>): Promise<DestructiveConfirmation>;
|
|
49
86
|
/** Human-readable explanation for a refused destructive action. */
|
|
50
87
|
export declare function describeRefusal(toolName: string, reason: RefusalReason): string;
|
|
51
88
|
//# sourceMappingURL=server-context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-context.d.ts","sourceRoot":"","sources":["../../src/utils/server-context.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"server-context.d.ts","sourceRoot":"","sources":["../../src/utils/server-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAMhD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAG/F;;;GAGG;AACH,eAAO,MAAM,aAAa,2BAAkC,CAAC;AAE7D;;;GAGG;AACH,wBAAgB,SAAS,IAAI,MAAM,GAAG,SAAS,CAE9C;AAED,uFAAuF;AACvF,eAAO,MAAM,qBAAqB,kCAAyC,CAAC;AAE5E;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,aAAa,GAAG,SAAS,CAE7D;AAKD;;;;;;;;GAQG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;IAChC,QAAQ,CAAC,MAAM,EAAE,mBAAmB;gBAA3B,MAAM,EAAE,mBAAmB;CAIjD;AAED,4CAA4C;AAC5C,MAAM,MAAM,aAAa;AACvB,uEAAuE;AACrE,aAAa;AACf,2EAA2E;GACz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