agentfootprint 12.0.0 → 12.1.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/CAPABILITIES.md +1 -0
- package/dist/answer-account/templates.js +12 -6
- package/dist/answer-account/templates.js.map +1 -1
- package/dist/answer-validation/types.js.map +1 -1
- package/dist/core/agent/assessment/assess.js +94 -32
- package/dist/core/agent/assessment/assess.js.map +1 -1
- package/dist/core/agent/assessment/reasons.js +2 -2
- package/dist/core/agent/assessment/reasons.js.map +1 -1
- package/dist/core/agent/assessment/sources.js +61 -23
- package/dist/core/agent/assessment/sources.js.map +1 -1
- package/dist/core/agent/negativeClaims/delivery.js +10 -1
- package/dist/core/agent/negativeClaims/delivery.js.map +1 -1
- package/dist/esm/answer-account/templates.d.ts +1 -1
- package/dist/esm/answer-account/templates.js +12 -6
- package/dist/esm/answer-account/templates.js.map +1 -1
- package/dist/esm/answer-validation/types.d.ts +10 -0
- package/dist/esm/answer-validation/types.js.map +1 -1
- package/dist/esm/core/agent/assessment/assess.d.ts +6 -3
- package/dist/esm/core/agent/assessment/assess.js +95 -33
- package/dist/esm/core/agent/assessment/assess.js.map +1 -1
- package/dist/esm/core/agent/assessment/reasons.js +2 -2
- package/dist/esm/core/agent/assessment/reasons.js.map +1 -1
- package/dist/esm/core/agent/assessment/sources.d.ts +26 -1
- package/dist/esm/core/agent/assessment/sources.js +59 -22
- package/dist/esm/core/agent/assessment/sources.js.map +1 -1
- package/dist/esm/core/agent/assessment/types.d.ts +3 -1
- package/dist/esm/core/agent/negativeClaims/delivery.d.ts +9 -1
- package/dist/esm/core/agent/negativeClaims/delivery.js +10 -1
- package/dist/esm/core/agent/negativeClaims/delivery.js.map +1 -1
- package/dist/esm/identity/types.d.ts +12 -0
- package/dist/esm/identity/types.js.map +1 -1
- package/dist/esm/identity/withCredentialRetry.d.ts +5 -0
- package/dist/esm/identity/withCredentialRetry.js +16 -3
- package/dist/esm/identity/withCredentialRetry.js.map +1 -1
- package/dist/esm/lib/boundedJson.d.ts +27 -0
- package/dist/esm/lib/boundedJson.js +33 -0
- package/dist/esm/lib/boundedJson.js.map +1 -1
- package/dist/esm/mcp/callChecks.d.ts +160 -0
- package/dist/esm/mcp/callChecks.js +237 -0
- package/dist/esm/mcp/callChecks.js.map +1 -0
- package/dist/esm/mcp/gatewayTransport.d.ts +8 -0
- package/dist/esm/mcp/gatewayTransport.js +35 -2
- package/dist/esm/mcp/gatewayTransport.js.map +1 -1
- package/dist/esm/mcp/index.d.ts +3 -1
- package/dist/esm/mcp/index.js +7 -0
- package/dist/esm/mcp/index.js.map +1 -1
- package/dist/esm/mcp/listingGenerations.d.ts +54 -0
- package/dist/esm/mcp/listingGenerations.js +75 -0
- package/dist/esm/mcp/listingGenerations.js.map +1 -0
- package/dist/esm/mcp/mcpClient.js +108 -23
- package/dist/esm/mcp/mcpClient.js.map +1 -1
- package/dist/esm/mcp/toolList.d.ts +90 -0
- package/dist/esm/mcp/toolList.js +123 -0
- package/dist/esm/mcp/toolList.js.map +1 -0
- package/dist/esm/mcp/types.d.ts +118 -2
- package/dist/esm/tool-providers/index.d.ts +2 -2
- package/dist/esm/tool-providers/index.js +8 -0
- package/dist/esm/tool-providers/index.js.map +1 -1
- package/dist/identity/types.js.map +1 -1
- package/dist/identity/withCredentialRetry.js +16 -3
- package/dist/identity/withCredentialRetry.js.map +1 -1
- package/dist/lib/boundedJson.js +35 -1
- package/dist/lib/boundedJson.js.map +1 -1
- package/dist/mcp/callChecks.js +247 -0
- package/dist/mcp/callChecks.js.map +1 -0
- package/dist/mcp/gatewayTransport.js +35 -2
- package/dist/mcp/gatewayTransport.js.map +1 -1
- package/dist/mcp/index.js +10 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/listingGenerations.js +80 -0
- package/dist/mcp/listingGenerations.js.map +1 -0
- package/dist/mcp/mcpClient.js +108 -23
- package/dist/mcp/mcpClient.js.map +1 -1
- package/dist/mcp/toolList.js +128 -0
- package/dist/mcp/toolList.js.map +1 -0
- package/dist/tool-providers/index.js +9 -1
- package/dist/tool-providers/index.js.map +1 -1
- package/dist/types/answer-account/templates.d.ts +1 -1
- package/dist/types/answer-account/templates.d.ts.map +1 -1
- package/dist/types/answer-validation/types.d.ts +10 -0
- package/dist/types/answer-validation/types.d.ts.map +1 -1
- package/dist/types/core/agent/assessment/assess.d.ts +6 -3
- package/dist/types/core/agent/assessment/assess.d.ts.map +1 -1
- package/dist/types/core/agent/assessment/reasons.d.ts.map +1 -1
- package/dist/types/core/agent/assessment/sources.d.ts +26 -1
- package/dist/types/core/agent/assessment/sources.d.ts.map +1 -1
- package/dist/types/core/agent/assessment/types.d.ts +3 -1
- package/dist/types/core/agent/assessment/types.d.ts.map +1 -1
- package/dist/types/core/agent/negativeClaims/delivery.d.ts +9 -1
- package/dist/types/core/agent/negativeClaims/delivery.d.ts.map +1 -1
- package/dist/types/identity/types.d.ts +12 -0
- package/dist/types/identity/types.d.ts.map +1 -1
- package/dist/types/identity/withCredentialRetry.d.ts +5 -0
- package/dist/types/identity/withCredentialRetry.d.ts.map +1 -1
- package/dist/types/lib/boundedJson.d.ts +27 -0
- package/dist/types/lib/boundedJson.d.ts.map +1 -1
- package/dist/types/mcp/callChecks.d.ts +161 -0
- package/dist/types/mcp/callChecks.d.ts.map +1 -0
- package/dist/types/mcp/gatewayTransport.d.ts +8 -0
- package/dist/types/mcp/gatewayTransport.d.ts.map +1 -1
- package/dist/types/mcp/index.d.ts +3 -1
- package/dist/types/mcp/index.d.ts.map +1 -1
- package/dist/types/mcp/listingGenerations.d.ts +55 -0
- package/dist/types/mcp/listingGenerations.d.ts.map +1 -0
- package/dist/types/mcp/mcpClient.d.ts.map +1 -1
- package/dist/types/mcp/toolList.d.ts +91 -0
- package/dist/types/mcp/toolList.d.ts.map +1 -0
- package/dist/types/mcp/types.d.ts +118 -2
- package/dist/types/mcp/types.d.ts.map +1 -1
- package/dist/types/tool-providers/index.d.ts +2 -2
- package/dist/types/tool-providers/index.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* callChecks — a listing never makes a callable tool lose its checks.
|
|
3
|
+
*
|
|
4
|
+
* Pattern: the SDK's three per-tool call checks, carried by every tool the
|
|
5
|
+
* library hands out, plus one typed refusal.
|
|
6
|
+
* Role: The MCP SDK's `Client` runs three checks inside `callTool`, and it
|
|
7
|
+
* keeps them only for the tools of its most recent `tools/list`
|
|
8
|
+
* answer (1.32: `cacheToolMetadata` replaces them on every answer):
|
|
9
|
+
*
|
|
10
|
+
* 1. a tool with `execution.taskSupport: 'required'` is refused before a
|
|
11
|
+
* plain `tools/call` is sent;
|
|
12
|
+
* 2. a tool with an `outputSchema` must answer with `structuredContent`,
|
|
13
|
+
* unless the answer is an error;
|
|
14
|
+
* 3. that `structuredContent` must match the schema.
|
|
15
|
+
*
|
|
16
|
+
* So a tool that declares any of them carries them itself, as the listing it
|
|
17
|
+
* came from declared them. The library leaves them to the SDK only for a tool
|
|
18
|
+
* of a ONE-page list whose answer is still the latest, with no list request
|
|
19
|
+
* out (`listingGenerations.ts`), both when the call starts and when its answer
|
|
20
|
+
* comes in: the one-page normal case, which runs exactly as it always did.
|
|
21
|
+
* Every other call runs the tool's own checks, at the SDK's moments — the first
|
|
22
|
+
* before sending, the other two once the answer is in, before anything reads it
|
|
23
|
+
* — and raises the SDK's error: its own `McpError` where this arm loaded the
|
|
24
|
+
* SDK, otherwise an error with the same name, code and message. Those calls
|
|
25
|
+
* are to a tool of a paged list, a tool whose list a later answer replaced (a
|
|
26
|
+
* refresh that failed or succeeded; a reference held across it), and any call
|
|
27
|
+
* made while a list is being read.
|
|
28
|
+
*
|
|
29
|
+
* All of this covers the lists the library reads (`tools()`, `refresh()`); a
|
|
30
|
+
* listing it does not send — the SDK client's own automatic refresh, a
|
|
31
|
+
* `listTools` call of the caller's — is not seen (`listingGenerations.ts`).
|
|
32
|
+
*
|
|
33
|
+
* The output checks need a JSON Schema validator equal to the client's: the
|
|
34
|
+
* SDK's default (`AjvJsonSchemaValidator`, loaded with the SDK on the Node
|
|
35
|
+
* loader arm), or the caller's `jsonSchemaValidator`. Where neither exists — an
|
|
36
|
+
* `sdk` or `connection` arm given none — an answer under these rules is never
|
|
37
|
+
* returned unchecked (`McpOutputUncheckedError`):
|
|
38
|
+
*
|
|
39
|
+
* - a call under the tool's own checks from the start, to a tool that
|
|
40
|
+
* declares an `outputSchema`, is refused before it is sent (`sent: false`);
|
|
41
|
+
* - a call that started under the SDK's checks is refused once its answer is
|
|
42
|
+
* in, unread, when the library sent a `tools/list` request while the call
|
|
43
|
+
* was out (`sent: true`): the SDK may have checked it against another list.
|
|
44
|
+
*
|
|
45
|
+
* A schema is compiled when a tool's own checks first need it, never before:
|
|
46
|
+
* the one-page normal case compiles nothing twice.
|
|
47
|
+
*/
|
|
48
|
+
/** JSON-RPC's codes for the two errors the SDK raises here. */
|
|
49
|
+
const INVALID_REQUEST = -32600;
|
|
50
|
+
const INVALID_PARAMS = -32602;
|
|
51
|
+
/**
|
|
52
|
+
* The kit for one connection, named `server`, whose list requests `listings`
|
|
53
|
+
* counts (`listingsOf(connection)`, shared by every client over it). `given` is
|
|
54
|
+
* the caller's `jsonSchemaValidator`; `loaded` holds what the library loaded
|
|
55
|
+
* with the SDK on the Node loader arm — the SDK's default validator class and
|
|
56
|
+
* its `McpError` — each `undefined` where it is not a constructor (another arm,
|
|
57
|
+
* or an SDK without it).
|
|
58
|
+
*/
|
|
59
|
+
export function callCheckKit(server, listings, given, loaded = {}) {
|
|
60
|
+
const Default = typeof loaded.Validator === 'function' ? loaded.Validator : undefined;
|
|
61
|
+
let created;
|
|
62
|
+
return {
|
|
63
|
+
server,
|
|
64
|
+
validator: () => {
|
|
65
|
+
if (given !== undefined)
|
|
66
|
+
return given;
|
|
67
|
+
if (Default === undefined)
|
|
68
|
+
return undefined;
|
|
69
|
+
created ??= new Default();
|
|
70
|
+
return created;
|
|
71
|
+
},
|
|
72
|
+
...(typeof loaded.McpError === 'function' && { McpError: loaded.McpError }),
|
|
73
|
+
listings,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* `value` as a validator, or `undefined` when it was not given. Refused by name
|
|
78
|
+
* when it is something else, before anything connects.
|
|
79
|
+
*/
|
|
80
|
+
export function validatorOption(value, at) {
|
|
81
|
+
if (value === undefined)
|
|
82
|
+
return undefined;
|
|
83
|
+
const getValidator = value !== null && (typeof value === 'object' || typeof value === 'function')
|
|
84
|
+
? value.getValidator
|
|
85
|
+
: undefined;
|
|
86
|
+
if (typeof getValidator === 'function')
|
|
87
|
+
return value;
|
|
88
|
+
throw new TypeError(`${at}: \`jsonSchemaValidator\` has no \`getValidator\` method. Pass a JSON Schema ` +
|
|
89
|
+
"validator as the MCP SDK's `Client` takes one: `new AjvJsonSchemaValidator()` from " +
|
|
90
|
+
"'@modelcontextprotocol/sdk/validation/ajv', or the one your client uses.");
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The checks `listed` carries — `undefined` when it declares none. `generation`
|
|
94
|
+
* is the one answer its list was read in, when it was read in one
|
|
95
|
+
* (`toolList.ts` · `ToolListing`); a paged list's tools have none, so the SDK
|
|
96
|
+
* never holds all of them.
|
|
97
|
+
*/
|
|
98
|
+
export function checksFor(listed, kit, generation) {
|
|
99
|
+
const schema = ownObject(listed, 'outputSchema');
|
|
100
|
+
const taskRequired = ownValue(ownObject(listed, 'execution'), 'taskSupport') === 'required';
|
|
101
|
+
if (schema === undefined && !taskRequired)
|
|
102
|
+
return undefined;
|
|
103
|
+
let compiled;
|
|
104
|
+
return {
|
|
105
|
+
server: kit.server,
|
|
106
|
+
tool: listed.name,
|
|
107
|
+
taskRequired,
|
|
108
|
+
outputDeclared: schema !== undefined,
|
|
109
|
+
heldBySdk: () => generation !== undefined && kit.listings.isLatest(generation),
|
|
110
|
+
validate: () => {
|
|
111
|
+
if (schema !== undefined)
|
|
112
|
+
compiled ??= kit.validator()?.getValidator(schema);
|
|
113
|
+
return compiled;
|
|
114
|
+
},
|
|
115
|
+
fail: (code, message) => kit.McpError !== undefined
|
|
116
|
+
? new kit.McpError(code, message)
|
|
117
|
+
: new McpErrorShape(code, message),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* True when this call's output cannot be checked here: it runs under the
|
|
122
|
+
* tool's own checks, the tool declares an `outputSchema`, no validator is
|
|
123
|
+
* reachable, and it is not refused as a required task anyway (that refusal is
|
|
124
|
+
* the SDK's, and comes first). The call is then refused before it is sent.
|
|
125
|
+
*/
|
|
126
|
+
export function outputUnchecked(checks) {
|
|
127
|
+
return checks.outputDeclared && !checks.taskRequired && checks.validate() === undefined;
|
|
128
|
+
}
|
|
129
|
+
/** The SDK's task refusal, word for word, before anything is sent. */
|
|
130
|
+
export function refuseRequiredTask(checks) {
|
|
131
|
+
if (!checks.taskRequired)
|
|
132
|
+
return;
|
|
133
|
+
throw checks.fail(INVALID_REQUEST, `Tool "${checks.tool}" requires task-based execution. ` +
|
|
134
|
+
'Use client.experimental.tasks.callToolStream() instead.');
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* The SDK's two output checks, in its order and with its sentences, once the
|
|
138
|
+
* answer is in and before anything reads it. An answer no validator here can
|
|
139
|
+
* check is never returned: it is refused, unread, as sent.
|
|
140
|
+
*/
|
|
141
|
+
export function checkOutput(checks, result) {
|
|
142
|
+
if (!checks.outputDeclared)
|
|
143
|
+
return;
|
|
144
|
+
const validate = checks.validate();
|
|
145
|
+
if (validate === undefined)
|
|
146
|
+
throw new McpOutputUncheckedError(checks.server, checks.tool, true);
|
|
147
|
+
const structured = ownValue(result, 'structuredContent');
|
|
148
|
+
if (!structured && !ownValue(result, 'isError')) {
|
|
149
|
+
throw checks.fail(INVALID_REQUEST, `Tool ${checks.tool} has an output schema but did not return structured content`);
|
|
150
|
+
}
|
|
151
|
+
if (!structured)
|
|
152
|
+
return;
|
|
153
|
+
let mismatch;
|
|
154
|
+
try {
|
|
155
|
+
const verdict = validate(structured);
|
|
156
|
+
if (!verdict.valid) {
|
|
157
|
+
mismatch = `Structured content does not match the tool's output schema: ${verdict.errorMessage}`;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
throw checks.fail(INVALID_PARAMS, `Failed to validate structured content: ${error instanceof Error ? error.message : String(error)}`);
|
|
162
|
+
}
|
|
163
|
+
if (mismatch !== undefined)
|
|
164
|
+
throw checks.fail(INVALID_PARAMS, mismatch);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* The SDK's `McpError`, for an arm that cannot reach the class itself (`sdk`,
|
|
168
|
+
* `connection`): the same name, `code`, `data` and message, so a caller that
|
|
169
|
+
* branches on those handles it as it handles the SDK's.
|
|
170
|
+
*/
|
|
171
|
+
class McpErrorShape extends Error {
|
|
172
|
+
code;
|
|
173
|
+
data;
|
|
174
|
+
constructor(code, message) {
|
|
175
|
+
super(`MCP error ${code}: ${message}`);
|
|
176
|
+
this.code = code;
|
|
177
|
+
this.data = undefined;
|
|
178
|
+
this.name = 'McpError';
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/** What the refusal says happened, refused before sending. */
|
|
182
|
+
const NOT_SENT = 'was not sent. The tool declares an outputSchema, the MCP SDK no longer holds the checks of ' +
|
|
183
|
+
'the tool list it came from (that list was paged, a later list replaced it, or a list is ' +
|
|
184
|
+
'being read)';
|
|
185
|
+
/** What the refusal says happened, refused once the answer was in. */
|
|
186
|
+
const SENT_UNREAD = 'was sent, and its answer is not returned. The tool declares an outputSchema, a tool list ' +
|
|
187
|
+
'was read while the call was out (so the MCP SDK may not have checked the answer against ' +
|
|
188
|
+
"this tool's schema)";
|
|
189
|
+
/**
|
|
190
|
+
* A tool call whose output this connection cannot check, refused. The tool
|
|
191
|
+
* declares an `outputSchema`, the MCP SDK no longer holds the checks of the
|
|
192
|
+
* tool list it came from, and this connection has no JSON Schema validator to
|
|
193
|
+
* check it with — so its answer is never returned:
|
|
194
|
+
*
|
|
195
|
+
* - `sent: false` — refused before it was sent: nothing reached the server.
|
|
196
|
+
* The tool came from a paged list, from a list a later answer replaced, or
|
|
197
|
+
* the call was made while a list was being read.
|
|
198
|
+
* - `sent: true` — the call was sent, and a `tools/list` request went out
|
|
199
|
+
* before its answer came in: the SDK may have checked that answer against
|
|
200
|
+
* the other list, so it is refused unread. The tool may have run.
|
|
201
|
+
*
|
|
202
|
+
* Pass `jsonSchemaValidator` — the validator your client uses — to `mcpClient`.
|
|
203
|
+
* Names the server and the tool, never an argument or an answer.
|
|
204
|
+
*/
|
|
205
|
+
export class McpOutputUncheckedError extends Error {
|
|
206
|
+
server;
|
|
207
|
+
tool;
|
|
208
|
+
sent;
|
|
209
|
+
code = 'ERR_MCP_OUTPUT_UNCHECKED';
|
|
210
|
+
reason = 'output-unchecked';
|
|
211
|
+
constructor(server, tool,
|
|
212
|
+
/** Whether the request left the client: `false` when the refusal came before it. */
|
|
213
|
+
sent) {
|
|
214
|
+
super(`mcpClient[${server}]: the call to '${tool}' ${sent ? SENT_UNREAD : NOT_SENT}, and this ` +
|
|
215
|
+
'connection has no JSON Schema validator to check its output with. Pass ' +
|
|
216
|
+
'`jsonSchemaValidator` to mcpClient: the validator your client uses.');
|
|
217
|
+
this.server = server;
|
|
218
|
+
this.tool = tool;
|
|
219
|
+
this.sent = sent;
|
|
220
|
+
this.name = 'McpOutputUncheckedError';
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/** An own data property, never an accessor's result; `undefined` otherwise. */
|
|
224
|
+
function ownValue(value, key) {
|
|
225
|
+
if (value === null || typeof value !== 'object')
|
|
226
|
+
return undefined;
|
|
227
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
228
|
+
return descriptor !== undefined && 'value' in descriptor ? descriptor.value : undefined;
|
|
229
|
+
}
|
|
230
|
+
/** An own data property that is a plain object (not an array); `undefined` otherwise. */
|
|
231
|
+
function ownObject(value, key) {
|
|
232
|
+
const found = ownValue(value, key);
|
|
233
|
+
return found !== null && typeof found === 'object' && !Array.isArray(found)
|
|
234
|
+
? found
|
|
235
|
+
: undefined;
|
|
236
|
+
}
|
|
237
|
+
//# sourceMappingURL=callChecks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callChecks.js","sourceRoot":"","sources":["../../../src/mcp/callChecks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AAQH,+DAA+D;AAC/D,MAAM,eAAe,GAAG,CAAC,KAAK,CAAC;AAC/B,MAAM,cAAc,GAAG,CAAC,KAAK,CAAC;AAqB9B;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAC1B,MAAc,EACd,QAA4B,EAC5B,KAAyC,EACzC,SAAwE,EAAE;IAE1E,MAAM,OAAO,GAAG,OAAO,MAAM,CAAC,SAAS,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;IACtF,IAAI,OAA2C,CAAC;IAChD,OAAO;QACL,MAAM;QACN,SAAS,EAAE,GAAG,EAAE;YACd,IAAI,KAAK,KAAK,SAAS;gBAAE,OAAO,KAAK,CAAC;YACtC,IAAI,OAAO,KAAK,SAAS;gBAAE,OAAO,SAAS,CAAC;YAC5C,OAAO,KAAK,IAAK,OAA4C,EAAE,CAAC;YAChE,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,GAAG,CAAC,OAAO,MAAM,CAAC,QAAQ,KAAK,UAAU,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAyB,EAAE,CAAC;QAC5F,QAAQ;KACT,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,KAAc,EAAE,EAAU;IACxD,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC1C,MAAM,YAAY,GAChB,KAA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YACzE,qEAAqE,CACxE,CAAC;QATO,WAAM,GAAN,MAAM,CAAQ;QACd,SAAI,GAAJ,IAAI,CAAQ;QAEZ,SAAI,GAAJ,IAAI,CAAS;QAOtB,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF;AAED,+EAA+E;AAC/E,SAAS,QAAQ,CAAC,KAAc,EAAE,GAAW;IAC3C,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IAClE,MAAM,UAAU,GAAG,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC/D,OAAO,UAAU,KAAK,SAAS,IAAI,OAAO,IAAI,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAC1F,CAAC;AAED,yFAAyF;AACzF,SAAS,SAAS,CAAC,KAAc,EAAE,GAAW;IAC5C,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACnC,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACzE,CAAC,CAAE,KAA2C;QAC9C,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC"}
|
|
@@ -146,6 +146,14 @@ export type FetchLike = (input: string | URL | Request, init?: RequestInit) => P
|
|
|
146
146
|
* Build the `fetch` the MCP SDK will use: one that vends a credential, applies
|
|
147
147
|
* it to this one request, and keeps nothing.
|
|
148
148
|
*
|
|
149
|
+
* The vend is a wait, and it honours the request's abort signal — resolved as
|
|
150
|
+
* fetch resolves it (`init.signal`, else a Request input's own): the provider
|
|
151
|
+
* is handed it (`CredentialRequest.signal`), the wait ends at the abort with the
|
|
152
|
+
* abort, and the signal is checked again once the credential arrives. So an
|
|
153
|
+
* aborted or timed-out request is never sent: the gateway stops waiting and
|
|
154
|
+
* never uses a late credential. A provider that ignores cancellation may still
|
|
155
|
+
* finish its own work.
|
|
156
|
+
*
|
|
149
157
|
* Exported for tests — the secrecy invariant is asserted against this function
|
|
150
158
|
* directly, because that is where a leak would happen and driving a whole SDK
|
|
151
159
|
* to reach it would test less while looking like it tested more.
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
* Pattern: Adapter + Decorator over `fetch`. Role: Layer-3 tool integration.
|
|
35
35
|
*/
|
|
36
36
|
import { isCredentialIssued } from '../identity/types.js';
|
|
37
|
+
import { throwIfAborted, untilAborted } from '../lib/abort.js';
|
|
37
38
|
const DEFAULT_SERVICE = 'gateway';
|
|
38
39
|
/**
|
|
39
40
|
* Describe an MCP connection whose auth headers are vended per request.
|
|
@@ -88,10 +89,29 @@ export class GatewayAuthorizationRequiredError extends Error {
|
|
|
88
89
|
this.authorizationUrl = authorizationUrl;
|
|
89
90
|
}
|
|
90
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* The signal `fetch(input, init)` would honour — fetch's own rule, as
|
|
94
|
+
* `new Request(input, init)` applies it: an `init` that names a `signal`
|
|
95
|
+
* replaces the Request's, and `null` there means no signal at all; otherwise a
|
|
96
|
+
* Request input keeps its own.
|
|
97
|
+
*/
|
|
98
|
+
function effectiveSignal(input, init) {
|
|
99
|
+
if (init?.signal !== undefined)
|
|
100
|
+
return init.signal ?? undefined;
|
|
101
|
+
return typeof Request !== 'undefined' && input instanceof Request ? input.signal : undefined;
|
|
102
|
+
}
|
|
91
103
|
/**
|
|
92
104
|
* Build the `fetch` the MCP SDK will use: one that vends a credential, applies
|
|
93
105
|
* it to this one request, and keeps nothing.
|
|
94
106
|
*
|
|
107
|
+
* The vend is a wait, and it honours the request's abort signal — resolved as
|
|
108
|
+
* fetch resolves it (`init.signal`, else a Request input's own): the provider
|
|
109
|
+
* is handed it (`CredentialRequest.signal`), the wait ends at the abort with the
|
|
110
|
+
* abort, and the signal is checked again once the credential arrives. So an
|
|
111
|
+
* aborted or timed-out request is never sent: the gateway stops waiting and
|
|
112
|
+
* never uses a late credential. A provider that ignores cancellation may still
|
|
113
|
+
* finish its own work.
|
|
114
|
+
*
|
|
95
115
|
* Exported for tests — the secrecy invariant is asserted against this function
|
|
96
116
|
* directly, because that is where a leak would happen and driving a whole SDK
|
|
97
117
|
* to reach it would test less while looking like it tested more.
|
|
@@ -100,11 +120,24 @@ export class GatewayAuthorizationRequiredError extends Error {
|
|
|
100
120
|
*/
|
|
101
121
|
export function createVendingFetch(transport, baseFetch = globalThis.fetch.bind(globalThis)) {
|
|
102
122
|
return async (input, init) => {
|
|
103
|
-
|
|
123
|
+
// The request's own signal, as fetch itself resolves it: the transport's,
|
|
124
|
+
// plus — for a dispatched call or under a deadline — the cancellation the
|
|
125
|
+
// retry series links in; or a Request input's own.
|
|
126
|
+
const signal = effectiveSignal(input, init);
|
|
127
|
+
// An aborted request asks no provider and sends nothing (`lib/abort.ts`).
|
|
128
|
+
throwIfAborted(signal);
|
|
129
|
+
// The provider gets the signal, to stop its own work. The wait is raced
|
|
130
|
+
// against it, so a provider that ignores it cannot hold the request open.
|
|
131
|
+
const result = await untilAborted(transport.credentials.getCredential({
|
|
104
132
|
service: transport.service,
|
|
105
133
|
...(transport.scopes !== undefined && { scopes: transport.scopes }),
|
|
106
134
|
...(transport.mode !== undefined && { mode: transport.mode }),
|
|
107
|
-
|
|
135
|
+
...(signal !== undefined && { signal }),
|
|
136
|
+
}), signal);
|
|
137
|
+
// Checked again once the credential is here, before the request is handed
|
|
138
|
+
// on: a credential that lands after the abort is never used, so an aborted
|
|
139
|
+
// or timed-out request is never sent, however late the provider answers.
|
|
140
|
+
throwIfAborted(signal);
|
|
108
141
|
if (!isCredentialIssued(result)) {
|
|
109
142
|
throw new GatewayAuthorizationRequiredError(transport.service, result.authorizationUrl);
|
|
110
143
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gatewayTransport.js","sourceRoot":"","sources":["../../../src/mcp/gatewayTransport.ts"],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nThrottle, ThrottleFetch, ThrottleRetryInfo, ThrottleRetryOptions, } from './throttleRetry.js';
|
|
14
14
|
export type { McpReplayDeduplication, McpReplayKind, McpReplayOptions, McpReplayPolicy, McpReplayTool, } from './replay.js';
|
|
15
15
|
export { McpReplayUnavailableError, type McpReplayUnavailableReason } from './replayUnavailable.js';
|
|
16
|
-
export
|
|
16
|
+
export { McpToolListIncompleteError, type McpToolListIncompleteReason } from './toolList.js';
|
|
17
|
+
export { McpOutputUncheckedError } from './callChecks.js';
|
|
18
|
+
export type { McpCallToolResult, McpClient, McpClientOptions, McpConnection, McpConnectionOptions, McpJsonSchemaValidator, McpSdk, McpGatewayTransport, McpHttpTransport, McpStdioTransport, McpTransport, McpSdkClient, McpServeOptions, McpServeHandle, McpServeTransport, McpHttpServeTransport, McpStdioServeTransport, McpSdkServer, } from './types.js';
|
package/dist/esm/mcp/index.js
CHANGED
|
@@ -18,4 +18,11 @@ export { retryingFetch } from './throttleRetry.js';
|
|
|
18
18
|
// A call under 'app-authorized' that a connection cannot honour is refused
|
|
19
19
|
// before it is sent, with a typed reason.
|
|
20
20
|
export { McpReplayUnavailableError } from './replayUnavailable.js';
|
|
21
|
+
// A tool list that could not be read to its end (past 100 requests, or a cursor
|
|
22
|
+
// sent twice) is refused with this error and a typed reason, never cut short.
|
|
23
|
+
export { McpToolListIncompleteError } from './toolList.js';
|
|
24
|
+
// A tool whose list the SDK no longer holds, and whose output this connection
|
|
25
|
+
// cannot check — no JSON Schema validator reachable — is refused, never answered
|
|
26
|
+
// unchecked.
|
|
27
|
+
export { McpOutputUncheckedError } from './callChecks.js';
|
|
21
28
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/mcp/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,e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ools/list` answer the MCP SDK's `Client` holds
|
|
3
|
+
* its per-tool call checks for, as far as one connection can tell.
|
|
4
|
+
*
|
|
5
|
+
* Pattern: a count of the list requests one connection sent and settled.
|
|
6
|
+
* Role: The SDK's `Client` keeps its per-tool call checks (`callChecks.ts`)
|
|
7
|
+
* for the tools of the last `tools/list` answer it received: every
|
|
8
|
+
* answer replaces them. A request that FAILED can replace them too: the
|
|
9
|
+
* SDK caches an answer before it returns it, and caching can throw after
|
|
10
|
+
* the old checks are cleared (1.32: an `outputSchema` its validator
|
|
11
|
+
* cannot compile). The library cannot see inside the SDK, but it sends
|
|
12
|
+
* every list request it makes. So it counts them:
|
|
13
|
+
*
|
|
14
|
+
* - a request is OUT from the moment it is sent until it settles, because the
|
|
15
|
+
* SDK replaces its checks before the library sees the answer;
|
|
16
|
+
* - each request that settles, answered or failed, starts a new GENERATION.
|
|
17
|
+
*
|
|
18
|
+
* The SDK holds the checks of a listing's one answer only while the generation
|
|
19
|
+
* that answer settled at is the latest and no request is out. The SDK keeps one
|
|
20
|
+
* set of checks per client, so there is one count per connection object: every
|
|
21
|
+
* `mcpClient` over the same client shares it (`listingsOf`). A `tools/list`
|
|
22
|
+
* request the library did not send — your own code calling `listTools` on a
|
|
23
|
+
* client passed as `connection`, or that client's own automatic refresh
|
|
24
|
+
* (`listChanged.tools` with `autoRefresh`) — is not counted: the library cannot
|
|
25
|
+
* see it, and a tool it handed out goes on leaving its checks to an SDK that no
|
|
26
|
+
* longer holds them. That limit is documented, and pinned by
|
|
27
|
+
* `test/mcp/listingKeepsChecks.limits.test.ts`.
|
|
28
|
+
*/
|
|
29
|
+
/** One settled `tools/list` request's answer, and the generation it settled at. */
|
|
30
|
+
export interface SettledListing<T> {
|
|
31
|
+
readonly answer: T;
|
|
32
|
+
readonly generation: number;
|
|
33
|
+
}
|
|
34
|
+
/** The `tools/list` requests one connection has out, and the generations they settled at. */
|
|
35
|
+
export declare class ListingGenerations {
|
|
36
|
+
private settled;
|
|
37
|
+
private out;
|
|
38
|
+
/**
|
|
39
|
+
* Send one `tools/list` request with `send`, counted as out from the moment it
|
|
40
|
+
* is sent until it settles. Settling starts a new generation, answered or not.
|
|
41
|
+
*
|
|
42
|
+
* @throws whatever `send` rejects with, as it rejected
|
|
43
|
+
*/
|
|
44
|
+
ask<T>(send: () => Promise<T>): Promise<SettledListing<T>>;
|
|
45
|
+
/** True while `generation` is the latest settled one and no request is out. */
|
|
46
|
+
isLatest(generation: number): boolean;
|
|
47
|
+
private settle;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The count for `connection`: the same one for every `mcpClient` that adapts
|
|
51
|
+
* the same client, because the SDK keeps one set of checks per client and a
|
|
52
|
+
* listing by any of them replaces it.
|
|
53
|
+
*/
|
|
54
|
+
export declare function listingsOf(connection: object): ListingGenerations;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* listingGenerations — which `tools/list` answer the MCP SDK's `Client` holds
|
|
3
|
+
* its per-tool call checks for, as far as one connection can tell.
|
|
4
|
+
*
|
|
5
|
+
* Pattern: a count of the list requests one connection sent and settled.
|
|
6
|
+
* Role: The SDK's `Client` keeps its per-tool call checks (`callChecks.ts`)
|
|
7
|
+
* for the tools of the last `tools/list` answer it received: every
|
|
8
|
+
* answer replaces them. A request that FAILED can replace them too: the
|
|
9
|
+
* SDK caches an answer before it returns it, and caching can throw after
|
|
10
|
+
* the old checks are cleared (1.32: an `outputSchema` its validator
|
|
11
|
+
* cannot compile). The library cannot see inside the SDK, but it sends
|
|
12
|
+
* every list request it makes. So it counts them:
|
|
13
|
+
*
|
|
14
|
+
* - a request is OUT from the moment it is sent until it settles, because the
|
|
15
|
+
* SDK replaces its checks before the library sees the answer;
|
|
16
|
+
* - each request that settles, answered or failed, starts a new GENERATION.
|
|
17
|
+
*
|
|
18
|
+
* The SDK holds the checks of a listing's one answer only while the generation
|
|
19
|
+
* that answer settled at is the latest and no request is out. The SDK keeps one
|
|
20
|
+
* set of checks per client, so there is one count per connection object: every
|
|
21
|
+
* `mcpClient` over the same client shares it (`listingsOf`). A `tools/list`
|
|
22
|
+
* request the library did not send — your own code calling `listTools` on a
|
|
23
|
+
* client passed as `connection`, or that client's own automatic refresh
|
|
24
|
+
* (`listChanged.tools` with `autoRefresh`) — is not counted: the library cannot
|
|
25
|
+
* see it, and a tool it handed out goes on leaving its checks to an SDK that no
|
|
26
|
+
* longer holds them. That limit is documented, and pinned by
|
|
27
|
+
* `test/mcp/listingKeepsChecks.limits.test.ts`.
|
|
28
|
+
*/
|
|
29
|
+
/** The `tools/list` requests one connection has out, and the generations they settled at. */
|
|
30
|
+
export class ListingGenerations {
|
|
31
|
+
settled = 0;
|
|
32
|
+
out = 0;
|
|
33
|
+
/**
|
|
34
|
+
* Send one `tools/list` request with `send`, counted as out from the moment it
|
|
35
|
+
* is sent until it settles. Settling starts a new generation, answered or not.
|
|
36
|
+
*
|
|
37
|
+
* @throws whatever `send` rejects with, as it rejected
|
|
38
|
+
*/
|
|
39
|
+
async ask(send) {
|
|
40
|
+
this.out += 1;
|
|
41
|
+
try {
|
|
42
|
+
const answer = await send();
|
|
43
|
+
return { answer, generation: this.settle() };
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
this.settle();
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/** True while `generation` is the latest settled one and no request is out. */
|
|
51
|
+
isLatest(generation) {
|
|
52
|
+
return this.out === 0 && this.settled === generation;
|
|
53
|
+
}
|
|
54
|
+
settle() {
|
|
55
|
+
this.out -= 1;
|
|
56
|
+
this.settled += 1;
|
|
57
|
+
return this.settled;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/** One count per connection object, held only as long as the connection is. */
|
|
61
|
+
const BY_CONNECTION = new WeakMap();
|
|
62
|
+
/**
|
|
63
|
+
* The count for `connection`: the same one for every `mcpClient` that adapts
|
|
64
|
+
* the same client, because the SDK keeps one set of checks per client and a
|
|
65
|
+
* listing by any of them replaces it.
|
|
66
|
+
*/
|
|
67
|
+
export function listingsOf(connection) {
|
|
68
|
+
let listings = BY_CONNECTION.get(connection);
|
|
69
|
+
if (listings === undefined) {
|
|
70
|
+
listings = new ListingGenerations();
|
|
71
|
+
BY_CONNECTION.set(connection, listings);
|
|
72
|
+
}
|
|
73
|
+
return listings;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=listingGenerations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listingGenerations.js","sourceRoot":"","sources":["../../../src/mcp/listingGenerations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAQH,6FAA6F;AAC7F,MAAM,OAAO,kBAAkB;IACrB,OAAO,GAAG,CAAC,CAAC;IACZ,GAAG,GAAG,CAAC,CAAC;IAEhB;;;;;OAKG;IACH,KAAK,CAAC,GAAG,CAAI,IAAsB;QACjC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;QACd,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;YAC5B,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;QAC/C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,EAAE,CAAC;YACd,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED,+EAA+E;IAC/E,QAAQ,CAAC,UAAkB;QACzB,OAAO,IAAI,CAAC,GAAG,KAAK,CAAC,IAAI,IAAI,CAAC,OAAO,KAAK,UAAU,CAAC;IACvD,CAAC;IAEO,MAAM;QACZ,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;QACd,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC;QAClB,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF;AAED,+EAA+E;AAC/E,MAAM,aAAa,GAAG,IAAI,OAAO,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