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:

  • structuredContent for 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

  • input validates tool arguments (Zod or Standard Schema)
  • output validates the return value and types the View result

CSP allowlists

Default CSP is deny-all for iframe network access.

  • connectconnect-src allowlist for fetch from the View
  • resources — 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

  • execute runs on the server only
  • Text is always produced
  • Presence of view.tsx attaches UI. Do not set resourceUri manually
  • execute must not return undefined