MCP JavaScript API

Everything the MCP extension adds to pb_hooks and page code, generated from the TypeScript declarations it ships (your app's types.d.ts has the same, so your editor knows them). For how to use it, see its docs; for Go, the Go API.

$mcp

The app's MCP server (/mcp): tools map to the app's own REST endpoints.

$mcp.addEndpoint({ name: "blog_publish_post", description: "Publish a draft post.", method: "POST",
  path: "/api/blog/posts/{id}/publish", inputSchema: { type: "object", required: ["id"], properties: { id: { type: "string" } } } })

$mcp.addEndpoint()

$mcp.addEndpoint(def: mcp.Endpoint): void

Declares a tool, at the top level of a pb_hooks file. Adding the same name again replaces it.

Parameter Type
def mcp.Endpoint

$mcp.pathValue()

$mcp.pathValue(value: string): string

Escapes a value for one {name} part of a tool's path.

Parameter Type
value string

Returns string.

$mcp.instructions()

$mcp.instructions(text: string): void

Adds text to the server's instructions for the model.

Parameter Type
text string

$mcp.tools()

$mcp.tools(): string[]

The names of every tool.

Returns string[].

Types

mcp.ToolRequest

The REST request a tool makes; a request transform may change it.

Member Type
method string
path string
query? { [key: string]: string }
body? any
headers? { [key: string]: string }

mcp.Endpoint

One MCP tool, mapped to one REST endpoint.

Member Type
name string Tool name, e.g. "blog_publish_post".
title? string
description string
method string HTTP method of the endpoint.
path string Endpoint path; {name} parts come from the tool's arguments, the rest go to the JSON body.
inputSchema? { [key: string]: any } JSON Schema of the tool's arguments.
outputSchema? { [key: string]: any } JSON Schema of the tool's result.
title? string
readOnlyHint? boolean
destructiveHint? boolean
idempotentHint? boolean
openWorldHint? boolean
request? (c: { args: { [key: string]: any }; auth: core.Record | null; request: ToolRequest }) => ToolRequest | void Shapes the request (it can't change who the call runs as). Return nothing to keep the default.
response? (r: { args: { [key: string]: any }; auth: core.Record | null; status: number; headers: { [key: string]: string }; body: string; json: any; truncated: boolean; }) => any Shapes the result the model sees; throw for an error the model can read.