agentfootprint 12.0.1 → 12.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/AGENTS.md +1 -1
- package/CAPABILITIES.md +3 -0
- package/ai-instructions/claude-code/SKILL.md +1 -1
- package/dist/adapters/mcp/agentcoreRuntime/invoke.js +113 -7
- package/dist/adapters/mcp/agentcoreRuntime/invoke.js.map +1 -1
- package/dist/adapters/mcp/agentcoreRuntime/session.js +21 -21
- package/dist/adapters/mcp/agentcoreRuntime/session.js.map +1 -1
- package/dist/adapters/mcp/agentcoreRuntime/transport.js +79 -5
- package/dist/adapters/mcp/agentcoreRuntime/transport.js.map +1 -1
- package/dist/core/Agent.js +6 -0
- package/dist/core/Agent.js.map +1 -1
- package/dist/core/agent/stages/toolCalls.js +4 -0
- package/dist/core/agent/stages/toolCalls.js.map +1 -1
- package/dist/core/slots/buildToolsSlot.js +8 -0
- package/dist/core/slots/buildToolsSlot.js.map +1 -1
- package/dist/esm/adapters/mcp/agentcoreRuntime/invoke.d.ts +23 -4
- package/dist/esm/adapters/mcp/agentcoreRuntime/invoke.js +112 -6
- package/dist/esm/adapters/mcp/agentcoreRuntime/invoke.js.map +1 -1
- package/dist/esm/adapters/mcp/agentcoreRuntime/session.d.ts +20 -6
- package/dist/esm/adapters/mcp/agentcoreRuntime/session.js +21 -21
- package/dist/esm/adapters/mcp/agentcoreRuntime/session.js.map +1 -1
- package/dist/esm/adapters/mcp/agentcoreRuntime/transport.js +81 -7
- package/dist/esm/adapters/mcp/agentcoreRuntime/transport.js.map +1 -1
- package/dist/esm/core/Agent.js +6 -0
- package/dist/esm/core/Agent.js.map +1 -1
- package/dist/esm/core/agent/stages/toolCalls.js +4 -0
- package/dist/esm/core/agent/stages/toolCalls.js.map +1 -1
- package/dist/esm/core/slots/buildToolsSlot.d.ts +12 -0
- package/dist/esm/core/slots/buildToolsSlot.js +8 -0
- package/dist/esm/core/slots/buildToolsSlot.js.map +1 -1
- package/dist/esm/events/payloads.d.ts +41 -0
- package/dist/esm/events/registry.d.ts +3 -1
- package/dist/esm/events/registry.js +2 -0
- package/dist/esm/events/registry.js.map +1 -1
- package/dist/esm/identity/types.d.ts +7 -3
- package/dist/esm/identity/types.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +4 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/boundedJson.d.ts +14 -7
- package/dist/esm/lib/boundedJson.js +14 -7
- 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/callLifetime.js +5 -2
- package/dist/esm/mcp/callLifetime.js.map +1 -1
- package/dist/esm/mcp/clientPort.d.ts +78 -0
- package/dist/esm/mcp/clientPort.js +33 -0
- package/dist/esm/mcp/clientPort.js.map +1 -0
- package/dist/esm/mcp/gatewayTransport.js +13 -3
- package/dist/esm/mcp/gatewayTransport.js.map +1 -1
- package/dist/esm/mcp/index.d.ts +11 -1
- package/dist/esm/mcp/index.js +15 -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.d.ts +18 -1
- package/dist/esm/mcp/mcpClient.js +302 -57
- package/dist/esm/mcp/mcpClient.js.map +1 -1
- package/dist/esm/mcp/mockMcpClient.js +13 -0
- package/dist/esm/mcp/mockMcpClient.js.map +1 -1
- package/dist/esm/mcp/pool/boundTool.d.ts +58 -0
- package/dist/esm/mcp/pool/boundTool.js +218 -0
- package/dist/esm/mcp/pool/boundTool.js.map +1 -0
- package/dist/esm/mcp/pool/clientSet.d.ts +73 -0
- package/dist/esm/mcp/pool/clientSet.js +152 -0
- package/dist/esm/mcp/pool/clientSet.js.map +1 -0
- package/dist/esm/mcp/pool/definitions.d.ts +103 -0
- package/dist/esm/mcp/pool/definitions.js +168 -0
- package/dist/esm/mcp/pool/definitions.js.map +1 -0
- package/dist/esm/mcp/pool/errors.d.ts +76 -0
- package/dist/esm/mcp/pool/errors.js +91 -0
- package/dist/esm/mcp/pool/errors.js.map +1 -0
- package/dist/esm/mcp/pool/identityKey.d.ts +57 -0
- package/dist/esm/mcp/pool/identityKey.js +94 -0
- package/dist/esm/mcp/pool/identityKey.js.map +1 -0
- package/dist/esm/mcp/pool/lease.d.ts +36 -0
- package/dist/esm/mcp/pool/lease.js +51 -0
- package/dist/esm/mcp/pool/lease.js.map +1 -0
- package/dist/esm/mcp/pool/listTools.d.ts +33 -0
- package/dist/esm/mcp/pool/listTools.js +146 -0
- package/dist/esm/mcp/pool/listTools.js.map +1 -0
- package/dist/esm/mcp/pool/mcpClientPool.d.ts +121 -0
- package/dist/esm/mcp/pool/mcpClientPool.js +151 -0
- package/dist/esm/mcp/pool/mcpClientPool.js.map +1 -0
- package/dist/esm/mcp/pool/options.d.ts +183 -0
- package/dist/esm/mcp/pool/options.js +119 -0
- package/dist/esm/mcp/pool/options.js.map +1 -0
- package/dist/esm/mcp/pool/plan.d.ts +77 -0
- package/dist/esm/mcp/pool/plan.js +134 -0
- package/dist/esm/mcp/pool/plan.js.map +1 -0
- package/dist/esm/mcp/pool/pool.d.ts +307 -0
- package/dist/esm/mcp/pool/pool.js +1071 -0
- package/dist/esm/mcp/pool/pool.js.map +1 -0
- package/dist/esm/mcp/pool/pooledClient.d.ts +93 -0
- package/dist/esm/mcp/pool/pooledClient.js +90 -0
- package/dist/esm/mcp/pool/pooledClient.js.map +1 -0
- package/dist/esm/mcp/pool/record.d.ts +80 -0
- package/dist/esm/mcp/pool/record.js +75 -0
- package/dist/esm/mcp/pool/record.js.map +1 -0
- package/dist/esm/mcp/pool/sessionEnded.d.ts +24 -0
- package/dist/esm/mcp/pool/sessionEnded.js +31 -0
- package/dist/esm/mcp/pool/sessionEnded.js.map +1 -0
- package/dist/esm/mcp/pool/work.d.ts +116 -0
- package/dist/esm/mcp/pool/work.js +213 -0
- package/dist/esm/mcp/pool/work.js.map +1 -0
- package/dist/esm/mcp/requestGuard.d.ts +70 -0
- package/dist/esm/mcp/requestGuard.js +98 -0
- package/dist/esm/mcp/requestGuard.js.map +1 -0
- package/dist/esm/mcp/requestLedger.d.ts +35 -1
- package/dist/esm/mcp/requestLedger.js +76 -3
- package/dist/esm/mcp/requestLedger.js.map +1 -1
- package/dist/esm/mcp/seriesEvidence.d.ts +10 -6
- package/dist/esm/mcp/seriesEvidence.js +16 -7
- package/dist/esm/mcp/seriesEvidence.js.map +1 -1
- package/dist/esm/mcp/terminate.d.ts +94 -0
- package/dist/esm/mcp/terminate.js +184 -0
- package/dist/esm/mcp/terminate.js.map +1 -0
- package/dist/esm/mcp/throttleRetry.js +71 -7
- package/dist/esm/mcp/throttleRetry.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 +197 -3
- package/dist/esm/redaction/knownStrings.js +34 -0
- package/dist/esm/redaction/knownStrings.js.map +1 -1
- package/dist/esm/tool-providers/index.d.ts +2 -2
- package/dist/esm/tool-providers/index.js +15 -1
- package/dist/esm/tool-providers/index.js.map +1 -1
- package/dist/esm/tools/mcpClientUse.d.ts +59 -0
- package/dist/esm/tools/mcpClientUse.js +216 -0
- package/dist/esm/tools/mcpClientUse.js.map +1 -0
- package/dist/esm/tools/toolProvider.d.ts +16 -0
- package/dist/esm/tools/toolSessions.d.ts +41 -0
- package/dist/esm/tools/toolSessions.js +41 -1
- package/dist/esm/tools/toolSessions.js.map +1 -1
- package/dist/events/registry.js +2 -0
- package/dist/events/registry.js.map +1 -1
- package/dist/identity/types.js.map +1 -1
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/dist/lib/boundedJson.js +14 -7
- 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/callLifetime.js +5 -2
- package/dist/mcp/callLifetime.js.map +1 -1
- package/dist/mcp/clientPort.js +38 -0
- package/dist/mcp/clientPort.js.map +1 -0
- package/dist/mcp/gatewayTransport.js +13 -3
- package/dist/mcp/gatewayTransport.js.map +1 -1
- package/dist/mcp/index.js +25 -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 +306 -59
- package/dist/mcp/mcpClient.js.map +1 -1
- package/dist/mcp/mockMcpClient.js +13 -0
- package/dist/mcp/mockMcpClient.js.map +1 -1
- package/dist/mcp/pool/boundTool.js +223 -0
- package/dist/mcp/pool/boundTool.js.map +1 -0
- package/dist/mcp/pool/clientSet.js +157 -0
- package/dist/mcp/pool/clientSet.js.map +1 -0
- package/dist/mcp/pool/definitions.js +174 -0
- package/dist/mcp/pool/definitions.js.map +1 -0
- package/dist/mcp/pool/errors.js +96 -0
- package/dist/mcp/pool/errors.js.map +1 -0
- package/dist/mcp/pool/identityKey.js +99 -0
- package/dist/mcp/pool/identityKey.js.map +1 -0
- package/dist/mcp/pool/lease.js +55 -0
- package/dist/mcp/pool/lease.js.map +1 -0
- package/dist/mcp/pool/listTools.js +150 -0
- package/dist/mcp/pool/listTools.js.map +1 -0
- package/dist/mcp/pool/mcpClientPool.js +155 -0
- package/dist/mcp/pool/mcpClientPool.js.map +1 -0
- package/dist/mcp/pool/options.js +123 -0
- package/dist/mcp/pool/options.js.map +1 -0
- package/dist/mcp/pool/plan.js +140 -0
- package/dist/mcp/pool/plan.js.map +1 -0
- package/dist/mcp/pool/pool.js +1075 -0
- package/dist/mcp/pool/pool.js.map +1 -0
- package/dist/mcp/pool/pooledClient.js +94 -0
- package/dist/mcp/pool/pooledClient.js.map +1 -0
- package/dist/mcp/pool/record.js +80 -0
- package/dist/mcp/pool/record.js.map +1 -0
- package/dist/mcp/pool/sessionEnded.js +35 -0
- package/dist/mcp/pool/sessionEnded.js.map +1 -0
- package/dist/mcp/pool/work.js +219 -0
- package/dist/mcp/pool/work.js.map +1 -0
- package/dist/mcp/requestGuard.js +106 -0
- package/dist/mcp/requestGuard.js.map +1 -0
- package/dist/mcp/requestLedger.js +76 -3
- package/dist/mcp/requestLedger.js.map +1 -1
- package/dist/mcp/seriesEvidence.js +16 -7
- package/dist/mcp/seriesEvidence.js.map +1 -1
- package/dist/mcp/terminate.js +193 -0
- package/dist/mcp/terminate.js.map +1 -0
- package/dist/mcp/throttleRetry.js +71 -7
- package/dist/mcp/throttleRetry.js.map +1 -1
- package/dist/mcp/toolList.js +128 -0
- package/dist/mcp/toolList.js.map +1 -0
- package/dist/redaction/knownStrings.js +34 -0
- package/dist/redaction/knownStrings.js.map +1 -1
- package/dist/tool-providers/index.js +20 -1
- package/dist/tool-providers/index.js.map +1 -1
- package/dist/tools/mcpClientUse.js +225 -0
- package/dist/tools/mcpClientUse.js.map +1 -0
- package/dist/tools/toolSessions.js +44 -1
- package/dist/tools/toolSessions.js.map +1 -1
- package/dist/types/adapters/mcp/agentcoreRuntime/invoke.d.ts +23 -4
- package/dist/types/adapters/mcp/agentcoreRuntime/invoke.d.ts.map +1 -1
- package/dist/types/adapters/mcp/agentcoreRuntime/session.d.ts +20 -6
- package/dist/types/adapters/mcp/agentcoreRuntime/session.d.ts.map +1 -1
- package/dist/types/adapters/mcp/agentcoreRuntime/transport.d.ts.map +1 -1
- package/dist/types/core/Agent.d.ts.map +1 -1
- package/dist/types/core/agent/stages/toolCalls.d.ts.map +1 -1
- package/dist/types/core/slots/buildToolsSlot.d.ts +12 -0
- package/dist/types/core/slots/buildToolsSlot.d.ts.map +1 -1
- package/dist/types/events/payloads.d.ts +41 -0
- package/dist/types/events/payloads.d.ts.map +1 -1
- package/dist/types/events/registry.d.ts +3 -1
- package/dist/types/events/registry.d.ts.map +1 -1
- package/dist/types/identity/types.d.ts +7 -3
- package/dist/types/identity/types.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lib/boundedJson.d.ts +14 -7
- 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/callLifetime.d.ts.map +1 -1
- package/dist/types/mcp/clientPort.d.ts +79 -0
- package/dist/types/mcp/clientPort.d.ts.map +1 -0
- package/dist/types/mcp/gatewayTransport.d.ts.map +1 -1
- package/dist/types/mcp/index.d.ts +11 -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 +18 -1
- package/dist/types/mcp/mcpClient.d.ts.map +1 -1
- package/dist/types/mcp/mockMcpClient.d.ts.map +1 -1
- package/dist/types/mcp/pool/boundTool.d.ts +59 -0
- package/dist/types/mcp/pool/boundTool.d.ts.map +1 -0
- package/dist/types/mcp/pool/clientSet.d.ts +74 -0
- package/dist/types/mcp/pool/clientSet.d.ts.map +1 -0
- package/dist/types/mcp/pool/definitions.d.ts +104 -0
- package/dist/types/mcp/pool/definitions.d.ts.map +1 -0
- package/dist/types/mcp/pool/errors.d.ts +77 -0
- package/dist/types/mcp/pool/errors.d.ts.map +1 -0
- package/dist/types/mcp/pool/identityKey.d.ts +58 -0
- package/dist/types/mcp/pool/identityKey.d.ts.map +1 -0
- package/dist/types/mcp/pool/lease.d.ts +37 -0
- package/dist/types/mcp/pool/lease.d.ts.map +1 -0
- package/dist/types/mcp/pool/listTools.d.ts +34 -0
- package/dist/types/mcp/pool/listTools.d.ts.map +1 -0
- package/dist/types/mcp/pool/mcpClientPool.d.ts +122 -0
- package/dist/types/mcp/pool/mcpClientPool.d.ts.map +1 -0
- package/dist/types/mcp/pool/options.d.ts +184 -0
- package/dist/types/mcp/pool/options.d.ts.map +1 -0
- package/dist/types/mcp/pool/plan.d.ts +78 -0
- package/dist/types/mcp/pool/plan.d.ts.map +1 -0
- package/dist/types/mcp/pool/pool.d.ts +308 -0
- package/dist/types/mcp/pool/pool.d.ts.map +1 -0
- package/dist/types/mcp/pool/pooledClient.d.ts +94 -0
- package/dist/types/mcp/pool/pooledClient.d.ts.map +1 -0
- package/dist/types/mcp/pool/record.d.ts +81 -0
- package/dist/types/mcp/pool/record.d.ts.map +1 -0
- package/dist/types/mcp/pool/sessionEnded.d.ts +25 -0
- package/dist/types/mcp/pool/sessionEnded.d.ts.map +1 -0
- package/dist/types/mcp/pool/work.d.ts +117 -0
- package/dist/types/mcp/pool/work.d.ts.map +1 -0
- package/dist/types/mcp/requestGuard.d.ts +71 -0
- package/dist/types/mcp/requestGuard.d.ts.map +1 -0
- package/dist/types/mcp/requestLedger.d.ts +35 -1
- package/dist/types/mcp/requestLedger.d.ts.map +1 -1
- package/dist/types/mcp/seriesEvidence.d.ts +10 -6
- package/dist/types/mcp/seriesEvidence.d.ts.map +1 -1
- package/dist/types/mcp/terminate.d.ts +95 -0
- package/dist/types/mcp/terminate.d.ts.map +1 -0
- package/dist/types/mcp/throttleRetry.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 +197 -3
- package/dist/types/mcp/types.d.ts.map +1 -1
- package/dist/types/redaction/knownStrings.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/dist/types/tools/mcpClientUse.d.ts +60 -0
- package/dist/types/tools/mcpClientUse.d.ts.map +1 -0
- package/dist/types/tools/toolProvider.d.ts +16 -0
- package/dist/types/tools/toolProvider.d.ts.map +1 -1
- package/dist/types/tools/toolSessions.d.ts +41 -0
- package/dist/types/tools/toolSessions.d.ts.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* errors — the pool's two refusals, each one fixed sentence.
|
|
4
|
+
*
|
|
5
|
+
* Pattern: typed errors whose message reaches the model and whose fields reach
|
|
6
|
+
* the app.
|
|
7
|
+
* Role: A refusal comes before the `tools/call` is sent, and says so
|
|
8
|
+
* (`sent: false`) for the record of what that attempt did. Control
|
|
9
|
+
* requests made on the way — the `initialize` of a replacement client,
|
|
10
|
+
* a revalidating `tools/list` — may already have reached the server;
|
|
11
|
+
* `sent` describes the `tools/call` only.
|
|
12
|
+
*
|
|
13
|
+
* A message is a fixed sentence per reason. It names no identity, no key, no
|
|
14
|
+
* session and no count: the counts ride typed fields the app reads, and the
|
|
15
|
+
* original error of a failed open rides `cause`, for the app, never composed
|
|
16
|
+
* into the message.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.PoolFullError = exports.POOL_FULL_SENTENCE = exports.McpPoolRefusedError = exports.MCP_POOL_REFUSAL_SENTENCES = void 0;
|
|
20
|
+
/** The sentence each refusal reaches the model as. */
|
|
21
|
+
exports.MCP_POOL_REFUSAL_SENTENCES = Object.freeze({
|
|
22
|
+
'no-identity': "This tool needs the caller's identity and none was named, so the call this result answers was not sent.",
|
|
23
|
+
'incomplete-identity': 'This tool needs a complete caller identity and the one named is incomplete, so the call this result answers was not sent.',
|
|
24
|
+
'identity-mismatch': 'This tool was listed for another conversation, so the tool call was not sent.',
|
|
25
|
+
'init-timeout': 'The connection to this server did not open in time, so the tool call was not sent.',
|
|
26
|
+
'init-failed': 'The connection to this server could not be opened, so the tool call was not sent.',
|
|
27
|
+
'stale-tools': "This tool's definition is no longer current, so the tool call was not sent. List the tools again.",
|
|
28
|
+
'binding-changed': 'This tool was listed for another configuration of this server, so the tool call was not sent. List the tools again.',
|
|
29
|
+
'request-unmatched': "The pool could not check this tool's request against its listing before sending it, so the tool call was not sent.",
|
|
30
|
+
'lease-expired': 'This connection lease has expired, so the tool call was not sent.',
|
|
31
|
+
closed: 'The connection pool for this server is closed, so the tool call was not sent.',
|
|
32
|
+
});
|
|
33
|
+
/**
|
|
34
|
+
* The pool refused before the `tools/call` was sent — by `reason`.
|
|
35
|
+
*
|
|
36
|
+
* `init-failed` keeps the open's own error as `cause`, for the app; its text is
|
|
37
|
+
* never in the message.
|
|
38
|
+
*/
|
|
39
|
+
class McpPoolRefusedError extends Error {
|
|
40
|
+
reason;
|
|
41
|
+
server;
|
|
42
|
+
code = 'ERR_MCP_POOL_REFUSED';
|
|
43
|
+
/** The `tools/call` was not sent. Control requests on the way may have been. */
|
|
44
|
+
sent = false;
|
|
45
|
+
constructor(reason,
|
|
46
|
+
/** The pool's name: the server. */
|
|
47
|
+
server, options = {}) {
|
|
48
|
+
super(exports.MCP_POOL_REFUSAL_SENTENCES[reason], {
|
|
49
|
+
...(options.cause !== undefined && { cause: options.cause }),
|
|
50
|
+
});
|
|
51
|
+
this.reason = reason;
|
|
52
|
+
this.server = server;
|
|
53
|
+
this.name = 'McpPoolRefusedError';
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.McpPoolRefusedError = McpPoolRefusedError;
|
|
57
|
+
/** The one sentence a full pool reaches the model as. */
|
|
58
|
+
exports.POOL_FULL_SENTENCE = 'The connection pool for this server was full, so the tool call was not sent.';
|
|
59
|
+
/**
|
|
60
|
+
* A budget was full, so the work was refused at once — there is no queue. Its
|
|
61
|
+
* scope is the `tools/call`, as with `sent: false`. The counts ride typed fields.
|
|
62
|
+
*/
|
|
63
|
+
class PoolFullError extends Error {
|
|
64
|
+
server;
|
|
65
|
+
limit;
|
|
66
|
+
max;
|
|
67
|
+
busy;
|
|
68
|
+
ending;
|
|
69
|
+
operations;
|
|
70
|
+
code = 'ERR_MCP_POOL_FULL';
|
|
71
|
+
sent = false;
|
|
72
|
+
constructor(
|
|
73
|
+
/** The pool's name: the server. */
|
|
74
|
+
server,
|
|
75
|
+
/** Which budget was full. */
|
|
76
|
+
limit,
|
|
77
|
+
/** That budget's size. */
|
|
78
|
+
max,
|
|
79
|
+
/** Busy clients when it was refused. */
|
|
80
|
+
busy,
|
|
81
|
+
/** Clients being ended when it was refused. */
|
|
82
|
+
ending,
|
|
83
|
+
/** Operations charged when it was refused. */
|
|
84
|
+
operations) {
|
|
85
|
+
super(exports.POOL_FULL_SENTENCE);
|
|
86
|
+
this.server = server;
|
|
87
|
+
this.limit = limit;
|
|
88
|
+
this.max = max;
|
|
89
|
+
this.busy = busy;
|
|
90
|
+
this.ending = ending;
|
|
91
|
+
this.operations = operations;
|
|
92
|
+
this.name = 'PoolFullError';
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.PoolFullError = PoolFullError;
|
|
96
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/mcp/pool/errors.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AAeH,sDAAsD;AACzC,QAAA,0BAA0B,GAA6C,MAAM,CAAC,MAAM,CAAC;IAChG,aAAa,EACX,yGAAyG;IAC3G,qBAAqB,EACnB,2HAA2H;IAC7H,mBAAmB,EACjB,+EAA+E;IACjF,cAAc,EACZ,oFAAoF;IACtF,aAAa,EACX,mFAAmF;IACrF,aAAa,EACX,mGAAmG;IACrG,iBAAiB,EACf,qHAAqH;IACvH,mBAAmB,EACjB,oHAAoH;IACtH,eAAe,EAAE,mEAAmE;IACpF,MAAM,EAAE,+EAA+E;CACxF,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAa,mBAAoB,SAAQ,KAAK;IAMjC;IAEA;IAPF,IAAI,GAAG,sBAA+B,CAAC;IAChD,gFAAgF;IACvE,IAAI,GAAG,KAAc,CAAC;IAE/B,YACW,MAAsB;IAC/B,mCAAmC;IAC1B,MAAc,EACvB,UAAwC,EAAE;QAE1C,KAAK,CAAC,kCAA0B,CAAC,MAAM,CAAC,EAAE;YACxC,GAAG,CAAC,OAAO,CAAC,KAAK,KAAK,SAAS,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC;SAC7D,CAAC,CAAC;QAPM,WAAM,GAAN,MAAM,CAAgB;QAEtB,WAAM,GAAN,MAAM,CAAQ;QAMvB,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AAhBD,kDAgBC;AAKD,yDAAyD;AAC5C,QAAA,kBAAkB,GAC7B,8EAA8E,CAAC;AAEjF;;;GAGG;AACH,MAAa,aAAc,SAAQ,KAAK;IAM3B;IAEA;IAEA;IAEA;IAEA;IAEA;IAfF,IAAI,GAAG,mBAA4B,CAAC;IACpC,IAAI,GAAG,KAAc,CAAC;IAE/B;IACE,mCAAmC;IAC1B,MAAc;IACvB,6BAA6B;IACpB,KAAmB;IAC5B,0BAA0B;IACjB,GAAW;IACpB,wCAAwC;IAC/B,IAAY;IACrB,+CAA+C;IACtC,MAAc;IACvB,8CAA8C;IACrC,UAAkB;QAE3B,KAAK,CAAC,0BAAkB,CAAC,CAAC;QAZjB,WAAM,GAAN,MAAM,CAAQ;QAEd,UAAK,GAAL,KAAK,CAAc;QAEnB,QAAG,GAAH,GAAG,CAAQ;QAEX,SAAI,GAAJ,IAAI,CAAQ;QAEZ,WAAM,GAAN,MAAM,CAAQ;QAEd,eAAU,GAAV,UAAU,CAAQ;QAG3B,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;CACF;AArBD,sCAqBC"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* identityKey — the conversation a pooled client belongs to, as one key.
|
|
4
|
+
*
|
|
5
|
+
* Pattern: the library's one identity encoding, never a second.
|
|
6
|
+
* Role: The client key is `identityNamespace` of the identity the CALLER
|
|
7
|
+
* named — each field through `encodeIdentityField`, the encoding the
|
|
8
|
+
* memory layer calls the tenant boundary. It is injective: tenant
|
|
9
|
+
* `acme/hr` with principal `alice` and tenant `acme` with principal
|
|
10
|
+
* `hr/alice` are two keys, and an absent field and a field named `_`
|
|
11
|
+
* are two keys. A pool is one server, so the key needs no server
|
|
12
|
+
* segment, and two pools never share a client.
|
|
13
|
+
*
|
|
14
|
+
* Two doors only: the run's caller identity (`ToolDispatchContext.callerIdentity`,
|
|
15
|
+
* `ToolExecutionContext.identity`) and the identity app code passes to `acquire`
|
|
16
|
+
* and `terminate`. Never tool arguments, model output, a message, a request
|
|
17
|
+
* body, or a `sessionId` alone. No identity value is ever written to an error,
|
|
18
|
+
* an event or a report: the wire carries `keyHash`, the tool-session digest.
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.scopeMatcher = exports.poolKeyOf = void 0;
|
|
22
|
+
const encode_js_1 = require("../../memory/identity/encode.js");
|
|
23
|
+
const types_js_1 = require("../../memory/identity/types.js");
|
|
24
|
+
const toolSessions_js_1 = require("../../tools/toolSessions.js");
|
|
25
|
+
/**
|
|
26
|
+
* The key for `identity`, or why there is none: `'no-identity'` when nothing was
|
|
27
|
+
* named (a derived identity counts as none), `'incomplete-identity'` when it
|
|
28
|
+
* lacks a `conversationId`, a required `principal` or a required `tenant`, or a
|
|
29
|
+
* field is not a string.
|
|
30
|
+
*/
|
|
31
|
+
function poolKeyOf(identity, rules) {
|
|
32
|
+
if (identity === undefined || identity === null)
|
|
33
|
+
return 'no-identity';
|
|
34
|
+
if (typeof identity !== 'object' || Array.isArray(identity))
|
|
35
|
+
return 'incomplete-identity';
|
|
36
|
+
const raw = identity;
|
|
37
|
+
const fields = {};
|
|
38
|
+
for (const name of ['tenant', 'principal', 'conversationId']) {
|
|
39
|
+
let value;
|
|
40
|
+
try {
|
|
41
|
+
value = raw[name];
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return 'incomplete-identity';
|
|
45
|
+
}
|
|
46
|
+
if (value === undefined || value === null || value === '')
|
|
47
|
+
continue;
|
|
48
|
+
if (typeof value !== 'string')
|
|
49
|
+
return 'incomplete-identity';
|
|
50
|
+
fields[name] = value;
|
|
51
|
+
}
|
|
52
|
+
if (fields.conversationId === undefined)
|
|
53
|
+
return 'incomplete-identity';
|
|
54
|
+
if (rules.requirePrincipal && fields.principal === undefined)
|
|
55
|
+
return 'incomplete-identity';
|
|
56
|
+
if (rules.requireTenant && fields.tenant === undefined)
|
|
57
|
+
return 'incomplete-identity';
|
|
58
|
+
const named = Object.freeze({
|
|
59
|
+
conversationId: fields.conversationId,
|
|
60
|
+
...(fields.tenant !== undefined && { tenant: fields.tenant }),
|
|
61
|
+
...(fields.principal !== undefined && { principal: fields.principal }),
|
|
62
|
+
});
|
|
63
|
+
const key = (0, types_js_1.identityNamespace)(named);
|
|
64
|
+
const tenant = (0, encode_js_1.encodeIdentityField)(named.tenant);
|
|
65
|
+
return {
|
|
66
|
+
key,
|
|
67
|
+
principal: `${tenant}/${(0, encode_js_1.encodeIdentityField)(named.principal)}`,
|
|
68
|
+
tenant,
|
|
69
|
+
keyHash: (0, toolSessions_js_1.hashSessionKey)(key),
|
|
70
|
+
identity: named,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
exports.poolKeyOf = poolKeyOf;
|
|
74
|
+
/**
|
|
75
|
+
* Which keys a scope names. The tenant is matched exactly, always — an absent
|
|
76
|
+
* tenant is the absent segment, never a wildcard, because the tenant is the
|
|
77
|
+
* boundary. A scope that names a `conversationId` names exactly that one
|
|
78
|
+
* conversation (an absent principal is then the absent segment, as in the key).
|
|
79
|
+
* A scope without one names every conversation of its principal, and a scope
|
|
80
|
+
* without a principal either names every conversation of its tenant.
|
|
81
|
+
*/
|
|
82
|
+
function scopeMatcher(scope) {
|
|
83
|
+
const tenant = (0, encode_js_1.encodeIdentityField)(scope.tenant);
|
|
84
|
+
if (scope.conversationId !== undefined && scope.conversationId !== '') {
|
|
85
|
+
const exact = (0, types_js_1.identityNamespace)({
|
|
86
|
+
conversationId: scope.conversationId,
|
|
87
|
+
...(scope.tenant !== undefined && { tenant: scope.tenant }),
|
|
88
|
+
...(scope.principal !== undefined && { principal: scope.principal }),
|
|
89
|
+
});
|
|
90
|
+
return (key) => key.key === exact;
|
|
91
|
+
}
|
|
92
|
+
if (scope.principal !== undefined && scope.principal !== '') {
|
|
93
|
+
const principal = `${tenant}/${(0, encode_js_1.encodeIdentityField)(scope.principal)}`;
|
|
94
|
+
return (key) => key.principal === principal;
|
|
95
|
+
}
|
|
96
|
+
return (key) => key.tenant === tenant;
|
|
97
|
+
}
|
|
98
|
+
exports.scopeMatcher = scopeMatcher;
|
|
99
|
+
//# sourceMappingURL=identityKey.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identityKey.js","sourceRoot":"","sources":["../../../src/mcp/pool/identityKey.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AAEH,+DAAsE;AACtE,6DAAmE;AACnE,iEAA6D;AAuB7D;;;;;GAKG;AACH,SAAgB,SAAS,CACvB,QAAiB,EACjB,KAAoB;IAEpB,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,IAAI;QAAE,OAAO,aAAa,CAAC;IACtE,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC;QAAE,OAAO,qBAAqB,CAAC;IAC1F,MAAM,GAAG,GAAG,QAAmC,CAAC;IAChD,MAAM,MAAM,GAAwD,EAAE,CAAC;IACvE,KAAK,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE,WAAW,EAAE,gBAAgB,CAAU,EAAE,CAAC;QACtE,IAAI,KAAc,CAAC;QACnB,IAAI,CAAC;YACH,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;QACpB,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,qBAAqB,CAAC;QAC/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,IAAA,+BAAmB,EAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACjD,IAAI,KAAK,CAAC,cAAc,KAAK,SAAS,IAAI,KAAK,CAAC,cAAc,KAAK,EAAE,EAAE,CAAC;QACtE,MAAM,KAAK,GAAG,IAAA,4BAAiB,EAAC;YAC9B,cAAc,EAAE,KAAK,CAAC,cAAc;YACpC,GAAG,CAAC,KAAK,CAAC,MAAM,KAAK,SAAS,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC;YAC3D,GAAG,CAAC,KAAK,CAAC,SAAS,KAAK,SAAS,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC;SACrE,CAAC,CAAC;QACH,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,KAAK,KAAK,CAAC;IACpC,CAAC;IACD,IAAI,KAAK,CAAC,SAAS,KAAK,SAAS,IAAI,KAAK,CAAC,SAAS,KAAK,EAAE,EAAE,CAAC;QAC5D,MAAM,SAAS,GAAG,GAAG,MAAM,IAAI,IAAA,+BAAmB,EAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;QACtE,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,SAAS,KAAK,SAAS,CAAC;IAC9C,CAAC;IACD,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,KAAK,MAAM,CAAC;AACxC,CAAC;AAnBD,oCAmBC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* lease — the app's explicit, bounded hold on one conversation's client.
|
|
4
|
+
*
|
|
5
|
+
* Pattern: a handle that releases at most once, by hand or by `await using`.
|
|
6
|
+
* Role: § 3.3 and § 5.2 of the design. `acquire` is for code that drives a
|
|
7
|
+
* sequence itself, or a host that must keep a conversation's client
|
|
8
|
+
* from eviction for a whole turn (it holds one around `agent.run()`, and
|
|
9
|
+
* the provider then finds the same client). It is the only way to
|
|
10
|
+
* protect a client between calls: there is no hidden grace period.
|
|
11
|
+
*
|
|
12
|
+
* The `acquire` that opened it was the operation; the held lease is not one. It
|
|
13
|
+
* is bounded by `maxLeaseMs`: past it, it is revoked at the next pool
|
|
14
|
+
* interaction and reported, and its next use throws `lease-expired`. Calls
|
|
15
|
+
* already in flight keep their own leases until they settle.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.leaseHandle = void 0;
|
|
19
|
+
const lifecycle_js_1 = require("../../strategies/lifecycle.js");
|
|
20
|
+
const boundTool_js_1 = require("./boundTool.js");
|
|
21
|
+
const listTools_js_1 = require("./listTools.js");
|
|
22
|
+
const record_js_1 = require("./record.js");
|
|
23
|
+
/** The lease handle for `held`, on `key`'s client. */
|
|
24
|
+
function leaseHandle(pool, key, held) {
|
|
25
|
+
const release = () => {
|
|
26
|
+
if (held.released)
|
|
27
|
+
return;
|
|
28
|
+
held.released = true;
|
|
29
|
+
pool.endLease(held);
|
|
30
|
+
pool.interact();
|
|
31
|
+
};
|
|
32
|
+
const handle = {
|
|
33
|
+
async tools(options) {
|
|
34
|
+
pool.interact();
|
|
35
|
+
if (held.revoked || held.released)
|
|
36
|
+
throw pool.refused('lease-expired');
|
|
37
|
+
const facts = new record_js_1.UseFacts(pool.settings.name, 'list');
|
|
38
|
+
try {
|
|
39
|
+
return await (0, listTools_js_1.listTools)(pool, key, options?.signal, facts);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
(0, boundTool_js_1.noteRefusal)(facts, error);
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
release,
|
|
47
|
+
[lifecycle_js_1.ASYNC_DISPOSE]: async () => release(),
|
|
48
|
+
};
|
|
49
|
+
// The computed key gives TypeScript a symbol index rather than the one
|
|
50
|
+
// well-known member `AsyncDisposable` names; at runtime it IS
|
|
51
|
+
// `Symbol.asyncDispose` on every engine this package supports.
|
|
52
|
+
return handle;
|
|
53
|
+
}
|
|
54
|
+
exports.leaseHandle = leaseHandle;
|
|
55
|
+
//# sourceMappingURL=lease.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lease.js","sourceRoot":"","sources":["../../../src/mcp/pool/lease.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,gEAA8D;AAE9D,iDAA6C;AAE7C,iDAA2C;AAE3C,2CAAuC;AAiBvC,sDAAsD;AACtD,SAAgB,WAAW,CAAC,IAAU,EAAE,GAAY,EAAE,IAAe;IACnE,MAAM,OAAO,GAAG,GAAS,EAAE;QACzB,IAAI,IAAI,CAAC,QAAQ;YAAE,OAAO;QAC1B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACpB,IAAI,CAAC,QAAQ,EAAE,CAAC;IAClB,CAAC,CAAC;IACF,MAAM,MAAM,GAAG;QACb,KAAK,CAAC,KAAK,CAAC,OAA2C;YACrD,IAAI,CAAC,QAAQ,EAAE,CAAC;YAChB,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,QAAQ;gBAAE,MAAM,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;YACvE,MAAM,KAAK,GAAG,IAAI,oBAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YACvD,IAAI,CAAC;gBACH,OAAO,MAAM,IAAA,wBAAS,EAAC,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;YAC5D,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAA,0BAAW,EAAC,KAAK,EAAE,KAAK,CAAC,CAAC;gBAC1B,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;QACD,OAAO;QACP,CAAC,4BAAa,CAAC,EAAE,KAAK,IAAmB,EAAE,CAAC,OAAO,EAAE;KACtD,CAAC;IACF,uEAAuE;IACvE,8DAA8D;IAC9D,+DAA+D;IAC/D,OAAO,MAAiC,CAAC;AAC3C,CAAC;AA1BD,kCA0BC"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* listTools — one conversation's tools, bound to it: one listing operation.
|
|
4
|
+
*
|
|
5
|
+
* Pattern: one admitted operation per call, the provider's and the lease's alike.
|
|
6
|
+
* Role: § 3.2 and § 6 of the design. A listing is one `list(ctx)` for one
|
|
7
|
+
* conversation, admitted against `maxOperations`. Its setup — the open
|
|
8
|
+
* of the key's client, the `tools/list` — runs inside its slot.
|
|
9
|
+
*
|
|
10
|
+
* - PER CLIENT: the conversation's own client is opened (or reused) and its own
|
|
11
|
+
* list served, listed again when it cannot be served as it stands.
|
|
12
|
+
* - SHARED, under the app's contract: the plan is resolved and the context
|
|
13
|
+
* computed WITHOUT opening anything; a current entry is served touching no
|
|
14
|
+
* client (`client: 'not-needed'`); a listing already under way for it is
|
|
15
|
+
* joined; otherwise the listing runs on THIS conversation's own client —
|
|
16
|
+
* never in another conversation's session.
|
|
17
|
+
* - THE CALLER'S CONTEXT AFTER EVERY WAIT: the app's names are asked again
|
|
18
|
+
* after a joined listing and after this one's own (`Pool.ensureListed`); a
|
|
19
|
+
* list is served only under the context the caller has at that moment, and
|
|
20
|
+
* a moved context is resolved again — at most three rounds, then refused
|
|
21
|
+
* (`binding-changed`).
|
|
22
|
+
*
|
|
23
|
+
* A refused listing never reaches the model as a tool result: it fails that
|
|
24
|
+
* iteration's tool discovery (`agentfootprint.tools.discovery_failed`), as any
|
|
25
|
+
* failing `ToolProvider` does. A list that cannot be read to its end
|
|
26
|
+
* (`McpToolListIncompleteError`, from the client's own discovery) is never
|
|
27
|
+
* served cut short.
|
|
28
|
+
*/
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.listTools = void 0;
|
|
31
|
+
const abort_js_1 = require("../../lib/abort.js");
|
|
32
|
+
const toolSessions_js_1 = require("../../tools/toolSessions.js");
|
|
33
|
+
const sessionEnded_js_1 = require("./sessionEnded.js");
|
|
34
|
+
const boundTool_js_1 = require("./boundTool.js");
|
|
35
|
+
const plan_js_1 = require("./plan.js");
|
|
36
|
+
/** List `key`'s conversation's tools, bound to it, under one admitted operation. */
|
|
37
|
+
async function listTools(pool, key, signal, facts) {
|
|
38
|
+
facts.keyHash = key.keyHash;
|
|
39
|
+
pool.interact();
|
|
40
|
+
const operation = pool.admit('listing', 'listing', signal);
|
|
41
|
+
try {
|
|
42
|
+
for (let round = 0; round < 3; round += 1) {
|
|
43
|
+
const current = pool.clients.currentFor(key.key);
|
|
44
|
+
let plan;
|
|
45
|
+
if (current === undefined) {
|
|
46
|
+
try {
|
|
47
|
+
plan = (0, plan_js_1.resolvePlan)(pool.settings, key);
|
|
48
|
+
}
|
|
49
|
+
catch (cause) {
|
|
50
|
+
throw pool.refused('init-failed', cause);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// A key with a client: the app's names asked again, so a changed
|
|
54
|
+
// authorization reaches this conversation as it would a new one.
|
|
55
|
+
const definitions = current === undefined ? plan : pool.refreshContext(current);
|
|
56
|
+
if (definitions.shared) {
|
|
57
|
+
const served = await sharedWithoutClient(pool, key, definitions.context, operation.signal);
|
|
58
|
+
if (served !== undefined) {
|
|
59
|
+
// After that wait, the caller's names once more: served only under
|
|
60
|
+
// the context they give now — otherwise resolved again.
|
|
61
|
+
if (!callerStillIn(pool, key, plan, served.context))
|
|
62
|
+
continue;
|
|
63
|
+
facts.client = 'not-needed';
|
|
64
|
+
facts.definitions = 'shared';
|
|
65
|
+
facts.definitionsAgeMs = Math.max(0, pool.now() - served.list.listedAt);
|
|
66
|
+
return bindAll(pool, key, served, undefined);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const client = await pool.leaseClient(key, operation, facts, plan);
|
|
70
|
+
let served;
|
|
71
|
+
try {
|
|
72
|
+
// Under the client's context of now, checked with no wait since.
|
|
73
|
+
served = await pool.ensureListed(client, operation);
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
throw classifiedListing(pool, client, facts, error);
|
|
77
|
+
}
|
|
78
|
+
facts.definitions = served.shared ? 'shared' : 'listed';
|
|
79
|
+
if (served.shared)
|
|
80
|
+
facts.definitionsAgeMs = Math.max(0, pool.now() - served.list.listedAt);
|
|
81
|
+
return bindAll(pool, key, served, client);
|
|
82
|
+
}
|
|
83
|
+
// The app's names kept moving under this listing.
|
|
84
|
+
throw pool.refused('binding-changed');
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
operation.finish();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.listTools = listTools;
|
|
91
|
+
/**
|
|
92
|
+
* Do the caller's names still give `context` — asked now? Through the key's
|
|
93
|
+
* client when it has one by now, else over the plan's configuration. False
|
|
94
|
+
* when `share` cannot answer: the next round says why.
|
|
95
|
+
*/
|
|
96
|
+
function callerStillIn(pool, key, plan, context) {
|
|
97
|
+
const current = pool.clients.currentFor(key.key);
|
|
98
|
+
if (current !== undefined)
|
|
99
|
+
return pool.contextHolds(current, context);
|
|
100
|
+
if (plan === undefined)
|
|
101
|
+
return false;
|
|
102
|
+
try {
|
|
103
|
+
return (0, plan_js_1.contextFor)(pool.settings, key, plan.configHash).context === context;
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The shared entry for `plan`, when it can be served without touching a client
|
|
111
|
+
* — at once, or once a listing already under way for it is done.
|
|
112
|
+
*/
|
|
113
|
+
async function sharedWithoutClient(pool, key, context, signal) {
|
|
114
|
+
const entry = pool.shared.entryFor(context, key.tenant);
|
|
115
|
+
const servable = () => entry.list.servable(pool.now(), pool.settings.definitionTtlMs);
|
|
116
|
+
if (!servable() && entry.list.listing !== undefined) {
|
|
117
|
+
// Joined inside this operation's own slot; if it fails, this one lists itself.
|
|
118
|
+
await (0, abort_js_1.untilAborted)(entry.list.listing, signal).catch(() => undefined);
|
|
119
|
+
}
|
|
120
|
+
return servable() ? { list: entry.list, shared: true, context } : undefined;
|
|
121
|
+
}
|
|
122
|
+
/** Every definition of `served`, bound to `key` and to the list it came from. */
|
|
123
|
+
function bindAll(pool, key, served, client) {
|
|
124
|
+
const base = {
|
|
125
|
+
key,
|
|
126
|
+
context: served.context,
|
|
127
|
+
shared: served.shared,
|
|
128
|
+
listId: served.list.id,
|
|
129
|
+
generation: served.list.generation,
|
|
130
|
+
...(!served.shared && client !== undefined && { clientId: client.clientId }),
|
|
131
|
+
};
|
|
132
|
+
return served.list.all().map((definition) => (0, boundTool_js_1.boundTool)(pool, { ...base, definition }));
|
|
133
|
+
}
|
|
134
|
+
/** A listing that failed because the client's session expired or its handle was lost. */
|
|
135
|
+
function classifiedListing(pool, client, facts, error) {
|
|
136
|
+
if (client.lost === 'expired') {
|
|
137
|
+
facts.client = 'expired';
|
|
138
|
+
facts.evidence = 'server-404';
|
|
139
|
+
return new sessionEnded_js_1.ServerEndedSessionError(pool.settings.name, client.clientId, error);
|
|
140
|
+
}
|
|
141
|
+
if (client.lost === 'handle-lost') {
|
|
142
|
+
facts.client = 'handle-lost';
|
|
143
|
+
facts.evidence = 'transport-forgot-handle';
|
|
144
|
+
return (0, toolSessions_js_1.isLocalSessionHandleLost)(error)
|
|
145
|
+
? error
|
|
146
|
+
: new toolSessions_js_1.LocalSessionHandleLostError({ cause: error });
|
|
147
|
+
}
|
|
148
|
+
return error;
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=listTools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listTools.js","sourceRoot":"","sources":["../../../src/mcp/pool/listTools.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;;;AAEH,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K,CAAC,MAAM,GAAG,aAAa,CAAC;QAC7B,KAAK,CAAC,QAAQ,GAAG,yBAAyB,CAAC;QAC3C,OAAO,IAAA,0CAAwB,EAAC,KAAK,CAAC;YACpC,CAAC,CAAC,KAAK;YACP,CAAC,CAAC,IAAI,6CAA2B,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IACxD,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* mcpClientPool — a client per conversation, for one MCP server.
|
|
4
|
+
*
|
|
5
|
+
* const orders = mcpClientPool({
|
|
6
|
+
* name: 'orders',
|
|
7
|
+
* transport: () =>
|
|
8
|
+
* agentCoreRuntimeMcpTransport({ agentRuntimeArn, region, session: 'reuse', client: aws }),
|
|
9
|
+
* });
|
|
10
|
+
* const agent = Agent.create({ provider, model }).toolProvider(orders.toolProvider()).build();
|
|
11
|
+
* await agent.run({ message, identity: { tenant, principal, conversationId } });
|
|
12
|
+
*
|
|
13
|
+
* Pattern: Facade over one state machine (`pool.ts`), its accounting (`work.ts`),
|
|
14
|
+
* its definitions (`definitions.ts`) and its bound tools (`boundTool.ts`).
|
|
15
|
+
* Role: `docs/design/2026-10-mcp-client-pool.md`. A `'reuse'` session costs a
|
|
16
|
+
* cold start once per conversation instead of once per call — but only
|
|
17
|
+
* if each conversation has a client of its own, opened once, bounded,
|
|
18
|
+
* never closed while in use, ended remotely and said to be. This is
|
|
19
|
+
* the one place that does all of it:
|
|
20
|
+
*
|
|
21
|
+
* - one client per authenticated conversation, keyed by the library's
|
|
22
|
+
* identity encoding of the identity the CALLER named;
|
|
23
|
+
* - one open per key, under the pool's own signal and `initTimeoutMs`;
|
|
24
|
+
* - three budgets — open clients, endings, outstanding operations — each
|
|
25
|
+
* charged until the work under it has SETTLED, and `PoolFullError` at once
|
|
26
|
+
* when one is full: there is no queue;
|
|
27
|
+
* - tool definitions per client incarnation by default, shared only under the
|
|
28
|
+
* app's declared contract, every tool re-checked after each wait and at the
|
|
29
|
+
* send gate;
|
|
30
|
+
* - every ending through `terminate()`, with the remote outcome reported, and
|
|
31
|
+
* `close()` still only local.
|
|
32
|
+
*
|
|
33
|
+
* What it does not do: repeat a call, share anything across processes, bound a
|
|
34
|
+
* remote session it could not end, or make a server enforce per-user
|
|
35
|
+
* permissions.
|
|
36
|
+
*/
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.mcpClientPool = void 0;
|
|
39
|
+
const mcpClientUse_js_1 = require("../../tools/mcpClientUse.js");
|
|
40
|
+
const toolSessions_js_1 = require("../../tools/toolSessions.js");
|
|
41
|
+
const boundTool_js_1 = require("./boundTool.js");
|
|
42
|
+
const identityKey_js_1 = require("./identityKey.js");
|
|
43
|
+
const lease_js_1 = require("./lease.js");
|
|
44
|
+
const listTools_js_1 = require("./listTools.js");
|
|
45
|
+
const options_js_1 = require("./options.js");
|
|
46
|
+
const pool_js_1 = require("./pool.js");
|
|
47
|
+
const record_js_1 = require("./record.js");
|
|
48
|
+
/**
|
|
49
|
+
* Build a pool for one MCP server.
|
|
50
|
+
*
|
|
51
|
+
* @throws TypeError when an option is missing, mistyped or out of range, or when
|
|
52
|
+
* `connection` is given — here, when the pool is built
|
|
53
|
+
*/
|
|
54
|
+
function mcpClientPool(options) {
|
|
55
|
+
const settings = (0, options_js_1.readPoolOptions)(options);
|
|
56
|
+
const pool = new pool_js_1.Pool(settings);
|
|
57
|
+
const rules = {
|
|
58
|
+
requirePrincipal: settings.requirePrincipal,
|
|
59
|
+
requireTenant: settings.requireTenant,
|
|
60
|
+
};
|
|
61
|
+
let closing;
|
|
62
|
+
const provider = {
|
|
63
|
+
id: `mcp-pool:${settings.name}`,
|
|
64
|
+
list: async (ctx) => {
|
|
65
|
+
const facts = new record_js_1.UseFacts(settings.name, 'list');
|
|
66
|
+
try {
|
|
67
|
+
const key = (0, identityKey_js_1.poolKeyOf)(ctx.callerIdentity, rules);
|
|
68
|
+
if (typeof key === 'string')
|
|
69
|
+
throw pool.refused(key);
|
|
70
|
+
return await (0, listTools_js_1.listTools)(pool, key, ctx.signal, facts);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
(0, boundTool_js_1.noteRefusal)(facts, error);
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
// Filed against the context the tools slot passed; the slot emits it.
|
|
78
|
+
(0, mcpClientUse_js_1.fileListUse)(ctx, facts.toUse());
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
return {
|
|
83
|
+
name: settings.name,
|
|
84
|
+
toolProvider: () => provider,
|
|
85
|
+
async acquire(identity, acquireOptions) {
|
|
86
|
+
const key = (0, identityKey_js_1.poolKeyOf)(identity, rules);
|
|
87
|
+
if (typeof key === 'string')
|
|
88
|
+
throw pool.refused(key);
|
|
89
|
+
pool.interact();
|
|
90
|
+
const operation = pool.admit('acquire', 'open', acquireOptions?.signal);
|
|
91
|
+
try {
|
|
92
|
+
const facts = new record_js_1.UseFacts(settings.name, 'list');
|
|
93
|
+
for (let round = 0; round < 3; round += 1) {
|
|
94
|
+
const client = await pool.leaseClient(key, operation, facts);
|
|
95
|
+
// After that wait, before anything is held: the pool may have closed,
|
|
96
|
+
// the caller may have gone, the client may have been named by a
|
|
97
|
+
// terminate. Refused, the operation's own lease ends with it below.
|
|
98
|
+
if (pool.closed)
|
|
99
|
+
throw pool.refused('closed');
|
|
100
|
+
operation.check();
|
|
101
|
+
if (client.serving)
|
|
102
|
+
return (0, lease_js_1.leaseHandle)(pool, key, pool.holdLease(client));
|
|
103
|
+
}
|
|
104
|
+
throw pool.refused('init-failed');
|
|
105
|
+
}
|
|
106
|
+
finally {
|
|
107
|
+
operation.finish();
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
async terminate(scope) {
|
|
111
|
+
assertScope(scope, settings.name);
|
|
112
|
+
pool.interact();
|
|
113
|
+
return pool.terminate((0, identityKey_js_1.scopeMatcher)(scope), 'terminated', toolSessions_js_1.TOOL_TEARDOWN_TIMEOUT_MS);
|
|
114
|
+
},
|
|
115
|
+
close() {
|
|
116
|
+
closing ??= pool.closeAll(toolSessions_js_1.TOOL_TEARDOWN_TIMEOUT_MS);
|
|
117
|
+
return closing;
|
|
118
|
+
},
|
|
119
|
+
settled: () => pool.settled(),
|
|
120
|
+
permissionsChanged(scope) {
|
|
121
|
+
assertFields(scope, settings.name, 'permissionsChanged');
|
|
122
|
+
pool.permissionsChanged(scope);
|
|
123
|
+
},
|
|
124
|
+
toolsChanged: () => pool.toolsChanged(),
|
|
125
|
+
sweep: () => pool.interact(),
|
|
126
|
+
stats: () => pool.stats(),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
exports.mcpClientPool = mcpClientPool;
|
|
130
|
+
/**
|
|
131
|
+
* A `terminate` scope names a principal or a conversation: ending every
|
|
132
|
+
* conversation of a whole tenant is `close()`'s job, and a mistyped scope must
|
|
133
|
+
* not do it.
|
|
134
|
+
*/
|
|
135
|
+
function assertScope(scope, name) {
|
|
136
|
+
assertFields(scope, name, 'terminate');
|
|
137
|
+
const named = (value) => value !== undefined && value !== '';
|
|
138
|
+
if (!named(scope.principal) && !named(scope.conversationId)) {
|
|
139
|
+
throw new TypeError(`mcpClientPool[${name}].terminate: the scope must name a principal or a conversation ` +
|
|
140
|
+
'({ tenant, principal } or { tenant, principal, conversationId }).');
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/** Every field present is a string. Never quoted: a scope is an identity. */
|
|
144
|
+
function assertFields(scope, name, door) {
|
|
145
|
+
if (scope === null || typeof scope !== 'object') {
|
|
146
|
+
throw new TypeError(`mcpClientPool[${name}].${door}: the scope must be an object.`);
|
|
147
|
+
}
|
|
148
|
+
for (const field of ['tenant', 'principal', 'conversationId']) {
|
|
149
|
+
const value = scope[field];
|
|
150
|
+
if (value !== undefined && typeof value !== 'string') {
|
|
151
|
+
throw new TypeError(`mcpClientPool[${name}].${door}: \`${field}\` must be a string when present.`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=mcpClientPool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcpClientPool.js","sourceRoot":"","sources":["../../../src/mcp/pool/mcpClientPool.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;;;AAGH,iEAA0D;AAC1D,iEAAuE;AAEvE,iDAA6C;AAC7C,qDAA2D;AAC3D,yCAA4D;AAC5D,iDAA2C;AAC3C,6CAAgG;AAChG,uCAAoD;AACpD,2CAAuC;AA4EvC;;;;;GAKG;AACH,SAAgB,aAAa,CAAC,OAA6B;IACzD,MAAM,QAAQ,GAAG,IAAA,4BAAe,EAAC,OAAO,CAAC,CAAC;IAC1C,MAAM,IAAI,GAAG,IAAI,cAAI,CAAC,QAAQ,CAAC,CAAC;IAChC,MAAM,KAAK,GAAG;QACZ,gBAAgB,EAAE,QAAQ,CAAC,gBAAgB;QAC3C,aAAa,EAAE,QAAQ,CAAC,aAAa;KACtC,CAAC;IACF,IAAI,OAA4D,CAAC;IAEjE,MAAM,QAAQ,GAAiB;QAC7B,EAAE,EAAE,YAAY,QAAQ,CAAC,IAAI,EAAE;QAC/B,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;YAClB,MAAM,KAAK,GAAG,IAAI,oBAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YAClD,IAAI,CAAC;gBACH,MAAM,GAAG,GAAG,IAAA,0BAAS,EAAC,GAAG,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;gBACjD,IAAI,OAAO,GAAG,KAAK,QAAQ;oBAAE,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;gBACrD,OAAO,MAAM,IAAA,wBAAS,EAA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