@cogitator-ai/mcp 19.8.2 → 19.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +130 -8
- package/dist/adapter/tool-adapter.d.ts +8 -8
- package/dist/adapter/tool-adapter.d.ts.map +1 -1
- package/dist/adapter/tool-adapter.js +21 -16
- package/dist/adapter/tool-adapter.js.map +1 -1
- package/dist/client/input.d.ts +47 -0
- package/dist/client/input.d.ts.map +1 -0
- package/dist/client/input.js +125 -0
- package/dist/client/input.js.map +1 -0
- package/dist/client/mcp-client.d.ts +84 -8
- package/dist/client/mcp-client.d.ts.map +1 -1
- package/dist/client/mcp-client.js +614 -112
- package/dist/client/mcp-client.js.map +1 -1
- package/dist/client/oauth.d.ts +42 -0
- package/dist/client/oauth.d.ts.map +1 -0
- package/dist/client/oauth.js +171 -0
- package/dist/client/oauth.js.map +1 -0
- package/dist/client/param-headers.d.ts +10 -0
- package/dist/client/param-headers.d.ts.map +1 -0
- package/dist/client/param-headers.js +65 -0
- package/dist/client/param-headers.js.map +1 -0
- package/dist/client/raw-dispatch.d.ts +40 -0
- package/dist/client/raw-dispatch.d.ts.map +1 -0
- package/dist/client/raw-dispatch.js +148 -0
- package/dist/client/raw-dispatch.js.map +1 -0
- package/dist/client/rounds.d.ts +14 -0
- package/dist/client/rounds.d.ts.map +1 -0
- package/dist/client/rounds.js +33 -0
- package/dist/client/rounds.js.map +1 -0
- package/dist/client/tasks.d.ts +70 -0
- package/dist/client/tasks.d.ts.map +1 -0
- package/dist/client/tasks.js +186 -0
- package/dist/client/tasks.js.map +1 -0
- package/dist/client/transports.d.ts +5 -3
- package/dist/client/transports.d.ts.map +1 -1
- package/dist/client/transports.js +9 -8
- package/dist/client/transports.js.map +1 -1
- package/dist/digest.d.ts +8 -0
- package/dist/digest.d.ts.map +1 -0
- package/dist/digest.js +25 -0
- package/dist/digest.js.map +1 -0
- package/dist/index.d.ts +7 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/server/approval.d.ts +17 -5
- package/dist/server/approval.d.ts.map +1 -1
- package/dist/server/approval.js +26 -12
- package/dist/server/approval.js.map +1 -1
- package/dist/server/execution.d.ts +134 -0
- package/dist/server/execution.d.ts.map +1 -0
- package/dist/server/execution.js +185 -0
- package/dist/server/execution.js.map +1 -0
- package/dist/server/mcp-server.d.ts +45 -19
- package/dist/server/mcp-server.d.ts.map +1 -1
- package/dist/server/mcp-server.js +551 -120
- package/dist/server/mcp-server.js.map +1 -1
- package/dist/server/questions.d.ts +19 -2
- package/dist/server/questions.d.ts.map +1 -1
- package/dist/server/questions.js +38 -21
- package/dist/server/questions.js.map +1 -1
- package/dist/server/request-state.d.ts +55 -0
- package/dist/server/request-state.d.ts.map +1 -0
- package/dist/server/request-state.js +66 -0
- package/dist/server/request-state.js.map +1 -0
- package/dist/server/serve-agents.d.ts.map +1 -1
- package/dist/server/serve-agents.js +203 -18
- package/dist/server/serve-agents.js.map +1 -1
- package/dist/server/tasks.d.ts +75 -0
- package/dist/server/tasks.d.ts.map +1 -0
- package/dist/server/tasks.js +280 -0
- package/dist/server/tasks.js.map +1 -0
- package/dist/server/tool-args.d.ts +24 -0
- package/dist/server/tool-args.d.ts.map +1 -0
- package/dist/server/tool-args.js +58 -0
- package/dist/server/tool-args.js.map +1 -0
- package/dist/types.d.ts +341 -11
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -5
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
* MCP Client
|
|
3
3
|
*
|
|
4
4
|
* Connects to external MCP servers and provides access to their tools,
|
|
5
|
-
* resources, and prompts.
|
|
5
|
+
* resources, and prompts. Speaks protocol 2026-07-28 to servers that do and
|
|
6
|
+
* 2025-11-25 to older ones.
|
|
6
7
|
*/
|
|
7
8
|
import type { Tool } from '@cogitator-ai/types';
|
|
8
|
-
import type { MCPClientConfig, MCPResource, MCPResourceContent, MCPPrompt, MCPPromptMessage, MCPToolDefinition, MCPToolContent, MCPCallToolOptions, ToolAdapterOptions } from '../types.js';
|
|
9
|
+
import type { MCPClientConfig, MCPResource, MCPResourceContent, MCPPrompt, MCPPromptMessage, MCPProtocolEra, MCPServerDiscovery, MCPSubscription, MCPSubscriptionFilter, MCPSubscriptionHandlers, MCPToolCallResult, MCPToolDefinition, MCPToolContent, MCPCallToolOptions, ToolAdapterOptions } from '../types.js';
|
|
9
10
|
/**
|
|
10
11
|
* Error raised when an MCP server reports a tool failure (`isError: true`).
|
|
11
12
|
* Tool failures are deterministic results, so they are never retried.
|
|
@@ -22,8 +23,8 @@ export declare class MCPToolError extends Error {
|
|
|
22
23
|
*/
|
|
23
24
|
export declare class MCPToolInterruptedError extends Error {
|
|
24
25
|
readonly toolName: string;
|
|
25
|
-
readonly reason: 'timeout' | 'connection-lost';
|
|
26
|
-
constructor(toolName: string, reason: 'timeout' | 'connection-lost', cause: unknown);
|
|
26
|
+
readonly reason: 'timeout' | 'connection-lost' | 'task-lost';
|
|
27
|
+
constructor(toolName: string, reason: 'timeout' | 'connection-lost' | 'task-lost', cause: unknown);
|
|
27
28
|
}
|
|
28
29
|
/**
|
|
29
30
|
* MCP Client for connecting to external MCP servers
|
|
@@ -59,19 +60,38 @@ export declare class MCPClient {
|
|
|
59
60
|
private config;
|
|
60
61
|
private retryConfig;
|
|
61
62
|
private serverCapabilities;
|
|
63
|
+
private readonly authProvider;
|
|
64
|
+
private readonly dispatcher;
|
|
65
|
+
private readonly taskStore;
|
|
66
|
+
private readonly roundStore;
|
|
67
|
+
private readonly toolDefinitions;
|
|
68
|
+
private readonly listeners;
|
|
69
|
+
private readonly connectionWatchers;
|
|
70
|
+
/**
|
|
71
|
+
* How many open legacy subscriptions follow each resource: the server keeps one subscription
|
|
72
|
+
* per connection and URI, so it is unsubscribed only once the last of them closes
|
|
73
|
+
*/
|
|
74
|
+
private readonly resourceRefs;
|
|
75
|
+
private readonly validator;
|
|
76
|
+
private prior;
|
|
77
|
+
private negotiatedVersion;
|
|
78
|
+
private serverTakesTasks;
|
|
62
79
|
private constructor();
|
|
63
80
|
/**
|
|
64
81
|
* Connect to an MCP server
|
|
65
82
|
*/
|
|
66
83
|
static connect(config: MCPClientConfig): Promise<MCPClient>;
|
|
84
|
+
private createSdkClient;
|
|
67
85
|
/**
|
|
68
86
|
* Create transport based on configuration
|
|
69
87
|
*/
|
|
70
|
-
private
|
|
88
|
+
private createTransport;
|
|
71
89
|
/**
|
|
72
|
-
* Initialize connection and capabilities
|
|
90
|
+
* Initialize connection and capabilities. A server that asks for OAuth sends the person to
|
|
91
|
+
* authorize once (`auth.authorize`), then the client connects again
|
|
73
92
|
*/
|
|
74
93
|
private initialize;
|
|
94
|
+
private connectOnce;
|
|
75
95
|
/**
|
|
76
96
|
* Check if connected to server
|
|
77
97
|
*/
|
|
@@ -80,6 +100,14 @@ export declare class MCPClient {
|
|
|
80
100
|
* Get server capabilities
|
|
81
101
|
*/
|
|
82
102
|
getCapabilities(): typeof this.serverCapabilities;
|
|
103
|
+
/** The protocol revision the connection speaks, such as `2026-07-28` */
|
|
104
|
+
get protocolVersion(): string | undefined;
|
|
105
|
+
/** `modern` for protocol 2026-07-28 and later, `legacy` for a server of an earlier revision */
|
|
106
|
+
get era(): MCPProtocolEra;
|
|
107
|
+
/** What the server tells the model about using it, if anything */
|
|
108
|
+
get instructions(): string | undefined;
|
|
109
|
+
/** What the server says of itself: revision, capabilities, instructions and name */
|
|
110
|
+
discover(): MCPServerDiscovery;
|
|
83
111
|
/**
|
|
84
112
|
* Check if currently reconnecting
|
|
85
113
|
*/
|
|
@@ -89,7 +117,8 @@ export declare class MCPClient {
|
|
|
89
117
|
*
|
|
90
118
|
* Concurrent callers share the same in-flight reconnection, so parallel
|
|
91
119
|
* operations that all observe a dropped connection wait for one reconnect
|
|
92
|
-
* instead of failing.
|
|
120
|
+
* instead of failing. The revision found on the first connect is kept, so a
|
|
121
|
+
* reconnect does not ask the server again.
|
|
93
122
|
*/
|
|
94
123
|
reconnect(): Promise<void>;
|
|
95
124
|
private performReconnect;
|
|
@@ -116,14 +145,56 @@ export declare class MCPClient {
|
|
|
116
145
|
* value(s) of text content, or a `toolContent()` result when the content holds images, audio
|
|
117
146
|
* or binary resources. Throws {@link MCPToolError} when the server reports `isError: true`.
|
|
118
147
|
*
|
|
148
|
+
* A server may ask for input during the call (elicitation): it is asked through the run of
|
|
149
|
+
* the call (`options.interrupt`), else from the `elicitation` handler, else declined. A server
|
|
150
|
+
* may answer with a task, which is polled until it ends, and cancelled when `signal` aborts.
|
|
151
|
+
*
|
|
119
152
|
* A call is sent once. Only with `idempotent: true` (a read-only or idempotent tool) is it sent
|
|
120
153
|
* again after a timeout or a lost connection, otherwise those throw
|
|
121
154
|
* {@link MCPToolInterruptedError}, since the server may have run the call. A connection that was
|
|
122
|
-
* already lost is restored before the call is sent.
|
|
155
|
+
* already lost is restored before the call is sent. A task survives a lost connection: its
|
|
156
|
+
* polling goes on once the connection is back.
|
|
123
157
|
*/
|
|
124
158
|
callTool(name: string, args: Record<string, unknown>, options?: MCPCallToolOptions): Promise<unknown>;
|
|
159
|
+
/**
|
|
160
|
+
* Call a tool and return the server's result as it is: content, `structuredContent` and
|
|
161
|
+
* `isError`. Input requests and tasks are handled as for {@link callTool}
|
|
162
|
+
*/
|
|
163
|
+
callToolResult(name: string, args: Record<string, unknown>, options?: MCPCallToolOptions): Promise<MCPToolCallResult>;
|
|
164
|
+
private answererFor;
|
|
165
|
+
/** The task an earlier run of the same tool call started, polled again, if there is one */
|
|
166
|
+
private reattachTask;
|
|
167
|
+
private settle;
|
|
168
|
+
/** Whether calls go out with the tasks extension: the server takes tasks and the client does */
|
|
169
|
+
private takesTasks;
|
|
170
|
+
private sendToolCall;
|
|
171
|
+
/**
|
|
172
|
+
* `tools/call` sent past the SDK client, which cannot read a task: with the tasks extension
|
|
173
|
+
* in the request's capabilities and the `Mcp-Param-*` headers of the tool's arguments
|
|
174
|
+
*/
|
|
175
|
+
private sendRawToolCall;
|
|
176
|
+
/** A tool result as the server sent it, checked against the tool's output schema */
|
|
177
|
+
private toolResultOf;
|
|
178
|
+
private toolDefinition;
|
|
179
|
+
/** Whether someone can answer the elicitation requests of a call: its run or the handler */
|
|
180
|
+
private canAnswer;
|
|
181
|
+
/**
|
|
182
|
+
* The capabilities a request declares (protocol 2026-07-28 declares them per request):
|
|
183
|
+
* elicitation when someone can answer, and the tasks extension when the client takes tasks
|
|
184
|
+
*/
|
|
185
|
+
private capabilities;
|
|
186
|
+
/** The `_meta` of a request sent past the SDK client */
|
|
187
|
+
private requestMeta;
|
|
125
188
|
/** A call that must not run twice: sent once, on a connection restored beforehand if needed. */
|
|
126
189
|
private callOnce;
|
|
190
|
+
/**
|
|
191
|
+
* Hear of the server's changes: its tool, prompt or resource lists, or updates of resources.
|
|
192
|
+
* On protocol 2026-07-28 this opens a `subscriptions/listen` stream, on earlier revisions the
|
|
193
|
+
* server sends list changes on its own and resources are subscribed one by one. The filter of
|
|
194
|
+
* the subscription is what the server agreed to
|
|
195
|
+
*/
|
|
196
|
+
subscribe(filter: MCPSubscriptionFilter, handlers: MCPSubscriptionHandlers): Promise<MCPSubscription>;
|
|
197
|
+
private notify;
|
|
127
198
|
/**
|
|
128
199
|
* List available resources from the MCP server with automatic retry
|
|
129
200
|
*/
|
|
@@ -145,6 +216,11 @@ export declare class MCPClient {
|
|
|
145
216
|
* Get a prompt from the MCP server with automatic retry
|
|
146
217
|
*/
|
|
147
218
|
getPrompt(name: string, args?: Record<string, string>): Promise<MCPPromptMessage[]>;
|
|
219
|
+
/**
|
|
220
|
+
* A request that a server of protocol 2026-07-28 may answer with input requests, sent again
|
|
221
|
+
* with the answers of the elicitation handler until it completes
|
|
222
|
+
*/
|
|
223
|
+
private withInput;
|
|
148
224
|
/**
|
|
149
225
|
* Close the connection to the MCP server
|
|
150
226
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-client.d.ts","sourceRoot":"","sources":["../../src/client/mcp-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