UNPKG

run402-mcp

Version:

MCP server for Run402 — full-stack backend infrastructure for AI agents: Postgres, auth, storage, serverless functions and atomic deploys. Paid with x402/MPP. Includes $0.03 image generation.

119 lines • 5.78 kB
/** * MCP tools on a function's release entry (`functions.<name>.tools`). * * A function file or an Astro endpoint file declares its tools beside the * handler, as static literals: * * export const tool = { description: "…", input: { type: "object", … } }; * export const tools = { list_notes: { … }, add_note: { … } }; * * Deploy tooling reads the export by parsing, never by running it (the Node * extractor, `node/tool-declarations.ts`), and carries it in the release. The * gateway takes a function's tools only from its release entry: an omitted * `tools` means none, as with `triggers`. * * This module is the isomorphic half: the rules one entry obeys (shared by * the extractor and by the spec check for `tools` passed as data), the * refusal's shape, the error a deploy throws for it, and the slot the Node * entry point installs its source reader into. */ import { Run402DeployError } from "./errors.js"; import type { FunctionToolSpec } from "./namespaces/deploy.types.js"; /** Codes a tool declaration is refused with before any request, and by the gateway at plan with HTTP 422. */ export type McpToolErrorCode = "MCP_TOOL_NOT_STATIC" | "MCP_TOOL_SCHEMA_INVALID" | "MCP_TOOL_NAME_INVALID" | "MCP_TOOL_NAME_DUPLICATE" | "MCP_TOOL_ROUTE_ELSEWHERE" | "MCP_TOOL_PATH_UNSUPPORTED"; /** Why a tool declaration is refused, as data. */ export interface ToolDeclarationProblem { code: McpToolErrorCode; message: string; /** The source file as the caller named it; null for an inline source or for `tools` passed as data. */ file: string | null; /** 1-based line in `file`. Present only when it is exact. */ line?: number; /** Where in the export or the spec, e.g. `tools.add_note.input.type`. */ field_path: string; /** The tool's name, when the declaration got far enough to have one. */ tool?: string; } export declare const MCP_TOOL_DESCRIPTION_MAX = 1024; export declare const MCP_TOOL_TITLE_MAX = 128; /** Serialized size ceiling for one declaration (description plus schema). */ export declare const MCP_TOOL_DECLARATION_MAX_BYTES: number; /** MCP tool names: 1 to 128 of `A-Z a-z 0-9 _ - .`. */ export declare function isValidMcpToolName(name: string): boolean; type EntryProblem = Pick<ToolDeclarationProblem, "code" | "message" | "field_path">; export type FunctionToolEntryCheck = { ok: true; tool: FunctionToolSpec; } | { ok: false; problem: EntryProblem; }; /** * Split a tool path into its `{param}` names. A `{param}` stands for one whole * path segment; a wildcard, a rest segment, or a parameter that is only part * of a segment has no tool binding. */ export declare function toolPathParams(path: string): { ok: true; params: string[]; } | { ok: false; code: "MCP_TOOL_SCHEMA_INVALID" | "MCP_TOOL_PATH_UNSUPPORTED"; message: string; }; /** * Check one tool entry, already a plain value, against the rules every * carrier shares, and return it with its fields in a fixed order. * `pathParams` overrides the parameters read from `path` (an Astro endpoint's * path is its route, never a field of the declaration). */ export declare function checkFunctionToolEntry(value: unknown, fieldPath: string, opts?: { pathParams?: readonly string[]; }): FunctionToolEntryCheck; /** One group of tools and where it came from: a function of a spec, or a source file of a build. */ export interface ToolNameGroup { /** The function name or the file, as the refusal should name it. */ owner: string; tools: ReadonlyArray<Pick<FunctionToolSpec, "name">>; /** The name a tool with no `name` takes (a function file's single `tool`: the function name). */ defaultName?: string; } /** The first tool name two tools of one build share, with the two owners in the order given. */ export declare function findDuplicateToolName(groups: readonly ToolNameGroup[]): { name: string; owners: [string, string]; } | null; /** `src/pages/api/notes.ts:12`, `functions.replace.api.source:12`, or just the name when there is no exact line. */ export declare function toolProblemLocation(problem: Pick<ToolDeclarationProblem, "file" | "line">, fallback?: string): string | null; /** * The error a deploy throws for a refused tool declaration, before any * request: the gateway's code for the same condition, `resource` * `functions.<function>.tools[.<tool>]`, the file, line and field path under * `details`, and an `edit_request` next action. */ export declare function toolDeclarationError(problem: ToolDeclarationProblem, where: { functionName: string; sourceField?: string; functions?: string[]; }): Run402DeployError; /** What the installed reader is given: one function's entry source, as text. */ export interface FunctionToolLiftInput { functionName: string; source: string; /** The source's path on disk, when it has one. */ file: string | null; /** The spec field the source came from, e.g. `functions.replace.api.source`. */ sourceField: string; } /** Reads the tools a function's entry source declares; throws {@link Run402DeployError} on a refused declaration. */ export type FunctionToolLifter = (input: FunctionToolLiftInput) => FunctionToolSpec[]; /** * Install the reader `apply` calls for every function source it reads when * the entry names no `tools`. Reading a declaration means parsing JavaScript, * which is Node-only, so `@run402/sdk/node` installs it when it loads; with * none installed, `tools` is forwarded only when the caller passes it. */ export declare function installFunctionToolLifter(lifter: FunctionToolLifter | null): void; export declare function installedFunctionToolLifter(): FunctionToolLifter | null; export {}; //# sourceMappingURL=function-tools.d.ts.map