@arbol-ai/maximus 8.0.1 → 8.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.
- package/dist/analytics/analytics.d.ts +16 -16
- package/dist/analytics/analytics.js +4 -4
- package/dist/body.d.ts +2 -2
- package/dist/body.js +2 -2
- package/dist/capture/index.d.ts +37 -0
- package/dist/capture/index.js +181 -0
- package/dist/chunks/{define-app-x7uY70_1.js → define-app-CQpWqqqE.js} +44 -14
- package/dist/chunks/delay-BsKQP_lF.js +12 -0
- package/dist/chunks/{json-B14evE6-.js → destination-DIkn8W6K.js} +65 -1
- package/dist/chunks/digest-C51F1bhA.js +12 -0
- package/dist/chunks/{errors-C5w9WY1l.js → errors-BoutSmiy.js} +2 -3
- package/dist/chunks/execution-Bpq6s4nA.js +265 -0
- package/dist/chunks/{generate-C-9FKW0o.js → generate-Dg88LzLU.js} +1 -1
- package/dist/chunks/{handler-iebR-urt.js → handler-DSpyrWc-.js} +6 -2
- package/dist/chunks/{http-layout-DS8DnPyu.js → http-layout-BcYH4I2w.js} +1 -1
- package/dist/chunks/{http-paths-DMBxwpp6.js → http-paths-D043DkJv.js} +50 -81
- package/dist/chunks/http-routes-B6tCsnxB.js +29 -0
- package/dist/chunks/{openapi-CeolxIqa.js → openapi-D2rds7vy.js} +32 -130
- package/dist/chunks/{openapi-file-Bz9FRaE6.js → openapi-file-BK8zET5U.js} +24 -6
- package/dist/chunks/{pages-iZTvFs5a.js → pages-B7ysoFAM.js} +1 -1
- package/dist/chunks/result-CF4OzG9O.js +29 -0
- package/dist/chunks/{runtime-D94vx21X.js → runtime-CGtS2rOb.js} +165 -11
- package/dist/chunks/schemas-_UJcx_uY.js +813 -0
- package/dist/chunks/{server-Bzf1Q1_4.js → server-CVhTLNj2.js} +38 -101
- package/dist/chunks/{src-CPrJpbOM.js → src-D67OfW9B.js} +94 -27
- package/dist/chunks/tasks-C873C3le.js +100 -0
- package/dist/chunks/tasks-DYdY-dBI.js +267 -0
- package/dist/chunks/{telemetry-C3LfZcOB.js → telemetry-BtxJh69Q.js} +4 -4
- package/dist/chunks/{types-DTIuIEJ-.d.ts → types-BfGa2aJT.d.ts} +537 -124
- package/dist/chunks/validation-CpzAxj2_.js +201 -0
- package/dist/chunks/{workers-types-BRk_Xa_5.d.ts → workers-types-Cxf-5cH7.d.ts} +6 -1
- package/dist/diagnostics.d.ts +1 -1
- package/dist/diagnostics.js +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +1 -1
- package/dist/http-paths.d.ts +1 -1
- package/dist/http-paths.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +12 -11
- package/dist/internals.d.ts +2 -2
- package/dist/internals.js +6 -6
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/tasks.d.ts +33 -0
- package/dist/mcp/tasks.js +3 -0
- package/dist/project/config.d.ts +2 -2
- package/dist/project/config.js +3 -2
- package/dist/project/index.d.ts +2 -2
- package/dist/project/index.js +3 -3
- package/dist/schemas.d.ts +2 -2
- package/dist/schemas.js +3 -3
- package/dist/standard-failures.d.ts +1 -1
- package/dist/tooling/cli.js +2 -2
- package/dist/vite/index.d.ts +2 -2
- package/dist/vite/index.js +15 -9
- package/dist/webhooks.d.ts +13 -2
- package/dist/webhooks.js +38 -1
- package/dist/workers/runtime.d.ts +1 -1
- package/dist/workers/runtime.js +1 -1
- package/package.json +15 -3
- package/skills/maximus/SKILL.md +14 -4
- package/skills/maximus/references/project.md +4 -0
- package/skills/maximus/references/routes-and-tools.md +11 -1
- package/templates/project/CLAUDE.md.template +3 -3
- package/templates/project/README.md.template +1 -0
- package/templates/project/tsconfig.json.template +1 -0
- package/dist/chunks/execution-rOiLo8VG.js +0 -84
- package/dist/chunks/result-CKgZHrnj.js +0 -56
- package/dist/chunks/schemas-p_aRcMC1.js +0 -227
- package/dist/chunks/validation-fTohBT6R.js +0 -420
|
@@ -1,45 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { i as standardErrors } from "./errors-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { L as wireInput } from "./schemas-_UJcx_uY.js";
|
|
2
|
+
import { i as standardErrors } from "./errors-BoutSmiy.js";
|
|
3
|
+
import { d as MAX_BODY_BYTES_CEILING, h as mcpOpenWorld, v as operationMatchesScopes } from "./tasks-DYdY-dBI.js";
|
|
4
|
+
import { d as canonical, p as standaloneSchema } from "./openapi-D2rds7vy.js";
|
|
5
|
+
import { o as reportUnexpected } from "./telemetry-BtxJh69Q.js";
|
|
5
6
|
import { t as toYaml } from "./yaml-Dk2L24yQ.js";
|
|
6
|
-
import {
|
|
7
|
-
import { Value } from "@sinclair/typebox/value";
|
|
7
|
+
import { a as mcpTask, n as attachTasks, o as toolResult, r as declaresTasks } from "./tasks-C873C3le.js";
|
|
8
8
|
import { McpServer, ProtocolError, ProtocolErrorCode, createMcpHandler } from "@modelcontextprotocol/server";
|
|
9
|
+
import { SkillCatalog, memorySkillFiles } from "@modelcontextprotocol/server/ext/skills";
|
|
9
10
|
|
|
10
11
|
// src/mcp/skills.ts
|
|
11
|
-
/**
|
|
12
|
-
* The MCP Skills extension (SEP-2640): `skills/list` and `skills/get` describe each skill by its
|
|
13
|
-
* frontmatter and the manifest of its one file, whose size and SHA-256 digest hosts verify, and
|
|
14
|
-
* `resources/read` serves that `SKILL.md`. An optional tool serves the same skills to clients that import
|
|
15
|
-
* only tools.
|
|
16
|
-
*/
|
|
17
|
-
/** The official Skills extension (SEP-2640) a server declares in its capabilities. */
|
|
18
|
-
const SKILLS_EXTENSION = "io.modelcontextprotocol/skills";
|
|
19
12
|
/** Skills change only with a deployment and are the same for every caller, so hosts may share them. */
|
|
20
13
|
const SKILL_CACHE = {
|
|
21
14
|
ttlMs: 3e5,
|
|
22
15
|
cacheScope: "public"
|
|
23
16
|
};
|
|
24
|
-
/**
|
|
25
|
-
|
|
26
|
-
return { "~standard": {
|
|
27
|
-
version: 1,
|
|
28
|
-
vendor: "maximus",
|
|
29
|
-
validate: (value) => Value.Check(schema, value) ? { value } : { issues: [{ message: "Invalid params" }] }
|
|
30
|
-
} };
|
|
31
|
-
}
|
|
32
|
-
/** `skills/list` params: an optional page cursor, which one page of every skill never issues. */
|
|
33
|
-
const ListSkillsParams = standardSchema(Type.Object({ cursor: Type.Optional(Type.String()) }));
|
|
34
|
-
/** `skills/get` params: the URI of the skill's `SKILL.md`. */
|
|
35
|
-
const GetSkillParams = standardSchema(Type.Object({ uri: Type.String() }));
|
|
36
|
-
/**
|
|
37
|
-
* A skill's `SKILL.md` URI, `skill://<name>/SKILL.md`: the file's directory carries the skill's name, as
|
|
38
|
-
* SEP-2640 requires.
|
|
39
|
-
*/
|
|
40
|
-
function skillUri(skill) {
|
|
41
|
-
return `skill://${skill.name}/SKILL.md`;
|
|
42
|
-
}
|
|
17
|
+
/** Each application's catalog, built on first use: an application's skills never change. */
|
|
18
|
+
const catalogs = /* @__PURE__ */ new WeakMap();
|
|
43
19
|
/** The served `SKILL.md`: frontmatter generated from the name and description, then the instructions. */
|
|
44
20
|
function skillDocument(skill) {
|
|
45
21
|
return `---\n${toYaml({
|
|
@@ -47,58 +23,23 @@ function skillDocument(skill) {
|
|
|
47
23
|
description: skill.description
|
|
48
24
|
})}---\n\n${skill.text.trim()}\n`;
|
|
49
25
|
}
|
|
50
|
-
/** A catalog entry. Hosts verify every file they read against its manifest's size and SHA-256 digest. */
|
|
51
|
-
async function skillEntry(skill) {
|
|
52
|
-
const uri = skillUri(skill);
|
|
53
|
-
const bytes = new TextEncoder().encode(skillDocument(skill));
|
|
54
|
-
return {
|
|
55
|
-
uri,
|
|
56
|
-
frontmatter: {
|
|
57
|
-
name: skill.name,
|
|
58
|
-
description: skill.description
|
|
59
|
-
},
|
|
60
|
-
resources: [{
|
|
61
|
-
uri,
|
|
62
|
-
digest: `sha256:${await sha256Hex(bytes)}`,
|
|
63
|
-
size: bytes.byteLength
|
|
64
|
-
}]
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
26
|
/**
|
|
68
|
-
*
|
|
69
|
-
* `
|
|
70
|
-
*
|
|
27
|
+
* The catalog that serves the skills through the Skills extension, each as `skill://<name>/SKILL.md`, every
|
|
28
|
+
* one on a single `skills/list` page, with the public cache hint. Building it checks each skill as hosts do,
|
|
29
|
+
* and throws for one they would refuse.
|
|
71
30
|
*/
|
|
72
|
-
function
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
text: skillDocument(skill)
|
|
83
|
-
}] })));
|
|
31
|
+
async function skillCatalog(skills) {
|
|
32
|
+
let catalog = catalogs.get(skills);
|
|
33
|
+
if (!catalog) {
|
|
34
|
+
const files = Object.fromEntries(skills.map((skill) => [`${skill.name}/SKILL.md`, skillDocument(skill)]));
|
|
35
|
+
catalog = await SkillCatalog.load(memorySkillFiles(files), {
|
|
36
|
+
cacheHint: SKILL_CACHE,
|
|
37
|
+
pageSize: Number.POSITIVE_INFINITY,
|
|
38
|
+
strict: true
|
|
39
|
+
});
|
|
40
|
+
catalogs.set(skills, catalog);
|
|
84
41
|
}
|
|
85
|
-
|
|
86
|
-
if (params.cursor !== void 0) throw new ProtocolError(ProtocolErrorCode.InvalidParams, "Invalid skills cursor");
|
|
87
|
-
return {
|
|
88
|
-
resultType: "complete",
|
|
89
|
-
skills: await Promise.all(skills.map(skillEntry)),
|
|
90
|
-
...SKILL_CACHE
|
|
91
|
-
};
|
|
92
|
-
}));
|
|
93
|
-
server.server.setRequestHandler("skills/get", { params: GetSkillParams }, (params) => answer(async () => {
|
|
94
|
-
const skill = skills.find((candidate) => skillUri(candidate) === params.uri);
|
|
95
|
-
if (!skill) throw new ProtocolError(ProtocolErrorCode.InvalidParams, "Unknown skill");
|
|
96
|
-
return {
|
|
97
|
-
resultType: "complete",
|
|
98
|
-
skill: await skillEntry(skill),
|
|
99
|
-
...SKILL_CACHE
|
|
100
|
-
};
|
|
101
|
-
}));
|
|
42
|
+
return catalog;
|
|
102
43
|
}
|
|
103
44
|
/**
|
|
104
45
|
* The same skills as one read-only tool, for clients that import only tools. Its description names every
|
|
@@ -284,7 +225,7 @@ function carriedMessages(body) {
|
|
|
284
225
|
* lets a stateless server list the caller's tools, run them through `invoke` and serve the resources,
|
|
285
226
|
* prompts and skills. A 5xx answer is reported as an unexpected error.
|
|
286
227
|
*/
|
|
287
|
-
async function handleMcp({ request, requestId, authenticated, application, operations, contractText, url, invoke, admitCarried, refused, body, bodyLimit }) {
|
|
228
|
+
async function handleMcp({ request, requestId, authenticated, application, operations, contractText, url, invoke, admitCarried, refused, body, bodyLimit, tasks }) {
|
|
288
229
|
const refusal = await admitCarried(carriedMessages(body) - 1);
|
|
289
230
|
if (refusal) return refusal;
|
|
290
231
|
const bodyBytes = new TextEncoder().encode(body).byteLength;
|
|
@@ -303,7 +244,7 @@ async function handleMcp({ request, requestId, authenticated, application, opera
|
|
|
303
244
|
throw new ProtocolError(ProtocolErrorCode.InternalError, "Internal error");
|
|
304
245
|
}
|
|
305
246
|
};
|
|
306
|
-
const response = await createMcpHandler(() => {
|
|
247
|
+
const response = await createMcpHandler(async () => {
|
|
307
248
|
const skills = application.mcp?.skills ?? [];
|
|
308
249
|
const skillToolName = skills.length ? application.mcp?.skillTool : void 0;
|
|
309
250
|
const server = new McpServer({
|
|
@@ -315,12 +256,11 @@ async function handleMcp({ request, requestId, authenticated, application, opera
|
|
|
315
256
|
capabilities: {
|
|
316
257
|
tools: { listChanged: false },
|
|
317
258
|
resources: { listChanged: false },
|
|
318
|
-
prompts: { listChanged: false }
|
|
319
|
-
...skills.length ? { extensions: { [SKILLS_EXTENSION]: {} } } : {}
|
|
259
|
+
prompts: { listChanged: false }
|
|
320
260
|
}
|
|
321
261
|
});
|
|
322
262
|
const visible = operations.filter((entry) => Boolean(entry[1].mcp) && operationMatchesScopes(entry[1], authenticated.scopes) && (!entry[1].actorKinds || entry[1].actorKinds.includes(authenticated.actorKind)));
|
|
323
|
-
server.server.setRequestHandler("tools/call", (call) => answer(async () => {
|
|
263
|
+
server.server.setRequestHandler("tools/call", (call, ctx) => answer(async () => {
|
|
324
264
|
if (skillToolName && call.params.name === skillToolName) return readSkill(skills, call.params.arguments ?? {});
|
|
325
265
|
const selected = visible.find(([, op]) => op.mcp.name === call.params.name);
|
|
326
266
|
if (!selected) {
|
|
@@ -340,21 +280,18 @@ async function handleMcp({ request, requestId, authenticated, application, opera
|
|
|
340
280
|
}]
|
|
341
281
|
};
|
|
342
282
|
}
|
|
343
|
-
const
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
text: JSON.stringify(result.value)
|
|
348
|
-
}],
|
|
349
|
-
structuredContent: result.value
|
|
350
|
-
} : {
|
|
351
|
-
isError: true,
|
|
352
|
-
content: [{
|
|
353
|
-
type: "text",
|
|
354
|
-
text: JSON.stringify(result.error)
|
|
355
|
-
}]
|
|
283
|
+
const task = op.task && declaresTasks(ctx.mcpReq.envelope) ? await tasks?.start(name, call.params.arguments ?? {}) : void 0;
|
|
284
|
+
if (task?.status === "working") return {
|
|
285
|
+
...mcpTask(task),
|
|
286
|
+
resultType: "task"
|
|
356
287
|
};
|
|
288
|
+
return toolResult(task?.result ?? await invoke(name, op, call.params.arguments ?? {}));
|
|
357
289
|
}));
|
|
290
|
+
if (tasks && visible.some(([, op]) => op.task)) attachTasks(server, {
|
|
291
|
+
...tasks,
|
|
292
|
+
get: (id) => answer(() => tasks.get(id)),
|
|
293
|
+
cancel: (id) => answer(() => tasks.cancel(id))
|
|
294
|
+
});
|
|
358
295
|
server.server.setRequestHandler("tools/list", (listing) => answer(() => {
|
|
359
296
|
const cursor = listing.params?.cursor;
|
|
360
297
|
const previous = cursor === void 0 ? -1 : visible.findIndex(([name]) => pageCursor(name) === cursor);
|
|
@@ -400,7 +337,7 @@ async function handleMcp({ request, requestId, authenticated, application, opera
|
|
|
400
337
|
}
|
|
401
338
|
}] })));
|
|
402
339
|
}
|
|
403
|
-
if (skills.length)
|
|
340
|
+
if (skills.length) (await skillCatalog(skills)).attach(server);
|
|
404
341
|
return server;
|
|
405
342
|
}, { maxRequestBodySize: MAX_BODY_BYTES_CEILING }).fetch(request);
|
|
406
343
|
if (response.status >= 500) reportUnexpected(/* @__PURE__ */ new Error("MCP transport failure"), "mcp", requestId);
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import { i as standardErrors } from "./errors-
|
|
1
|
+
import { i as standardErrors } from "./errors-BoutSmiy.js";
|
|
2
2
|
import { r as readBodyText } from "./body-DOIHwIIl.js";
|
|
3
|
-
import { i as binaryBody, n as defineApp, r as attachmentResponse } from "./define-app-
|
|
4
|
-
import { t as createHttpRouteResolver } from "./http-paths-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { t as
|
|
9
|
-
import { a as
|
|
10
|
-
import { n as
|
|
3
|
+
import { i as binaryBody, n as defineApp, r as attachmentResponse } from "./define-app-CQpWqqqE.js";
|
|
4
|
+
import { t as createHttpRouteResolver } from "./http-paths-D043DkJv.js";
|
|
5
|
+
import { a as taskAccess, b as operationScopes, m as isPublicOperation, o as taskView, p as composeOperations, s as withTaskOperations, u as DEFAULT_MAX_BODY_BYTES, v as operationMatchesScopes } from "./tasks-DYdY-dBI.js";
|
|
6
|
+
import { c as tokenAudiences, g as isCrossSiteWrite, h as queryKinds, i as createTokenAuthorization, l as tokenIssuer, m as queryInput, o as presentedToken, t as createOpenApi } from "./openapi-D2rds7vy.js";
|
|
7
|
+
import { r as ok, t as err } from "./result-CF4OzG9O.js";
|
|
8
|
+
import { t as sha256Hex } from "./digest-C51F1bhA.js";
|
|
9
|
+
import { a as recordExecution, i as recordAdmission, l as withTelemetry, o as reportUnexpected, s as telemetryEnabled } from "./telemetry-BtxJh69Q.js";
|
|
10
|
+
import { n as recordCapture, t as executeOperation } from "./execution-Bpq6s4nA.js";
|
|
11
|
+
import { a as ownsPrefix, i as nativePaths, n as composition, o as servesCloudflareAccess, r as httpTransports, s as servesOwnBearer, t as VERSIONED_PATH } from "./http-layout-BcYH4I2w.js";
|
|
12
|
+
import { r as mediaType } from "./destination-DIkn8W6K.js";
|
|
11
13
|
import { t as toYaml } from "./yaml-Dk2L24yQ.js";
|
|
12
|
-
import { Type as Type$1, Type as t } from "
|
|
14
|
+
import { Type as Type$1, Type as t } from "typebox";
|
|
13
15
|
|
|
14
16
|
// src/builder.ts
|
|
15
17
|
/**
|
|
@@ -102,7 +104,11 @@ var ApplicationBuilder = class ApplicationBuilder {
|
|
|
102
104
|
* the rule; most of the rules about one operation also name that operation.
|
|
103
105
|
*/
|
|
104
106
|
build() {
|
|
105
|
-
|
|
107
|
+
const { operations, namespace } = this.definition;
|
|
108
|
+
return defineApp()({
|
|
109
|
+
...this.definition,
|
|
110
|
+
operations: withTaskOperations(operations, namespace)
|
|
111
|
+
});
|
|
106
112
|
}
|
|
107
113
|
};
|
|
108
114
|
/**
|
|
@@ -282,6 +288,8 @@ function createHttpHandler(manifest, hooks = {}) {
|
|
|
282
288
|
let surface = "http";
|
|
283
289
|
let plain = false;
|
|
284
290
|
let requestEnv = env;
|
|
291
|
+
let verified;
|
|
292
|
+
const userAgent = incoming.headers.get("user-agent")?.slice(0, 200) || void 0;
|
|
285
293
|
const context = {
|
|
286
294
|
requestId,
|
|
287
295
|
fail: (error, headers) => failure(error, requestId, resolutionContext(), headers),
|
|
@@ -304,6 +312,19 @@ function createHttpHandler(manifest, hooks = {}) {
|
|
|
304
312
|
applicationScopes,
|
|
305
313
|
background
|
|
306
314
|
});
|
|
315
|
+
/** Captures a refusal before execution, of this request's operation or the one a transport names. */
|
|
316
|
+
function captureRefusal(error, refused, scopedEnv) {
|
|
317
|
+
recordCapture(manifest, scopedEnv, background, {
|
|
318
|
+
operation: refused,
|
|
319
|
+
surface,
|
|
320
|
+
requestId,
|
|
321
|
+
principal,
|
|
322
|
+
...verified ? { verified } : {},
|
|
323
|
+
requestStarted: started,
|
|
324
|
+
result: err(error),
|
|
325
|
+
call: userAgent ? { userAgent } : {}
|
|
326
|
+
});
|
|
327
|
+
}
|
|
307
328
|
/** A refusal before execution, observed as a rejected admission. */
|
|
308
329
|
function reject(error) {
|
|
309
330
|
recordAdmission(manifest, requestEnv, background, {
|
|
@@ -314,6 +335,7 @@ function createHttpHandler(manifest, hooks = {}) {
|
|
|
314
335
|
started,
|
|
315
336
|
errorCode: error.code
|
|
316
337
|
});
|
|
338
|
+
captureRefusal(error, operation, requestEnv);
|
|
317
339
|
return failure(error, requestId, resolutionContext());
|
|
318
340
|
}
|
|
319
341
|
/**
|
|
@@ -386,6 +408,21 @@ function createHttpHandler(manifest, hooks = {}) {
|
|
|
386
408
|
requestId
|
|
387
409
|
};
|
|
388
410
|
principal = actor;
|
|
411
|
+
const authority = authenticated.client ? {
|
|
412
|
+
surface: transport ? "mcp" : "http",
|
|
413
|
+
scopes: authenticated.scopes,
|
|
414
|
+
client: authenticated.client,
|
|
415
|
+
...accessToken ? { token: accessToken } : {}
|
|
416
|
+
} : void 0;
|
|
417
|
+
const tasks = taskAccess(manifest, scopedEnv, actor, authority);
|
|
418
|
+
if (manifest.capture) {
|
|
419
|
+
const token = presentedToken(incoming, manifest.tokens);
|
|
420
|
+
verified = {
|
|
421
|
+
scopes: authenticated.scopes,
|
|
422
|
+
...authenticated.client ? { client: authenticated.client } : {},
|
|
423
|
+
...token ? { token } : {}
|
|
424
|
+
};
|
|
425
|
+
}
|
|
389
426
|
if (!await withinRateLimit(scopedEnv, authenticated)) return reject(standardErrors.rateLimited.create());
|
|
390
427
|
let request = incoming;
|
|
391
428
|
let bodyText = "";
|
|
@@ -415,22 +452,26 @@ function createHttpHandler(manifest, hooks = {}) {
|
|
|
415
452
|
* Runs one operation through the shared execution path as the admitted caller, and records the call.
|
|
416
453
|
*/
|
|
417
454
|
async function invoke(name, op, input) {
|
|
418
|
-
if (transport && !operations.some(([selectedName, selected]) => selectedName === name && selected === op))
|
|
419
|
-
|
|
420
|
-
error
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
}
|
|
455
|
+
if (transport && !operations.some(([selectedName, selected]) => selectedName === name && selected === op)) {
|
|
456
|
+
const error = standardErrors.notFound.create();
|
|
457
|
+
captureRefusal(error, null, scopedEnv);
|
|
458
|
+
return {
|
|
459
|
+
ok: false,
|
|
460
|
+
error
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
if (transport && !operationMatchesScopes(op, authenticated.scopes)) {
|
|
464
|
+
const error = standardErrors.forbidden.create();
|
|
465
|
+
captureRefusal(error, name, scopedEnv);
|
|
466
|
+
return {
|
|
467
|
+
ok: false,
|
|
468
|
+
error
|
|
469
|
+
};
|
|
470
|
+
}
|
|
426
471
|
if (telemetryEnabled(manifest.telemetry, scopedEnv)) hooks.annotate?.(name, requestId);
|
|
472
|
+
const call = userAgent ? { userAgent } : {};
|
|
427
473
|
const invocationStarted = performance.now();
|
|
428
|
-
const output = await executeOperation(manifest, op, scopedEnv, actor, input,
|
|
429
|
-
surface: transport ? "mcp" : "http",
|
|
430
|
-
scopes: authenticated.scopes,
|
|
431
|
-
client: authenticated.client,
|
|
432
|
-
...accessToken ? { token: accessToken } : {}
|
|
433
|
-
} : void 0, background, byteOperation ? binaryBody(incoming, op.maxBodyBytes ?? fallbackBodyBytes) : void 0);
|
|
474
|
+
const output = await executeOperation(manifest, op, scopedEnv, actor, input, authority, background, byteOperation ? binaryBody(incoming, op.maxBodyBytes ?? fallbackBodyBytes) : void 0, call);
|
|
434
475
|
recordExecution(manifest, scopedEnv, background, {
|
|
435
476
|
principal: actor,
|
|
436
477
|
operation: name,
|
|
@@ -438,6 +479,17 @@ function createHttpHandler(manifest, hooks = {}) {
|
|
|
438
479
|
started: invocationStarted,
|
|
439
480
|
result: output
|
|
440
481
|
});
|
|
482
|
+
recordCapture(manifest, scopedEnv, background, {
|
|
483
|
+
operation: name,
|
|
484
|
+
surface: transport ? "mcp" : "http",
|
|
485
|
+
requestId,
|
|
486
|
+
principal: actor,
|
|
487
|
+
...verified ? { verified } : {},
|
|
488
|
+
requestStarted: started,
|
|
489
|
+
executionStarted: invocationStarted,
|
|
490
|
+
result: output,
|
|
491
|
+
call
|
|
492
|
+
});
|
|
441
493
|
return output;
|
|
442
494
|
}
|
|
443
495
|
if (transport) return transport.handle({
|
|
@@ -460,14 +512,29 @@ function createHttpHandler(manifest, hooks = {}) {
|
|
|
460
512
|
started,
|
|
461
513
|
errorCode: error.code
|
|
462
514
|
});
|
|
515
|
+
captureRefusal(error, name ?? null, scopedEnv);
|
|
463
516
|
},
|
|
464
517
|
body: bodyText,
|
|
465
|
-
bodyLimit: (op) => op.maxBodyBytes ?? fallbackBodyBytes
|
|
518
|
+
bodyLimit: (op) => op.maxBodyBytes ?? fallbackBodyBytes,
|
|
519
|
+
...tasks ? { tasks } : {}
|
|
466
520
|
});
|
|
467
521
|
if (!operationRoute) return reject(standardErrors.notFound.create());
|
|
468
522
|
const input = operationInput(operationRoute, incoming, url, bodyText);
|
|
469
523
|
if (!input.ok) return reject(input.error);
|
|
470
|
-
const
|
|
524
|
+
const task = operationRoute.definition.op.task && /\brespond-async\b/i.test(incoming.headers.get("prefer") ?? "") ? await tasks?.start(operationRoute.definition.name, input.value) : void 0;
|
|
525
|
+
if (task?.status === "working") return Response.json({
|
|
526
|
+
success: true,
|
|
527
|
+
data: taskView(task),
|
|
528
|
+
error: null,
|
|
529
|
+
metadata: { requestId }
|
|
530
|
+
}, {
|
|
531
|
+
status: 202,
|
|
532
|
+
headers: {
|
|
533
|
+
"preference-applied": "respond-async",
|
|
534
|
+
location: `${manifest.origin}${paths.mount(`/v1/operation-tasks/${task.taskId}`)}`
|
|
535
|
+
}
|
|
536
|
+
});
|
|
537
|
+
const output = task?.result ?? await invoke(operationRoute.definition.name, operationRoute.definition.op, input.value);
|
|
471
538
|
if (!output.ok) return failure(output.error, requestId, resolutionContext());
|
|
472
539
|
const exposure = operationRoute.definition.op.http;
|
|
473
540
|
if (exposure?.response === "attachment") return attachmentResponse(output.value, exposure.successStatus ?? 200);
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { i as TASK_POLL_MS } from "./tasks-DYdY-dBI.js";
|
|
2
|
+
import { ProtocolError, ProtocolErrorCode } from "@modelcontextprotocol/server";
|
|
3
|
+
|
|
4
|
+
// src/mcp/tasks.ts
|
|
5
|
+
/**
|
|
6
|
+
* The MCP Tasks extension (`io.modelcontextprotocol/tasks`, revision 2026-07-28) on the official SDK, in the
|
|
7
|
+
* wire format `@modelcontextprotocol/ext-tasks` defines: the declared extension, `tasks/get` and `tasks/cancel`,
|
|
8
|
+
* a task as a client reads it, and the checks a relay needs. They are a few lines of their own rather than that
|
|
9
|
+
* package's guards, which load all of zod. `@arbol-ai/maximus/mcp/tasks` exports them, so a gateway serves the
|
|
10
|
+
* same methods for the tasks it relays.
|
|
11
|
+
*/
|
|
12
|
+
/** The Tasks extension's id, which a client declares on each request and a server among its capabilities. */
|
|
13
|
+
const TASKS_EXTENSION = "io.modelcontextprotocol/tasks";
|
|
14
|
+
/** The value, when it is a plain object. */
|
|
15
|
+
const record = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
16
|
+
/**
|
|
17
|
+
* Whether a request's `_meta` declares the Tasks extension: an empty object at
|
|
18
|
+
* `io.modelcontextprotocol/clientCapabilities` › `extensions` › `io.modelcontextprotocol/tasks`, as
|
|
19
|
+
* `@modelcontextprotocol/ext-tasks` reads it.
|
|
20
|
+
*/
|
|
21
|
+
function declaresTasks(meta) {
|
|
22
|
+
const capabilities = record(record(meta)?.["io.modelcontextprotocol/clientCapabilities"]);
|
|
23
|
+
const extensions = record(capabilities?.extensions);
|
|
24
|
+
const declared = extensions && Object.hasOwn(extensions, "io.modelcontextprotocol/tasks") ? record(extensions[TASKS_EXTENSION]) : void 0;
|
|
25
|
+
return declared !== void 0 && Object.keys(declared).length === 0;
|
|
26
|
+
}
|
|
27
|
+
/** Whether a `tools/call` result is a task the server created, `resultType: "task"`, rather than the call's result. */
|
|
28
|
+
function isTaskResult(result) {
|
|
29
|
+
const task = record(result);
|
|
30
|
+
return task?.resultType === "task" && typeof task.taskId === "string" && [
|
|
31
|
+
"working",
|
|
32
|
+
"input_required",
|
|
33
|
+
"completed",
|
|
34
|
+
"failed",
|
|
35
|
+
"cancelled"
|
|
36
|
+
].includes(String(task.status));
|
|
37
|
+
}
|
|
38
|
+
/** A Result as a tool call answers it: the value, or the failure as a tool error the model can read. */
|
|
39
|
+
function toolResult(result) {
|
|
40
|
+
return result.ok ? {
|
|
41
|
+
content: [{
|
|
42
|
+
type: "text",
|
|
43
|
+
text: JSON.stringify(result.value)
|
|
44
|
+
}],
|
|
45
|
+
structuredContent: result.value
|
|
46
|
+
} : {
|
|
47
|
+
isError: true,
|
|
48
|
+
content: [{
|
|
49
|
+
type: "text",
|
|
50
|
+
text: JSON.stringify(result.error)
|
|
51
|
+
}]
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** A task as an MCP client reads it. A failed operation completes its tool call with a tool error. */
|
|
55
|
+
function mcpTask(task) {
|
|
56
|
+
const state = {
|
|
57
|
+
taskId: task.taskId,
|
|
58
|
+
createdAt: new Date(task.createdAt).toISOString(),
|
|
59
|
+
lastUpdatedAt: new Date(task.lastUpdatedAt).toISOString(),
|
|
60
|
+
ttlMs: task.ttlMs,
|
|
61
|
+
pollIntervalMs: TASK_POLL_MS
|
|
62
|
+
};
|
|
63
|
+
if (task.result) return {
|
|
64
|
+
...state,
|
|
65
|
+
status: "completed",
|
|
66
|
+
result: toolResult(task.result)
|
|
67
|
+
};
|
|
68
|
+
return {
|
|
69
|
+
...state,
|
|
70
|
+
status: task.status === "cancelled" ? "cancelled" : "working"
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/** The params of `tasks/get` and `tasks/cancel`: the task's id. */
|
|
74
|
+
const TaskIdParams = { "~standard": {
|
|
75
|
+
version: 1,
|
|
76
|
+
vendor: "maximus",
|
|
77
|
+
validate: (params) => {
|
|
78
|
+
const taskId = record(params)?.taskId;
|
|
79
|
+
return typeof taskId === "string" ? { value: { taskId } } : { issues: [{ message: "taskId is a string" }] };
|
|
80
|
+
}
|
|
81
|
+
} };
|
|
82
|
+
/**
|
|
83
|
+
* Declares the Tasks extension on `server` and serves `tasks/get` and `tasks/cancel` for the caller's tasks. A
|
|
84
|
+
* task id the caller did not start, or one that expired, is invalid params (-32602).
|
|
85
|
+
*/
|
|
86
|
+
function attachTasks(server, tasks) {
|
|
87
|
+
server.server.registerCapabilities({ extensions: { [TASKS_EXTENSION]: {} } });
|
|
88
|
+
const find = async (method, taskId) => {
|
|
89
|
+
const task = await tasks[method](taskId);
|
|
90
|
+
if (!task) throw new ProtocolError(ProtocolErrorCode.InvalidParams, "Unknown task");
|
|
91
|
+
return task;
|
|
92
|
+
};
|
|
93
|
+
server.server.setRequestHandler("tasks/get", { params: TaskIdParams }, async ({ taskId }) => mcpTask(await find("get", taskId)));
|
|
94
|
+
server.server.setRequestHandler("tasks/cancel", { params: TaskIdParams }, async ({ taskId }) => {
|
|
95
|
+
await find("cancel", taskId);
|
|
96
|
+
return {};
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export { mcpTask as a, isTaskResult as i, attachTasks as n, toolResult as o, declaresTasks as r, TASKS_EXTENSION as t };
|