@arbol-ai/maximus 7.3.1 → 8.0.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 +36 -38
- package/bin/maximus.js +4 -0
- package/config/oxfmt.mjs +1 -0
- package/config/oxlint.mjs +10 -0
- package/dist/analytics/analytics.d.ts +21 -9
- package/dist/analytics/analytics.js +19 -5
- package/dist/body.d.ts +1 -1
- package/dist/body.js +2 -2
- package/dist/chunks/agent-skills-Ef65jTf_.js +49 -0
- package/dist/chunks/agent-skills-m7y1EUch.js +3 -0
- package/dist/chunks/{body-6LichrQm.js → body-DOIHwIIl.js} +14 -7
- package/dist/chunks/{correlation-BEkcFFGT.js → correlation-4b23a-a4.js} +8 -5
- package/dist/chunks/define-app-CfVZBt7D.js +336 -0
- package/dist/chunks/errors-WfyKhiyk.js +131 -0
- package/dist/chunks/execution-CfZEx_JP.js +84 -0
- package/dist/chunks/generate-C-9FKW0o.js +197 -0
- package/dist/chunks/handler-DWTGoduQ.js +140 -0
- package/dist/chunks/http-layout-_h7xwgPC.js +128 -0
- package/dist/chunks/http-paths-DMBxwpp6.js +218 -0
- package/dist/chunks/{json-Bu4BLT25.js → json-B14evE6-.js} +21 -5
- package/dist/chunks/names-ncD7A3DV.js +280 -0
- package/dist/chunks/openapi-CV0KmJpS.js +1588 -0
- package/dist/chunks/openapi-file-OjSs9mRv.js +83 -0
- package/dist/chunks/pages-DyC0m8Zb.js +14 -0
- package/dist/chunks/prepare-configured-BmRJLg6J.js +3 -0
- package/dist/chunks/prepare-configured-Cithjf80.js +52 -0
- package/dist/chunks/project-files-C0OX7MQQ.js +130 -0
- package/dist/chunks/query-kind-CWKAXEME.js +40 -0
- package/dist/chunks/record-DQUDTpEA.js +10 -0
- package/dist/chunks/result-CKgZHrnj.js +56 -0
- package/dist/chunks/{runtime-BPnaa-NK.js → runtime-CVVf5hmp.js} +50 -25
- package/dist/chunks/scaffold-DGrcjR3h.js +3 -0
- package/dist/chunks/scaffold-DZD6dfoZ.js +138 -0
- package/dist/chunks/{schemas-CzTvbXb6.js → schemas-p_aRcMC1.js} +30 -14
- package/dist/chunks/server-CCc7fil4.js +410 -0
- package/dist/chunks/src--HZrH1U9.js +568 -0
- package/dist/chunks/standard-failures-CLjxS2ea.js +74 -0
- package/dist/chunks/{telemetry-BTwB68m5.js → telemetry-C3LfZcOB.js} +32 -11
- package/dist/chunks/{types-BWxDd3tY.d.ts → types-BQYB4Ads.d.ts} +998 -337
- package/dist/chunks/{validation-r-sgmsqb.js → validation-fTohBT6R.js} +69 -28
- package/dist/chunks/workers-types-iONp32T4.d.ts +143 -0
- package/dist/chunks/yaml-Dk2L24yQ.js +74 -0
- package/dist/diagnostics.d.ts +6 -4
- package/dist/diagnostics.js +2 -2
- package/dist/errors.d.ts +2 -2
- package/dist/errors.js +2 -125
- package/dist/http-paths.d.ts +1 -1
- package/dist/http-paths.js +1 -197
- package/dist/index.d.ts +2 -2
- package/dist/index.js +12 -10
- package/dist/internals.d.ts +1 -1
- package/dist/internals.js +5 -3
- package/dist/mcp/index.d.ts +3 -2
- package/dist/mcp/index.js +5 -387
- package/dist/postgres/index.d.ts +25 -8
- package/dist/postgres/index.js +17 -8
- package/dist/project/config.d.ts +139 -0
- package/dist/project/config.js +196 -0
- package/dist/project/index.d.ts +17 -4
- package/dist/project/index.js +44 -9
- package/dist/projection.d.ts +14 -13
- package/dist/projection.js +8 -32
- package/dist/schemas.d.ts +1 -1
- package/dist/schemas.js +2 -2
- package/dist/standard-failures.d.ts +2 -89
- package/dist/standard-failures.js +1 -72
- package/dist/tooling/cli.js +151 -107
- package/dist/tooling/testing.js +2 -2
- package/dist/vite/cloudflare-workers.js +25 -0
- package/dist/vite/index.d.ts +157 -0
- package/dist/vite/index.js +1477 -0
- package/dist/webhooks.d.ts +12 -10
- package/dist/webhooks.js +26 -12
- package/dist/workers/runtime.d.ts +1 -1
- package/dist/workers/runtime.js +1 -1
- package/package.json +30 -22
- package/skills/maximus/SKILL.md +165 -69
- package/skills/maximus/references/deploying.md +73 -0
- package/skills/maximus/references/errors-and-results.md +114 -55
- package/skills/maximus/references/project.md +202 -0
- package/skills/maximus/references/routes-and-tools.md +256 -0
- package/skills/maximus/references/testing.md +137 -50
- package/skills/maximus/references/transports.md +113 -100
- package/skills/maximus/references/writing-code.md +84 -0
- package/templates/mcp/mcp/instructions.md.template +2 -0
- package/templates/mcp/routes/v1/greeting.get.ts.template +12 -0
- package/templates/mcp/tests/mcp.test.ts.template +36 -0
- package/templates/project/.agents/skills/project/SKILL.md.template +21 -12
- package/templates/project/.github/workflows/ci.yml.template +4 -1
- package/templates/project/CLAUDE.md.template +41 -22
- package/templates/project/README.md.template +54 -47
- package/templates/project/middleware/10-response.ts.template +16 -0
- package/templates/project/package.json.template +16 -8
- package/templates/project/pages/index.ts.template +2 -4
- package/templates/project/routes/v1/greeting.get.ts.template +10 -0
- package/templates/project/routes/v1/greeting.post.ts.template +12 -0
- package/templates/project/tests/greeting.test.ts.template +45 -0
- package/templates/project/tsconfig.json.template +8 -5
- package/templates/project/vite.config.ts.template +15 -7
- package/templates/web/app/main.tsx.template +16 -0
- package/templates/web/app/root.tsx.template +17 -0
- package/templates/web/app/routes/index.tsx.template +9 -0
- package/templates/web/index.html.template +12 -0
- package/templates/web/package.json.template +12 -0
- package/templates/web/tsconfig.json.template +7 -0
- package/templates/web/vite.config.ts.template +22 -0
- package/dist/chunks/execution-B-yy4C7N.js +0 -691
- package/dist/chunks/prepare-project-zi106pWF.js +0 -146
- package/dist/chunks/record-DY-lX9w1.js +0 -34
- package/dist/chunks/src-DPSpGNnT.js +0 -1164
- package/dist/client/client.d.ts +0 -129
- package/dist/client/client.js +0 -321
- package/dist/tooling/vite.d.ts +0 -3
- package/dist/tooling/vite.js +0 -44
- package/skills/maximus/references/adding-an-operation.md +0 -179
- package/skills/maximus/references/building-a-service.md +0 -167
- package/skills/maximus/references/migration-from-v2.md +0 -62
- package/skills/maximus/references/migration-to-v5.md +0 -37
- package/skills/maximus/references/publishing-and-verification.md +0 -39
- package/templates/project/cloudflare.config.ts.template +0 -24
- package/templates/project/routes/v1/greeting.ts.template +0 -22
- package/templates/project/src/app.ts.template +0 -2
- package/templates/project/src/application.ts.template +0 -26
- package/templates/project/src/index.ts.template +0 -3
- package/templates/project/src/worker.ts.template +0 -6
- package/templates/service/.agents/skills/project/SKILL.md.template +0 -10
- package/templates/service/.github/workflows/ci.yml.template +0 -21
- package/templates/service/.gitignore.template +0 -9
- package/templates/service/CLAUDE.md.template +0 -5
- package/templates/service/README.md.template +0 -45
- package/templates/service/cloudflare.config.ts.template +0 -30
- package/templates/service/package.json.template +0 -36
- package/templates/service/src/app.ts.template +0 -30
- package/templates/service/src/index.ts.template +0 -13
- package/templates/service/tests/contract.test.ts.template +0 -12
- package/templates/service/tsconfig.json.template +0 -16
- package/templates/service/vite.config.ts.template +0 -13
- package/templates/service/vitest.config.ts.template +0 -10
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { t as linkAgentSkills } from "./agent-skills-Ef65jTf_.js";
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, symlinkSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
4
|
+
import { randomBytes } from "node:crypto";
|
|
5
|
+
|
|
6
|
+
// src/tooling/internal/scaffold.ts
|
|
7
|
+
/**
|
|
8
|
+
* `maximus init`: a new project from the starter template, with the MCP server (unless asked not to) and
|
|
9
|
+
* the web app (when asked to) laid over it, a development token only its owner can read, and the agent
|
|
10
|
+
* skills linked where coding agents look for them.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* The Maximus package's own directory: the nearest one above this module with a package.json. The build
|
|
14
|
+
* bundles this module into the CLI, so its depth below the package differs from the source's.
|
|
15
|
+
*/
|
|
16
|
+
function packageDirectory() {
|
|
17
|
+
let directory = import.meta.dirname;
|
|
18
|
+
while (!existsSync(join(directory, "package.json"))) {
|
|
19
|
+
const parent = dirname(directory);
|
|
20
|
+
if (parent === directory) throw new Error("Found no package.json above the Maximus CLI.");
|
|
21
|
+
directory = parent;
|
|
22
|
+
}
|
|
23
|
+
return directory;
|
|
24
|
+
}
|
|
25
|
+
/** Whether a value is a plain JSON object, which a layer's JSON merges into the one below it. */
|
|
26
|
+
function isObject(value) {
|
|
27
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
28
|
+
}
|
|
29
|
+
/** A layer's JSON over the one below it: objects merged field by field, lists joined without repeats. */
|
|
30
|
+
function mergeJson(base, layer) {
|
|
31
|
+
if (Array.isArray(base) && Array.isArray(layer)) return [.../* @__PURE__ */ new Set([...base, ...layer])];
|
|
32
|
+
if (isObject(base) && isObject(layer)) {
|
|
33
|
+
const merged = { ...base };
|
|
34
|
+
for (const [key, value] of Object.entries(layer)) merged[key] = key in base ? mergeJson(base[key], value) : value;
|
|
35
|
+
return merged;
|
|
36
|
+
}
|
|
37
|
+
return layer;
|
|
38
|
+
}
|
|
39
|
+
/** The fields of a package.json whose keys are package names, which formatters keep sorted. */
|
|
40
|
+
const DEPENDENCIES = /* @__PURE__ */ new Set([
|
|
41
|
+
"dependencies",
|
|
42
|
+
"devDependencies",
|
|
43
|
+
"peerDependencies",
|
|
44
|
+
"optionalDependencies"
|
|
45
|
+
]);
|
|
46
|
+
/**
|
|
47
|
+
* JSON as the project's formatter writes it: objects one field per line, a list of scalars on one line when
|
|
48
|
+
* it fits in 110 columns, and dependency maps in name order.
|
|
49
|
+
*/
|
|
50
|
+
function formatJson(value, indent = "", key = "") {
|
|
51
|
+
if (Array.isArray(value)) {
|
|
52
|
+
const items = value.map((item) => formatJson(item, `${indent} `));
|
|
53
|
+
const inline = `[${items.join(", ")}]`;
|
|
54
|
+
return value.every((item) => typeof item !== "object" || item === null) && indent.length + key.length + inline.length <= 106 ? inline : `[\n${items.map((item) => `${indent} ${item}`).join(",\n")}\n${indent}]`;
|
|
55
|
+
}
|
|
56
|
+
if (isObject(value)) {
|
|
57
|
+
const entries = DEPENDENCIES.has(key) ? Object.entries(value).toSorted(([a], [b]) => a < b ? -1 : Number(a > b)) : Object.entries(value);
|
|
58
|
+
if (!entries.length) return "{}";
|
|
59
|
+
return `{\n${entries.map(([name, child]) => `${indent} ${JSON.stringify(name)}: ${formatJson(child, `${indent} `, name)}`).join(",\n")}\n${indent}}`;
|
|
60
|
+
}
|
|
61
|
+
return JSON.stringify(value);
|
|
62
|
+
}
|
|
63
|
+
/** Every template file of a layer, by the path it takes in the project. */
|
|
64
|
+
function templateFiles(template) {
|
|
65
|
+
const files = /* @__PURE__ */ new Map();
|
|
66
|
+
for (const file of readdirSync(template, {
|
|
67
|
+
recursive: true,
|
|
68
|
+
withFileTypes: true
|
|
69
|
+
})) if (file.isFile() && file.name.endsWith(".template")) {
|
|
70
|
+
const source = resolve(file.parentPath, file.name);
|
|
71
|
+
files.set(relative(template, source).replace(/\.template$/, ""), source);
|
|
72
|
+
}
|
|
73
|
+
return files;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Writes a new project from the starter template into a directory that does not exist yet: the API, the MCP
|
|
77
|
+
* server unless `mcp` is false, and a web app when `web` is true.
|
|
78
|
+
*/
|
|
79
|
+
function scaffold(directory, name, options = {}) {
|
|
80
|
+
if (!/^(?=.{2,41}$)[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(name)) throw new TypeError("Use a lowercase kebab-case project name of 2 to 41 characters.");
|
|
81
|
+
const root = resolve(directory);
|
|
82
|
+
if (existsSync(root)) throw new Error("Choose a new directory; existing projects are never overwritten.");
|
|
83
|
+
const own = packageDirectory();
|
|
84
|
+
const { version } = JSON.parse(readFileSync(join(own, "package.json"), "utf-8"));
|
|
85
|
+
const values = {
|
|
86
|
+
__PROJECT_NAME__: name,
|
|
87
|
+
__MAXIMUS_VERSION__: version,
|
|
88
|
+
__COMPATIBILITY_DATE__: (/* @__PURE__ */ new Date()).toISOString().slice(0, 10)
|
|
89
|
+
};
|
|
90
|
+
const layers = [
|
|
91
|
+
{
|
|
92
|
+
template: "project",
|
|
93
|
+
removes: []
|
|
94
|
+
},
|
|
95
|
+
...options.mcp === false ? [] : [{
|
|
96
|
+
template: "mcp",
|
|
97
|
+
removes: []
|
|
98
|
+
}],
|
|
99
|
+
...options.web ? [{
|
|
100
|
+
template: "web",
|
|
101
|
+
removes: ["pages/index.ts"]
|
|
102
|
+
}] : []
|
|
103
|
+
];
|
|
104
|
+
const files = /* @__PURE__ */ new Map();
|
|
105
|
+
for (const { template, removes } of layers) {
|
|
106
|
+
for (const path of removes) files.delete(path);
|
|
107
|
+
for (const [path, source] of templateFiles(join(own, "templates", template))) {
|
|
108
|
+
let text = readFileSync(source, "utf-8");
|
|
109
|
+
for (const [placeholder, value] of Object.entries(values)) text = text.replaceAll(placeholder, value);
|
|
110
|
+
const below = files.get(path);
|
|
111
|
+
files.set(path, below !== void 0 && path.endsWith(".json") ? `${formatJson(mergeJson(JSON.parse(below), JSON.parse(text)))}\n` : text);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
for (const [path, text] of files) {
|
|
115
|
+
const target = resolve(root, path);
|
|
116
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
117
|
+
writeFileSync(target, text, { flag: "wx" });
|
|
118
|
+
}
|
|
119
|
+
writeFileSync(resolve(root, ".dev.vars"), `DEVELOPMENT_TOKEN=${randomBytes(32).toString("hex")}\n`, {
|
|
120
|
+
flag: "wx",
|
|
121
|
+
mode: 384
|
|
122
|
+
});
|
|
123
|
+
symlinkSync("CLAUDE.md", resolve(root, "AGENTS.md"));
|
|
124
|
+
for (const harness of [".claude", ".codex"]) {
|
|
125
|
+
mkdirSync(resolve(root, harness, "skills"), { recursive: true });
|
|
126
|
+
symlinkSync("../../.agents/skills/project", resolve(root, harness, "skills/project"));
|
|
127
|
+
}
|
|
128
|
+
const skills = linkAgentSkills(root);
|
|
129
|
+
return {
|
|
130
|
+
directory: root,
|
|
131
|
+
mcp: options.mcp !== false,
|
|
132
|
+
web: options.web === true,
|
|
133
|
+
skills,
|
|
134
|
+
next: "Run bun install and bun run dev. Set origin and tokens.issuer in vite.config.ts before the first deployment; bun run verify runs the types, lint, tests and build, and bun run deploy deploys."
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export { scaffold as n, packageDirectory as t };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as codecFault, c as defaultSchema, d as inputSchema, n as decodeSchema, o as decodeIssues, s as SchemaValidationError } from "./validation-fTohBT6R.js";
|
|
2
2
|
import { Kind, Type, Type as Type$1, Type as t } from "@sinclair/typebox";
|
|
3
3
|
|
|
4
4
|
// src/schema-reader.ts
|
|
5
5
|
/**
|
|
6
6
|
* Reads untrusted data — a stored record, a provider or model answer — through its schema's owner
|
|
7
7
|
* semantics: defaults applied, normalizers run before their checks, unknown keys of a strip object
|
|
8
|
-
* dropped. A refusal carries every issue with its path; nothing is coerced.
|
|
8
|
+
* dropped. A refusal carries every issue with its path; nothing is coerced. An owner codec that fails
|
|
9
|
+
* throws what it threw.
|
|
9
10
|
*/
|
|
10
11
|
function checkSchema(schema, input) {
|
|
11
12
|
try {
|
|
@@ -15,7 +16,7 @@ function checkSchema(schema, input) {
|
|
|
15
16
|
};
|
|
16
17
|
} catch (error) {
|
|
17
18
|
const issues = decodeIssues(error);
|
|
18
|
-
if (!issues) throw error;
|
|
19
|
+
if (!issues) throw codecFault(error);
|
|
19
20
|
return {
|
|
20
21
|
success: false,
|
|
21
22
|
error: new SchemaValidationError(issues)
|
|
@@ -30,7 +31,10 @@ function readSchema(schema, input) {
|
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
// src/attachment-schema.ts
|
|
33
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* The file an HTTP operation answers with and its output schema, with nothing that needs a runtime. An
|
|
36
|
+
* attachment is never a JSON or RPC value.
|
|
37
|
+
*/
|
|
34
38
|
/** The output of an operation that answers with a file (`http.response: 'attachment'`). */
|
|
35
39
|
const AttachmentOutputSchema = Type.Unsafe({
|
|
36
40
|
[Kind]: "HttpAttachment",
|
|
@@ -63,8 +67,10 @@ const PageInfoSchema = Type.Object({
|
|
|
63
67
|
additionalProperties: false
|
|
64
68
|
});
|
|
65
69
|
/**
|
|
66
|
-
* A list's `limit`: an integer from 1 to `maximum` (100), `default` (25
|
|
67
|
-
* A list whose items are costly lowers the maximum:
|
|
70
|
+
* A list's `limit`: an integer from 1 to `maximum` (100), `default` (25, or the maximum when it is lower)
|
|
71
|
+
* when the caller sends none. A list whose items are costly lowers the maximum:
|
|
72
|
+
* `{ ...PageQueryFields, limit: pageLimit({ maximum: 20 }) }`. A default outside 1 to the maximum, or a
|
|
73
|
+
* value that is not an integer, throws a TypeError.
|
|
68
74
|
*/
|
|
69
75
|
function pageLimit(options = {}) {
|
|
70
76
|
const { maximum = 100, default: fallback = Math.min(25, maximum) } = options;
|
|
@@ -75,16 +81,19 @@ function pageLimit(options = {}) {
|
|
|
75
81
|
description: `Maximum items returned in one page. Defaults to ${fallback}; larger reads require another cursor.`
|
|
76
82
|
}), fallback);
|
|
77
83
|
}
|
|
78
|
-
/**
|
|
84
|
+
/**
|
|
85
|
+
* The query fields of a list, spread into its input beside its own filters: an optional opaque `cursor`, a
|
|
86
|
+
* `direction` (`forward` by default, or `backward`) and a `limit` (`pageLimit()`).
|
|
87
|
+
*/
|
|
79
88
|
const PageQueryFields = {
|
|
80
89
|
cursor: Type.Optional(Type.String({ description: "Opaque cursor returned by pageInfo; omit it to request the first page." })),
|
|
81
90
|
direction: defaultSchema(Type.Union([Type.Literal("forward"), Type.Literal("backward")], { description: "Direction to traverse the stable keyset ordering from the supplied cursor." }), "forward"),
|
|
82
91
|
limit: pageLimit()
|
|
83
92
|
};
|
|
84
93
|
/**
|
|
85
|
-
* The output of a list of `item`, named by `$id` (`AppointmentPage`)
|
|
86
|
-
*
|
|
87
|
-
* one suffixed `_2`.
|
|
94
|
+
* The output of a list of `item`, named by `$id` (`AppointmentPage`), a PascalCase name of up to 128
|
|
95
|
+
* characters; any other throws a TypeError. Give each list its own name and use it for that list only: two
|
|
96
|
+
* different shapes under one `$id` become two components, the second one suffixed `_2`.
|
|
88
97
|
*/
|
|
89
98
|
function Page(item, options) {
|
|
90
99
|
if (!PAGE_ID.test(options.$id)) throw new TypeError(`Page "${options.$id}" needs a PascalCase schema name, such as AppointmentPage.`);
|
|
@@ -135,7 +144,7 @@ const HexColorSchema = Type.String({
|
|
|
135
144
|
pattern: "^#[0-9a-fA-F]{6}$",
|
|
136
145
|
description: "A color, as #rrggbb."
|
|
137
146
|
});
|
|
138
|
-
/** What
|
|
147
|
+
/** What a delete answers: the deleted resource's id and `deleted: true`, named `DeletedObject`. */
|
|
139
148
|
const DeletedObjectSchema = Type.Object({
|
|
140
149
|
id: Type.String({ description: "The id of the deleted resource." }),
|
|
141
150
|
deleted: Type.Literal(true)
|
|
@@ -148,7 +157,10 @@ const SignedUrlFieldSchema = {
|
|
|
148
157
|
...HttpsUrlSchema,
|
|
149
158
|
description: "The signed URL. Anyone holding it has access until it expires."
|
|
150
159
|
};
|
|
151
|
-
/**
|
|
160
|
+
/**
|
|
161
|
+
* A link that grants access by itself until it expires, such as a file download: its HTTPS `url` and its
|
|
162
|
+
* `expiresAt` date-time, named `SignedUrl`.
|
|
163
|
+
*/
|
|
152
164
|
const SignedUrlSchema = Type.Object({
|
|
153
165
|
url: SignedUrlFieldSchema,
|
|
154
166
|
expiresAt: Type.String({
|
|
@@ -159,7 +171,7 @@ const SignedUrlSchema = Type.Object({
|
|
|
159
171
|
$id: "SignedUrl",
|
|
160
172
|
additionalProperties: false
|
|
161
173
|
});
|
|
162
|
-
/** Another resource, by its id and the name people know it by
|
|
174
|
+
/** Another resource, by its id and the name people know it by, named `NamedReference`. */
|
|
163
175
|
const NamedReferenceSchema = Type.Object({
|
|
164
176
|
id: Type.String({ description: "The id of the referenced resource." }),
|
|
165
177
|
name: Type.String({ description: "Its name." })
|
|
@@ -167,7 +179,10 @@ const NamedReferenceSchema = Type.Object({
|
|
|
167
179
|
$id: "NamedReference",
|
|
168
180
|
additionalProperties: false
|
|
169
181
|
});
|
|
170
|
-
/**
|
|
182
|
+
/**
|
|
183
|
+
* A postal address, shaped as FHIR `Address` (its lines, city, state, postal code, ISO 3166-1 alpha-2 country
|
|
184
|
+
* code and use), every field optional, named `PostalAddress`.
|
|
185
|
+
*/
|
|
171
186
|
const PostalAddressSchema = Type.Object({
|
|
172
187
|
city: Type.Optional(Type.String({ maxLength: 120 })),
|
|
173
188
|
countryCode: Type.Optional(Type.String({
|
|
@@ -205,6 +220,7 @@ const OrganizationIdSchema = Type.String({
|
|
|
205
220
|
/** A lowercase RFC 9562 UUID of version 1 to 8, named `Uuid`. */
|
|
206
221
|
const UuidSchema = Type.String({
|
|
207
222
|
$id: "Uuid",
|
|
223
|
+
format: "uuid",
|
|
208
224
|
pattern: "^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
|
|
209
225
|
});
|
|
210
226
|
|
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
import { S as wireInput } from "./validation-fTohBT6R.js";
|
|
2
|
+
import { i as standardErrors } from "./errors-WfyKhiyk.js";
|
|
3
|
+
import { C as MAX_BODY_BYTES_CEILING, D as mcpOpenWorld, d as canonical, k as operationMatchesScopes, p as standaloneSchema, u as sha256Hex } from "./openapi-CV0KmJpS.js";
|
|
4
|
+
import { i as reportUnexpected } from "./telemetry-C3LfZcOB.js";
|
|
5
|
+
import { t as toYaml } from "./yaml-Dk2L24yQ.js";
|
|
6
|
+
import { Type } from "@sinclair/typebox";
|
|
7
|
+
import { Value } from "@sinclair/typebox/value";
|
|
8
|
+
import { McpServer, ProtocolError, ProtocolErrorCode, createMcpHandler } from "@modelcontextprotocol/server";
|
|
9
|
+
|
|
10
|
+
// 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
|
+
/** Skills change only with a deployment and are the same for every caller, so hosts may share them. */
|
|
20
|
+
const SKILL_CACHE = {
|
|
21
|
+
ttlMs: 3e5,
|
|
22
|
+
cacheScope: "public"
|
|
23
|
+
};
|
|
24
|
+
/** Adapts a TypeBox schema to the Standard Schema the SDK validates custom method params with. */
|
|
25
|
+
function standardSchema(schema) {
|
|
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
|
+
}
|
|
43
|
+
/** The served `SKILL.md`: frontmatter generated from the name and description, then the instructions. */
|
|
44
|
+
function skillDocument(skill) {
|
|
45
|
+
return `---\n${toYaml({
|
|
46
|
+
name: skill.name,
|
|
47
|
+
description: skill.description
|
|
48
|
+
})}---\n\n${skill.text.trim()}\n`;
|
|
49
|
+
}
|
|
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
|
+
/**
|
|
68
|
+
* Serves skills through the Skills extension: `skills/list`, `skills/get`, and `resources/read` of each
|
|
69
|
+
* `SKILL.md`, each request answered through `answer`, which reports an unexpected failure without its text.
|
|
70
|
+
* Clients without the extension still find the files among the server's resources.
|
|
71
|
+
*/
|
|
72
|
+
function registerSkills(server, skills, answer) {
|
|
73
|
+
for (const skill of skills) {
|
|
74
|
+
const uri = skillUri(skill);
|
|
75
|
+
server.registerResource(skill.name, uri, {
|
|
76
|
+
description: skill.description,
|
|
77
|
+
mimeType: "text/markdown",
|
|
78
|
+
cacheHint: SKILL_CACHE
|
|
79
|
+
}, () => answer(() => ({ contents: [{
|
|
80
|
+
uri,
|
|
81
|
+
mimeType: "text/markdown",
|
|
82
|
+
text: skillDocument(skill)
|
|
83
|
+
}] })));
|
|
84
|
+
}
|
|
85
|
+
server.server.setRequestHandler("skills/list", { params: ListSkillsParams }, (params) => answer(async () => {
|
|
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
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The same skills as one read-only tool, for clients that import only tools. Its description names every
|
|
105
|
+
* skill, so a semantic tool search for one of those tasks can find it.
|
|
106
|
+
*/
|
|
107
|
+
function skillTool(name, skills) {
|
|
108
|
+
return {
|
|
109
|
+
name,
|
|
110
|
+
title: "Read a workflow skill",
|
|
111
|
+
description: [
|
|
112
|
+
"Read the instructions of one workflow skill before doing its task: the steps, tools and pitfalls of work that spans several tools. A skill grants no tools or permissions.",
|
|
113
|
+
"Skills:",
|
|
114
|
+
...skills.map((skill) => `- ${skill.name}: ${skill.description}`)
|
|
115
|
+
].join("\n"),
|
|
116
|
+
inputSchema: {
|
|
117
|
+
type: "object",
|
|
118
|
+
properties: { name: {
|
|
119
|
+
type: "string",
|
|
120
|
+
enum: skills.map((skill) => skill.name),
|
|
121
|
+
description: "The skill to read."
|
|
122
|
+
} },
|
|
123
|
+
required: ["name"],
|
|
124
|
+
additionalProperties: false
|
|
125
|
+
},
|
|
126
|
+
outputSchema: {
|
|
127
|
+
type: "object",
|
|
128
|
+
properties: {
|
|
129
|
+
name: { type: "string" },
|
|
130
|
+
description: { type: "string" },
|
|
131
|
+
instructions: {
|
|
132
|
+
type: "string",
|
|
133
|
+
description: "The Markdown instructions."
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
required: [
|
|
137
|
+
"name",
|
|
138
|
+
"description",
|
|
139
|
+
"instructions"
|
|
140
|
+
],
|
|
141
|
+
additionalProperties: false
|
|
142
|
+
},
|
|
143
|
+
annotations: {
|
|
144
|
+
readOnlyHint: true,
|
|
145
|
+
destructiveHint: false,
|
|
146
|
+
idempotentHint: true,
|
|
147
|
+
openWorldHint: false
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/** Answers a skill tool call. An unknown name is a tool error, which the model can correct. */
|
|
152
|
+
function readSkill(skills, input) {
|
|
153
|
+
const skill = skills.find((candidate) => candidate.name === input.name);
|
|
154
|
+
if (!skill) return {
|
|
155
|
+
isError: true,
|
|
156
|
+
content: [{
|
|
157
|
+
type: "text",
|
|
158
|
+
text: `Unknown skill. Read one of: ${skills.map((entry) => entry.name).join(", ")}.`
|
|
159
|
+
}]
|
|
160
|
+
};
|
|
161
|
+
const value = {
|
|
162
|
+
name: skill.name,
|
|
163
|
+
description: skill.description,
|
|
164
|
+
instructions: skill.text.trim()
|
|
165
|
+
};
|
|
166
|
+
return {
|
|
167
|
+
content: [{
|
|
168
|
+
type: "text",
|
|
169
|
+
text: JSON.stringify(value)
|
|
170
|
+
}],
|
|
171
|
+
structuredContent: value
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// src/mcp/server.ts
|
|
176
|
+
/**
|
|
177
|
+
* The MCP server a request to `/mcp` meets, built with the official SDK: one stateless server per request
|
|
178
|
+
* lists the caller's tools and runs them through the shared execution path, and serves the OpenAPI document
|
|
179
|
+
* and the guides as resources, the guides as prompts and the skills through the Skills extension. `mcp()`
|
|
180
|
+
* loads this module on the first MCP request, so a Worker's other requests never evaluate the SDK.
|
|
181
|
+
*/
|
|
182
|
+
/** Operation tools on one `tools/list` page; the skill tool, when served, comes before them on the first. */
|
|
183
|
+
const PAGE_SIZE = 50;
|
|
184
|
+
/** Each operation's tool definition, built on first listing: an application's operations never change. */
|
|
185
|
+
const definitions = /* @__PURE__ */ new WeakMap();
|
|
186
|
+
/**
|
|
187
|
+
* The tool an operation lists as. Both schemas are self-contained, as MCP clients compile them: no `$id`,
|
|
188
|
+
* which one schema may not repeat. The hints follow the operation's effect and tool declaration; they are not
|
|
189
|
+
* authorization.
|
|
190
|
+
*/
|
|
191
|
+
function toolDefinition(op) {
|
|
192
|
+
let tool = definitions.get(op);
|
|
193
|
+
if (!tool) {
|
|
194
|
+
tool = {
|
|
195
|
+
name: op.mcp.name,
|
|
196
|
+
title: op.title,
|
|
197
|
+
description: op.description,
|
|
198
|
+
inputSchema: toolInputSchema(wireInput(op.input)),
|
|
199
|
+
outputSchema: {
|
|
200
|
+
...standaloneSchema(op.output),
|
|
201
|
+
type: "object"
|
|
202
|
+
},
|
|
203
|
+
annotations: {
|
|
204
|
+
readOnlyHint: op.effect === "read",
|
|
205
|
+
destructiveHint: op.effect === "delete",
|
|
206
|
+
idempotentHint: op.mcp.idempotent,
|
|
207
|
+
openWorldHint: mcpOpenWorld(op.mcp)
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
definitions.set(op, tool);
|
|
211
|
+
}
|
|
212
|
+
return tool;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* An operation's input as a tool's `inputSchema`: an object at the root, as MCP requires and hosts enforce.
|
|
216
|
+
* A union input (`{ channel: 'email', … } | { channel: 'sms', … }`) lists as one object with every member's
|
|
217
|
+
* fields and key patterns, a field required when every member requires it, and a field the members declare
|
|
218
|
+
* differently as their choices. Hosts that refuse a root `anyOf`, the Anthropic API among them, would fail
|
|
219
|
+
* every tool of the request; each call is still checked against the exact union.
|
|
220
|
+
*/
|
|
221
|
+
function toolInputSchema(input) {
|
|
222
|
+
const schema = standaloneSchema(input);
|
|
223
|
+
const { anyOf, ...root } = schema;
|
|
224
|
+
const bundled = root.$defs ?? {};
|
|
225
|
+
const members = Array.isArray(anyOf) ? anyOf.map((member) => localDefinition(member, bundled)) : [];
|
|
226
|
+
if (!members.length || members.some((member) => member.type !== "object")) return {
|
|
227
|
+
...schema,
|
|
228
|
+
type: "object"
|
|
229
|
+
};
|
|
230
|
+
const fields = (member) => member.properties ?? {};
|
|
231
|
+
const names = [...new Set(members.flatMap((member) => Object.keys(fields(member))))];
|
|
232
|
+
const patterns = /* @__PURE__ */ new Map();
|
|
233
|
+
for (const member of members) for (const [pattern, keys] of Object.entries(member.patternProperties ?? {})) {
|
|
234
|
+
const declared = patterns.get(pattern) ?? [];
|
|
235
|
+
declared.push(keys);
|
|
236
|
+
patterns.set(pattern, declared);
|
|
237
|
+
}
|
|
238
|
+
const required = names.filter((name) => members.every((member) => Array.isArray(member.required) && member.required.includes(name)));
|
|
239
|
+
return {
|
|
240
|
+
type: "object",
|
|
241
|
+
...root,
|
|
242
|
+
properties: Object.fromEntries(names.map((name) => [name, fieldChoices(members.flatMap((member) => name in fields(member) ? [fields(member)[name] ?? {}] : []))])),
|
|
243
|
+
...patterns.size ? { patternProperties: Object.fromEntries([...patterns].map(([pattern, schemas]) => [pattern, fieldChoices(schemas)])) } : {},
|
|
244
|
+
...required.length ? { required } : {},
|
|
245
|
+
...members.every((member) => member.additionalProperties === false) ? { additionalProperties: false } : {},
|
|
246
|
+
type: "object"
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
/** A union member, or the definition under `$defs` its `$ref` names. */
|
|
250
|
+
function localDefinition(member, bundled) {
|
|
251
|
+
const reference = typeof member.$ref === "string" ? member.$ref : "";
|
|
252
|
+
return reference.startsWith("#/$defs/") ? bundled[reference.slice(8)] ?? member : member;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* One field of a listed union: the one schema every member that declares it gives it, the members' literals
|
|
256
|
+
* as an `enum` (a discriminator), or else each distinct schema as a choice.
|
|
257
|
+
*/
|
|
258
|
+
function fieldChoices(schemas) {
|
|
259
|
+
const distinct = [...new Map(schemas.map((schema) => [canonical(schema), schema])).values()];
|
|
260
|
+
const [first] = distinct;
|
|
261
|
+
if (distinct.length === 1 && first) return first;
|
|
262
|
+
const literal = (schema) => "const" in schema && Object.keys(schema).every((key) => key === "const" || key === "type");
|
|
263
|
+
if (first && distinct.every(literal) && distinct.every((schema) => schema.type === first.type)) return {
|
|
264
|
+
...first.type === void 0 ? {} : { type: first.type },
|
|
265
|
+
enum: distinct.map((schema) => schema.const)
|
|
266
|
+
};
|
|
267
|
+
return { anyOf: distinct };
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* How many JSON-RPC messages a body carries: each message of a batch, which only 2025-03-26 clients send,
|
|
271
|
+
* or one. A body that is no batch is the SDK's to read and refuse.
|
|
272
|
+
*/
|
|
273
|
+
function carriedMessages(body) {
|
|
274
|
+
if (!body.trimStart().startsWith("[")) return 1;
|
|
275
|
+
try {
|
|
276
|
+
const batch = JSON.parse(body);
|
|
277
|
+
return Array.isArray(batch) ? Math.max(batch.length, 1) : 1;
|
|
278
|
+
} catch {
|
|
279
|
+
return 1;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Answers one MCP request of an admitted caller: admits the rest of a batch against the rate limit, then
|
|
284
|
+
* lets a stateless server list the caller's tools, run them through `invoke` and serve the resources,
|
|
285
|
+
* prompts and skills. A 5xx answer is reported as an unexpected error.
|
|
286
|
+
*/
|
|
287
|
+
async function handleMcp({ request, requestId, authenticated, application, operations, contractText, url, invoke, admitCarried, refused, body, bodyLimit }) {
|
|
288
|
+
const refusal = await admitCarried(carriedMessages(body) - 1);
|
|
289
|
+
if (refusal) return refusal;
|
|
290
|
+
const bodyBytes = new TextEncoder().encode(body).byteLength;
|
|
291
|
+
/** The cursor of the page after the one that ends with an operation, valid for this version only. */
|
|
292
|
+
const pageCursor = (name) => `${application.version}:${name}`;
|
|
293
|
+
/**
|
|
294
|
+
* Runs one of the server's own handlers: a protocol error answers as thrown, and any other failure is
|
|
295
|
+
* reported by its safe description and answers a generic internal error, never its message.
|
|
296
|
+
*/
|
|
297
|
+
const answer = async (work) => {
|
|
298
|
+
try {
|
|
299
|
+
return await work();
|
|
300
|
+
} catch (error) {
|
|
301
|
+
if (error instanceof ProtocolError) throw error;
|
|
302
|
+
reportUnexpected(error, "mcp", requestId);
|
|
303
|
+
throw new ProtocolError(ProtocolErrorCode.InternalError, "Internal error");
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
const response = await createMcpHandler(() => {
|
|
307
|
+
const skills = application.mcp?.skills ?? [];
|
|
308
|
+
const skillToolName = skills.length ? application.mcp?.skillTool : void 0;
|
|
309
|
+
const server = new McpServer({
|
|
310
|
+
name: application.name,
|
|
311
|
+
title: application.title,
|
|
312
|
+
version: application.version
|
|
313
|
+
}, {
|
|
314
|
+
instructions: application.mcp?.instructions,
|
|
315
|
+
capabilities: {
|
|
316
|
+
tools: { listChanged: false },
|
|
317
|
+
resources: { listChanged: false },
|
|
318
|
+
prompts: { listChanged: false },
|
|
319
|
+
...skills.length ? { extensions: { [SKILLS_EXTENSION]: {} } } : {}
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
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 () => {
|
|
324
|
+
if (skillToolName && call.params.name === skillToolName) return readSkill(skills, call.params.arguments ?? {});
|
|
325
|
+
const selected = visible.find(([, op]) => op.mcp.name === call.params.name);
|
|
326
|
+
if (!selected) {
|
|
327
|
+
const hidden = operations.find(([, op]) => op.mcp?.name === call.params.name);
|
|
328
|
+
refused(hidden ? standardErrors.forbidden.create() : standardErrors.notFound.create(), hidden?.[0]);
|
|
329
|
+
throw new ProtocolError(ProtocolErrorCode.InvalidParams, "Tool not found");
|
|
330
|
+
}
|
|
331
|
+
const [name, op] = selected;
|
|
332
|
+
if (bodyBytes > bodyLimit(op)) {
|
|
333
|
+
const failure = standardErrors.tooLarge.create();
|
|
334
|
+
refused(failure, name);
|
|
335
|
+
return {
|
|
336
|
+
isError: true,
|
|
337
|
+
content: [{
|
|
338
|
+
type: "text",
|
|
339
|
+
text: JSON.stringify(failure)
|
|
340
|
+
}]
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
const result = await invoke(name, op, call.params.arguments ?? {});
|
|
344
|
+
return result.ok ? {
|
|
345
|
+
content: [{
|
|
346
|
+
type: "text",
|
|
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
|
+
}]
|
|
356
|
+
};
|
|
357
|
+
}));
|
|
358
|
+
server.server.setRequestHandler("tools/list", (listing) => answer(() => {
|
|
359
|
+
const cursor = listing.params?.cursor;
|
|
360
|
+
const previous = cursor === void 0 ? -1 : visible.findIndex(([name]) => pageCursor(name) === cursor);
|
|
361
|
+
if (cursor !== void 0 && previous < 0) throw new ProtocolError(ProtocolErrorCode.InvalidParams, "Invalid cursor");
|
|
362
|
+
const page = visible.slice(previous + 1, previous + 1 + PAGE_SIZE);
|
|
363
|
+
const last = page.at(-1);
|
|
364
|
+
return {
|
|
365
|
+
tools: [...skillToolName && cursor === void 0 ? [skillTool(skillToolName, skills)] : [], ...page.map(([, op]) => toolDefinition(op))],
|
|
366
|
+
...last && previous + 1 + PAGE_SIZE < visible.length ? { nextCursor: pageCursor(last[0]) } : {}
|
|
367
|
+
};
|
|
368
|
+
}));
|
|
369
|
+
for (const extension of ["json", "yaml"]) {
|
|
370
|
+
const uri = url(`/openapi.${extension}`);
|
|
371
|
+
const mimeType = extension === "json" ? "application/json" : "application/yaml";
|
|
372
|
+
server.registerResource(`openapi-${extension}`, uri, {
|
|
373
|
+
title: `${application.title} OpenAPI (${extension.toUpperCase()})`,
|
|
374
|
+
description: "The service's OpenAPI document. Reading it grants no authority to run its operations.",
|
|
375
|
+
mimeType
|
|
376
|
+
}, () => answer(() => ({ contents: [{
|
|
377
|
+
uri,
|
|
378
|
+
mimeType,
|
|
379
|
+
text: contractText(extension)
|
|
380
|
+
}] })));
|
|
381
|
+
}
|
|
382
|
+
for (const guide of application.mcp?.guides ?? []) {
|
|
383
|
+
const uri = `${application.origin}/guides/${guide.name}`;
|
|
384
|
+
server.registerResource(guide.name, uri, {
|
|
385
|
+
title: guide.title,
|
|
386
|
+
mimeType: "text/markdown"
|
|
387
|
+
}, () => answer(() => ({ contents: [{
|
|
388
|
+
uri,
|
|
389
|
+
mimeType: "text/markdown",
|
|
390
|
+
text: guide.text
|
|
391
|
+
}] })));
|
|
392
|
+
server.registerPrompt(guide.name, {
|
|
393
|
+
title: guide.title,
|
|
394
|
+
description: "Read the integration usage guide."
|
|
395
|
+
}, () => answer(() => ({ messages: [{
|
|
396
|
+
role: "user",
|
|
397
|
+
content: {
|
|
398
|
+
type: "text",
|
|
399
|
+
text: guide.text
|
|
400
|
+
}
|
|
401
|
+
}] })));
|
|
402
|
+
}
|
|
403
|
+
if (skills.length) registerSkills(server, skills, answer);
|
|
404
|
+
return server;
|
|
405
|
+
}, { maxRequestBodySize: MAX_BODY_BYTES_CEILING }).fetch(request);
|
|
406
|
+
if (response.status >= 500) reportUnexpected(/* @__PURE__ */ new Error("MCP transport failure"), "mcp", requestId);
|
|
407
|
+
return response;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
export { handleMcp };
|