Tools
defineTool, schemas, return data, result(), and CSP allowlists.
A tool is a server function exposed to the model through MCP.
import { z } from "zod";
import { defineTool } from "bitmcp";
export default defineTool({
description: "Get a forecast and show an interactive chart",
input: z.object({ city: z.string() }),
output: z.object({
city: z.string(),
summary: z.string(),
points: z.array(z.object({ t: z.string(), temp: z.number() })),
}),
async execute({ city }) {
return { city, summary: `Mild in ${city}`, points: [] };
},
});Return data
Returning an object produces:
structuredContentfor the View- Text for every host (generated summary or JSON)
Custom text:
import { result } from "bitmcp";
return result(data, `Forecast for ${city}: ${data.summary}`);Schemas
inputvalidates tool arguments (Zod or Standard Schema)outputvalidates the return value and types the View result
CSP allowlists
Default CSP is deny-all for iframe network access.
connect—connect-srcallowlist for fetch from the Viewresources— asset src allowlist for CDN scripts or styles
Visibility
Defaults to ["model", "app"]. Model-visible tools appear in tools/list. Use defineAction for app-only tools.
Rules
executeruns on the server only- Text is always produced
- Presence of
view.tsxattaches UI. Do not setresourceUrimanually executemust not returnundefined