API Reference
This page lists the public APIs used in typical Chapplin projects.
defineTool
Section titled “defineTool”import { defineTool } from "chapplin";
export const tool = defineTool({ name: "my_tool", config: { description: "...", inputSchema: { ... }, outputSchema: { ... }, annotations: { ... }, }, async handler(args, extra) { return { content: [{ type: "text", text: "..." }], structuredContent: { ... }, _meta: { ... }, }; },});inputSchema/outputSchemause Zod object shapes_metais UI-only data (not sent to the LLM)
defineApp
Section titled “defineApp”import { defineApp } from "chapplin";
export const app = defineApp<typeof tool>({ config: { appInfo: { name: "my-app", version: "1.0.0" }, capabilities: {}, options: {}, }, meta: { prefersBorder: true, }, ui: (props) => <div />,});defineAppmust be used asdefineApp<typeof tool>configis passed to the MCP App constructor
defineResource
Section titled “defineResource”import { defineResource } from "chapplin";
export const resource = defineResource({ name: "app-config", config: { uri: "config://app/settings", mimeType: "application/json", }, async handler(uri) { return { contents: [{ uri: uri.href, text: "{}" }], }; },});definePrompt
Section titled “definePrompt”import { definePrompt } from "chapplin";
export const prompt = definePrompt({ name: "code-review", config: { description: "...", argsSchema: { ... }, }, handler(args) { return { messages: [{ role: "user", content: { type: "text", text: "..." } }], }; },});Vite Plugin
Section titled “Vite Plugin”import { chapplin } from "chapplin/vite";
chapplin({ entry: "./src/index.ts", target: "react", // react | preact | solid | hono toolsDir: "tools", resourcesDir: "resources", promptsDir: "prompts", tsconfigPath: "tsconfig.json",});Virtual Module: chapplin:register
Section titled “Virtual Module: chapplin:register”import { register } from "chapplin:register";
register(server);register(server) registers all collected tools/resources/prompts (and MCP Apps) onto the given MCP server.
Runtime Helpers
Section titled “Runtime Helpers”chapplin/reactchapplin/preactchapplin/solidchapplin/hono
useApp
Section titled “useApp”It provides access to the MCP App context.
Check out the example usage in model-context-protocol/ext-apps.
// Example usage of useApp from chapplin/reactimport { useApp } from "chapplin/react";
const app = useApp();const openUrl = (url: string) => app.openLink({ url });