@mastra/mcp 2.6.0-alpha.3 → 2.7.0-alpha.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/dist/client/actions/prompt.d.ts.map +1 -1
- package/dist/client/actions/resource.d.ts.map +1 -1
- package/dist/client/client.d.ts +12 -0
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/configuration.d.ts +40 -0
- package/dist/client/configuration.d.ts.map +1 -1
- package/dist/client/error-utils.d.ts +9 -0
- package/dist/client/error-utils.d.ts.map +1 -1
- package/dist/client/index.d.ts +2 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/tasks/intercept.d.ts +22 -0
- package/dist/client/tasks/intercept.d.ts.map +1 -0
- package/dist/client/tasks/options.d.ts +4 -0
- package/dist/client/tasks/options.d.ts.map +1 -0
- package/dist/client/tasks/requester.d.ts +26 -0
- package/dist/client/tasks/requester.d.ts.map +1 -0
- package/dist/client/tasks/wait.d.ts +60 -0
- package/dist/client/tasks/wait.d.ts.map +1 -0
- package/dist/client/types.d.ts +47 -0
- package/dist/client/types.d.ts.map +1 -1
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-auth-fga.md +1 -1
- package/dist/docs/references/reference-tools-mcp-client.md +48 -0
- package/dist/docs/references/reference-tools-mcp-server.md +216 -1
- package/dist/index.cjs +3206 -114
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3204 -118
- package/dist/index.js.map +1 -1
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/request.d.ts +6 -0
- package/dist/server/request.d.ts.map +1 -1
- package/dist/server/server.d.ts +131 -1
- package/dist/server/server.d.ts.map +1 -1
- package/dist/server/tasks/background-store.d.ts +107 -0
- package/dist/server/tasks/background-store.d.ts.map +1 -0
- package/dist/server/tasks/config.d.ts +226 -0
- package/dist/server/tasks/config.d.ts.map +1 -0
- package/dist/server/tasks/emit.d.ts +16 -0
- package/dist/server/tasks/emit.d.ts.map +1 -0
- package/dist/server/tasks/handlers.d.ts +33 -0
- package/dist/server/tasks/handlers.d.ts.map +1 -0
- package/dist/server/tasks/in-memory-store.d.ts +71 -0
- package/dist/server/tasks/in-memory-store.d.ts.map +1 -0
- package/dist/server/tasks/index.d.ts +9 -0
- package/dist/server/tasks/index.d.ts.map +1 -0
- package/dist/server/tasks/inspector.d.ts +13 -0
- package/dist/server/tasks/inspector.d.ts.map +1 -0
- package/dist/server/tasks/store.d.ts +260 -0
- package/dist/server/tasks/store.d.ts.map +1 -0
- package/dist/server/tasks/workflow-runs.d.ts +63 -0
- package/dist/server/tasks/workflow-runs.d.ts.map +1 -0
- package/dist/shared/tasks/capability.d.ts +18 -0
- package/dist/shared/tasks/capability.d.ts.map +1 -0
- package/dist/shared/tasks/constants.d.ts +34 -0
- package/dist/shared/tasks/constants.d.ts.map +1 -0
- package/dist/shared/tasks/index.d.ts +6 -0
- package/dist/shared/tasks/index.d.ts.map +1 -0
- package/dist/shared/tasks/schemas.d.ts +187 -0
- package/dist/shared/tasks/schemas.d.ts.map +1 -0
- package/dist/shared/tasks/task-id.d.ts +27 -0
- package/dist/shared/tasks/task-id.d.ts.map +1 -0
- package/dist/shared/tasks/types.d.ts +21 -0
- package/dist/shared/tasks/types.d.ts.map +1 -0
- package/package.json +11 -10
package/dist/server/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,oBAAoB,CAAC;AACnC,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,oBAAoB,CAAC;AACnC,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
|
package/dist/server/request.d.ts
CHANGED
|
@@ -29,6 +29,12 @@ export declare function toRequestContext(ctx: ServerContext, mapAuthInfoToUser:
|
|
|
29
29
|
* never share a principal. A token refreshed mid-round therefore starts over.
|
|
30
30
|
*/
|
|
31
31
|
export declare function principalOf(ctx: ServerContext, requestContext: RequestContext): string;
|
|
32
|
+
/**
|
|
33
|
+
* A readable name for the caller, for operators debugging a server: the principal, except that a
|
|
34
|
+
* token principal keeps only a short prefix of the token's hash. Never a credential, so it can be
|
|
35
|
+
* stored and shown; it is not unique enough to authorize anything.
|
|
36
|
+
*/
|
|
37
|
+
export declare function clientLabelOf(ctx: ServerContext, requestContext: RequestContext): string;
|
|
32
38
|
export declare function hashArguments(value: unknown): string;
|
|
33
39
|
/**
|
|
34
40
|
* What the server signs into `requestState` when a handler suspends. It names the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/server/request.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAElE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAElE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAKvD;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,GAAG,uBAAuB,CA0BtG;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,aAAa,GAAG,kBAAkB,GAAG,SAAS,CAO9E;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,aAAa,EAClB,iBAAiB,EAAE,uBAAuB,GA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AC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,OAAO,CAAC;IACxB,GAAG,EAAE,MAAM,CAAC;CACb;AAED,qEAAqE;AACrE,eAAO,MAAM,SAAS,UAAU,CAAC;AAEjC,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,OAAO,CAAC;IACxB,sFAAsF;IACtF,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,EAAE,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAAC;CAC1C;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,aAAa,EAClB,cAAc,EAAE,cAAc,EAC9B,QAAQ,EAAE,IAAI,CAAC,oBAAoB,EAAE,QAAQ,GAAG,MAAM,GAAG,UAAU,CAAC,GACnE,iBAAiB,GAAG,SAAS,CA+B/B"}
|
package/dist/server/server.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type * as http from 'node:http';
|
|
2
2
|
import type { Agent, ToolsInput } from '@mastra/core/agent';
|
|
3
3
|
import { MCPServerBase } from '@mastra/core/mcp';
|
|
4
|
-
import type { MCPServerConfig as CoreMCPServerConfig, MCPServerEventInfo, MCPServerEventsInspector, MCPToolExecutionResultV2, ServerDetailInfo, ServerInfo } from '@mastra/core/mcp';
|
|
4
|
+
import type { MCPServerConfig as CoreMCPServerConfig, MCPServerEventInfo, MCPServerEventsInspector, MCPServerTasksInfo, MCPServerTasksInspector, MCPToolExecutionResultV2, ServerDetailInfo, ServerInfo } from '@mastra/core/mcp';
|
|
5
5
|
import { RequestContext } from '@mastra/core/request-context';
|
|
6
6
|
import type { InternalCoreTool, MCPToolType } from '@mastra/core/tools';
|
|
7
7
|
import type { Workflow } from '@mastra/core/workflows';
|
|
@@ -9,6 +9,7 @@ import type { Resource, jsonSchemaValidator } from '@modelcontextprotocol/server
|
|
|
9
9
|
import { ServerPromptActions, ServerResourceActions, ServerToolActions } from './actions.js';
|
|
10
10
|
import { ServerEventActions } from './events/actions.js';
|
|
11
11
|
import type { MCPServerEventDefinition, MCPServerEventsOptions } from './events/types.js';
|
|
12
|
+
import type { MCPServerTasksOptions } from './tasks/config.js';
|
|
12
13
|
import type { AppResources, MCPServerCacheHints, MCPServerHTTPRequestOptions, MCPServerPrompts, MCPServerRequestStateOptions, MCPServerResources } from './types.js';
|
|
13
14
|
export interface MCPServerConfig extends CoreMCPServerConfig {
|
|
14
15
|
resources?: MCPServerResources;
|
|
@@ -33,6 +34,14 @@ export interface MCPServerConfig extends CoreMCPServerConfig {
|
|
|
33
34
|
* @experimental SEP-3415 is a draft; this API may change.
|
|
34
35
|
*/
|
|
35
36
|
eventsOptions?: MCPServerEventsOptions;
|
|
37
|
+
/**
|
|
38
|
+
* Serves `tools/call` as MCP Tasks (`io.modelcontextprotocol/tasks`) for the tools you opt in: a
|
|
39
|
+
* client that declared the extension gets a task handle and polls `tasks/get` for the result.
|
|
40
|
+
* Other clients keep getting synchronous answers.
|
|
41
|
+
*
|
|
42
|
+
* @experimental SEP-2663 extension; API may change.
|
|
43
|
+
*/
|
|
44
|
+
tasks?: MCPServerTasksOptions;
|
|
36
45
|
/**
|
|
37
46
|
* How requests from 2025-era clients (those that open with `initialize`) are served
|
|
38
47
|
* over HTTP.
|
|
@@ -113,8 +122,16 @@ export declare class MCPServer extends MCPServerBase {
|
|
|
113
122
|
private readonly eventRegistry;
|
|
114
123
|
private readonly eventsOptions;
|
|
115
124
|
private eventsInspector;
|
|
125
|
+
private tasksInspector;
|
|
116
126
|
private readonly webhooks?;
|
|
117
127
|
private readonly legacy;
|
|
128
|
+
private readonly tasks;
|
|
129
|
+
/** Where tasks are kept: `tasks.store`, or the store picked on first use. */
|
|
130
|
+
private readonly taskStore;
|
|
131
|
+
/** Cancels for the workflow runs executing in this process, by run id, while they execute. */
|
|
132
|
+
private readonly executingRuns;
|
|
133
|
+
/** Prepared on Mastra registration so its executors exist before the manager recovers rows. */
|
|
134
|
+
private backgroundTaskStore?;
|
|
118
135
|
private httpHandler?;
|
|
119
136
|
private nodeHandler?;
|
|
120
137
|
private stdioHandle?;
|
|
@@ -128,6 +145,8 @@ export declare class MCPServer extends MCPServerBase {
|
|
|
128
145
|
* so a tool cannot suspend into a request no client can answer.
|
|
129
146
|
*/
|
|
130
147
|
private assertFormRepresentable;
|
|
148
|
+
/** The input-request form for `resumeSchema`, or `undefined` when the protocol can't present it. */
|
|
149
|
+
private representableForm;
|
|
131
150
|
/**
|
|
132
151
|
* Input-request forms are a restricted flat-object subset of JSON Schema, so
|
|
133
152
|
* the dialect declaration is left off the requested schema.
|
|
@@ -187,10 +206,92 @@ export declare class MCPServer extends MCPServerBase {
|
|
|
187
206
|
* carry any field. A thrown error ends the whole span tree and is rethrown.
|
|
188
207
|
*/
|
|
189
208
|
private traceRequest;
|
|
209
|
+
/**
|
|
210
|
+
* Writes a task's root span out now rather than with the exporter's next batch: the task's later
|
|
211
|
+
* spans may be recorded by another process, and if this one dies first, a trace without its root
|
|
212
|
+
* drops out of trace lists.
|
|
213
|
+
*/
|
|
214
|
+
private flushTaskRoot;
|
|
190
215
|
/** Answers a suspended round: one keyed form derived from the handler's `resumeSchema`. */
|
|
191
216
|
private inputRequired;
|
|
217
|
+
/** The form a suspended handler asks the client to fill in. */
|
|
218
|
+
private inputRequestForm;
|
|
192
219
|
private serverRequest;
|
|
193
220
|
private registerToolHandlers;
|
|
221
|
+
/** Logs a tool's failure and wraps it as the error a client receives. */
|
|
222
|
+
private toolError;
|
|
223
|
+
/**
|
|
224
|
+
* `'auto'` mode: runs the tool under the request for up to `syncWindowMs`. A tool that settles in
|
|
225
|
+
* time is answered like any synchronous call; otherwise the same execution carries on as a task,
|
|
226
|
+
* no longer tied to the request's cancellation.
|
|
227
|
+
*/
|
|
228
|
+
private runWithinSyncWindow;
|
|
229
|
+
/**
|
|
230
|
+
* Creates the task (durably, before answering) and hands its work to the store. `initialAttempt`
|
|
231
|
+
* builds the run of an execution that already started under the request; it stays in this
|
|
232
|
+
* process. Rejects with {@link MCPTaskLimitError}, creating nothing, at a task cap.
|
|
233
|
+
*/
|
|
234
|
+
private startToolTask;
|
|
235
|
+
/** The request context a task keeps for its later attempts. */
|
|
236
|
+
private persistTaskRequestContext;
|
|
237
|
+
/** Creates a task durably. `pinned` keeps its first attempt on this worker, which already runs it. */
|
|
238
|
+
private createTask;
|
|
239
|
+
/**
|
|
240
|
+
* The work of a tool task, rebuilt from nothing but what the task's `context` records, so a store
|
|
241
|
+
* can dispatch it again after a restart. Each attempt runs the tool once; an answered suspension
|
|
242
|
+
* runs it again with `resumeData`, as everywhere else in Mastra.
|
|
243
|
+
*/
|
|
244
|
+
private toolTaskWork;
|
|
245
|
+
/**
|
|
246
|
+
* Opens a span in a task's trace, as a child of the task's root (the `tools/call` that created
|
|
247
|
+
* it), from any process. Uses the resume parentage workflows and agents use: the root id becomes
|
|
248
|
+
* the span's Mastra parent, so storage keeps one tree. `tracingOptions.parentSpanId` would not:
|
|
249
|
+
* it only correlates with an external system, and storage would record another root.
|
|
250
|
+
*/
|
|
251
|
+
private openTaskSpan;
|
|
252
|
+
/** Ends an attempt's span with how the attempt ended, and passes the outcome on. */
|
|
253
|
+
private endAttemptSpan;
|
|
254
|
+
/**
|
|
255
|
+
* A first run already under way (an `'auto'` tool's or workflow's, under the request, or a
|
|
256
|
+
* workflow run started under `opened`) as attempt 1 of its task: the attempt span ends with that run.
|
|
257
|
+
*/
|
|
258
|
+
private tracedInitialAttempt;
|
|
259
|
+
private toTaskOutcome;
|
|
260
|
+
/** A tool that throws inside a task completes it with `isError`, as a synchronous call would answer. */
|
|
261
|
+
private toolErrorOutcome;
|
|
262
|
+
/**
|
|
263
|
+
* Starts the run behind a `run_<key>` task. `'auto'` answers synchronously when the run finishes
|
|
264
|
+
* within `syncWindowMs`; a run that suspends or outlasts the window continues as a task.
|
|
265
|
+
*/
|
|
266
|
+
private startWorkflowTask;
|
|
267
|
+
/** The first attempt of a workflow task: the run this request started, in this process. */
|
|
268
|
+
private liveWorkflowAttempt;
|
|
269
|
+
/**
|
|
270
|
+
* The work of a workflow task, rebuilt from its context. It never starts the run: a first attempt
|
|
271
|
+
* dispatched again (after a restart) re-attaches to it, and an answered suspension resumes it.
|
|
272
|
+
*/
|
|
273
|
+
private workflowTaskWork;
|
|
274
|
+
private resumeWorkflowRun;
|
|
275
|
+
/**
|
|
276
|
+
* Polls the run until it finishes or suspends on a step the client can answer. The only way to
|
|
277
|
+
* follow a run from any instance, whichever engine runs it.
|
|
278
|
+
*/
|
|
279
|
+
private watchWorkflowRun;
|
|
280
|
+
/**
|
|
281
|
+
* What a run's state means for its task, or `undefined` while there is nothing to report: the
|
|
282
|
+
* run is still going, or waits on a step whose `resumeSchema` no input request can present (the
|
|
283
|
+
* task stays `working` until the run is resumed some other way).
|
|
284
|
+
*/
|
|
285
|
+
private workflowRunOutcome;
|
|
286
|
+
/**
|
|
287
|
+
* Cancels the task's run, for a declined input or the store's onCancel (`tasks/cancel`, TTL
|
|
288
|
+
* expiry), on whichever instance that happens. A run executing in this process is cancelled here.
|
|
289
|
+
* A run executing in another process is left alone: writing `canceled` under it doesn't stop it,
|
|
290
|
+
* its next write overwrites the status, and its own cancel would then find it `canceled` and do
|
|
291
|
+
* nothing. A run that waits (suspended, pending) is cancelled in storage. A finished run is left alone.
|
|
292
|
+
*/
|
|
293
|
+
private cancelWorkflowRun;
|
|
294
|
+
private workflowFor;
|
|
194
295
|
/**
|
|
195
296
|
* Runs one round of a tool. The tool sees the same `suspend` / `resumeData` /
|
|
196
297
|
* `suspendPayload` vocabulary as under an agent or workflow; nothing else is
|
|
@@ -215,6 +316,21 @@ export declare class MCPServer extends MCPServerBase {
|
|
|
215
316
|
*/
|
|
216
317
|
startHTTP({ url, httpPath, req, res, options }: MCPServerHTTPOptions): Promise<void>;
|
|
217
318
|
close(): Promise<void>;
|
|
319
|
+
/** Whether the id was given (in the config, or as a Mastra registration key) rather than generated per process. */
|
|
320
|
+
private hasStableId;
|
|
321
|
+
setId(id: Parameters<MCPServerBase['setId']>[0]): void;
|
|
322
|
+
/** @internal */
|
|
323
|
+
__registerMastra(mastra: Parameters<MCPServerBase['__registerMastra']>[0]): void;
|
|
324
|
+
/**
|
|
325
|
+
* Builds the background-task store and registers an executor for every task tool, when tasks
|
|
326
|
+
* are on, no store was passed in, and Mastra has background tasks.
|
|
327
|
+
*/
|
|
328
|
+
private prepareBackgroundTaskStore;
|
|
329
|
+
/**
|
|
330
|
+
* Mastra's background tasks when the storage keeps per-row expiry (so a task's TTL, not the
|
|
331
|
+
* global cleanup, decides when it is deleted); an in-memory store otherwise.
|
|
332
|
+
*/
|
|
333
|
+
private selectTaskStore;
|
|
218
334
|
getServerInfo(): ServerInfo;
|
|
219
335
|
getServerDetail(): ServerDetailInfo;
|
|
220
336
|
getToolListInfo(requestContext?: RequestContext): {
|
|
@@ -256,6 +372,20 @@ export declare class MCPServer extends MCPServerBase {
|
|
|
256
372
|
* @experimental
|
|
257
373
|
*/
|
|
258
374
|
getEventsInspector(): MCPServerEventsInspector | undefined;
|
|
375
|
+
/**
|
|
376
|
+
* Which tools run as MCP tasks and whether the task store can be listed, or `undefined` when
|
|
377
|
+
* no tool runs as a task. Used by Studio.
|
|
378
|
+
* @experimental
|
|
379
|
+
*/
|
|
380
|
+
getTasksInfo(): MCPServerTasksInfo | undefined;
|
|
381
|
+
/**
|
|
382
|
+
* Lists, cancels and answers this server's tasks across principals, through the task store's
|
|
383
|
+
* admin view, or `undefined` when no tool runs as a task or the store can't be listed. Used by
|
|
384
|
+
* Studio; there is no protocol equivalent of the listing.
|
|
385
|
+
* @experimental
|
|
386
|
+
*/
|
|
387
|
+
getTasksInspector(): MCPServerTasksInspector | undefined;
|
|
388
|
+
private taskToolTypes;
|
|
259
389
|
private eventsDeps;
|
|
260
390
|
}
|
|
261
391
|
export { ServerPromptActions, ServerResourceActions, ServerToolActions };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server/server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server/server.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,IAAI,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAE5D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EACV,eAAe,IAAI,mBAAmB,EACtC,kBAAkB,EAClB,wBAAwB,EAExB,kBAAkB,EAClB,uBAAuB,EACvB,wBAAwB,EACxB,gBAAgB,EAChB,UAAU,EACX,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAyB,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAIrF,OAAO,KAAK,EAAE,gBAAgB,EAA2B,WAAW,EAAc,MAAM,oBAAoB,CAAC;AAE7G,OAAO,KAAK,EAAkB,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAmBvE,OAAO,KAAK,EAWV,QAAQ,EAMR,mBAAmB,EACpB,MAAM,8BAA8B,CAAC;AAWtC,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC1F,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAItD,OAAO,KAAK,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAevF,OAAO,KAAK,EAAE,qBAAqB,EAA6C,MAAM,gBAAgB,CAAC;AAyBvG,OAAO,KAAK,EACV,YAAY,EAEZ,mBAAmB,EACnB,2BAA2B,EAC3B,gBAAgB,EAEhB,4BAA4B,EAC5B,kBAAkB,EACnB,MAAM,SAAS,CAAC;AAEjB,MAAM,WAAW,eAAgB,SAAQ,mBAAmB;IAC1D,SAAS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;QAAE,MAAM,EAAE,kBAAkB,EAAE,CAAA;KAAE,GAAG,SAAS,CAG5D;IAED;;;;OAIG;IACH,kBAAkB,IAAI,wBAAwB,GAAG,SAAS,CAIzD;IAED;;;;OAIG;IACH,YAAY,IAAI,kBAAkB,GAAG,SAAS,CAG7C;IAED;;;;;OAKG;IACH,iBAAiB,IAAI,uBAAuB,GAAG,SAAS,CAOvD;IAED,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,UAAU;CASnB;AA6GD,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { BackgroundTask, BackgroundTaskManager } from '@mastra/core/background-tasks';
|
|
2
|
+
import type { IMastraLogger } from '@mastra/core/logger';
|
|
3
|
+
import type { MCPDetailedTask, MCPTask, MCPTaskInputRequests, MCPTaskInputResponses } from '../../shared/tasks/index.js';
|
|
4
|
+
import type { MCPTaskAccess, MCPTaskAdminOutcome, MCPTaskCreateParams, MCPTaskListOptions, MCPTaskListPage, MCPTaskRunOptions, MCPTaskStore, MCPTaskStoreAdmin, MCPTaskTrace, MCPTaskWork } from './store.js';
|
|
5
|
+
export { principalKeyOf, taskKeyOf } from './store.js';
|
|
6
|
+
/** What the store needs from a task's `context`: which tool it runs. */
|
|
7
|
+
export interface BackgroundToolTaskContext extends Record<string, unknown> {
|
|
8
|
+
toolName: string;
|
|
9
|
+
}
|
|
10
|
+
export interface BackgroundTaskMCPTaskStoreOptions {
|
|
11
|
+
manager: BackgroundTaskManager;
|
|
12
|
+
/** The MCP server's id; scopes rows, owners and static executors to this server. */
|
|
13
|
+
serverId: string;
|
|
14
|
+
/** Rebuilds a task's work from nothing but its persisted context. */
|
|
15
|
+
workFor: (context: BackgroundToolTaskContext) => MCPTaskWork;
|
|
16
|
+
/** Whether a crashed attempt of this tool runs again. */
|
|
17
|
+
recoverFor: (toolName: string) => boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Called with a task's context when it is cancelled or expires before finishing, on whichever
|
|
20
|
+
* instance does so, even while no attempt runs (e.g. while it waits for input). Stops whatever
|
|
21
|
+
* the task stands for outside the store, such as a suspended workflow run. Not awaited: the
|
|
22
|
+
* cancel answers and the sweep goes on without waiting for it; errors are logged.
|
|
23
|
+
*/
|
|
24
|
+
onCancel?: (context: BackgroundToolTaskContext) => void | Promise<void>;
|
|
25
|
+
/** Read on every log, since Mastra sets the server's logger after registering it. */
|
|
26
|
+
logger?: () => IMastraLogger;
|
|
27
|
+
}
|
|
28
|
+
/** The MCP side of a task, kept in the row's `metadata`. */
|
|
29
|
+
export interface BackgroundTaskEnvelope {
|
|
30
|
+
v: 1;
|
|
31
|
+
/** The caller's principal, hashed with {@link principalKeyOf}. */
|
|
32
|
+
principalKey: string;
|
|
33
|
+
/** The span of the request that created the task; every attempt's span is its child. */
|
|
34
|
+
trace?: MCPTaskTrace;
|
|
35
|
+
/** Who sent the task, readable for operators; never a credential, and never used to authorize. */
|
|
36
|
+
clientLabel?: string;
|
|
37
|
+
ttlMs: number | null;
|
|
38
|
+
pollIntervalMs?: number;
|
|
39
|
+
recover: boolean;
|
|
40
|
+
/** The open suspension's requests, and the answers given to them so far. */
|
|
41
|
+
inputRequests?: MCPTaskInputRequests;
|
|
42
|
+
inputResponses?: MCPTaskInputResponses;
|
|
43
|
+
/** Every input key this task ever asked for; keys must be unique over its lifetime. */
|
|
44
|
+
usedInputKeys: string[];
|
|
45
|
+
/**
|
|
46
|
+
* Attempts started so far, for a traced task's attempt spans. Core's reclaim of a lost attempt
|
|
47
|
+
* leaves `retryCount` alone, so the row itself can't tell a recovered run from a first one.
|
|
48
|
+
*/
|
|
49
|
+
attempts?: number;
|
|
50
|
+
}
|
|
51
|
+
export declare const TASK_LOST_MESSAGE = "task lost: the server restarted while it was running";
|
|
52
|
+
export declare const TASK_EXPIRED_MESSAGE = "Task expired before it finished";
|
|
53
|
+
/**
|
|
54
|
+
* Projects a background-task row onto the MCP task it backs, as `tasks/get` answers it.
|
|
55
|
+
*
|
|
56
|
+
* A row still running past its TTL reads as `failed` before the sweep gets to it.
|
|
57
|
+
*/
|
|
58
|
+
export declare function projectTask(row: BackgroundTask, envelope: BackgroundTaskEnvelope, taskId: string, now: number): MCPDetailedTask;
|
|
59
|
+
/**
|
|
60
|
+
* An {@link MCPTaskStore} on Mastra's background tasks: every MCP task is a background-task row in
|
|
61
|
+
* Mastra's storage, so any instance sharing that storage can read, answer and cancel it, and run it.
|
|
62
|
+
*
|
|
63
|
+
* Rows are owned by `mcp-server:<serverId>` and keyed by a hash of the task id. Each attempt runs
|
|
64
|
+
* the tool's work rebuilt from the row (`workFor`), through a static executor registered for
|
|
65
|
+
* every task tool, so a worker other than the creating one can run it.
|
|
66
|
+
*/
|
|
67
|
+
export declare class BackgroundTaskMCPTaskStore implements MCPTaskStore, MCPTaskStoreAdmin {
|
|
68
|
+
#private;
|
|
69
|
+
constructor(options: BackgroundTaskMCPTaskStoreOptions);
|
|
70
|
+
/** The `agentId` every row of this server carries. */
|
|
71
|
+
get owner(): string;
|
|
72
|
+
/**
|
|
73
|
+
* Registers the executor that runs `toolName`'s tasks on any worker. It must be registered on
|
|
74
|
+
* every instance before the manager recovers rows, or recovered attempts find no executor.
|
|
75
|
+
*/
|
|
76
|
+
registerTool(toolName: string): void;
|
|
77
|
+
create(params: MCPTaskCreateParams, { pinToWorker, clientLabel }?: {
|
|
78
|
+
pinToWorker?: boolean;
|
|
79
|
+
clientLabel?: string;
|
|
80
|
+
}): Promise<MCPTask>;
|
|
81
|
+
run(taskId: string, work: MCPTaskWork, options?: MCPTaskRunOptions): void;
|
|
82
|
+
get(taskId: string, access: MCPTaskAccess): Promise<MCPDetailedTask | undefined>;
|
|
83
|
+
update(taskId: string, inputResponses: MCPTaskInputResponses, access: MCPTaskAccess): Promise<boolean>;
|
|
84
|
+
cancel(taskId: string, access: MCPTaskAccess): Promise<boolean>;
|
|
85
|
+
/** Lists this server's tasks across principals, most recently created first. */
|
|
86
|
+
list(options?: MCPTaskListOptions): Promise<MCPTaskListPage>;
|
|
87
|
+
updateByKey(taskKey: string, inputResponses: MCPTaskInputResponses): Promise<MCPTaskAdminOutcome>;
|
|
88
|
+
cancelByKey(taskKey: string): Promise<MCPTaskAdminOutcome>;
|
|
89
|
+
traceOf(taskId: string, access: MCPTaskAccess): Promise<MCPTaskTrace | undefined>;
|
|
90
|
+
/**
|
|
91
|
+
* Stops sweeping, waits for a sweep already running to stop at its next step, then unregisters
|
|
92
|
+
* this store's executors. Rows stay in storage.
|
|
93
|
+
*/
|
|
94
|
+
close(): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Repairs what no request would: expires rows past their TTL, resumes answered rows whose
|
|
97
|
+
* process-local resume was lost, and settles rows whose worker died while this manager was
|
|
98
|
+
* already running (the manager itself only recovers rows when it starts).
|
|
99
|
+
*/
|
|
100
|
+
sweep(): Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Starts the periodic sweep before any task request, so this instance settles rows a dead worker
|
|
103
|
+
* left behind even if no client ever asks it about a task. Does nothing once the store is closed.
|
|
104
|
+
*/
|
|
105
|
+
startSweeping(): void;
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=background-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"background-store.d.ts","sourceRoot":"","sources":["../../../src/server/tasks/background-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,qBAAqB,EAA6B,MAAM,+BAA+B,CAAC;AACtH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAIzD,OAAO,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAUhH,OAAO,KAAK,EACV,aAAa,EACb,mBAAmB,EAGnB,mBAAmB,EAEnB,kBAAkB,EAClB,eAAe,EAEf,iBAAiB,EACjB,YAAY,EACZ,iBA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O,CAAC,mBAAmB,CAAC,CAEhG;IAED,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAEzD;IAuDK,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CAEtF;IA+DD;;;OAGG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAO3B;IAED;;;;OAIG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAIrB;IAED;;;OAGG;IACH,aAAa,IAAI,IAAI,CAEpB;CAiSF"}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import type { RequestContext } from '@mastra/core/request-context';
|
|
2
|
+
import type { MCPToolType } from '@mastra/core/tools';
|
|
3
|
+
import type { MCPDetailedTask } from '../../shared/tasks/index.js';
|
|
4
|
+
import type { MCPTaskAccess, MCPTaskCreateParams, MCPTaskLimits, MCPTaskRunOptions, MCPTaskStore, MCPTaskStoreAdmin, MCPTaskWork } from './store.js';
|
|
5
|
+
/**
|
|
6
|
+
* How a tool answers `tools/call` for a client that declared the Tasks extension.
|
|
7
|
+
*
|
|
8
|
+
* - `'off'`: always answers synchronously.
|
|
9
|
+
* - `'always'`: answers with a task straight away.
|
|
10
|
+
* - `'auto'`: answers synchronously when the tool finishes within `syncWindowMs`, and with a task otherwise.
|
|
11
|
+
*
|
|
12
|
+
* @experimental SEP-2663 extension; API may change.
|
|
13
|
+
*/
|
|
14
|
+
export type MCPServerTaskMode = 'off' | 'auto' | 'always';
|
|
15
|
+
/** @experimental SEP-2663 extension; API may change. */
|
|
16
|
+
export interface MCPServerToolTaskConfig {
|
|
17
|
+
mode: MCPServerTaskMode;
|
|
18
|
+
/** For `'auto'`: how long to wait for a synchronous answer, in ms. Default 2000. */
|
|
19
|
+
syncWindowMs?: number;
|
|
20
|
+
/** Overrides `tasks.ttlMs` for this tool's tasks. */
|
|
21
|
+
ttlMs?: number | null;
|
|
22
|
+
/** Overrides `tasks.recover` for this tool's tasks. */
|
|
23
|
+
recover?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* How one workflow's `run_<key>` tool is served as a task. There is no `recover`: a task whose
|
|
27
|
+
* server restarted re-attaches to its workflow run, which core's workflow recovery continues.
|
|
28
|
+
*
|
|
29
|
+
* @experimental SEP-2663 extension; API may change.
|
|
30
|
+
*/
|
|
31
|
+
export type MCPServerWorkflowTaskConfig = Omit<MCPServerToolTaskConfig, 'recover'>;
|
|
32
|
+
/**
|
|
33
|
+
* What `tasks.authorize` receives on every `tasks/get`, `tasks/update` and `tasks/cancel`.
|
|
34
|
+
*
|
|
35
|
+
* @experimental SEP-2663 extension; API may change.
|
|
36
|
+
*/
|
|
37
|
+
export interface MCPServerTaskAuthorizeContext {
|
|
38
|
+
/** The caller, already matched against the principal the task was created by. */
|
|
39
|
+
principal: string;
|
|
40
|
+
task: MCPDetailedTask;
|
|
41
|
+
/** The caller's request context, including `user` when the server maps one from the request's auth info. */
|
|
42
|
+
requestContext: RequestContext;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Serves `tools/call` as MCP Tasks (`io.modelcontextprotocol/tasks`) for the tools you opt in.
|
|
46
|
+
*
|
|
47
|
+
* @experimental SEP-2663 extension; API may change.
|
|
48
|
+
*/
|
|
49
|
+
export interface MCPServerTasksOptions {
|
|
50
|
+
/** Mode for every tool, workflow and agent not listed in `tools`, `workflows` or `agents`. Default `'off'`. */
|
|
51
|
+
default?: MCPServerTaskMode;
|
|
52
|
+
/** Per-tool mode, keyed by tool name. */
|
|
53
|
+
tools?: Record<string, MCPServerTaskMode | MCPServerToolTaskConfig>;
|
|
54
|
+
/**
|
|
55
|
+
* Per-workflow mode, keyed by the server's `workflows` key; applies to its `run_<key>` tool. A
|
|
56
|
+
* workflow task follows its workflow run: a suspended step asks the client for input, and
|
|
57
|
+
* cancelling the task cancels the run.
|
|
58
|
+
*/
|
|
59
|
+
workflows?: Record<string, MCPServerTaskMode | MCPServerWorkflowTaskConfig>;
|
|
60
|
+
/** Per-agent mode, keyed by the server's `agents` key; applies to its `ask_<key>` tool. */
|
|
61
|
+
agents?: Record<string, MCPServerTaskMode | MCPServerToolTaskConfig>;
|
|
62
|
+
/**
|
|
63
|
+
* Tools that only run as tasks, by the name clients call them (`run_<workflow>` and
|
|
64
|
+
* `ask_<agent>` for workflows and agents): a client that did not declare the Tasks extension
|
|
65
|
+
* gets a -32021 error instead of a synchronous answer.
|
|
66
|
+
*/
|
|
67
|
+
required?: string[];
|
|
68
|
+
/** How long a task is kept from creation, in ms; `null` keeps it until the server closes. Default 24 hours. */
|
|
69
|
+
ttlMs?: number | null;
|
|
70
|
+
/**
|
|
71
|
+
* Whether a task whose server crashed or restarted mid-attempt runs the tool or agent again from
|
|
72
|
+
* the start. Only applies to stores that outlive a process (Mastra background tasks). Only turn
|
|
73
|
+
* this on for idempotent tools: `execute` may run twice. When off, such a task fails as lost.
|
|
74
|
+
* Workflow tasks ignore it: they always re-attach to their run. Default `false`.
|
|
75
|
+
*/
|
|
76
|
+
recover?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Where tasks are kept. By default, Mastra's background tasks when the server is registered on a
|
|
79
|
+
* Mastra instance with `backgroundTasks` enabled and storage that supports task expiry, so every
|
|
80
|
+
* instance sharing that storage serves the same tasks. Otherwise an {@link InMemoryMCPTaskStore},
|
|
81
|
+
* which serves a single instance.
|
|
82
|
+
*/
|
|
83
|
+
store?: MCPTaskStore;
|
|
84
|
+
/**
|
|
85
|
+
* Most open (`working` or `input_required`) tasks one client may hold. Past it, a call that
|
|
86
|
+
* would start a task answers with `isError: true` instead. Default 100, or
|
|
87
|
+
* `maxRetainedTasksPerClient` when that is lower. A custom `store` that ignores `limits` in
|
|
88
|
+
* `create` enforces no cap.
|
|
89
|
+
*/
|
|
90
|
+
maxOpenTasksPerClient?: number;
|
|
91
|
+
/**
|
|
92
|
+
* Most open tasks across all clients. Default 1000, or `maxRetainedTasks` when that is lower.
|
|
93
|
+
* Enforced the same way as `maxOpenTasksPerClient`.
|
|
94
|
+
*/
|
|
95
|
+
maxOpenTasks?: number;
|
|
96
|
+
/**
|
|
97
|
+
* Most tasks one client may have in the store, open or finished, until each is forgotten
|
|
98
|
+
* (`ttlMs` plus a short retention). The in-memory store keeps finished results until then, so
|
|
99
|
+
* this bounds its memory when a client runs many short tasks. Past it, a call that would start a
|
|
100
|
+
* task answers like at the open cap. Default 1000, or `maxOpenTasksPerClient` when that is
|
|
101
|
+
* higher; setting it below `maxOpenTasksPerClient` throws. Only the in-memory store enforces it.
|
|
102
|
+
*/
|
|
103
|
+
maxRetainedTasksPerClient?: number;
|
|
104
|
+
/**
|
|
105
|
+
* Most tasks in the store across all clients, open or finished. Default 10000, or `maxOpenTasks`
|
|
106
|
+
* when that is higher. Enforced the same way as `maxRetainedTasksPerClient`.
|
|
107
|
+
*/
|
|
108
|
+
maxRetainedTasks?: number;
|
|
109
|
+
/**
|
|
110
|
+
* Decides whether the caller may read, answer or cancel a task. Tasks are always bound to the
|
|
111
|
+
* principal that created them; this narrows access further. A refusal answers as an unknown task.
|
|
112
|
+
*/
|
|
113
|
+
authorize?: (context: MCPServerTaskAuthorizeContext) => boolean | Promise<boolean>;
|
|
114
|
+
}
|
|
115
|
+
/** How one tool is served as a task. */
|
|
116
|
+
export interface ResolvedToolTaskMode {
|
|
117
|
+
mode: MCPServerTaskMode;
|
|
118
|
+
syncWindowMs: number;
|
|
119
|
+
ttlMs: number | null;
|
|
120
|
+
recover: boolean;
|
|
121
|
+
}
|
|
122
|
+
export interface ResolvedTasksConfig {
|
|
123
|
+
/** Whether any tool can answer with a task; gates the capability and the `tasks/*` handlers. */
|
|
124
|
+
enabled: boolean;
|
|
125
|
+
/** The store passed in, if any. */
|
|
126
|
+
store?: MCPTaskStore;
|
|
127
|
+
limits: MCPTaskLimits;
|
|
128
|
+
required: ReadonlySet<string>;
|
|
129
|
+
authorize?: MCPServerTasksOptions['authorize'];
|
|
130
|
+
modeFor(name: string, toolType: MCPToolType | undefined): ResolvedToolTaskMode;
|
|
131
|
+
}
|
|
132
|
+
/** The keys a server serves, for checking `tasks` against. */
|
|
133
|
+
export interface TasksConfigSurfaces {
|
|
134
|
+
tools: readonly string[];
|
|
135
|
+
workflows?: readonly string[];
|
|
136
|
+
agents?: readonly string[];
|
|
137
|
+
}
|
|
138
|
+
/** Validates `tasks` against the configured tools, workflows and agents. Throws on anything a server could not serve. */
|
|
139
|
+
export declare function resolveTasksConfig(options: MCPServerTasksOptions | undefined, surfaces: TasksConfigSurfaces): ResolvedTasksConfig;
|
|
140
|
+
/**
|
|
141
|
+
* Picks the store on first use, once the server knows whether it runs on a Mastra instance with
|
|
142
|
+
* durable background tasks. `run` follows the `create` it pairs with, so the choice is made by then.
|
|
143
|
+
*/
|
|
144
|
+
export declare class SelectingMCPTaskStore implements MCPTaskStore {
|
|
145
|
+
#private;
|
|
146
|
+
constructor(select: () => Promise<MCPTaskStore>);
|
|
147
|
+
/** The chosen store, choosing it if no task request has yet. */
|
|
148
|
+
resolve(): Promise<MCPTaskStore>;
|
|
149
|
+
/**
|
|
150
|
+
* Chooses again on next use, for a server registered on Mastra after it served tasks. An
|
|
151
|
+
* in-memory store chosen before keeps the tasks created on it and goes on serving them.
|
|
152
|
+
*/
|
|
153
|
+
reselect(): void;
|
|
154
|
+
/** Cancels the work of the in-memory stores it chose; a background-task store is closed by the server. */
|
|
155
|
+
close(): void;
|
|
156
|
+
create(params: MCPTaskCreateParams): Promise<{
|
|
157
|
+
[x: string]: unknown;
|
|
158
|
+
taskId: string;
|
|
159
|
+
status: "cancelled" | "completed" | "failed" | "input_required" | "working";
|
|
160
|
+
statusMessage?: string | undefined;
|
|
161
|
+
createdAt: string;
|
|
162
|
+
lastUpdatedAt: string;
|
|
163
|
+
ttlMs: number | null;
|
|
164
|
+
pollIntervalMs?: number | undefined;
|
|
165
|
+
}>;
|
|
166
|
+
get(taskId: string, access: MCPTaskAccess): Promise<{
|
|
167
|
+
[x: string]: unknown;
|
|
168
|
+
taskId: string;
|
|
169
|
+
statusMessage?: string | undefined;
|
|
170
|
+
createdAt: string;
|
|
171
|
+
lastUpdatedAt: string;
|
|
172
|
+
ttlMs: number | null;
|
|
173
|
+
pollIntervalMs?: number | undefined;
|
|
174
|
+
status: "working";
|
|
175
|
+
} | {
|
|
176
|
+
[x: string]: unknown;
|
|
177
|
+
taskId: string;
|
|
178
|
+
statusMessage?: string | undefined;
|
|
179
|
+
createdAt: string;
|
|
180
|
+
lastUpdatedAt: string;
|
|
181
|
+
ttlMs: number | null;
|
|
182
|
+
pollIntervalMs?: number | undefined;
|
|
183
|
+
status: "input_required";
|
|
184
|
+
inputRequests: Record<string, {
|
|
185
|
+
[x: string]: unknown;
|
|
186
|
+
method: string;
|
|
187
|
+
params?: Record<string, unknown> | undefined;
|
|
188
|
+
}>;
|
|
189
|
+
} | {
|
|
190
|
+
[x: string]: unknown;
|
|
191
|
+
taskId: string;
|
|
192
|
+
statusMessage?: string | undefined;
|
|
193
|
+
createdAt: string;
|
|
194
|
+
lastUpdatedAt: string;
|
|
195
|
+
ttlMs: number | null;
|
|
196
|
+
pollIntervalMs?: number | undefined;
|
|
197
|
+
status: "completed";
|
|
198
|
+
result: Record<string, unknown>;
|
|
199
|
+
} | {
|
|
200
|
+
[x: string]: unknown;
|
|
201
|
+
taskId: string;
|
|
202
|
+
statusMessage?: string | undefined;
|
|
203
|
+
createdAt: string;
|
|
204
|
+
lastUpdatedAt: string;
|
|
205
|
+
ttlMs: number | null;
|
|
206
|
+
pollIntervalMs?: number | undefined;
|
|
207
|
+
status: "failed";
|
|
208
|
+
error: Record<string, unknown>;
|
|
209
|
+
} | {
|
|
210
|
+
[x: string]: unknown;
|
|
211
|
+
taskId: string;
|
|
212
|
+
statusMessage?: string | undefined;
|
|
213
|
+
createdAt: string;
|
|
214
|
+
lastUpdatedAt: string;
|
|
215
|
+
ttlMs: number | null;
|
|
216
|
+
pollIntervalMs?: number | undefined;
|
|
217
|
+
status: "cancelled";
|
|
218
|
+
} | undefined>;
|
|
219
|
+
update(taskId: string, inputResponses: Parameters<MCPTaskStore['update']>[1], access: MCPTaskAccess): Promise<boolean>;
|
|
220
|
+
cancel(taskId: string, access: MCPTaskAccess): Promise<boolean>;
|
|
221
|
+
traceOf(taskId: string, access: MCPTaskAccess): Promise<import("./store").MCPTaskTrace | undefined>;
|
|
222
|
+
run(taskId: string, work: MCPTaskWork, options?: MCPTaskRunOptions): void;
|
|
223
|
+
/** The chosen store's admin view, or `undefined` when it has none. */
|
|
224
|
+
admin(): Promise<MCPTaskStoreAdmin | undefined>;
|
|
225
|
+
}
|
|
226
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/server/tasks/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAG1D,OAAO,KAAK,EACV,aAAa,EACb,mBAAmB,EACnB,aAAa,EACb,iBAAiB,EACjB,YAAY,EACZ,iBAAiB,EACjB,WAAW,EACZ,MAAM,SAAS,CAAC;AAEjB;;;;;;;;GAQG;AACH,MAAM,MAAM,iBAAiB,GAAG,KAAK,GAAG,MAAM,GAAG,QAAQ,CAAC;AAE1D,wDAAwD;AACxD,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,iBAAiB,CAAC;IACxB,oFAAoF;IACpF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qDAAqD;IACrD,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,uDAAuD;IACvD,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;GAKG;AACH,MAAM,MAAM,2BA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;;;;;mBAE9C;IAEK,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,aAAa,oBAExG;IAEK,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,oBAEjD;IAEK,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,uDAElD;IAED,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAIxE;IAED,sEAAsE;IAChE,KAAK,IAAI,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAAC,CAGpD;CACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CallToolResult, Transport } from '@modelcontextprotocol/server';
|
|
2
|
+
import type { MCPTask } from '../../shared/tasks/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* A `tools/call` result standing in for a task handle. The SDK only lets a tool handler return a
|
|
5
|
+
* `CallToolResult`; {@link emitTaskResults} replaces this one with the `CreateTaskResult` on the
|
|
6
|
+
* wire. `isError` keeps the SDK from applying the tool's output schema to the placeholder.
|
|
7
|
+
*/
|
|
8
|
+
export declare function taskHandleResult(task: MCPTask): CallToolResult;
|
|
9
|
+
/** The task a result built by {@link taskHandleResult} stands for; `undefined` for any other result. */
|
|
10
|
+
export declare function taskOfHandleResult(result: unknown): MCPTask | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Sends results built by {@link taskHandleResult} as `CreateTaskResult`s. Only call handlers that
|
|
13
|
+
* checked the caller declared the Tasks extension may build them.
|
|
14
|
+
*/
|
|
15
|
+
export declare function emitTaskResults(transport: Transport): void;
|
|
16
|
+
//# sourceMappingURL=emit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../../../src/server/tasks/emit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAE9E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAKlD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,cAAc,CAM9D;AAED,wGAAwG;AACxG,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,CAGvE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI,CAc1D"}
|