@corbits/mcp 0.3.0 → 0.4.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.
Files changed (124) hide show
  1. package/README.md +120 -26
  2. package/dist/auth/callback.d.ts +14 -0
  3. package/dist/auth/callback.js +79 -0
  4. package/dist/auth/challenge.d.ts +9 -0
  5. package/dist/auth/challenge.js +52 -0
  6. package/dist/auth/contracts.d.ts +18 -0
  7. package/dist/auth/contracts.js +19 -0
  8. package/dist/auth/http.d.ts +2 -0
  9. package/dist/auth/http.js +2 -0
  10. package/dist/auth/index.d.ts +6 -0
  11. package/dist/auth/index.js +6 -0
  12. package/dist/auth/login.d.ts +62 -0
  13. package/dist/auth/login.js +175 -0
  14. package/dist/auth/oauth-http.d.ts +6 -0
  15. package/dist/auth/oauth-http.js +32 -0
  16. package/dist/auth/resource-server.d.ts +25 -0
  17. package/dist/auth/resource-server.js +94 -0
  18. package/dist/auth/url-policy.d.ts +10 -0
  19. package/dist/auth/url-policy.js +35 -0
  20. package/dist/client/resource-budget.d.ts +1 -0
  21. package/dist/client/resource-budget.js +1 -0
  22. package/dist/client/transport.d.ts +10 -0
  23. package/dist/client/transport.js +1 -0
  24. package/dist/client.d.ts +208 -26
  25. package/dist/client.js +1128 -90
  26. package/dist/extensions/apps.d.ts +58 -0
  27. package/dist/extensions/apps.js +55 -0
  28. package/dist/extensions/elicitation.d.ts +18 -0
  29. package/dist/extensions/elicitation.js +55 -0
  30. package/dist/extensions/index.d.ts +5 -0
  31. package/dist/extensions/index.js +5 -0
  32. package/dist/extensions/maturity.d.ts +44 -0
  33. package/dist/extensions/maturity.js +24 -0
  34. package/dist/extensions/skills/contracts.d.ts +53 -0
  35. package/dist/extensions/skills/contracts.js +1 -0
  36. package/dist/extensions/skills/index.d.ts +52 -0
  37. package/dist/extensions/skills/index.js +402 -0
  38. package/dist/extensions/tasks/contracts.d.ts +39 -0
  39. package/dist/extensions/tasks/contracts.js +1 -0
  40. package/dist/extensions/tasks/file-store.d.ts +12 -0
  41. package/dist/extensions/tasks/file-store.js +152 -0
  42. package/dist/extensions/tasks/index.d.ts +82 -0
  43. package/dist/extensions/tasks/index.js +221 -0
  44. package/dist/extensions/tasks/record.d.ts +3 -0
  45. package/dist/extensions/tasks/record.js +37 -0
  46. package/dist/hub/discover.d.ts +5 -1
  47. package/dist/hub/discover.js +36 -13
  48. package/dist/index.d.ts +3 -2
  49. package/dist/index.js +4 -2
  50. package/dist/interchange/client/capabilities.d.ts +4 -0
  51. package/dist/interchange/client/capabilities.js +53 -0
  52. package/dist/interchange/client/catalog.d.ts +14 -0
  53. package/dist/interchange/client/catalog.js +52 -0
  54. package/dist/interchange/client/contracts.d.ts +47 -0
  55. package/dist/interchange/client/contracts.js +1 -0
  56. package/dist/interchange/client/projection.d.ts +6 -0
  57. package/dist/interchange/client/projection.js +92 -0
  58. package/dist/interchange/client/skills.d.ts +16 -0
  59. package/dist/interchange/client/skills.js +87 -0
  60. package/dist/interchange/client.d.ts +8 -0
  61. package/dist/interchange/client.js +6 -0
  62. package/dist/interchange/server/contracts.d.ts +65 -0
  63. package/dist/interchange/server/contracts.js +1 -0
  64. package/dist/interchange/server.d.ts +5 -0
  65. package/dist/interchange/server.js +172 -0
  66. package/dist/naming.d.ts +2 -0
  67. package/dist/naming.js +7 -0
  68. package/dist/oauth-discovery.d.ts +107 -1
  69. package/dist/oauth-discovery.js +292 -56
  70. package/dist/protocol/content.d.ts +35 -0
  71. package/dist/protocol/content.js +64 -0
  72. package/dist/protocol/envelopes.d.ts +14 -0
  73. package/dist/protocol/envelopes.js +22 -0
  74. package/dist/protocol/errors.d.ts +26 -0
  75. package/dist/protocol/errors.js +31 -0
  76. package/dist/protocol/extensions.d.ts +34 -0
  77. package/dist/protocol/extensions.js +86 -0
  78. package/dist/protocol/headers.d.ts +12 -0
  79. package/dist/protocol/headers.js +128 -0
  80. package/dist/protocol/index.d.ts +11 -0
  81. package/dist/protocol/index.js +11 -0
  82. package/dist/protocol/json-schema.d.ts +8 -0
  83. package/dist/protocol/json-schema.js +152 -0
  84. package/dist/protocol/legacy.d.ts +12 -0
  85. package/dist/protocol/legacy.js +18 -0
  86. package/dist/protocol/methods.d.ts +116 -0
  87. package/dist/protocol/methods.js +78 -0
  88. package/dist/protocol/resource-budget.d.ts +9 -0
  89. package/dist/protocol/resource-budget.js +206 -0
  90. package/dist/protocol/schemas.d.ts +115 -0
  91. package/dist/protocol/schemas.js +553 -0
  92. package/dist/protocol/types.d.ts +295 -0
  93. package/dist/protocol/types.js +3 -0
  94. package/dist/protocol/ui.d.ts +3 -0
  95. package/dist/protocol/ui.js +18 -0
  96. package/dist/server/contracts.d.ts +67 -0
  97. package/dist/server/contracts.js +1 -0
  98. package/dist/server/errors.d.ts +6 -0
  99. package/dist/server/errors.js +21 -0
  100. package/dist/server/extensions.d.ts +7 -0
  101. package/dist/server/extensions.js +61 -0
  102. package/dist/server/fixtures.d.ts +2 -0
  103. package/dist/server/fixtures.js +34 -0
  104. package/dist/server/legacy.d.ts +9 -0
  105. package/dist/server/legacy.js +435 -0
  106. package/dist/server/tools.d.ts +17 -0
  107. package/dist/server/tools.js +93 -0
  108. package/dist/server.d.ts +14 -0
  109. package/dist/server.js +406 -0
  110. package/dist/sidecar-bundle.d.ts +7 -7
  111. package/dist/sidecar-bundle.js +36 -29
  112. package/dist/test-server.js +12 -3
  113. package/dist/tool.d.ts +8 -0
  114. package/dist/tool.js +35 -19
  115. package/dist/url.js +8 -3
  116. package/docs/conformance.md +135 -0
  117. package/docs/integration-status.md +98 -0
  118. package/docs/legacy-server.md +58 -0
  119. package/docs/migration.md +143 -0
  120. package/docs/public-api.md +106 -0
  121. package/examples/README.md +28 -0
  122. package/examples/standalone-client.ts +14 -0
  123. package/examples/standalone-server.ts +37 -0
  124. package/package.json +50 -15
@@ -0,0 +1,295 @@
1
+ export declare const MCP_PROTOCOL_VERSION = "2026-07-28";
2
+ export type FetchLike = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
3
+ export type MetaObject = Record<string, unknown>;
4
+ export type JsonSchema = boolean | Record<string, unknown>;
5
+ export type RequestId = string | number;
6
+ export type McpProtocolEra = "modern" | "legacy";
7
+ export type McpExtensionSettings = Readonly<Record<string, Readonly<Record<string, unknown>>>>;
8
+ export interface McpValidationContext {
9
+ /** Explicit resources/read result payload budget; independently checked, capped at 16 MiB. */
10
+ maxDecodedBytes?: number | undefined;
11
+ era?: McpProtocolEra;
12
+ protocolVersion?: string;
13
+ extensions?: readonly string[] | McpExtensionSettings;
14
+ clientCapabilities?: Record<string, unknown>;
15
+ serverCapabilities?: Record<string, unknown>;
16
+ inputSchema?: Record<string, unknown>;
17
+ outputSchema?: Record<string, unknown>;
18
+ }
19
+ export interface McpRpcError {
20
+ code: number;
21
+ message: string;
22
+ data?: unknown;
23
+ }
24
+ export interface ElicitRequestFormParams {
25
+ mode?: "form";
26
+ message: string;
27
+ requestedSchema: {
28
+ $schema?: string;
29
+ type: "object";
30
+ properties: Record<string, Record<string, unknown>>;
31
+ required?: string[];
32
+ };
33
+ }
34
+ export interface ElicitRequestURLParams {
35
+ mode: "url";
36
+ message: string;
37
+ url: string;
38
+ }
39
+ export type ElicitRequestParams = ElicitRequestFormParams | ElicitRequestURLParams;
40
+ export interface ElicitRequest {
41
+ method: "elicitation/create";
42
+ params: ElicitRequestParams;
43
+ }
44
+ export interface ElicitResult {
45
+ action: "accept" | "decline" | "cancel";
46
+ content?: Record<string, string | number | boolean | string[]>;
47
+ _meta?: MetaObject;
48
+ }
49
+ /** Deprecated input kinds are recognized but not advertised or executed by this package. */
50
+ export type InputRequest = ElicitRequest | {
51
+ method: "sampling/createMessage" | "roots/list";
52
+ params?: Record<string, unknown>;
53
+ };
54
+ export type InputRequests = Record<string, InputRequest>;
55
+ export type InputResponses = Record<string, ElicitResult | Record<string, unknown>>;
56
+ export interface InputRequiredResult {
57
+ resultType: "input_required";
58
+ inputRequests?: InputRequests;
59
+ requestState?: string;
60
+ _meta?: MetaObject;
61
+ }
62
+ export interface CompleteResult {
63
+ resultType?: "complete";
64
+ _meta?: MetaObject;
65
+ [key: string]: unknown;
66
+ }
67
+ export type TaskStatus = "working" | "input_required" | "completed" | "failed" | "cancelled";
68
+ export interface Task {
69
+ taskId: string;
70
+ status: TaskStatus;
71
+ createdAt: string;
72
+ lastUpdatedAt: string;
73
+ ttlMs: number | null;
74
+ pollIntervalMs?: number;
75
+ statusMessage?: string;
76
+ }
77
+ export type DetailedTask = (Task & {
78
+ status: "working" | "cancelled";
79
+ }) | (Task & {
80
+ status: "input_required";
81
+ inputRequests: InputRequests;
82
+ }) | (Task & {
83
+ status: "completed";
84
+ result: Record<string, unknown>;
85
+ }) | (Task & {
86
+ status: "failed";
87
+ error: McpRpcError;
88
+ });
89
+ export type CreateTaskResult = Task & {
90
+ resultType: "task";
91
+ _meta?: MetaObject;
92
+ };
93
+ export type GetTaskResult = DetailedTask & {
94
+ resultType: "complete";
95
+ _meta?: MetaObject;
96
+ };
97
+ export interface SkillResource {
98
+ uri: string;
99
+ digest: string;
100
+ size: number;
101
+ }
102
+ export interface Skill {
103
+ uri: string;
104
+ frontmatter: {
105
+ name: string;
106
+ description: string;
107
+ [key: string]: unknown;
108
+ };
109
+ resources: SkillResource[] | "dynamic";
110
+ _meta?: MetaObject;
111
+ }
112
+ export interface ResourceContents {
113
+ uri: string;
114
+ mimeType?: string;
115
+ _meta?: MetaObject;
116
+ }
117
+ export interface TextResourceContents extends ResourceContents {
118
+ text: string;
119
+ }
120
+ export interface BlobResourceContents extends ResourceContents {
121
+ blob: string;
122
+ }
123
+ export type McpResourceContents = TextResourceContents | BlobResourceContents;
124
+ export interface McpUiToolMeta {
125
+ resourceUri?: string;
126
+ visibility?: ("model" | "app")[];
127
+ [key: string]: unknown;
128
+ }
129
+ export interface McpUiResourceMeta {
130
+ csp?: {
131
+ connectDomains?: string[];
132
+ resourceDomains?: string[];
133
+ frameDomains?: string[];
134
+ baseUriDomains?: string[];
135
+ };
136
+ permissions?: {
137
+ camera?: Record<string, never>;
138
+ microphone?: Record<string, never>;
139
+ geolocation?: Record<string, never>;
140
+ clipboardWrite?: Record<string, never>;
141
+ };
142
+ domain?: string;
143
+ prefersBorder?: boolean;
144
+ [key: string]: unknown;
145
+ }
146
+ export interface McpPaginationParams {
147
+ cursor?: string;
148
+ _meta?: MetaObject;
149
+ }
150
+ export interface McpRetryParams {
151
+ inputResponses?: InputResponses;
152
+ requestState?: string;
153
+ _meta?: MetaObject;
154
+ }
155
+ export interface McpSubscriptionFilter {
156
+ toolsListChanged?: boolean;
157
+ promptsListChanged?: boolean;
158
+ resourcesListChanged?: boolean;
159
+ resourceSubscriptions?: readonly string[];
160
+ taskIds?: readonly string[];
161
+ }
162
+ export interface McpMethodMap {
163
+ "server/discover": {
164
+ params: {
165
+ _meta?: MetaObject;
166
+ };
167
+ result: CompleteResult & {
168
+ supportedVersions: string[];
169
+ capabilities: Record<string, unknown>;
170
+ };
171
+ };
172
+ "tools/list": {
173
+ params: McpPaginationParams;
174
+ result: CompleteResult & {
175
+ tools: Record<string, unknown>[];
176
+ };
177
+ };
178
+ "tools/call": {
179
+ params: McpRetryParams & {
180
+ name: string;
181
+ arguments?: Record<string, unknown>;
182
+ };
183
+ result: CompleteResult | InputRequiredResult | CreateTaskResult;
184
+ };
185
+ "prompts/list": {
186
+ params: McpPaginationParams;
187
+ result: CompleteResult & {
188
+ prompts: Record<string, unknown>[];
189
+ };
190
+ };
191
+ "prompts/get": {
192
+ params: McpRetryParams & {
193
+ name: string;
194
+ arguments?: Record<string, string>;
195
+ };
196
+ result: CompleteResult | InputRequiredResult;
197
+ };
198
+ "resources/list": {
199
+ params: McpPaginationParams;
200
+ result: CompleteResult & {
201
+ resources: Record<string, unknown>[];
202
+ };
203
+ };
204
+ "resources/templates/list": {
205
+ params: McpPaginationParams;
206
+ result: CompleteResult & {
207
+ resourceTemplates: Record<string, unknown>[];
208
+ };
209
+ };
210
+ "resources/read": {
211
+ params: McpRetryParams & {
212
+ uri: string;
213
+ };
214
+ result: CompleteResult | InputRequiredResult;
215
+ };
216
+ "completion/complete": {
217
+ params: {
218
+ ref: {
219
+ type: "ref/prompt";
220
+ name: string;
221
+ } | {
222
+ type: "ref/resource";
223
+ uri: string;
224
+ };
225
+ argument: {
226
+ name: string;
227
+ value: string;
228
+ };
229
+ context?: {
230
+ arguments?: Record<string, string>;
231
+ };
232
+ _meta?: MetaObject;
233
+ };
234
+ result: CompleteResult & {
235
+ completion: {
236
+ values: string[];
237
+ total?: number;
238
+ hasMore?: boolean;
239
+ };
240
+ };
241
+ };
242
+ "subscriptions/listen": {
243
+ params: {
244
+ notifications: McpSubscriptionFilter;
245
+ _meta?: MetaObject;
246
+ };
247
+ result: CompleteResult;
248
+ };
249
+ "tasks/get": {
250
+ params: {
251
+ taskId: string;
252
+ _meta?: MetaObject;
253
+ };
254
+ result: GetTaskResult;
255
+ };
256
+ "tasks/update": {
257
+ params: {
258
+ taskId: string;
259
+ inputResponses: InputResponses;
260
+ _meta?: MetaObject;
261
+ };
262
+ result: CompleteResult;
263
+ };
264
+ "tasks/cancel": {
265
+ params: {
266
+ taskId: string;
267
+ _meta?: MetaObject;
268
+ };
269
+ result: CompleteResult;
270
+ };
271
+ "skills/list": {
272
+ params: McpPaginationParams;
273
+ result: CompleteResult & {
274
+ skills: Skill[];
275
+ };
276
+ };
277
+ "skills/get": {
278
+ params: {
279
+ uri: string;
280
+ _meta?: MetaObject;
281
+ };
282
+ result: CompleteResult & {
283
+ skill: Skill;
284
+ };
285
+ };
286
+ "resources/directory/read": {
287
+ params: McpPaginationParams & {
288
+ uri: string;
289
+ };
290
+ result: CompleteResult & {
291
+ resources: Record<string, unknown>[];
292
+ };
293
+ };
294
+ }
295
+ export type McpMethod = keyof McpMethodMap;
@@ -0,0 +1,3 @@
1
+ // Wire contracts derived from MCP 2026-07-28 schema at
2
+ // 271ecc9accafdd9b83a3c869fa67c22953b2af80 and the extension pins in extensions.ts.
3
+ export const MCP_PROTOCOL_VERSION = "2026-07-28";
@@ -0,0 +1,3 @@
1
+ import type { McpUiToolMeta } from "./types.js";
2
+ /** Validate the value of a tool's _meta.ui, preserving future metadata fields. */
3
+ export declare function validateUiToolMeta(value: unknown): McpUiToolMeta;
@@ -0,0 +1,18 @@
1
+ import { McpError, McpErrorCode } from "./errors.js";
2
+ import { assertJsonBounds } from "./json-schema.js";
3
+ /** Validate the value of a tool's _meta.ui, preserving future metadata fields. */
4
+ export function validateUiToolMeta(value) {
5
+ if (typeof value !== "object" || value === null || Array.isArray(value))
6
+ throw new McpError("invalid tool UI metadata", undefined, McpErrorCode.InvalidParams);
7
+ assertJsonBounds(value);
8
+ const metadata = value;
9
+ if (metadata.resourceUri !== undefined &&
10
+ (typeof metadata.resourceUri !== "string" ||
11
+ !metadata.resourceUri.startsWith("ui://")))
12
+ throw new McpError("UI resourceUri must use ui://", undefined, McpErrorCode.InvalidParams);
13
+ if (metadata.visibility !== undefined &&
14
+ (!Array.isArray(metadata.visibility) ||
15
+ !metadata.visibility.every((entry) => entry === "model" || entry === "app")))
16
+ throw new McpError("invalid UI visibility", undefined, McpErrorCode.InvalidParams);
17
+ return metadata;
18
+ }
@@ -0,0 +1,67 @@
1
+ import type { McpAuthOperation, McpAuthPolicy, McpIdentity } from "../auth/contracts.js";
2
+ import type { McpExtensionSettings, McpValidationContext, McpMethodMap, McpSubscriptionFilter } from "../protocol/types.js";
3
+ /** Provider values are validated by the shared protocol boundary before transmission. */
4
+ export type McpOperationOutcome = McpMethodMap["tools/call"]["result"];
5
+ export type McpRequestContext = {
6
+ identity: McpIdentity | null;
7
+ /** Server policy. A public tool catalog must not ignore this on a private server. */
8
+ auth: McpAuthPolicy | "public";
9
+ requestId: string | number;
10
+ protocolVersion: string;
11
+ clientCapabilities: Record<string, unknown>;
12
+ signal: AbortSignal;
13
+ notify: (method: string, params: Record<string, unknown>) => void;
14
+ reportProgress: (progress: number, total?: number, message?: string) => void;
15
+ };
16
+ export type McpProvider = {
17
+ /** Authorization applies to both catalog and execution methods. */
18
+ resource: string;
19
+ action: string;
20
+ /**
21
+ * Method gate. Undefined uses `resource` and `action`.
22
+ * Null means this method has no single pair; the provider authorizes each
23
+ * binding with that binding's own resource and action.
24
+ * False denies immediately, the same response as `authorize` returning false.
25
+ */
26
+ authorization?: (params: Record<string, unknown>) => McpAuthOperation | null | false;
27
+ /** Private discover succeeds when any of these pairs is allowed. Defaults to resource/action. */
28
+ authorizationPairs?: readonly McpAuthOperation[];
29
+ schemas?: (params: Record<string, unknown>) => Pick<McpValidationContext, "inputSchema" | "outputSchema">;
30
+ /** subscriptions/listen only: accept a supported subset before acknowledgement.
31
+ * Without this hook no notifications are accepted. Must not emit notifications. */
32
+ acceptSubscription?: (params: Record<string, unknown>, context: McpRequestContext) => McpSubscriptionFilter | Promise<McpSubscriptionFilter>;
33
+ handle: (params: Record<string, unknown>, context: McpRequestContext) => McpOperationOutcome | Promise<McpOperationOutcome>;
34
+ };
35
+ /** Only known protocol methods may be registered. Discovery is server-owned. */
36
+ export type McpProviders = Readonly<Record<string, McpProvider>>;
37
+ export type McpLegacyRevision = "2025-11-25" | "2025-06-18" | "2025-03-26";
38
+ export type McpLegacyOptions = {
39
+ /** Explicitly supported revisions; defaults to all three 2025 Streamable HTTP revisions. */
40
+ versions?: readonly McpLegacyRevision[];
41
+ /** Absolute session lifetime, not renewed by traffic. Default: 30 minutes. */
42
+ sessionTtlMs?: number;
43
+ /** Per-server bound. Defaults to 1024; host must provide affinity across replicas. */
44
+ maxSessions?: number;
45
+ };
46
+ export type McpServerOptions = {
47
+ serverInfo: {
48
+ name: string;
49
+ version: string;
50
+ title?: string;
51
+ };
52
+ providers?: McpProviders;
53
+ /** Required for private servers; public access must be explicitly selected. */
54
+ auth: McpAuthPolicy | "public";
55
+ /** Requests with Origin are refused unless explicitly allowed here. */
56
+ allowedOrigins?: readonly string[];
57
+ /** Pass the resource-server auth factory challenge to preserve OAuth discovery headers. */
58
+ challenge?: (status: 401 | 403, scopes?: readonly string[]) => Response;
59
+ extensions?: McpExtensionSettings;
60
+ maxRequestBytes?: number;
61
+ /** Opt-in, identity-bound legacy sessions. Modern requests remain stateless. */
62
+ legacy?: McpLegacyOptions;
63
+ };
64
+ export type McpServer = {
65
+ fetch: (request: Request) => Promise<Response>;
66
+ close: () => Promise<void>;
67
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ /** Both HTTP and SSE errors preserve bounded JSON data, never arbitrary thrown objects. */
2
+ export declare function errorPayload(error: unknown, fallback: string): {
3
+ data?: {} | null;
4
+ code: number;
5
+ message: string;
6
+ };
@@ -0,0 +1,21 @@
1
+ import { McpError, assertJsonBounds } from "../protocol/index.js";
2
+ /** Both HTTP and SSE errors preserve bounded JSON data, never arbitrary thrown objects. */
3
+ export function errorPayload(error, fallback) {
4
+ if (!(error instanceof McpError))
5
+ return { code: -32603, message: fallback };
6
+ let data;
7
+ if (error.data !== undefined) {
8
+ try {
9
+ assertJsonBounds(error.data);
10
+ data = JSON.parse(JSON.stringify(error.data));
11
+ }
12
+ catch {
13
+ /* Invalid provider error data must not break the response stream. */
14
+ }
15
+ }
16
+ return {
17
+ code: error.code ?? -32603,
18
+ message: error.message,
19
+ ...(data === undefined ? {} : { data }),
20
+ };
21
+ }
@@ -0,0 +1,7 @@
1
+ import type { createTaskRuntime } from "../extensions/tasks/index.js";
2
+ import type { createSkillPublisher } from "../extensions/skills/index.js";
3
+ import type { McpProviders } from "./contracts.js";
4
+ /** Runtime owns durable state and input authorization; server owns wire validation. */
5
+ export declare function createTaskProviders(runtime: ReturnType<typeof createTaskRuntime>): McpProviders;
6
+ /** Host explicitly chooses the resource authorization domain for this snapshot. */
7
+ export declare function createSkillProviders(publisher: Awaited<ReturnType<typeof createSkillPublisher>>, resource: string): McpProviders;
@@ -0,0 +1,61 @@
1
+ import { McpError } from "../protocol/index.js";
2
+ const identity = (context) => {
3
+ if (!context.identity)
4
+ throw new McpError("Authenticated extension identity required", 401, -32602);
5
+ return context.identity;
6
+ };
7
+ /** Runtime owns durable state and input authorization; server owns wire validation. */
8
+ export function createTaskProviders(runtime) {
9
+ return {
10
+ "tasks/get": {
11
+ resource: "mcp:tasks",
12
+ action: "read",
13
+ handle: (params, context) => runtime.get(identity(context), String(params.taskId)),
14
+ },
15
+ "tasks/update": {
16
+ resource: "mcp:tasks",
17
+ action: "update",
18
+ handle: (params, context) => runtime.submitInput(identity(context), String(params.taskId), params.inputResponses),
19
+ },
20
+ "tasks/cancel": {
21
+ resource: "mcp:tasks",
22
+ action: "cancel",
23
+ handle: (params, context) => runtime.cancel(identity(context), String(params.taskId)),
24
+ },
25
+ };
26
+ }
27
+ /** Host explicitly chooses the resource authorization domain for this snapshot. */
28
+ export function createSkillProviders(publisher, resource) {
29
+ const noCursor = (params) => {
30
+ if (params.cursor !== undefined)
31
+ throw new McpError("Unknown cursor", 400, -32602);
32
+ };
33
+ return {
34
+ "skills/list": {
35
+ resource,
36
+ action: "read",
37
+ handle: (params) => {
38
+ noCursor(params);
39
+ return publisher.list();
40
+ },
41
+ },
42
+ "skills/get": {
43
+ resource,
44
+ action: "read",
45
+ handle: (params) => publisher.get(String(params.uri)),
46
+ },
47
+ "resources/read": {
48
+ resource,
49
+ action: "read",
50
+ handle: (params) => publisher.read(String(params.uri)),
51
+ },
52
+ "resources/directory/read": {
53
+ resource,
54
+ action: "read",
55
+ handle: (params) => {
56
+ noCursor(params);
57
+ return publisher.directoryRead(String(params.uri));
58
+ },
59
+ },
60
+ };
61
+ }
@@ -0,0 +1,2 @@
1
+ export declare function rpc(method: string, params?: Record<string, unknown>, headers?: Record<string, string>): Request;
2
+ export declare function result(response: Response): Promise<Record<string, unknown>>;
@@ -0,0 +1,34 @@
1
+ export function rpc(method, params = {}, headers = {}) {
2
+ const name = params.name ?? params.uri ?? params.taskId;
3
+ return new Request("http://localhost/mcp", {
4
+ method: "POST",
5
+ headers: {
6
+ "Content-Type": "application/json",
7
+ Accept: "application/json, text/event-stream",
8
+ "MCP-Protocol-Version": "2026-07-28",
9
+ "Mcp-Method": method,
10
+ ...(typeof name === "string" ? { "Mcp-Name": name } : {}),
11
+ ...headers,
12
+ },
13
+ body: JSON.stringify({
14
+ jsonrpc: "2.0",
15
+ id: 1,
16
+ method,
17
+ params: {
18
+ ...params,
19
+ _meta: {
20
+ "io.modelcontextprotocol/protocolVersion": "2026-07-28",
21
+ "io.modelcontextprotocol/clientInfo": { name: "test", version: "1" },
22
+ "io.modelcontextprotocol/clientCapabilities": {},
23
+ ...params._meta,
24
+ },
25
+ },
26
+ }),
27
+ });
28
+ }
29
+ export async function result(response) {
30
+ if (response.headers.get("content-type")?.includes("application/json"))
31
+ return (await response.json());
32
+ const events = (await response.text()).trim().split("\n\n");
33
+ return JSON.parse(events.at(-1).slice(6));
34
+ }
@@ -0,0 +1,9 @@
1
+ import { type McpIdentity } from "../auth/contracts.js";
2
+ import type { McpLegacyRevision, McpProviders, McpServerOptions } from "./contracts.js";
3
+ /** Isolated legacy transport. No HTTP+SSE endpoint, GET stream, resumption, MRTR or extensions. */
4
+ export declare function createLegacyServer(options: McpServerOptions, providers: McpProviders): {
5
+ versions: McpLegacyRevision[];
6
+ lifecycle(request: Request): Promise<Response>;
7
+ handle(request: Request, body: unknown, identity: McpIdentity | null): Promise<Response | undefined>;
8
+ close(): void;
9
+ };