@prunellejs/mcp 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/llms.txt +1 -1
- package/package.json +2 -2
- package/src/index.ts +7 -0
- package/src/rpc.ts +3 -0
package/llms.txt
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
- `token`: `string | { env: string } | { file: string } | (() => string | undefined | Promise<string | undefined>)` (relative `{ file }` paths resolve against the app root). `authenticate`: `(token, ctx) => boolean | object | string | number | null | undefined | Promise<...>` validates dynamic bearer tokens and populates `ctx.locals` (e.g. `ctx.locals.user`) for actions, guards, handlers, and resources; falsy return or thrown error answers `401` and counts against the failed-auth lockout. When both `token` and `authenticate` are set, both must pass. With neither configured (or a `token` shorter than 32 bytes), the endpoint returns `404` and a production start refuses (`openssl rand -hex 32` makes a static token); missing/invalid `Authorization: Bearer <token>` returns `401`, and a client past 10 failed attempts a minute gets `429` with `Retry-After` until the window passes, even with a valid token.
|
|
15
15
|
- A tool backed by an `action()` counts each call against that action's `rateLimit` (or `protect.rateLimit`), in a counter apart from the web form's, and answers an error result `Too many requests to <tool>: retry after N s`. `protect.honeypot` and `protect.minTime` do not apply: they guard a rendered form, and the bearer token is the machine client's proof.
|
|
16
16
|
- `tools`: `Record<string, McpTool>` — each entry either wraps an existing Prunelle `action` (`{ action, description, ... }`) or defines `{ schema?, handler(input, ctx), description, ... }`. Wrap with `mcpTool(...)` for strict `format`/`handler` inference.
|
|
17
|
-
- Per-tool options: `inputSchema`, `schemaRef` (references `options.schemas` to emit a compact stub in `tools/list` while keeping full server validation), `annotations` (`title`, `readOnlyHint`, `destructiveHint`, `idempotentHint`, `openWorldHint`), `format(output, input)`, `maxOutputChars`, `pruneEmpty`.
|
|
17
|
+
- Per-tool options: `inputSchema`, `schemaRef` (references `options.schemas` to emit a compact stub in `tools/list` while keeping full server validation; the named schema must be a Standard Schema, and a name missing from `schemas` or a plain JSON Schema on a tool with no `schema` of its own throws at start), `annotations` (`title`, `readOnlyHint`, `destructiveHint`, `idempotentHint`, `openWorldHint`), `format(output, input)`, `maxOutputChars`, `pruneEmpty`.
|
|
18
18
|
- `schemas`: shared schemas exposed on demand via auto-added `describe_schema` tool and `prunelle://schemas/<name>` resources.
|
|
19
19
|
- `resources`: `Record<uri, { name?, description?, mimeType?, read: string | ((ctx) => string | Promise<string>) }>`.
|
|
20
20
|
- Compact output & footprint options: `compactSchemas` (default `true`; pass `{ foldHomogeneousObjects: true }` to opt into folding homogeneous optional objects into `additionalProperties`), `pruneEmpty` (`false | 'nullish' | true`), `maxOutputChars`, `formatResult(output, toolName, input)`, `mapError(err)`, `budget` (default `{ maxToolBytes: 2048 }`; `strict: true` fails `prunelle check`; `false` disables).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prunellejs/mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Zero-dependency MCP plugin (JSON-only subset of Streamable HTTP, 2025-03-26) exposing Prunelle server actions as AI agent tools",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -21,6 +21,6 @@
|
|
|
21
21
|
"directory": "packages/plugin-mcp"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
|
-
"prunelle": "^0.
|
|
24
|
+
"prunelle": "^0.10.0"
|
|
25
25
|
}
|
|
26
26
|
}
|
package/src/index.ts
CHANGED
|
@@ -267,6 +267,13 @@ function buildCatalog(
|
|
|
267
267
|
|
|
268
268
|
for (const [name, def] of Object.entries(options.tools)) {
|
|
269
269
|
const rawSchema = isActionTool(def) ? def.action.schema : def.schema
|
|
270
|
+
if (def.schemaRef !== undefined && !sharedJsonSchemas.has(def.schemaRef)) {
|
|
271
|
+
const available = sharedJsonSchemas.size > 0 ? [...sharedJsonSchemas.keys()].join(', ') : 'none'
|
|
272
|
+
throw new Error(`prunelle: mcp tool "${name}" has schemaRef "${def.schemaRef}", which is not a key of \`schemas\` (available: ${available}): fix the name or add the schema.`)
|
|
273
|
+
}
|
|
274
|
+
if (rawSchema === undefined && def.schemaRef !== undefined && !sharedValidators.has(def.schemaRef)) {
|
|
275
|
+
throw new Error(`prunelle: mcp tool "${name}" has schemaRef "${def.schemaRef}", a plain JSON Schema the server cannot validate against: pass a Standard Schema (Zod, Valibot, ArkType) under \`schemas\`, or give the tool its own \`schema\`.`)
|
|
276
|
+
}
|
|
270
277
|
const schema = rawSchema ?? (def.schemaRef !== undefined ? sharedValidators.get(def.schemaRef) : undefined)
|
|
271
278
|
const handler = isActionTool(def)
|
|
272
279
|
? ((input: unknown, ctx: ActionContext) => def.action.handler(input as never, ctx))
|
package/src/rpc.ts
CHANGED
|
@@ -280,6 +280,9 @@ export function createRpcDispatcher(cfg: RpcDispatcherConfig) {
|
|
|
280
280
|
if (tool === undefined)
|
|
281
281
|
throw Object.assign(new Error(`Unknown tool: ${name}${availableNamesHint}`), { rpcCode: -32602 })
|
|
282
282
|
|
|
283
|
+
// `tools/list` advertises an object, so a number, a string or an array never reaches a handler.
|
|
284
|
+
if (args !== undefined && args !== null && (typeof args !== 'object' || Array.isArray(args)))
|
|
285
|
+
throw Object.assign(new Error(`Invalid arguments for ${name}: expected an object`), { rpcCode: -32602 })
|
|
283
286
|
let input: unknown = args ?? {}
|
|
284
287
|
// When backed by an action that already declares a schema, `tool.action(input)` runs
|
|
285
288
|
// `validateSchema` once inside `invokeActionCore`; re-validating here would double-run transforms/codecs.
|