@mastra/mcp 2.6.0 → 2.7.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/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 -108
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3204 -112
- 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
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { RequestContext } from '@mastra/core/request-context';
|
|
2
|
+
import type { Server, ServerContext } from '@modelcontextprotocol/server';
|
|
3
|
+
import type { MCPDetailedTask } from '../../shared/tasks/index.js';
|
|
4
|
+
import type { MCPTaskStore, MCPTaskTrace } from './store.js';
|
|
5
|
+
/** How a `tasks/*` request is traced. */
|
|
6
|
+
export interface TaskRequestTracing {
|
|
7
|
+
/** Run without a span: polls are frequent and change nothing. */
|
|
8
|
+
untraced?: boolean;
|
|
9
|
+
/** The task's trace, which the request's span joins; `undefined` traces the request on its own. */
|
|
10
|
+
parentOf?: (requestContext: RequestContext) => Promise<MCPTaskTrace | undefined>;
|
|
11
|
+
/** Recorded on the request's span. Never the task id, which is a bearer token. */
|
|
12
|
+
metadata?: Record<string, unknown>;
|
|
13
|
+
}
|
|
14
|
+
export interface TaskHandlerDeps {
|
|
15
|
+
store: MCPTaskStore;
|
|
16
|
+
/** Resolves the request's context and runs `fn` under the request's span. Defaults to an empty context, untraced. */
|
|
17
|
+
trace?: <T>(server: Server, method: string, params: Record<string, unknown>, ctx: ServerContext, fn: (requestContext: RequestContext) => Promise<T>, tracing?: TaskRequestTracing) => Promise<T>;
|
|
18
|
+
/** The authenticated caller of a request, as tasks are bound to it at creation. */
|
|
19
|
+
principal: (ctx: ServerContext, requestContext: RequestContext) => string | Promise<string>;
|
|
20
|
+
/** Further narrows which callers may read, answer or cancel a task they created. */
|
|
21
|
+
authorize?: (context: {
|
|
22
|
+
principal: string;
|
|
23
|
+
task: MCPDetailedTask;
|
|
24
|
+
requestContext: RequestContext;
|
|
25
|
+
}) => boolean | Promise<boolean>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Registers `tasks/get`, `tasks/update` and `tasks/cancel` on one protocol instance. They are
|
|
29
|
+
* registered with explicit schemas, which the SDK requires to serve the Tasks extension's methods on
|
|
30
|
+
* the 2026-07-28 revision.
|
|
31
|
+
*/
|
|
32
|
+
export declare function registerTaskHandlers(server: Server, deps: TaskHandlerDeps): void;
|
|
33
|
+
//# sourceMappingURL=handlers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../../src/server/tasks/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAW1E,OAAO,KAAK,EAAE,eAAe,EAAyB,MAAM,oBAAoB,CAAC;AACjF,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE1D,yCAAyC;AACzC,MAAM,WAAW,kBAAkB;IACjC,iEAAiE;IACjE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,mGAAmG;IACnG,QAAQ,CAAC,EAAE,CAAC,cAAc,EAAE,cAAc,KAAK,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CAAC;IACjF,kFAAkF;IAClF,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,YAAY,CAAC;IACpB,qHAAqH;IACrH,KAAK,CAAC,EAAE,CAAC,CAAC,EACR,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,GAAG,EAAE,aAAa,EAClB,EAAE,EAAE,CAAC,cAAc,EAAE,cAAc,KAAK,OAAO,CAAC,CAAC,CAAC,EAClD,OAAO,CAAC,EAAE,kBAAkB,KACzB,OAAO,CAAC,CAAC,CAAC,CAAC;IAChB,mFAAmF;IACnF,SAAS,EAAE,CAAC,GAAG,EAAE,aAAa,EAAE,cAAc,EAAE,cAAc,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC5F,oFAAoF;IACpF,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE;QACpB,SAAS,EAAE,MAAM,CAAC;QAClB,IAAI,EAAE,eAAe,CAAC;QACtB,cAAc,EAAE,cAAc,CAAC;KAChC,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAClC;AAOD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,GAAG,IAAI,CAkFhF"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { CallToolResult } from '@modelcontextprotocol/server';
|
|
2
|
+
import type { MCPDetailedTask, MCPTask, MCPTaskError, MCPTaskInputRequests, MCPTaskInputResponses } from '../../shared/tasks/index.js';
|
|
3
|
+
import type { MCPTaskAccess, MCPTaskAdminOutcome, MCPTaskCreateParams, MCPTaskListOptions, MCPTaskListPage, MCPTaskRunOptions, MCPTaskStore, MCPTaskStoreAdmin, MCPTaskTrace, MCPTaskWork } from './store.js';
|
|
4
|
+
/**
|
|
5
|
+
* Writes the state of one in-memory task. The code executing the task holds it.
|
|
6
|
+
*
|
|
7
|
+
* @experimental SEP-2663 extension; API may change.
|
|
8
|
+
*/
|
|
9
|
+
export interface MCPTaskHandle {
|
|
10
|
+
readonly taskId: string;
|
|
11
|
+
/** Aborts when the task is cancelled or expires. */
|
|
12
|
+
readonly signal: AbortSignal;
|
|
13
|
+
/** Sets the status message shown while the task works. */
|
|
14
|
+
status(message: string): void;
|
|
15
|
+
/**
|
|
16
|
+
* Moves the task to `input_required` and resolves with the client's answers once every key is
|
|
17
|
+
* answered. Keys must be unique over the task's lifetime. Rejects if the task is cancelled or expires.
|
|
18
|
+
*/
|
|
19
|
+
requireInput(requests: MCPTaskInputRequests): Promise<MCPTaskInputResponses>;
|
|
20
|
+
complete(result: CallToolResult): void;
|
|
21
|
+
fail(error: MCPTaskError): void;
|
|
22
|
+
}
|
|
23
|
+
/** @experimental SEP-2663 extension; API may change. */
|
|
24
|
+
export interface InMemoryMCPTaskStoreOptions {
|
|
25
|
+
/** How long an expired task still answers `failed` before it is forgotten. Default 60 seconds. */
|
|
26
|
+
expiredRetentionMs?: number;
|
|
27
|
+
/** Clock, for tests. Default `Date.now`. */
|
|
28
|
+
now?: () => number;
|
|
29
|
+
/**
|
|
30
|
+
* Called with a task's context when it is cancelled or expires before finishing, even while no
|
|
31
|
+
* attempt runs (e.g. while it waits for input). Stops whatever the task stands for outside the
|
|
32
|
+
* store, such as a suspended workflow run. Not awaited: the cancel answers and expiry goes on
|
|
33
|
+
* without waiting for it. Errors are ignored; report them from the hook.
|
|
34
|
+
*/
|
|
35
|
+
onCancel?: (context: Record<string, unknown>) => void | Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Default {@link MCPTaskStore}: tasks live in this process. A task created here can only be read on
|
|
39
|
+
* the same instance and does not survive a restart, so use it for single-instance servers.
|
|
40
|
+
*
|
|
41
|
+
* When a task's TTL elapses its work is aborted and it turns `failed`; it is forgotten after
|
|
42
|
+
* `expiredRetentionMs`. Finished tasks stay in memory until then, so `limits.retainedPerPrincipal`
|
|
43
|
+
* and `limits.retainedTotal` bound how many tasks it holds; a task with a `null` TTL counts until
|
|
44
|
+
* the store closes.
|
|
45
|
+
*
|
|
46
|
+
* @experimental SEP-2663 extension; API may change.
|
|
47
|
+
*/
|
|
48
|
+
export declare class InMemoryMCPTaskStore implements MCPTaskStore, MCPTaskStoreAdmin {
|
|
49
|
+
#private;
|
|
50
|
+
constructor(options?: InMemoryMCPTaskStoreOptions);
|
|
51
|
+
create(params: MCPTaskCreateParams, { clientLabel }?: {
|
|
52
|
+
clientLabel?: string;
|
|
53
|
+
}): Promise<MCPTask>;
|
|
54
|
+
get(taskId: string, access: MCPTaskAccess): Promise<MCPDetailedTask | undefined>;
|
|
55
|
+
update(taskId: string, inputResponses: MCPTaskInputResponses, access: MCPTaskAccess): Promise<boolean>;
|
|
56
|
+
cancel(taskId: string, access: MCPTaskAccess): Promise<boolean>;
|
|
57
|
+
list(options?: MCPTaskListOptions): Promise<MCPTaskListPage>;
|
|
58
|
+
updateByKey(taskKey: string, inputResponses: MCPTaskInputResponses): Promise<MCPTaskAdminOutcome>;
|
|
59
|
+
cancelByKey(taskKey: string): Promise<MCPTaskAdminOutcome>;
|
|
60
|
+
traceOf(taskId: string, access: MCPTaskAccess): Promise<MCPTaskTrace | undefined>;
|
|
61
|
+
/** Whether this store holds the task, for any caller. */
|
|
62
|
+
has(taskId: string): boolean;
|
|
63
|
+
/** The context recorded at creation. */
|
|
64
|
+
context(taskId: string): Record<string, unknown> | undefined;
|
|
65
|
+
run(taskId: string, work: MCPTaskWork, options?: MCPTaskRunOptions): void;
|
|
66
|
+
/** The writer for a task this store holds. Writes after the task is terminal are ignored. */
|
|
67
|
+
handle(taskId: string): MCPTaskHandle;
|
|
68
|
+
/** Cancels all running work, invalidates every handle and forgets every task. */
|
|
69
|
+
close(): void;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=in-memory-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory-store.d.ts","sourceRoot":"","sources":["../../../src/server/tasks/in-memory-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAQnE,OAAO,KAAK,EACV,eAAe,EACf,OAAO,EACP,YAAY,EACZ,oBAAoB,EACpB,qBAAqB,EAEtB,MAAM,oBAAoB,CAAC;AAU5B,OAAO,KAAK,EACV,aAAa,EACb,mBAAmB,EAGnB,mBAAmB,EAEnB,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,WAAW,EACZ,MAAM,SAAS,CAAC;AAEjB;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,oDAAoD;IACpD,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,0DAA0D;IAC1D,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B;;;OAGG;IACH,YAAY,CAAC,QAAQ,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAC7E,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,CAAC;IACvC,IAAI,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC;CACjC;AAED,wDAAwD;AACxD,MAAM,WAAW,2BAA2B;IAC1C,kGAAkG;IAClG,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,4CAA4C;IAC5C,GAAG,CAAC,EAAE,MAAM,MAAM,CA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AG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAE3D;IAED,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,GAAE,iBAAsB,GAAG,IAAI,CAkB5E;IAwED,6FAA6F;IAC7F,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,CAyCpC;IAED,iFAAiF;IACjF,KAAK,IAAI,IAAI,CAUZ;CAqGF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { isMCPTaskStoreAdmin, principalKeyOf, taskKeyOf } from './store.js';
|
|
2
|
+
export type { MCPTaskAccess, MCPTaskAdminOutcome, MCPTaskListing, MCPTaskListOptions, MCPTaskListPage, MCPTaskStoreAdmin, MCPTaskAttempt, MCPTaskAttemptTrace, MCPTaskTrace, MCPTaskAttemptOutcome, MCPTaskCreateParams, MCPTaskLimits, MCPTaskRunOptions, MCPTaskStore, MCPTaskWork, } from './store.js';
|
|
3
|
+
export { MCPTaskLimitError } from './store.js';
|
|
4
|
+
export { InMemoryMCPTaskStore } from './in-memory-store.js';
|
|
5
|
+
export type { InMemoryMCPTaskStoreOptions, MCPTaskHandle } from './in-memory-store.js';
|
|
6
|
+
export type { MCPServerTaskAuthorizeContext, MCPServerTaskMode, MCPServerTasksOptions, MCPServerToolTaskConfig, MCPServerWorkflowTaskConfig, } from './config.js';
|
|
7
|
+
export { isWorkflowTaskContext } from './workflow-runs.js';
|
|
8
|
+
export type { WorkflowTaskContext } from './workflow-runs.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/tasks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACzE,YAAY,EACV,aAAa,EACb,mBAAmB,EACnB,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,mBAAmB,EACnB,YAAY,EACZ,qBAAqB,EACrB,mBAAmB,EACnB,aAAa,EACb,iBAAiB,EACjB,YAAY,EACZ,WAAW,GACZ,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,YAAY,EAAE,2BAA2B,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACpF,YAAY,EACV,6BAA6B,EAC7B,iBAAiB,EACjB,qBAAqB,EACrB,uBAAuB,EACvB,2BAA2B,GAC5B,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,YAAY,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { MCPServerTaskSurfaceInfo, MCPServerTasksInfo, MCPServerTasksInspector } from '@mastra/core/mcp';
|
|
2
|
+
import type { MCPToolType } from '@mastra/core/tools';
|
|
3
|
+
import type { ResolvedTasksConfig } from './config.js';
|
|
4
|
+
import type { MCPTaskStoreAdmin } from './store.js';
|
|
5
|
+
/** The tools served as tasks, as Studio shows them. */
|
|
6
|
+
export declare function listTaskSurfaces(tasks: ResolvedTasksConfig, tools: Array<[name: string, toolType: MCPToolType | undefined]>): MCPServerTaskSurfaceInfo[];
|
|
7
|
+
export declare function tasksInfo(tasks: ResolvedTasksConfig, tools: Array<[name: string, toolType: MCPToolType | undefined]>): MCPServerTasksInfo;
|
|
8
|
+
/**
|
|
9
|
+
* Studio's view of the task store. Cancel and answer go through the store's `cancelByKey` and
|
|
10
|
+
* `updateByKey`, the same code as `tasks/cancel` and `tasks/update`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createTasksInspector(admin: () => Promise<MCPTaskStoreAdmin | undefined>): MCPServerTasksInspector;
|
|
13
|
+
//# sourceMappingURL=inspector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inspector.d.ts","sourceRoot":"","sources":["../../../src/server/tasks/inspector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,wBAAwB,EACxB,kBAAkB,EAClB,uBAAuB,EACxB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEpD,OAAO,KAAK,EAAkB,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjE,uDAAuD;AACvD,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,mBAAmB,EAC1B,KAAK,EAAE,KAAK,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,GAAG,SAAS,CAAC,CAAC,GAC9D,wBAAwB,EAAE,CAe5B;AAED,wBAAgB,SAAS,CACvB,KAAK,EAAE,mBAAmB,EAC1B,KAAK,EAAE,KAAK,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,GAAG,SAAS,CAAC,CAAC,GAC9D,kBAAkB,CAOpB;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAAC,GAAG,uBAAuB,CAsBjH"}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import type { CallToolResult } from '@modelcontextprotocol/server';
|
|
2
|
+
import type { MCPDetailedTask, MCPTask, MCPTaskInputRequests, MCPTaskInputResponses, MCPTaskStatus } from '../../shared/tasks/index.js';
|
|
3
|
+
export { taskKeyOf } from '../../shared/tasks/index.js';
|
|
4
|
+
/** How a principal is stored and shown. Principals can carry user and subject ids, so only their hash is kept. */
|
|
5
|
+
export declare function principalKeyOf(principal: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* What {@link MCPTaskStore.create} durably records.
|
|
8
|
+
*
|
|
9
|
+
* @experimental SEP-2663 extension; API may change.
|
|
10
|
+
*/
|
|
11
|
+
export interface MCPTaskCreateParams {
|
|
12
|
+
/** Retention from creation in ms; `null` keeps the task until the store is cleared. */
|
|
13
|
+
ttlMs: number | null;
|
|
14
|
+
/** Fixed poll interval to suggest. Omit to let the store suggest one that grows with the task's age. */
|
|
15
|
+
pollIntervalMs?: number;
|
|
16
|
+
/** The authenticated caller that created the task. Only the same principal can read, answer or cancel it. */
|
|
17
|
+
principal: string;
|
|
18
|
+
/** Store-defined data the server's execution needs to find the work again, e.g. a workflow run id. */
|
|
19
|
+
context?: Record<string, unknown>;
|
|
20
|
+
/** The span of the request that created the task. Kept with the task so every attempt joins its trace. */
|
|
21
|
+
trace?: MCPTaskTrace;
|
|
22
|
+
/**
|
|
23
|
+
* Most open (`working` or `input_required`) tasks allowed for this principal and for the whole
|
|
24
|
+
* store, counting the one being created, plus the optional retained-task bounds. Over any of them,
|
|
25
|
+
* `create` rejects with {@link MCPTaskLimitError} and records nothing. Omitted: no limit.
|
|
26
|
+
*/
|
|
27
|
+
limits?: MCPTaskLimits;
|
|
28
|
+
}
|
|
29
|
+
/** @experimental SEP-2663 extension; API may change. */
|
|
30
|
+
export interface MCPTaskLimits {
|
|
31
|
+
perPrincipal: number;
|
|
32
|
+
total: number;
|
|
33
|
+
/**
|
|
34
|
+
* Most tasks the store may hold for this principal and in total, open or finished but not yet
|
|
35
|
+
* forgotten, counting the one being created. A store that keeps finished results outside process
|
|
36
|
+
* memory may ignore these.
|
|
37
|
+
*/
|
|
38
|
+
retainedPerPrincipal?: number;
|
|
39
|
+
retainedTotal?: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Thrown by {@link MCPTaskStore.create} when the task would go over one of its `limits`.
|
|
43
|
+
*
|
|
44
|
+
* @experimental SEP-2663 extension; API may change.
|
|
45
|
+
*/
|
|
46
|
+
export declare class MCPTaskLimitError extends Error {
|
|
47
|
+
readonly scope: 'principal' | 'total';
|
|
48
|
+
readonly limit: number;
|
|
49
|
+
/** `'open'` for the open-task limits, `'retained'` for the retained ones. */
|
|
50
|
+
readonly kind: 'open' | 'retained';
|
|
51
|
+
constructor(scope: 'principal' | 'total', limit: number,
|
|
52
|
+
/** `'open'` for the open-task limits, `'retained'` for the retained ones. */
|
|
53
|
+
kind?: 'open' | 'retained');
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Where a task's trace starts: the span of the `tools/call` that created it.
|
|
57
|
+
*
|
|
58
|
+
* @experimental SEP-2663 extension; API may change.
|
|
59
|
+
*/
|
|
60
|
+
export interface MCPTaskTrace {
|
|
61
|
+
traceId: string;
|
|
62
|
+
spanId: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The caller presented on a `tasks/*` request.
|
|
66
|
+
*
|
|
67
|
+
* @experimental SEP-2663 extension; API may change.
|
|
68
|
+
*/
|
|
69
|
+
export interface MCPTaskAccess {
|
|
70
|
+
principal: string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Where `MCPServer` keeps MCP tasks. The `tasks/*` handlers call `get`, `update` and `cancel`;
|
|
74
|
+
* `MCPServer` creates a task and hands its work to `run`. Where the work runs (in-process, on a
|
|
75
|
+
* background-task worker) is up to the store.
|
|
76
|
+
*
|
|
77
|
+
* - `create` must not resolve before an immediate `get(taskId)` would succeed, including on another
|
|
78
|
+
* instance when the store is shared (SEP-2663 durable creation).
|
|
79
|
+
* - `create` enforces `limits` by rejecting with {@link MCPTaskLimitError}. A store that ignores
|
|
80
|
+
* `limits` caps nothing.
|
|
81
|
+
* - `get`, `update` and `cancel` resolve `undefined`/`false` for an unknown, expired or
|
|
82
|
+
* foreign-principal task. The server answers all three cases with the same `-32602`.
|
|
83
|
+
* - `update` ignores unknown and already-answered input keys.
|
|
84
|
+
* - `cancel` is cooperative: it acknowledges, and the task may still complete or fail. It is a no-op
|
|
85
|
+
* on terminal tasks.
|
|
86
|
+
* - There is deliberately no `list`: task ids are bearer tokens and must not be enumerable.
|
|
87
|
+
*
|
|
88
|
+
* @experimental SEP-2663 extension; API may change.
|
|
89
|
+
*/
|
|
90
|
+
export interface MCPTaskStore {
|
|
91
|
+
create(params: MCPTaskCreateParams): Promise<MCPTask>;
|
|
92
|
+
get(taskId: string, access: MCPTaskAccess): Promise<MCPDetailedTask | undefined>;
|
|
93
|
+
update(taskId: string, inputResponses: MCPTaskInputResponses, access: MCPTaskAccess): Promise<boolean>;
|
|
94
|
+
cancel(taskId: string, access: MCPTaskAccess): Promise<boolean>;
|
|
95
|
+
/**
|
|
96
|
+
* Drives `work` for a task this store created: runs it now, runs it again with `resume` once every
|
|
97
|
+
* open input key is answered, and records each outcome. A rejected attempt marks the task `failed`
|
|
98
|
+
* (-32603). Outcomes that arrive after the task is terminal are ignored.
|
|
99
|
+
*
|
|
100
|
+
* `work` must be a pure function of the `context` given to `create`, so a store that outlives the
|
|
101
|
+
* process can rebuild and dispatch it again. With `options.initialAttempt`, that attempt stands in
|
|
102
|
+
* for the first call to `work`; every later attempt still goes through `work`.
|
|
103
|
+
*/
|
|
104
|
+
run(taskId: string, work: MCPTaskWork, options?: MCPTaskRunOptions): void;
|
|
105
|
+
/**
|
|
106
|
+
* The trace given to `create`, for a caller that may `get` the task; `undefined` otherwise.
|
|
107
|
+
* Lets `tasks/update` and `tasks/cancel` join the task's trace. Optional: without it they are
|
|
108
|
+
* traced on their own.
|
|
109
|
+
*/
|
|
110
|
+
traceOf?(taskId: string, access: MCPTaskAccess): Promise<MCPTaskTrace | undefined>;
|
|
111
|
+
}
|
|
112
|
+
/** @experimental SEP-2663 extension; API may change. */
|
|
113
|
+
export interface MCPTaskRunOptions {
|
|
114
|
+
/**
|
|
115
|
+
* A first attempt already running in this process, e.g. an `'auto'` tool that outlived its sync
|
|
116
|
+
* window. The store awaits `outcome` as attempt 1 instead of calling `work`, and calls `abort`
|
|
117
|
+
* if the task is cancelled or expires meanwhile.
|
|
118
|
+
*
|
|
119
|
+
* It is process-local and never persisted: it may hold request-local state, so a durable store
|
|
120
|
+
* treats it as process-affine and never dispatches it elsewhere.
|
|
121
|
+
*/
|
|
122
|
+
initialAttempt?: {
|
|
123
|
+
outcome: Promise<MCPTaskAttemptOutcome>;
|
|
124
|
+
abort: (reason?: unknown) => void;
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* One run of a task's work. The first attempt has no `resume`; after an `input_required` outcome
|
|
129
|
+
* the next attempt receives the client's answers.
|
|
130
|
+
*
|
|
131
|
+
* @experimental SEP-2663 extension; API may change.
|
|
132
|
+
*/
|
|
133
|
+
export interface MCPTaskAttempt {
|
|
134
|
+
/** Aborts when the task is cancelled or expires. */
|
|
135
|
+
signal: AbortSignal;
|
|
136
|
+
/**
|
|
137
|
+
* The task's trace and which attempt this is, for the attempt's span. A store that omits it runs
|
|
138
|
+
* the attempt untraced.
|
|
139
|
+
*/
|
|
140
|
+
trace?: MCPTaskAttemptTrace;
|
|
141
|
+
resume?: {
|
|
142
|
+
/** The answers to every key the previous attempt asked for. */
|
|
143
|
+
inputResponses: MCPTaskInputResponses;
|
|
144
|
+
/** What the previous attempt handed back with its input requests. */
|
|
145
|
+
suspendPayload: unknown;
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* How one attempt ended. Errors raised by the work itself belong in a `completed` result with
|
|
150
|
+
* `isError: true`; only a rejected attempt makes the task `failed`.
|
|
151
|
+
*
|
|
152
|
+
* @experimental SEP-2663 extension; API may change.
|
|
153
|
+
*/
|
|
154
|
+
export type MCPTaskAttemptOutcome = {
|
|
155
|
+
status: 'completed';
|
|
156
|
+
result: CallToolResult;
|
|
157
|
+
} | {
|
|
158
|
+
status: 'input_required';
|
|
159
|
+
/** Keys must be unique over the task's lifetime; a reused key fails the task. */
|
|
160
|
+
inputRequests: MCPTaskInputRequests;
|
|
161
|
+
suspendPayload?: unknown;
|
|
162
|
+
};
|
|
163
|
+
/** @experimental SEP-2663 extension; API may change. */
|
|
164
|
+
export interface MCPTaskAttemptTrace extends MCPTaskTrace {
|
|
165
|
+
/** The task's key, `taskKeyOf(taskId)`: safe to record, unlike the id. */
|
|
166
|
+
taskKey: string;
|
|
167
|
+
/** 1 for the first run; counts every retry and resume. */
|
|
168
|
+
attempt: number;
|
|
169
|
+
/** Run again with the answers to an `input_required` outcome. */
|
|
170
|
+
resumed: boolean;
|
|
171
|
+
/** Run again because an earlier attempt was lost with its process. */
|
|
172
|
+
recovered: boolean;
|
|
173
|
+
}
|
|
174
|
+
/** @experimental SEP-2663 extension; API may change. */
|
|
175
|
+
export type MCPTaskWork = (attempt: MCPTaskAttempt) => Promise<MCPTaskAttemptOutcome>;
|
|
176
|
+
/**
|
|
177
|
+
* A task as an {@link MCPTaskStoreAdmin} lists it. Carries the task key, never the task id.
|
|
178
|
+
*
|
|
179
|
+
* @experimental SEP-2663 extension; API may change.
|
|
180
|
+
*/
|
|
181
|
+
export interface MCPTaskListing {
|
|
182
|
+
taskKey: string;
|
|
183
|
+
/** The principal that created the task, hashed with {@link principalKeyOf}. */
|
|
184
|
+
principalKey: string;
|
|
185
|
+
/** Who sent the task, readable for operators (see `clientLabelOf`); never a credential. */
|
|
186
|
+
clientLabel?: string;
|
|
187
|
+
/** The `context` given to `create`. */
|
|
188
|
+
context?: Record<string, unknown>;
|
|
189
|
+
status: MCPTaskStatus;
|
|
190
|
+
statusMessage?: string;
|
|
191
|
+
createdAt: string;
|
|
192
|
+
lastUpdatedAt: string;
|
|
193
|
+
ttlMs: number | null;
|
|
194
|
+
/** Open input requests, while `input_required`. */
|
|
195
|
+
inputRequests?: MCPTaskInputRequests;
|
|
196
|
+
result?: Record<string, unknown>;
|
|
197
|
+
/** A JSON-RPC error object. */
|
|
198
|
+
error?: Record<string, unknown>;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Filters for {@link MCPTaskStoreAdmin.list}. Every filter narrows the result.
|
|
202
|
+
*
|
|
203
|
+
* @experimental SEP-2663 extension; API may change.
|
|
204
|
+
*/
|
|
205
|
+
export interface MCPTaskListOptions {
|
|
206
|
+
/** At most this many tasks. Default 50. */
|
|
207
|
+
limit?: number;
|
|
208
|
+
/** `nextCursor` of the previous page. */
|
|
209
|
+
cursor?: string;
|
|
210
|
+
status?: MCPTaskStatus;
|
|
211
|
+
/** The tool, workflow or agent name the task runs (`context.toolName`). */
|
|
212
|
+
surface?: string;
|
|
213
|
+
principalKey?: string;
|
|
214
|
+
taskKey?: string;
|
|
215
|
+
}
|
|
216
|
+
/** @experimental SEP-2663 extension; API may change. */
|
|
217
|
+
export interface MCPTaskListPage {
|
|
218
|
+
listings: MCPTaskListing[];
|
|
219
|
+
nextCursor?: string;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Pages lists by creation time. The cursor holds the last listed creation time and the keys
|
|
223
|
+
* already listed at that time, so tasks created in the same millisecond are neither lost nor repeated.
|
|
224
|
+
*/
|
|
225
|
+
interface TaskListCursor {
|
|
226
|
+
before: string;
|
|
227
|
+
seen: string[];
|
|
228
|
+
}
|
|
229
|
+
export declare function decodeTaskListCursor(cursor: string | undefined): TaskListCursor | undefined;
|
|
230
|
+
/** Whether a task comes after the cursor in newest-first order. */
|
|
231
|
+
export declare function isPastTaskListCursor(listing: MCPTaskListing, cursor: TaskListCursor | undefined): boolean;
|
|
232
|
+
/** The cursor for the page after `listings`, newest first. */
|
|
233
|
+
export declare function nextTaskListCursor(listings: MCPTaskListing[], previous: TaskListCursor | undefined): string | undefined;
|
|
234
|
+
/** Whether a listing matches the filters a store could not apply while reading. */
|
|
235
|
+
export declare function matchesTaskListOptions(listing: MCPTaskListing, options: MCPTaskListOptions): boolean;
|
|
236
|
+
/**
|
|
237
|
+
* What an admin action on a task did: `not_found` for an unknown or expired task, `ignored` when the
|
|
238
|
+
* task was found but nothing changed (already finished, or not waiting for those inputs).
|
|
239
|
+
*
|
|
240
|
+
* @experimental SEP-2663 extension; API may change.
|
|
241
|
+
*/
|
|
242
|
+
export type MCPTaskAdminOutcome = 'done' | 'ignored' | 'not_found';
|
|
243
|
+
/**
|
|
244
|
+
* Optional admin view of an {@link MCPTaskStore}, for Studio. It is not part of the protocol, and
|
|
245
|
+
* works on task keys ({@link taskKeyOf}) rather than task ids, across all principals. `updateByKey`
|
|
246
|
+
* and `cancelByKey` must run the same code as `update` and `cancel`.
|
|
247
|
+
*
|
|
248
|
+
* @experimental SEP-2663 extension; API may change.
|
|
249
|
+
*/
|
|
250
|
+
export interface MCPTaskStoreAdmin {
|
|
251
|
+
/** Most recently created first. `nextCursor` is set when more tasks match. */
|
|
252
|
+
list(options?: MCPTaskListOptions): Promise<MCPTaskListPage>;
|
|
253
|
+
updateByKey(taskKey: string, inputResponses: MCPTaskInputResponses): Promise<MCPTaskAdminOutcome>;
|
|
254
|
+
cancelByKey(taskKey: string): Promise<MCPTaskAdminOutcome>;
|
|
255
|
+
}
|
|
256
|
+
/** @experimental SEP-2663 extension; API may change. */
|
|
257
|
+
export declare function isMCPTaskStoreAdmin(store: MCPTaskStore): store is MCPTaskStore & MCPTaskStoreAdmin;
|
|
258
|
+
/** Projects a detailed task onto a listing. */
|
|
259
|
+
export declare function toListing(taskKey: string, principalKey: string, context: Record<string, unknown> | undefined, task: MCPDetailedTask, clientLabel?: string): MCPTaskListing;
|
|
260
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/server/tasks/store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EACV,eAAe,EACf,OAAO,EACP,oBAAoB,EACpB,qBAAqB,EACrB,aAAa,EACd,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,kHAAkH;AAClH,wBAAgB,cAAc,C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;CAC5D;AAED,wDAAwD;AACxD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,YAAY,GAAG,KAAK,IAAI,YAAY,GAAG,iBAAiB,CAOlG;AAED,+CAA+C;AAC/C,wBAAgB,SAAS,CACvB,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAC5C,IAAI,EAAE,eAAe,EACrB,WAAW,CAAC,EAAE,MAAM,GACnB,cAAc,CAehB"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { StepWithComponent, Workflow, WorkflowRunStatus } from '@mastra/core/workflows';
|
|
2
|
+
/**
|
|
3
|
+
* What a workflow task records at creation, as `MCPTaskCreateParams.context`. The task follows the
|
|
4
|
+
* run `runId`, which the server started exactly once when it created the task; nothing here can
|
|
5
|
+
* start it again. A custom `tasks.store` that cancels or expires a task cancels its run with
|
|
6
|
+
* `mastra.getWorkflow(workflowKey).createRun({ runId })` then `run.cancel()`.
|
|
7
|
+
*
|
|
8
|
+
* @experimental SEP-2663 extension; API may change.
|
|
9
|
+
*/
|
|
10
|
+
export interface WorkflowTaskContext extends Record<string, unknown> {
|
|
11
|
+
toolName: string;
|
|
12
|
+
kind: 'workflow';
|
|
13
|
+
workflowKey: string;
|
|
14
|
+
runId: string;
|
|
15
|
+
/** The caller's request context, minus the bearer token. */
|
|
16
|
+
requestContext: Record<string, unknown>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Whether a task's context is a workflow task's.
|
|
20
|
+
*
|
|
21
|
+
* @experimental SEP-2663 extension; API may change.
|
|
22
|
+
*/
|
|
23
|
+
export declare function isWorkflowTaskContext(context: Record<string, unknown> | undefined): context is WorkflowTaskContext;
|
|
24
|
+
/**
|
|
25
|
+
* A run as both `run.start()`/`run.resume()` (a `WorkflowResult`) and `getWorkflowRunById` (a
|
|
26
|
+
* `WorkflowState`) describe it, so a live run and a re-attached one answer the same.
|
|
27
|
+
*/
|
|
28
|
+
export interface WorkflowRunView {
|
|
29
|
+
status: WorkflowRunStatus;
|
|
30
|
+
input?: unknown;
|
|
31
|
+
steps?: Record<string, unknown>;
|
|
32
|
+
result?: unknown;
|
|
33
|
+
error?: unknown;
|
|
34
|
+
}
|
|
35
|
+
export declare function isFinalRunStatus(status: WorkflowRunStatus): boolean;
|
|
36
|
+
/** The text a finished run answers with: the same fields the synchronous `run_` tool returns. */
|
|
37
|
+
export declare function runSummary(view: WorkflowRunView): Record<string, unknown>;
|
|
38
|
+
export declare function runErrorMessage(view: WorkflowRunView): string;
|
|
39
|
+
export interface SuspendedStep {
|
|
40
|
+
/** The path `run.resume({ step })` takes: the step id, then nested steps inside nested workflows. */
|
|
41
|
+
path: string[];
|
|
42
|
+
step?: StepWithComponent;
|
|
43
|
+
/** The payload the step suspended with, without the engine's bookkeeping. */
|
|
44
|
+
payload: unknown;
|
|
45
|
+
/** When the step suspended; tells this suspension from a later one of the same step. */
|
|
46
|
+
suspendedAt?: number;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The first step the run is suspended on. A run with several (parallel branches) is resumed one at
|
|
50
|
+
* a time: after each resume it suspends again on the next.
|
|
51
|
+
*/
|
|
52
|
+
export declare function firstSuspendedStep(workflow: Workflow, view: WorkflowRunView): SuspendedStep | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Whether `answered` (recorded when the task asked) is still the run's current suspension. Another
|
|
55
|
+
* resume, from Studio or the API, moves the run on; a step that suspends again gets a new `suspendedAt`.
|
|
56
|
+
*/
|
|
57
|
+
export declare function isStillSuspended(view: WorkflowRunView, answered: AnsweredSuspension): boolean;
|
|
58
|
+
/** What a workflow task keeps of the suspension it asked about, to resume exactly that one. */
|
|
59
|
+
export interface AnsweredSuspension {
|
|
60
|
+
step: string[];
|
|
61
|
+
suspendedAt?: number;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=workflow-runs.d.ts.map
|
|
@@ -0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6E;IAC7E,OAAO,EAAE,OAAO,CAAC;IACjB,wFAAwF;IACxF,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,eAAe,GAAG,aAAa,GAAG,SAAS,CAavG;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,eAAe,EAAE,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAI7F;AAED,+FAA+F;AAC/F,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { TASKS_EXTENSION_ID } from './constants.js';
|
|
2
|
+
/**
|
|
3
|
+
* Whether a capabilities object declares the Tasks extension. A non-object entry counts as absent,
|
|
4
|
+
* and the legacy 2025-11-25 top-level `capabilities.tasks` key is ignored: it is not wire-compatible.
|
|
5
|
+
*
|
|
6
|
+
* @experimental SEP-2663 extension; API may change.
|
|
7
|
+
*/
|
|
8
|
+
export declare function hasTasksCapability(capabilities: {
|
|
9
|
+
extensions?: Record<string, unknown>;
|
|
10
|
+
} | undefined | null): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* The `extensions` entry a peer advertises to declare the Tasks extension. SEP-2663 defines no
|
|
13
|
+
* settings, so the value is an empty object.
|
|
14
|
+
*
|
|
15
|
+
* @experimental SEP-2663 extension; API may change.
|
|
16
|
+
*/
|
|
17
|
+
export declare function tasksCapabilityEntry(): Record<typeof TASKS_EXTENSION_ID, Record<string, never>>;
|
|
18
|
+
//# sourceMappingURL=capability.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capability.d.ts","sourceRoot":"","sources":["../../../src/shared/tasks/capability.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,YAAY,EAAE;IAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,GAAG,SAAS,GAAG,IAAI,GAAG,OAAO,CAGrH;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAAC,OAAO,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAE/F"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire constants for the MCP Tasks extension (SEP-2663, protocol revision 2026-07-28).
|
|
3
|
+
*
|
|
4
|
+
* @experimental SEP-2663 extension; API may change.
|
|
5
|
+
*/
|
|
6
|
+
/** Extension identifier used as the key under `capabilities.extensions`. */
|
|
7
|
+
export declare const TASKS_EXTENSION_ID = "io.modelcontextprotocol/tasks";
|
|
8
|
+
export declare const TASKS_METHODS: {
|
|
9
|
+
readonly get: 'tasks/get';
|
|
10
|
+
readonly update: 'tasks/update';
|
|
11
|
+
readonly cancel: 'tasks/cancel';
|
|
12
|
+
};
|
|
13
|
+
/** `resultType` of a `tools/call` result that is a task handle instead of a `CallToolResult`. */
|
|
14
|
+
export declare const TASK_RESULT_TYPE = "task";
|
|
15
|
+
export declare const TASK_STATUSES: readonly ['working', 'input_required', 'completed', 'failed', 'cancelled'];
|
|
16
|
+
export type MCPTaskStatus = (typeof TASK_STATUSES)[number];
|
|
17
|
+
/** `completed`, `failed` and `cancelled` are terminal: the task never changes again. */
|
|
18
|
+
export declare function isTerminalTaskStatus(status: MCPTaskStatus): boolean;
|
|
19
|
+
export declare const TASKS_ERROR_CODES: {
|
|
20
|
+
/** Unknown, expired or foreign task id. Also used for a principal mismatch, so existence is not revealed. */
|
|
21
|
+
readonly InvalidParams: -32602;
|
|
22
|
+
readonly InternalError: -32603;
|
|
23
|
+
/** The request needs a task but the client did not declare `io.modelcontextprotocol/tasks`. */
|
|
24
|
+
readonly MissingRequiredClientCapability: -32021;
|
|
25
|
+
};
|
|
26
|
+
/** How long a server keeps a task by default: 24 hours. */
|
|
27
|
+
export declare const DEFAULT_TASK_TTL_MS = 86400000;
|
|
28
|
+
/** Suggested poll interval while a task is young. */
|
|
29
|
+
export declare const DEFAULT_TASK_INITIAL_POLL_INTERVAL_MS = 2000;
|
|
30
|
+
/** Suggested poll interval once a task is older than {@link DEFAULT_TASK_INITIAL_POLL_WINDOW_MS}. */
|
|
31
|
+
export declare const DEFAULT_TASK_POLL_INTERVAL_MS = 5000;
|
|
32
|
+
/** How long a task counts as young for polling purposes. */
|
|
33
|
+
export declare const DEFAULT_TASK_INITIAL_POLL_WINDOW_MS = 60000;
|
|
34
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/shared/tasks/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,4EAA4E;AAC5E,eAAO,MAAM,kBAAkB,kCAAkC,CAAC;AAElE,eAAO,MAAM,aAAa;aACxB,GAAG,EAAE,WAAW;aAChB,MAAM,EAAE,cAAc;aACtB,MAAM,EAAE,cAAc;CACd,CAAC;AAEX,iGAAiG;AACjG,eAAO,MAAM,gBAAgB,SAAS,CAAC;AAEvC,eAAO,MAAM,aAAa,YAAI,SAAS,EAAE,gBAAgB,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,CAAU,CAAC;AAExG,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AAI3D,wFAAwF;AACxF,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAEnE;AAED,eAAO,MAAM,iBAAiB;IAC5B,6GAA6G;aAC7G,aAAa,EAAE,CAAC,KAAK;aACrB,aAAa,EAAE,CAAC,KAAK;IACrB,+FAA+F;aAC/F,+BAA+B,EAAE,CAAC,KAAK;CAC/B,CAAC;AAEX,2DAA2D;AAC3D,eAAO,MAAM,mBAAmB,WAAa,CAAC;AAE9C,qDAAqD;AACrD,eAAO,MAAM,qCAAqC,OAAQ,CAAC;AAE3D,qGAAqG;AACrG,eAAO,MAAM,6BAA6B,OAAQ,CAAC;AAEnD,4DAA4D;AAC5D,eAAO,MAAM,mCAAmC,QAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/shared/tasks/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,mBAAmB,SAAS,CAAC"}
|