@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
package/dist/mcp/index.js
CHANGED
|
@@ -1,270 +1,10 @@
|
|
|
1
|
-
import { standardErrors } from "../errors.js";
|
|
2
|
-
import { C as operationMatchesScopes, b as mcpOpenWorld, g as MAX_BODY_BYTES_CEILING, m as sha256Hex } from "../chunks/execution-B-yy4C7N.js";
|
|
3
|
-
import { a as canonical, o as standaloneSchema } from "../chunks/src-DPSpGNnT.js";
|
|
4
|
-
import { i as reportUnexpected } from "../chunks/telemetry-BTwB68m5.js";
|
|
5
|
-
import { Type } from "@sinclair/typebox";
|
|
6
|
-
import { Value } from "@sinclair/typebox/value";
|
|
7
|
-
import { stringify } from "yaml";
|
|
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${stringify({
|
|
46
|
-
name: skill.name,
|
|
47
|
-
description: skill.description
|
|
48
|
-
}, { lineWidth: 0 })}---\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
|
-
* Serve skills through the Skills extension: `skills/list`, `skills/get`, and `resources/read` of each
|
|
69
|
-
* `SKILL.md`, each request answered through `answer`, which counts it against the caller's rate limit.
|
|
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
|
-
/** Answer 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
1
|
// src/mcp/index.ts
|
|
176
2
|
/**
|
|
177
|
-
* `@arbol-ai/maximus/mcp`: the MCP transport. One stateless server per request, built with the official SDK,
|
|
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.
|
|
180
|
-
*/
|
|
181
|
-
/** Operation tools on one `tools/list` page; the skill tool, when served, comes before them on the first. */
|
|
182
|
-
const PAGE_SIZE = 50;
|
|
183
|
-
/** The JSON-RPC error of a request beyond the caller's rate limit: an implementation-defined server error. */
|
|
184
|
-
const RATE_LIMITED = -32e3;
|
|
185
|
-
/** Each operation's tool definition, built on first listing: an application's operations never change. */
|
|
186
|
-
const definitions = /* @__PURE__ */ new WeakMap();
|
|
187
|
-
/**
|
|
188
|
-
* The tool an operation lists as. Both schemas are self-contained, as MCP clients compile them: no `$id`,
|
|
189
|
-
* which one schema may not repeat. The hints follow the operation's effect and tool declaration; they are not
|
|
190
|
-
* authorization.
|
|
191
|
-
*/
|
|
192
|
-
function toolDefinition(op) {
|
|
193
|
-
let tool = definitions.get(op);
|
|
194
|
-
if (!tool) {
|
|
195
|
-
tool = {
|
|
196
|
-
name: op.mcp.name,
|
|
197
|
-
title: op.title,
|
|
198
|
-
description: op.description,
|
|
199
|
-
inputSchema: toolInputSchema(op.input),
|
|
200
|
-
outputSchema: {
|
|
201
|
-
...standaloneSchema(op.output),
|
|
202
|
-
type: "object"
|
|
203
|
-
},
|
|
204
|
-
annotations: {
|
|
205
|
-
readOnlyHint: op.effect === "read",
|
|
206
|
-
destructiveHint: op.effect === "delete",
|
|
207
|
-
idempotentHint: op.mcp.idempotent,
|
|
208
|
-
openWorldHint: mcpOpenWorld(op.mcp)
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
definitions.set(op, tool);
|
|
212
|
-
}
|
|
213
|
-
return tool;
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* An operation's input as a tool's `inputSchema`: an object at the root, as MCP requires and hosts enforce.
|
|
217
|
-
* A union input (`{ channel: 'email', … } | { channel: 'sms', … }`) lists as one object with every member's
|
|
218
|
-
* fields, required when every member requires them, and a field the members declare differently as their
|
|
219
|
-
* choices. Hosts that refuse a root `anyOf`, the Anthropic API among them, would fail every tool of the
|
|
220
|
-
* request; each call is still checked against the exact union.
|
|
221
|
-
*/
|
|
222
|
-
function toolInputSchema(input) {
|
|
223
|
-
const schema = standaloneSchema(input);
|
|
224
|
-
const { anyOf, ...root } = schema;
|
|
225
|
-
const bundled = root.$defs ?? {};
|
|
226
|
-
const members = Array.isArray(anyOf) ? anyOf.map((member) => localDefinition(member, bundled)) : [];
|
|
227
|
-
if (!members.length || members.some((member) => member.type !== "object")) return {
|
|
228
|
-
...schema,
|
|
229
|
-
type: "object"
|
|
230
|
-
};
|
|
231
|
-
const fields = (member) => member.properties ?? {};
|
|
232
|
-
const names = [...new Set(members.flatMap((member) => Object.keys(fields(member))))];
|
|
233
|
-
const required = names.filter((name) => members.every((member) => Array.isArray(member.required) && member.required.includes(name)));
|
|
234
|
-
return {
|
|
235
|
-
type: "object",
|
|
236
|
-
...root,
|
|
237
|
-
properties: Object.fromEntries(names.map((name) => [name, fieldChoices(members.flatMap((member) => name in fields(member) ? [fields(member)[name] ?? {}] : []))])),
|
|
238
|
-
...required.length ? { required } : {},
|
|
239
|
-
...members.every((member) => member.additionalProperties === false) ? { additionalProperties: false } : {},
|
|
240
|
-
type: "object"
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
/** A union member, or the definition under `$defs` its `$ref` names. */
|
|
244
|
-
function localDefinition(member, bundled) {
|
|
245
|
-
const reference = typeof member.$ref === "string" ? member.$ref : "";
|
|
246
|
-
return reference.startsWith("#/$defs/") ? bundled[reference.slice(8)] ?? member : member;
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* One field of a listed union: the one schema every member that declares it gives it, the members' literals
|
|
250
|
-
* as an `enum` (a discriminator), or else each distinct schema as a choice.
|
|
251
|
-
*/
|
|
252
|
-
function fieldChoices(schemas) {
|
|
253
|
-
const distinct = [...new Map(schemas.map((schema) => [canonical(schema), schema])).values()];
|
|
254
|
-
const [first] = distinct;
|
|
255
|
-
if (distinct.length === 1 && first) return first;
|
|
256
|
-
const literal = (schema) => "const" in schema && Object.keys(schema).every((key) => key === "const" || key === "type");
|
|
257
|
-
if (first && distinct.every(literal) && distinct.every((schema) => schema.type === first.type)) return {
|
|
258
|
-
...first.type === void 0 ? {} : { type: first.type },
|
|
259
|
-
enum: distinct.map((schema) => schema.const)
|
|
260
|
-
};
|
|
261
|
-
return { anyOf: distinct };
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
3
|
* The MCP transport, for `createWorker(app, { transports: [mcp()] })`: serves the operations that declare
|
|
265
4
|
* `mcp` as tools over Streamable HTTP at `/mcp` (or `path`), with the OpenAPI document and guides as
|
|
266
5
|
* resources, guides as prompts and skills through the Skills extension. A caller needs `<namespace>:mcp:use`
|
|
267
|
-
* and sees only the tools its scopes admit.
|
|
6
|
+
* and sees only the tools its scopes and actor kind admit. Each message of a JSON-RPC batch passes the rate
|
|
7
|
+
* limit as a request of its own, and each call is held to its operation's body limit.
|
|
268
8
|
*/
|
|
269
9
|
function mcp(options = {}) {
|
|
270
10
|
return {
|
|
@@ -272,131 +12,9 @@ function mcp(options = {}) {
|
|
|
272
12
|
path: options.path ?? "/mcp",
|
|
273
13
|
scope: (namespace) => `${namespace}:mcp:use`,
|
|
274
14
|
maxBodyBytes: (operations, fallback) => Math.max(fallback, ...operations.flatMap(([, op]) => op.mcp ? [op.maxBodyBytes ?? fallback] : [])),
|
|
275
|
-
async handle(
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* Counts one more request of this HTTP request against the caller's rate limit, as a request of its own
|
|
280
|
-
* (a JSON-RPC batch carries several), and refuses it once the limit does.
|
|
281
|
-
*/
|
|
282
|
-
const count = async () => {
|
|
283
|
-
if (!await admitRequest()) {
|
|
284
|
-
const failure = standardErrors.rateLimited.create();
|
|
285
|
-
throw new ProtocolError(RATE_LIMITED, failure.message, failure);
|
|
286
|
-
}
|
|
287
|
-
};
|
|
288
|
-
/**
|
|
289
|
-
* Runs one of the server's own handlers as a counted request, unless `invoke` counts it: a protocol
|
|
290
|
-
* error answers as thrown, and any other failure is reported by its safe description and answers a
|
|
291
|
-
* generic internal error, never its message.
|
|
292
|
-
*/
|
|
293
|
-
const answer = async (work, counted = true) => {
|
|
294
|
-
try {
|
|
295
|
-
if (counted) await count();
|
|
296
|
-
return await work();
|
|
297
|
-
} catch (error) {
|
|
298
|
-
if (error instanceof ProtocolError) throw error;
|
|
299
|
-
reportUnexpected(error, "mcp", requestId);
|
|
300
|
-
throw new ProtocolError(ProtocolErrorCode.InternalError, "Internal error");
|
|
301
|
-
}
|
|
302
|
-
};
|
|
303
|
-
const response = await createMcpHandler(() => {
|
|
304
|
-
const skills = application.mcp?.skills ?? [];
|
|
305
|
-
const skillToolName = skills.length ? application.mcp?.skillTool : void 0;
|
|
306
|
-
const server = new McpServer({
|
|
307
|
-
name: application.name,
|
|
308
|
-
title: application.title,
|
|
309
|
-
version: application.version
|
|
310
|
-
}, {
|
|
311
|
-
instructions: application.mcp?.instructions,
|
|
312
|
-
capabilities: {
|
|
313
|
-
tools: { listChanged: false },
|
|
314
|
-
resources: { listChanged: false },
|
|
315
|
-
prompts: { listChanged: false },
|
|
316
|
-
...skills.length ? { extensions: { [SKILLS_EXTENSION]: {} } } : {}
|
|
317
|
-
}
|
|
318
|
-
});
|
|
319
|
-
const visible = operations.filter((entry) => Boolean(entry[1].mcp) && operationMatchesScopes(entry[1], authenticated.scopes) && (!entry[1].actorKinds || entry[1].actorKinds.includes(authenticated.actorKind)));
|
|
320
|
-
server.server.setRequestHandler("tools/call", (call) => answer(async () => {
|
|
321
|
-
if (skillToolName && call.params.name === skillToolName) {
|
|
322
|
-
await count();
|
|
323
|
-
return readSkill(skills, call.params.arguments ?? {});
|
|
324
|
-
}
|
|
325
|
-
const selected = visible.find(([, op]) => op.mcp.name === call.params.name);
|
|
326
|
-
if (!selected) throw new ProtocolError(ProtocolErrorCode.InvalidParams, "Tool not found");
|
|
327
|
-
const [name, op] = selected;
|
|
328
|
-
if (bodyBytes > bodyLimit(op)) return {
|
|
329
|
-
isError: true,
|
|
330
|
-
content: [{
|
|
331
|
-
type: "text",
|
|
332
|
-
text: JSON.stringify(standardErrors.tooLarge.create())
|
|
333
|
-
}]
|
|
334
|
-
};
|
|
335
|
-
const result = await invoke(name, op, call.params.arguments ?? {});
|
|
336
|
-
return result.ok ? {
|
|
337
|
-
content: [{
|
|
338
|
-
type: "text",
|
|
339
|
-
text: JSON.stringify(result.value)
|
|
340
|
-
}],
|
|
341
|
-
structuredContent: result.value
|
|
342
|
-
} : {
|
|
343
|
-
isError: true,
|
|
344
|
-
content: [{
|
|
345
|
-
type: "text",
|
|
346
|
-
text: JSON.stringify(result.error)
|
|
347
|
-
}]
|
|
348
|
-
};
|
|
349
|
-
}, false));
|
|
350
|
-
server.server.setRequestHandler("tools/list", (listing) => answer(() => {
|
|
351
|
-
const cursor = listing.params?.cursor;
|
|
352
|
-
const previous = cursor === void 0 ? -1 : visible.findIndex(([name]) => pageCursor(name) === cursor);
|
|
353
|
-
if (cursor !== void 0 && previous < 0) throw new ProtocolError(ProtocolErrorCode.InvalidParams, "Invalid cursor");
|
|
354
|
-
const page = visible.slice(previous + 1, previous + 1 + PAGE_SIZE);
|
|
355
|
-
const last = page.at(-1);
|
|
356
|
-
return {
|
|
357
|
-
tools: [...skillToolName && cursor === void 0 ? [skillTool(skillToolName, skills)] : [], ...page.map(([, op]) => toolDefinition(op))],
|
|
358
|
-
...last && previous + 1 + PAGE_SIZE < visible.length ? { nextCursor: pageCursor(last[0]) } : {}
|
|
359
|
-
};
|
|
360
|
-
}));
|
|
361
|
-
for (const extension of ["json", "yaml"]) {
|
|
362
|
-
const uri = url(`/openapi.${extension}`);
|
|
363
|
-
const mimeType = extension === "json" ? "application/json" : "application/yaml";
|
|
364
|
-
server.registerResource(`openapi-${extension}`, uri, {
|
|
365
|
-
title: `${application.title} OpenAPI (${extension.toUpperCase()})`,
|
|
366
|
-
description: "The service's OpenAPI document. Reading it grants no authority to run its operations.",
|
|
367
|
-
mimeType
|
|
368
|
-
}, () => answer(() => ({ contents: [{
|
|
369
|
-
uri,
|
|
370
|
-
mimeType,
|
|
371
|
-
text: contractText(extension)
|
|
372
|
-
}] })));
|
|
373
|
-
}
|
|
374
|
-
for (const guide of application.mcp?.guides ?? []) {
|
|
375
|
-
const uri = `${application.origin}/guides/${guide.name}`;
|
|
376
|
-
server.registerResource(guide.name, uri, {
|
|
377
|
-
title: guide.title,
|
|
378
|
-
mimeType: "text/markdown"
|
|
379
|
-
}, () => answer(() => ({ contents: [{
|
|
380
|
-
uri,
|
|
381
|
-
mimeType: "text/markdown",
|
|
382
|
-
text: guide.text
|
|
383
|
-
}] })));
|
|
384
|
-
server.registerPrompt(guide.name, {
|
|
385
|
-
title: guide.title,
|
|
386
|
-
description: "Read the integration usage guide."
|
|
387
|
-
}, () => answer(() => ({ messages: [{
|
|
388
|
-
role: "user",
|
|
389
|
-
content: {
|
|
390
|
-
type: "text",
|
|
391
|
-
text: guide.text
|
|
392
|
-
}
|
|
393
|
-
}] })));
|
|
394
|
-
}
|
|
395
|
-
if (skills.length) registerSkills(server, skills, answer);
|
|
396
|
-
return server;
|
|
397
|
-
}, { maxRequestBodySize: MAX_BODY_BYTES_CEILING }).fetch(request);
|
|
398
|
-
if (response.status >= 500) reportUnexpected(/* @__PURE__ */ new Error("MCP transport failure"), "mcp", requestId);
|
|
399
|
-
return response;
|
|
15
|
+
async handle(context) {
|
|
16
|
+
const { handleMcp } = await import("../chunks/server-CCc7fil4.js");
|
|
17
|
+
return handleMcp(context);
|
|
400
18
|
}
|
|
401
19
|
};
|
|
402
20
|
}
|
package/dist/postgres/index.d.ts
CHANGED
|
@@ -13,7 +13,10 @@ interface TransactionFailure {
|
|
|
13
13
|
code: 'DATABASE_CONFLICT' | 'DATABASE_RETRY' | 'DATABASE_UNAVAILABLE' | 'COMMIT_UNCERTAIN' | 'DATABASE_FAILURE';
|
|
14
14
|
/** A fixed description of the failure, never the server's own message or the query text. */
|
|
15
15
|
message: string;
|
|
16
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Whether repeating the transaction may succeed: true for a serialization or deadlock abort and an
|
|
18
|
+
* unavailable database. It never makes replaying an effect outside the database safe.
|
|
19
|
+
*/
|
|
17
20
|
retryable: boolean;
|
|
18
21
|
/** Where the transaction was when it failed, such as `work` while the callback ran, or `commit`. */
|
|
19
22
|
stage: TransactionStage;
|
|
@@ -23,7 +26,12 @@ interface TransactionFailure {
|
|
|
23
26
|
*/
|
|
24
27
|
sqlState?: string;
|
|
25
28
|
}
|
|
26
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* Classifies a failure by its stage and by the SQLSTATE of a `pg` `DatabaseError`, the server's own error
|
|
31
|
+
* response, never by a message: a commit whose outcome is unknown is `COMMIT_UNCERTAIN`, a serialization
|
|
32
|
+
* failure or deadlock `DATABASE_RETRY`, a constraint violation `DATABASE_CONFLICT`, a failed connection or an
|
|
33
|
+
* unavailable server `DATABASE_UNAVAILABLE`, and anything else `DATABASE_FAILURE`.
|
|
34
|
+
*/
|
|
27
35
|
export declare function classifyTransactionFailure(error: unknown, stage: TransactionStage): TransactionFailure;
|
|
28
36
|
/** The organization a transaction works for, taken from the verified principal. */
|
|
29
37
|
interface TenantContext {
|
|
@@ -52,7 +60,12 @@ interface TransactionOptions {
|
|
|
52
60
|
idleTimeoutMs: number;
|
|
53
61
|
/** The transaction's isolation level; `read committed` when absent. */
|
|
54
62
|
isolation?: 'read committed' | 'repeatable read' | 'serializable';
|
|
55
|
-
/**
|
|
63
|
+
/**
|
|
64
|
+
* Retries a transaction the database aborted (`DATABASE_RETRY`), checking out a client again, up to
|
|
65
|
+
* `maxAttempts` attempts in all (1 to 5), waiting `baseDelayMs` (1 to 1000) times the attempt number, plus
|
|
66
|
+
* jitter, between them. Set it only when the callback does nothing but database work; without it, a
|
|
67
|
+
* transaction runs once.
|
|
68
|
+
*/
|
|
56
69
|
databaseOnlyRetry?: {
|
|
57
70
|
maxAttempts: number;
|
|
58
71
|
baseDelayMs: number;
|
|
@@ -67,11 +80,15 @@ type TransactionResult<T> = {
|
|
|
67
80
|
error: TransactionFailure;
|
|
68
81
|
};
|
|
69
82
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
* or
|
|
73
|
-
*
|
|
74
|
-
*
|
|
83
|
+
* Runs `work` in one short transaction on a client checked out of `pool`: it begins at the isolation level,
|
|
84
|
+
* sets the time budgets for this transaction alone, passes the tenant explicitly and commits. It answers the
|
|
85
|
+
* work's value, or a classified failure, rolling back while the client can still be trusted; an error without
|
|
86
|
+
* a SQLSTATE that the work throws is thrown on, as it was, after the rollback. A client whose state is
|
|
87
|
+
* unknown is discarded rather than returned to the pool. It installs no row-level security, and no session
|
|
88
|
+
* setting stands for isolation: every query must filter by `tenant.organizationId` and use composite keys
|
|
89
|
+
* itself, and the pool must connect as a restricted role. Keep the callback to database work, without
|
|
90
|
+
* provider, model or stream I/O. An uncertain commit is never retried; reconcile it by the work's own key
|
|
91
|
+
* before repeating anything. An invalid organization id or option throws a TypeError.
|
|
75
92
|
*/
|
|
76
93
|
export declare function withTenantTransaction<T>(pool: Pick<Pool, 'connect'>, tenant: TenantContext, options: TransactionOptions, work: (client: PoolClient, tenant: TenantContext) => Promise<T>): Promise<TransactionResult<T>>;
|
|
77
94
|
export type { TenantContext, TransactionFailure, TransactionOptions, TransactionResult, TransactionStage };
|
package/dist/postgres/index.js
CHANGED
|
@@ -6,7 +6,12 @@ import { DatabaseError } from "pg";
|
|
|
6
6
|
* Classifies a Postgres transaction failure by the server's SQLSTATE and the stage it happened in, never
|
|
7
7
|
* by its message.
|
|
8
8
|
*/
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Classifies a failure by its stage and by the SQLSTATE of a `pg` `DatabaseError`, the server's own error
|
|
11
|
+
* response, never by a message: a commit whose outcome is unknown is `COMMIT_UNCERTAIN`, a serialization
|
|
12
|
+
* failure or deadlock `DATABASE_RETRY`, a constraint violation `DATABASE_CONFLICT`, a failed connection or an
|
|
13
|
+
* unavailable server `DATABASE_UNAVAILABLE`, and anything else `DATABASE_FAILURE`.
|
|
14
|
+
*/
|
|
10
15
|
function classifyTransactionFailure(error, stage) {
|
|
11
16
|
const sqlState = error instanceof DatabaseError && /^[0-9A-Z]{5}$/.test(error.code ?? "") ? error.code : void 0;
|
|
12
17
|
if (stage === "commit" && (!sqlState || sqlState.startsWith("08") || sqlState === "40003" || sqlState.startsWith("57"))) return {
|
|
@@ -57,13 +62,13 @@ const ORGANIZATION_ID = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/;
|
|
|
57
62
|
* and unbounded retries.
|
|
58
63
|
*/
|
|
59
64
|
function validateOptions(tenant, options) {
|
|
60
|
-
if (!ORGANIZATION_ID.test(tenant.organizationId)) throw new TypeError("A trusted organization identifier is required.");
|
|
65
|
+
if (typeof tenant.organizationId !== "string" || !ORGANIZATION_ID.test(tenant.organizationId)) throw new TypeError("A trusted organization identifier is required.");
|
|
61
66
|
for (const value of [
|
|
62
67
|
options.statementTimeoutMs,
|
|
63
68
|
options.lockTimeoutMs,
|
|
64
69
|
options.idleTimeoutMs
|
|
65
70
|
]) if (!Number.isSafeInteger(value) || value < 1 || value > 6e4) throw new TypeError("Transaction time budgets must be between 1 and 60000 milliseconds.");
|
|
66
|
-
if (options.isolation && ![
|
|
71
|
+
if (options.isolation !== void 0 && ![
|
|
67
72
|
"read committed",
|
|
68
73
|
"repeatable read",
|
|
69
74
|
"serializable"
|
|
@@ -72,11 +77,15 @@ function validateOptions(tenant, options) {
|
|
|
72
77
|
if (retry && (!Number.isSafeInteger(retry.maxAttempts) || retry.maxAttempts < 1 || retry.maxAttempts > 5 || !Number.isSafeInteger(retry.baseDelayMs) || retry.baseDelayMs < 1 || retry.baseDelayMs > 1e3)) throw new TypeError("Database retries require bounded attempts and delay.");
|
|
73
78
|
}
|
|
74
79
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* or
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
+
* Runs `work` in one short transaction on a client checked out of `pool`: it begins at the isolation level,
|
|
81
|
+
* sets the time budgets for this transaction alone, passes the tenant explicitly and commits. It answers the
|
|
82
|
+
* work's value, or a classified failure, rolling back while the client can still be trusted; an error without
|
|
83
|
+
* a SQLSTATE that the work throws is thrown on, as it was, after the rollback. A client whose state is
|
|
84
|
+
* unknown is discarded rather than returned to the pool. It installs no row-level security, and no session
|
|
85
|
+
* setting stands for isolation: every query must filter by `tenant.organizationId` and use composite keys
|
|
86
|
+
* itself, and the pool must connect as a restricted role. Keep the callback to database work, without
|
|
87
|
+
* provider, model or stream I/O. An uncertain commit is never retried; reconcile it by the work's own key
|
|
88
|
+
* before repeating anything. An invalid organization id or option throws a TypeError.
|
|
80
89
|
*/
|
|
81
90
|
async function withTenantTransaction(pool, tenant, options, work) {
|
|
82
91
|
validateOptions(tenant, options);
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { Gt as ToolDeclaration, Lt as HandlerDeclaration, T as HttpMiddleware, an as Invocation, dn as OperationMiddleware, en as ApplicationBuilder, in as Exposure, jt as ContextDeclaration, pn as OperationShape, rn as AppManifest, un as OperationHandler } from "../chunks/types-BQYB4Ads.js";
|
|
2
|
+
import { TSchema } from "@sinclair/typebox";
|
|
3
|
+
/** A route's HTTP method. */
|
|
4
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
5
|
+
/**
|
|
6
|
+
* A route's operation name: `GET /v1/notes` is `listNotes`, `GET /v1/notes/{noteId}` is `getNote`,
|
|
7
|
+
* `POST /v1/notes` is `createNote`, `PATCH /v1/notes/{noteId}` is `updateNote`,
|
|
8
|
+
* `POST /v1/notes/{noteId}/archive` is `archiveNote` and `GET /v1/days/{date}/slots` is `listDaySlots`. A
|
|
9
|
+
* version other than 1 ends the name: `GET /v2/notes` is `listNotesV2`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function routeName(method: HttpMethod, path: string): string;
|
|
12
|
+
/** A segment or parameter name in PascalCase: `task-lists` and `task_lists` are `TaskLists`. */
|
|
13
|
+
type Word<S extends string> = S extends `${infer Head}-${infer Tail}` ? `${Word<Head>}${Word<Tail>}` : S extends `${infer Head}_${infer Tail}` ? `${Word<Head>}${Word<Tail>}` : Capitalize<S>;
|
|
14
|
+
/** A tool's operation name: the file `summarize-tasks` is `summarizeTasks`. */
|
|
15
|
+
type ToolName<F extends string> = Uncapitalize<Word<F>>;
|
|
16
|
+
/** A tool's MCP name: the file `summarize-tasks` is `summarize_tasks`. */
|
|
17
|
+
type ToolMcpName<F extends string> = F extends `${infer Head}-${infer Tail}` ? `${Head}_${ToolMcpName<Tail>}` : F;
|
|
18
|
+
/** A route's operation name: its `operationId`, else the name its method and path derive. */
|
|
19
|
+
type BoundRouteName<X, N extends string> = X extends {
|
|
20
|
+
operationId: infer D extends string;
|
|
21
|
+
} ? D : N;
|
|
22
|
+
/** A route's effect: the declared one, else its method's. */
|
|
23
|
+
type RouteEffect<X, M> = X extends {
|
|
24
|
+
effect: infer E;
|
|
25
|
+
} ? E : M extends 'GET' ? 'read' : M extends 'DELETE' ? 'delete' : 'write';
|
|
26
|
+
/** The exposure a bound route keeps: what it declares, its path and method, and its effect. */
|
|
27
|
+
type BoundRoute<X, M extends HttpMethod, P extends string> = Pick<X, Extract<keyof X, 'actorKinds' | 'visibility' | 'rpc'>> & {
|
|
28
|
+
http: (X extends {
|
|
29
|
+
http: infer H;
|
|
30
|
+
} ? H : unknown) & {
|
|
31
|
+
method: M;
|
|
32
|
+
path: P;
|
|
33
|
+
};
|
|
34
|
+
effect: RouteEffect<X, M>;
|
|
35
|
+
} & (X extends {
|
|
36
|
+
mcp: infer T;
|
|
37
|
+
} ? {
|
|
38
|
+
mcp: T & {
|
|
39
|
+
idempotent: boolean;
|
|
40
|
+
};
|
|
41
|
+
} : unknown);
|
|
42
|
+
/** The exposure a bound tool keeps: what it declares, its effect and its MCP tool. */
|
|
43
|
+
type BoundTool<X, F extends string> = Pick<X, Extract<keyof X, 'actorKinds' | 'rpc' | 'effect'>> & {
|
|
44
|
+
mcp: {
|
|
45
|
+
name: ToolMcpName<F>;
|
|
46
|
+
idempotent: boolean;
|
|
47
|
+
openWorld?: boolean;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
/** A tool's operation name, as `ToolName` types it. */
|
|
51
|
+
export declare function toolName(file: string): string;
|
|
52
|
+
/**
|
|
53
|
+
* Prepares every call's context with `context.ts`'s declaration, after admission: what it returns joins the
|
|
54
|
+
* context, and `fail(code)` answers the call. The base must not declare operations yet.
|
|
55
|
+
*/
|
|
56
|
+
export declare function bindContext<E, D extends object>(base: ApplicationBuilder<E, Invocation<E>, Record<never, never>>, declaration: ContextDeclaration<D, E>): ApplicationBuilder<E, Invocation<E> & Awaited<D>, Record<never, never>>;
|
|
57
|
+
/**
|
|
58
|
+
* Binds a `defineHandler` declaration to the application, under the path and method its filename gives. The
|
|
59
|
+
* operation is named by its `operationId`, else by `name`, the one `maximus prepare` derives from its method
|
|
60
|
+
* and path with `routeName`: `getNote` for `GET /v1/notes/{noteId}`.
|
|
61
|
+
*/
|
|
62
|
+
export declare function bindRoute<E, C, I extends TSchema, O extends TSchema, X, const P extends string, const M extends HttpMethod, const N extends string>(base: ApplicationBuilder<E, C, Record<never, never>>, declaration: HandlerDeclaration<I, O, X, C>, path: P, method: M, name: N): ApplicationBuilder<E, C, Record<never, never> & Record<BoundRouteName<X, N>, Pick<X, Extract<keyof X, "actorKinds" | "rpc" | "visibility">> & {
|
|
63
|
+
http: (X extends {
|
|
64
|
+
http: infer H;
|
|
65
|
+
} ? H : unknown) & {
|
|
66
|
+
method: M;
|
|
67
|
+
path: P;
|
|
68
|
+
};
|
|
69
|
+
effect: RouteEffect<X, M>;
|
|
70
|
+
} & (X extends {
|
|
71
|
+
mcp: infer T;
|
|
72
|
+
} ? {
|
|
73
|
+
mcp: T & {
|
|
74
|
+
idempotent: boolean;
|
|
75
|
+
};
|
|
76
|
+
} : unknown) & Omit<OperationShape, "execute" | "input" | "output" | "pipeline" | keyof Exposure> & {
|
|
77
|
+
input: I;
|
|
78
|
+
output: O;
|
|
79
|
+
} & {
|
|
80
|
+
execute: OperationHandler<C, I, O, BoundRoute<X, M, P>>;
|
|
81
|
+
}>>;
|
|
82
|
+
/**
|
|
83
|
+
* Binds a `defineTool` declaration to the application, under the name its file gives: `summarize-tasks` is
|
|
84
|
+
* the operation `summarizeTasks` and the tool `summarize_tasks`.
|
|
85
|
+
*/
|
|
86
|
+
export declare function bindTool<E, C, I extends TSchema, O extends TSchema, X, const F extends string>(base: ApplicationBuilder<E, C, Record<never, never>>, declaration: ToolDeclaration<I, O, X, C>, file: F): ApplicationBuilder<E, C, Record<never, never> & Record<Uncapitalize<Word<F>>, Pick<X, Extract<keyof X, "actorKinds" | "effect" | "rpc">> & {
|
|
87
|
+
mcp: {
|
|
88
|
+
name: ToolMcpName<F>;
|
|
89
|
+
idempotent: boolean;
|
|
90
|
+
openWorld?: boolean;
|
|
91
|
+
};
|
|
92
|
+
} & Omit<OperationShape, "execute" | "input" | "output" | "pipeline" | keyof Exposure> & {
|
|
93
|
+
input: I;
|
|
94
|
+
output: O;
|
|
95
|
+
} & {
|
|
96
|
+
execute: OperationHandler<C, I, O, BoundTool<X, F>>;
|
|
97
|
+
}>>;
|
|
98
|
+
/** A `middleware/` module that wraps every HTTP request before token admission: it sees no principal. */
|
|
99
|
+
export interface RequestMiddlewareModule<E> {
|
|
100
|
+
readonly phase: 'request';
|
|
101
|
+
readonly handle: HttpMiddleware<E>;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Declares a `middleware/` module that wraps every HTTP request, in filename order, before the request's
|
|
105
|
+
* token is verified: CORS, security headers, request ids. It cannot authenticate a caller or bypass admission.
|
|
106
|
+
*/
|
|
107
|
+
export declare function defineMiddleware<E>(handle: HttpMiddleware<E>): RequestMiddlewareModule<E>;
|
|
108
|
+
/** A `middleware/` module that runs after admission, on every operation over HTTP, MCP and RPC. */
|
|
109
|
+
export interface OperationMiddlewareModule<C> {
|
|
110
|
+
readonly phase: 'operation';
|
|
111
|
+
readonly handle: OperationMiddleware<C>;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Declares a `middleware/` module that runs after the caller is admitted, around every operation over HTTP,
|
|
115
|
+
* MCP and RPC, with the verified invocation: business policy that must hold on every transport.
|
|
116
|
+
*/
|
|
117
|
+
export declare function defineOperationMiddleware<C>(handle: OperationMiddleware<C>): OperationMiddlewareModule<C>;
|
|
118
|
+
/** What a `middleware/` module default-exports. */
|
|
119
|
+
export type ProjectMiddleware<E, C> = OperationMiddlewareModule<C> | RequestMiddlewareModule<E>;
|
|
120
|
+
/** The operation middleware of a module, with its own context type. */
|
|
121
|
+
type OperationHandle<M> = M extends OperationMiddlewareModule<infer C> ? OperationMiddleware<C> : never;
|
|
122
|
+
/** The request middleware of a module, with its own bindings type. */
|
|
123
|
+
type RequestHandle<M> = M extends RequestMiddlewareModule<infer E> ? HttpMiddleware<E> : never;
|
|
124
|
+
/**
|
|
125
|
+
* Splits `middleware/`'s modules by phase, in their order, keeping each module's own context type. A default
|
|
126
|
+
* export that neither helper made is refused.
|
|
127
|
+
*/
|
|
128
|
+
export declare function collectMiddleware<const Modules extends readonly ProjectMiddleware<never, never>[]>(modules: Modules): {
|
|
129
|
+
middleware: OperationHandle<Modules[number]>[];
|
|
130
|
+
requestMiddleware: RequestHandle<Modules[number]>[];
|
|
131
|
+
};
|
|
132
|
+
/** Applies the project's operation middleware to its base, before any route binds to it. */
|
|
133
|
+
export declare function useProjectMiddleware<E, C>(base: ApplicationBuilder<E, C, Record<never, never>>, middleware: readonly OperationMiddleware<C>[]): ApplicationBuilder<E, C, Record<never, never>>;
|
|
134
|
+
/**
|
|
135
|
+
* Refuses an application whose operations do not all run the project's middleware, as a route bound to an
|
|
136
|
+
* earlier base would: its policy would silently be skipped.
|
|
137
|
+
*/
|
|
138
|
+
export declare function checkProjectPipeline<E, C, BC, O extends Record<string, OperationShape>>(base: ApplicationBuilder<E, BC, Record<never, never>>, app: AppManifest<E, C, O>): AppManifest<E, C, O>;
|
|
139
|
+
export type { ToolMcpName, ToolName };
|