defineTool and defineAction

Tool options, ToolContext, and Result types.

defineTool

defineTool({
  name?: string;
  description: string;
  input?: Schema;
  output?: Schema;
  connect?: string[];
  resources?: string[];
  visibility?: ("model" | "app")[];
  annotations?: {
    readOnlyHint?: boolean;
    destructiveHint?: boolean;
    idempotentHint?: boolean;
    openWorldHint?: boolean;
  };
  confirm?: (input, ctx) => ConfirmResult | string;
  html?: string;
  execute: (input, ctx) => Promise<TOutput | Result<TOutput>> | TOutput | Result<TOutput>;
});

Happy-path fields: description, input, execute.

confirm sets destructiveHint: true unless you override annotations.

defineAction

Same config as defineTool, but:

  • kind: "action"
  • visibility: ["app"]

result()

result(data, text): Result<T>
isResult(value): boolean

ResultOf

type ResultOf<T> =
  T extends DefinedTool<unknown, infer TOutput> ? TOutput : never;

ToolContext

FieldDescription
ask(schema, message?)MRTR continuation inside execute
inputRequired(spec)Raw MRTR escape hatch
inputResponsesAnswers from a prior ask
handle()Mint opaque handle id
authAuth context when wired
requestIncoming HTTP request or stdio envelope

ConfirmResult

type ConfirmResult = {
  message: string;
  preview?: unknown;
};

preview is included on the MRTR structuredContent so a View can render it. Text clients still see message.

Constants

Exported from bitmcp:

  • PROTOCOL_VERSION: 2026-07-28
  • RESOURCE_MIME_TYPE: text/html;profile=mcp-app
  • EXTENSION_ID: io.modelcontextprotocol/ui