typespec-http-mcp 0.8.1 → 0.10.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 +65 -10
- package/dist/src/annotations.d.ts +41 -5
- package/dist/src/annotations.js +77 -5
- package/dist/src/emitter.js +17 -0
- package/dist/src/lib.d.ts +3 -0
- package/dist/src/lib.js +13 -0
- package/dist/src/runtime.d.ts +226 -3
- package/dist/src/runtime.js +175 -0
- package/dist/src/tools.d.ts +3 -0
- package/dist/src/tools.js +107 -22
- package/package.json +5 -4
- package/src/runtime.ts +389 -3
package/src/runtime.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
type CallToolResult,
|
|
3
|
+
type McpServer,
|
|
4
|
+
MissingRequiredClientCapabilityError,
|
|
5
|
+
ProtocolError,
|
|
6
|
+
ProtocolErrorCode,
|
|
7
|
+
type ServerContext,
|
|
8
|
+
} from "@modelcontextprotocol/server";
|
|
9
|
+
import { z, type ZodError, type ZodType } from "zod";
|
|
3
10
|
|
|
4
11
|
/**
|
|
5
12
|
* **What generated code imports at run time -- and the only thing this package puts in its output.**
|
|
@@ -528,7 +535,7 @@ export async function toolResult(
|
|
|
528
535
|
* **`C` is the caller context, and `registerTools` INFERS it from `context`.** An application whose
|
|
529
536
|
* `context` returns a `Caller` has handlers typed `(ctx: Caller, input)`, with nothing to declare.
|
|
530
537
|
*/
|
|
531
|
-
export interface ToolDeps<C = unknown> {
|
|
538
|
+
export interface ToolDeps<C = unknown, Call extends ToolCallShape = never> {
|
|
532
539
|
/**
|
|
533
540
|
* Whether the caller this server was built for may SEE this tool.
|
|
534
541
|
*
|
|
@@ -571,4 +578,383 @@ export interface ToolDeps<C = unknown> {
|
|
|
571
578
|
|
|
572
579
|
/** The result when {@link context} returns `null`. The application's to decide. */
|
|
573
580
|
readonly noContext: (context: ServerContext) => CallToolResult;
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Which tools may answer with an MCP task, and how a task is created. Absent, no tool ever does.
|
|
584
|
+
*
|
|
585
|
+
* **The application's to decide, because the document cannot say it.** The Tasks extension has
|
|
586
|
+
* no per-tool declaration: the server decides on each request whether to answer with a task.
|
|
587
|
+
* Whether a tool's work outlives a request is a fact about where the application runs it, not
|
|
588
|
+
* about the operation.
|
|
589
|
+
*
|
|
590
|
+
* **Typed by the generated `ToolCall`, so write `ToolDeps<Caller, ToolCall>` to set it.** The
|
|
591
|
+
* policy names operations, and only the generated module knows which exist. `ToolDeps<Caller>`
|
|
592
|
+
* names none, so it admits no operation, and wiring written before tasks existed compiles as it
|
|
593
|
+
* did.
|
|
594
|
+
*/
|
|
595
|
+
readonly tasks?: ToolTasks<C, Call>;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/** What a tool call is, to the code that runs it later: the operation and its validated input. */
|
|
599
|
+
export interface ToolCallShape {
|
|
600
|
+
readonly operationId: string;
|
|
601
|
+
readonly input: unknown;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
/**
|
|
605
|
+
* The application's task policy for the tools one `registerTools` call registers.
|
|
606
|
+
*
|
|
607
|
+
* **`decide` and `create` are METHOD signatures, deliberately.** That keeps the policy covariant in
|
|
608
|
+
* `Call`, so `ToolDeps<Caller>`, which lists no operation, is still a `ToolDeps<Caller, ToolCall>`.
|
|
609
|
+
* With property signatures the two would be unrelated, and every wiring written before tasks existed
|
|
610
|
+
* would stop compiling.
|
|
611
|
+
*
|
|
612
|
+
* **A request that did not declare the Tasks extension never reaches this policy.** It is answered
|
|
613
|
+
* inline, as if no policy were configured, because the extension forbids answering it with a task.
|
|
614
|
+
*/
|
|
615
|
+
export interface ToolTasks<C, Call extends ToolCallShape> {
|
|
616
|
+
/**
|
|
617
|
+
* The operations that may answer with a task.
|
|
618
|
+
*
|
|
619
|
+
* **Read at REGISTRATION, like `permits`**, because it changes what is published: a tool listed
|
|
620
|
+
* here publishes no `outputSchema`. The SDK refuses a task from a tool that publishes one, so a
|
|
621
|
+
* task tool is an ordinary tool without it, on every request.
|
|
622
|
+
*/
|
|
623
|
+
readonly operations: readonly Call["operationId"][];
|
|
624
|
+
|
|
625
|
+
/**
|
|
626
|
+
* Whether THIS call becomes a task or runs inline. Consulted only for a listed operation and a
|
|
627
|
+
* request that declared the extension. Absent, every such call becomes a task.
|
|
628
|
+
*
|
|
629
|
+
* Receives the validated input and the caller, so the answer can depend on the application's own
|
|
630
|
+
* state: work that is already finished can be answered at once.
|
|
631
|
+
*
|
|
632
|
+
* Type `call` as the whole `ToolCall` and narrow on `operationId`: as a method, this accepts a
|
|
633
|
+
* narrower parameter without complaint, and receives every listed operation's call regardless.
|
|
634
|
+
*/
|
|
635
|
+
decide?(call: Call, caller: C, context: ServerContext): Awaitable<"task" | "inline">;
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* Create the task and answer with its handle. In practice
|
|
639
|
+
* `(call, caller, context) => tasks.create(context, { context: { ...call, ... } })`, where the
|
|
640
|
+
* application chooses what the store needs to find or start the work: the call, an identifier
|
|
641
|
+
* for the caller, a service name when one store serves several services.
|
|
642
|
+
*/
|
|
643
|
+
create(call: Call, caller: C, context: ServerContext): Promise<TaskToolResult>;
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
/**
|
|
647
|
+
* The result McpServer answers when a tool callback throws: the message as text, marked as an error.
|
|
648
|
+
*
|
|
649
|
+
* Exported so the work behind a task settles a thrown error exactly as the blocking call would have
|
|
650
|
+
* answered it. The Tasks extension requires a tool error to complete the task with that result,
|
|
651
|
+
* and reserves `failed` for a protocol error.
|
|
652
|
+
*/
|
|
653
|
+
export function toolError(error: unknown): CallToolResult {
|
|
654
|
+
return {
|
|
655
|
+
content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
|
|
656
|
+
isError: true,
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
/**
|
|
661
|
+
* Refuses a task policy on a server no {@link TasksExtension} is attached to. A tool there would
|
|
662
|
+
* answer with a task the server does not advertise and nobody can poll: `tasks/get` would be an
|
|
663
|
+
* unknown method. Called by `registerTools` when the policy lists an operation.
|
|
664
|
+
*/
|
|
665
|
+
export function requireTasksAttached(server: McpServer): void {
|
|
666
|
+
if (server.server.getCapabilities().extensions?.[TASKS_EXTENSION_ID] === undefined) {
|
|
667
|
+
throw new Error(
|
|
668
|
+
"deps.tasks lists operations, but no Tasks extension is attached to this server. " +
|
|
669
|
+
"Call attach(server) on a TasksExtension before registerTools, or the tasks it creates cannot be polled.",
|
|
670
|
+
);
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* A tool's answer as the 2026-07-28 wire carries it, so as a completed task holds it: with the
|
|
676
|
+
* `resultType: "complete"` every result of that revision carries.
|
|
677
|
+
*
|
|
678
|
+
* **A task's result is exactly what the call would have answered**, and McpServer adds the
|
|
679
|
+
* discriminator to a blocking answer on its way out. A task's result reaches the client inside
|
|
680
|
+
* `tasks/get` instead, where nothing adds it, and the Tasks extension's reference client refuses a
|
|
681
|
+
* completed result without it.
|
|
682
|
+
*/
|
|
683
|
+
export function completed(result: CallToolResult): CallToolResult {
|
|
684
|
+
return { ...result, resultType: "complete" };
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* The MCP Tasks extension (`io.modelcontextprotocol/tasks`) lets a server answer `tools/call` with a
|
|
689
|
+
* task handle, which the client polls with `tasks/get`, answers with `tasks/update` and stops with
|
|
690
|
+
* `tasks/cancel`.
|
|
691
|
+
*
|
|
692
|
+
* **The declarations below have the shape of the SDK's own Tasks extension**, which is not yet in a
|
|
693
|
+
* release. A store written against them satisfies the SDK's `TaskStore` as well, so adopting the
|
|
694
|
+
* SDK's extension replaces one import and one `attach` call, and nothing else.
|
|
695
|
+
*/
|
|
696
|
+
export const TASKS_EXTENSION_ID = "io.modelcontextprotocol/tasks";
|
|
697
|
+
|
|
698
|
+
/**
|
|
699
|
+
* A task's state, as every task-related message carries it.
|
|
700
|
+
*
|
|
701
|
+
* **A type, not an interface, and its optional members admit `undefined`**, so a task typed by the
|
|
702
|
+
* SDK's own extension, an open object whose optional members do, is one of these and the reverse.
|
|
703
|
+
*/
|
|
704
|
+
export type Task = {
|
|
705
|
+
readonly taskId: string;
|
|
706
|
+
readonly status: "working" | "input_required" | "completed" | "cancelled" | "failed";
|
|
707
|
+
readonly statusMessage?: string | undefined;
|
|
708
|
+
/** ISO 8601. */
|
|
709
|
+
readonly createdAt: string;
|
|
710
|
+
/** ISO 8601. */
|
|
711
|
+
readonly lastUpdatedAt: string;
|
|
712
|
+
/** Retention from creation, in milliseconds; `null` is unlimited. */
|
|
713
|
+
readonly ttlMs: number | null;
|
|
714
|
+
/** How often a client should poll, in milliseconds. */
|
|
715
|
+
readonly pollIntervalMs?: number | undefined;
|
|
716
|
+
};
|
|
717
|
+
|
|
718
|
+
/** A request a task makes of the client while it waits, such as `elicitation/create`. */
|
|
719
|
+
export type TaskInputRequest = {
|
|
720
|
+
readonly method: string;
|
|
721
|
+
readonly params?: Readonly<Record<string, unknown>> | undefined;
|
|
722
|
+
};
|
|
723
|
+
|
|
724
|
+
/**
|
|
725
|
+
* What `tasks/get` answers: the task, with what its status carries.
|
|
726
|
+
*
|
|
727
|
+
* **`completed` carries the `CallToolResult` the call would have returned, `isError` included.**
|
|
728
|
+
* `failed` is only for a protocol error during execution, never for a tool that answered an error.
|
|
729
|
+
*/
|
|
730
|
+
export type DetailedTask =
|
|
731
|
+
| (Task & { readonly status: "working" })
|
|
732
|
+
| (Task & {
|
|
733
|
+
readonly status: "input_required";
|
|
734
|
+
readonly inputRequests: Readonly<Record<string, TaskInputRequest>>;
|
|
735
|
+
})
|
|
736
|
+
| (Task & { readonly status: "completed"; readonly result: Readonly<Record<string, unknown>> })
|
|
737
|
+
| (Task & { readonly status: "failed"; readonly error: Readonly<Record<string, unknown>> })
|
|
738
|
+
| (Task & { readonly status: "cancelled" });
|
|
739
|
+
|
|
740
|
+
/** A tool's answer when its work continues as a task. */
|
|
741
|
+
export type CreateTaskResult = Task & { readonly resultType: "task" };
|
|
742
|
+
|
|
743
|
+
/** The handle a tool callback returns in place of a `CallToolResult`. */
|
|
744
|
+
export type TaskToolResult = CallToolResult & CreateTaskResult;
|
|
745
|
+
|
|
746
|
+
/** What the extension asks a store to create. */
|
|
747
|
+
export interface CreateTaskParams {
|
|
748
|
+
/** Retention from creation, in milliseconds; `null` is unlimited. */
|
|
749
|
+
readonly ttlMs: number | null;
|
|
750
|
+
readonly pollIntervalMs?: number;
|
|
751
|
+
/**
|
|
752
|
+
* The identity of the request that created the task. A store MUST refuse every later access
|
|
753
|
+
* from a different principal, answering as for an unknown task.
|
|
754
|
+
*/
|
|
755
|
+
readonly principal?: string;
|
|
756
|
+
/** The store's own: whatever its execution needs to find or start the work. */
|
|
757
|
+
readonly context?: Readonly<Record<string, unknown>>;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
/** The identity presented on a `tasks/*` request. */
|
|
761
|
+
export interface TaskAccess {
|
|
762
|
+
readonly principal?: string;
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
/**
|
|
766
|
+
* Where tasks live and how their work is found. The extension owns the protocol; the store owns the
|
|
767
|
+
* state, and the application owns the execution behind it: a queue, a workflow, a durable object.
|
|
768
|
+
*
|
|
769
|
+
* - `create` MUST NOT resolve before a following `get` would find the task.
|
|
770
|
+
* - `get`, `update` and `cancel` answer `undefined` or `false` for a task that is unknown, expired
|
|
771
|
+
* or another principal's, and the extension answers all three alike.
|
|
772
|
+
* - `cancel` is cooperative and idempotent on a finished task.
|
|
773
|
+
* - Task ids MUST be unguessable.
|
|
774
|
+
*/
|
|
775
|
+
export interface TaskStore {
|
|
776
|
+
create(params: CreateTaskParams): Promise<Task>;
|
|
777
|
+
get(taskId: string, access?: TaskAccess): Promise<DetailedTask | undefined>;
|
|
778
|
+
update(
|
|
779
|
+
taskId: string,
|
|
780
|
+
inputResponses: Readonly<Record<string, unknown>>,
|
|
781
|
+
access?: TaskAccess,
|
|
782
|
+
): Promise<boolean>;
|
|
783
|
+
cancel(taskId: string, access?: TaskAccess): Promise<boolean>;
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
export interface TasksExtensionOptions {
|
|
787
|
+
/** Retention when `create` is given none, in milliseconds; `null` is unlimited. Default 24 hours. */
|
|
788
|
+
readonly defaultTtlMs?: number | null;
|
|
789
|
+
/** The polling hint when `create` is given none, in milliseconds. Default 5000. */
|
|
790
|
+
readonly defaultPollIntervalMs?: number;
|
|
791
|
+
/**
|
|
792
|
+
* The identity a task is bound to. Default: the OAuth client id, with the token subject when
|
|
793
|
+
* the token verifier puts one at `authInfo.extra.sub`. With no authentication it is `undefined`,
|
|
794
|
+
* and a task's id is then the only credential for it.
|
|
795
|
+
*/
|
|
796
|
+
readonly principal?: (context: ServerContext) => string | undefined;
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
export interface CreateTaskOptions {
|
|
800
|
+
readonly ttlMs?: number | null;
|
|
801
|
+
readonly pollIntervalMs?: number;
|
|
802
|
+
readonly context?: Readonly<Record<string, unknown>>;
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
const CLIENT_CAPABILITIES = "io.modelcontextprotocol/clientCapabilities";
|
|
806
|
+
|
|
807
|
+
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
808
|
+
typeof value === "object" && value !== null && !Array.isArray(value);
|
|
809
|
+
|
|
810
|
+
/**
|
|
811
|
+
* Whether THIS request declared the Tasks extension. A task may be returned only to a request that
|
|
812
|
+
* did, whatever an earlier request declared.
|
|
813
|
+
*/
|
|
814
|
+
export function declaresTasks(context: ServerContext): boolean {
|
|
815
|
+
const envelope: unknown = context.mcpReq.envelope;
|
|
816
|
+
const capabilities = isRecord(envelope) ? envelope[CLIENT_CAPABILITIES] : undefined;
|
|
817
|
+
const extensions = isRecord(capabilities) ? capabilities["extensions"] : undefined;
|
|
818
|
+
return isRecord(extensions) && TASKS_EXTENSION_ID in extensions;
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
function requireTasks(context: ServerContext, what: string): void {
|
|
822
|
+
if (declaresTasks(context)) return;
|
|
823
|
+
throw new MissingRequiredClientCapabilityError(
|
|
824
|
+
{ requiredCapabilities: { extensions: { [TASKS_EXTENSION_ID]: {} } } },
|
|
825
|
+
`${what} requires the request to declare the "${TASKS_EXTENSION_ID}" extension`,
|
|
826
|
+
);
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
/** On 2025-11-25, which carries no envelope, `tasks/get` and `tasks/cancel` named other methods. */
|
|
830
|
+
function requireModern(context: ServerContext): void {
|
|
831
|
+
if (context.mcpReq.envelope === undefined) {
|
|
832
|
+
throw new ProtocolError(ProtocolErrorCode.MethodNotFound, "Method not found");
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
function taskNotFound(): never {
|
|
837
|
+
throw new ProtocolError(ProtocolErrorCode.InvalidParams, "Task not found");
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
function defaultPrincipal(context: ServerContext): string | undefined {
|
|
841
|
+
const authInfo = context.http?.authInfo;
|
|
842
|
+
if (authInfo === undefined) return undefined;
|
|
843
|
+
const subject = authInfo.extra?.["sub"];
|
|
844
|
+
return typeof subject === "string"
|
|
845
|
+
? JSON.stringify([authInfo.clientId, subject])
|
|
846
|
+
: authInfo.clientId;
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
const taskParams = z.object({ taskId: z.string() });
|
|
850
|
+
const updateParams = taskParams.extend({
|
|
851
|
+
inputResponses: z.record(z.string(), z.unknown()).optional(),
|
|
852
|
+
});
|
|
853
|
+
|
|
854
|
+
/**
|
|
855
|
+
* Serves the Tasks extension: its capability, `tasks/get`, `tasks/update` and `tasks/cancel`, over
|
|
856
|
+
* the {@link TaskStore} the application supplies. A tool answers with a task through
|
|
857
|
+
* {@link TasksExtension.create}.
|
|
858
|
+
*
|
|
859
|
+
* One instance serves any number of servers; {@link TasksExtension.attach} each one before it
|
|
860
|
+
* connects. Under `createMcpHandler`, which builds a server per request, create the extension
|
|
861
|
+
* once and attach it in the factory.
|
|
862
|
+
*/
|
|
863
|
+
export class TasksExtension {
|
|
864
|
+
readonly id = TASKS_EXTENSION_ID;
|
|
865
|
+
readonly store: TaskStore;
|
|
866
|
+
readonly #defaultTtlMs: number | null;
|
|
867
|
+
readonly #defaultPollIntervalMs: number;
|
|
868
|
+
readonly #principal: (context: ServerContext) => string | undefined;
|
|
869
|
+
readonly #attached = new WeakSet<McpServer>();
|
|
870
|
+
|
|
871
|
+
constructor(store: TaskStore, options: TasksExtensionOptions = {}) {
|
|
872
|
+
this.store = store;
|
|
873
|
+
this.#defaultTtlMs = options.defaultTtlMs === undefined ? 86_400_000 : options.defaultTtlMs;
|
|
874
|
+
this.#defaultPollIntervalMs = options.defaultPollIntervalMs ?? 5000;
|
|
875
|
+
this.#principal = options.principal ?? defaultPrincipal;
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
/**
|
|
879
|
+
* Create a task for the current `tools/call`, bound to the caller, and return the handle the tool
|
|
880
|
+
* answers with. Refuses with `-32021` when the request did not declare the extension.
|
|
881
|
+
*/
|
|
882
|
+
async create(context: ServerContext, options: CreateTaskOptions = {}): Promise<TaskToolResult> {
|
|
883
|
+
requireTasks(context, "Answering with a task");
|
|
884
|
+
const principal = this.#principal(context);
|
|
885
|
+
const pollIntervalMs = options.pollIntervalMs ?? this.#defaultPollIntervalMs;
|
|
886
|
+
const task = await this.store.create({
|
|
887
|
+
ttlMs: options.ttlMs === undefined ? this.#defaultTtlMs : options.ttlMs,
|
|
888
|
+
pollIntervalMs,
|
|
889
|
+
...(principal === undefined ? {} : { principal }),
|
|
890
|
+
...(options.context === undefined ? {} : { context: options.context }),
|
|
891
|
+
});
|
|
892
|
+
return { resultType: "task", ...task } as TaskToolResult;
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
/**
|
|
896
|
+
* Serve the extension on `server`. Must run before it connects. Attaching this extension to the
|
|
897
|
+
* same server again does nothing; attaching a second Tasks extension throws and leaves the server
|
|
898
|
+
* as it was, because its `tasks/*` handlers would silently replace the first one's.
|
|
899
|
+
*/
|
|
900
|
+
attach(server: McpServer): void {
|
|
901
|
+
if (this.#attached.has(server)) return;
|
|
902
|
+
const protocol = server.server;
|
|
903
|
+
if (protocol.getCapabilities().extensions?.[TASKS_EXTENSION_ID] !== undefined) {
|
|
904
|
+
throw new Error(
|
|
905
|
+
`A Tasks extension is already attached to this server; one server serves one task store.`,
|
|
906
|
+
);
|
|
907
|
+
}
|
|
908
|
+
// Every method checked before any is registered, so a refusal leaves the server as it was.
|
|
909
|
+
for (const method of ["tasks/get", "tasks/update", "tasks/cancel"]) {
|
|
910
|
+
protocol.assertCanSetRequestHandler(method);
|
|
911
|
+
}
|
|
912
|
+
protocol.registerCapabilities({ extensions: { [TASKS_EXTENSION_ID]: {} } });
|
|
913
|
+
|
|
914
|
+
const access = (context: ServerContext): TaskAccess => {
|
|
915
|
+
const principal = this.#principal(context);
|
|
916
|
+
return principal === undefined ? {} : { principal };
|
|
917
|
+
};
|
|
918
|
+
|
|
919
|
+
protocol.setRequestHandler("tasks/get", { params: taskParams }, async (params, context) => {
|
|
920
|
+
requireModern(context);
|
|
921
|
+
requireTasks(context, "tasks/get");
|
|
922
|
+
const task = await this.store.get(params.taskId, access(context));
|
|
923
|
+
return task === undefined ? taskNotFound() : { resultType: "complete", ...task };
|
|
924
|
+
});
|
|
925
|
+
|
|
926
|
+
protocol.setRequestHandler(
|
|
927
|
+
"tasks/update",
|
|
928
|
+
{ params: updateParams },
|
|
929
|
+
async (params, context) => {
|
|
930
|
+
requireModern(context);
|
|
931
|
+
requireTasks(context, "tasks/update");
|
|
932
|
+
const dropped = context.mcpReq.droppedInputResponseKeys ?? [];
|
|
933
|
+
if (dropped.length > 0) {
|
|
934
|
+
throw new ProtocolError(
|
|
935
|
+
ProtocolErrorCode.InvalidParams,
|
|
936
|
+
`inputResponses entries must be bare results; refused: ${dropped.join(", ")}`,
|
|
937
|
+
);
|
|
938
|
+
}
|
|
939
|
+
const inputResponses = context.mcpReq.inputResponses ?? params.inputResponses;
|
|
940
|
+
if (inputResponses === undefined) {
|
|
941
|
+
throw new ProtocolError(
|
|
942
|
+
ProtocolErrorCode.InvalidParams,
|
|
943
|
+
"tasks/update requires inputResponses",
|
|
944
|
+
);
|
|
945
|
+
}
|
|
946
|
+
const found = await this.store.update(params.taskId, inputResponses, access(context));
|
|
947
|
+
return found ? { resultType: "complete" } : taskNotFound();
|
|
948
|
+
},
|
|
949
|
+
);
|
|
950
|
+
|
|
951
|
+
protocol.setRequestHandler("tasks/cancel", { params: taskParams }, async (params, context) => {
|
|
952
|
+
requireModern(context);
|
|
953
|
+
requireTasks(context, "tasks/cancel");
|
|
954
|
+
const found = await this.store.cancel(params.taskId, access(context));
|
|
955
|
+
return found ? { resultType: "complete" } : taskNotFound();
|
|
956
|
+
});
|
|
957
|
+
|
|
958
|
+
this.#attached.add(server);
|
|
959
|
+
}
|
|
574
960
|
}
|