mcpField
C
create-tool

create-tool

github.com/xmcp-devDevelopment053 installsUpdated 36w ago
Repository

About create-tool

create-tool is an interactive skill for creating xmcp tools. It gathers requirements and generates a TypeScript or TSX tool file with a schema, metadata, and handler as needed.

Key features

  1. 01Gather tool type and parameter requirements
  2. 02Generate Standard, HTML, or React handlers
  3. 03Set metadata and behavior annotations
  4. 04Create files under src/tools/
  5. 05Consult templates and a build checklist

Use cases

  1. 01Scaffold an xmcp data-query tool
  2. 02Create a tool with validated parameters
  3. 03Build a tool with an interactive widget
  4. 04Check generated files before building

MCP support

The skill generates tools for xmcp, including metadata and annotations used to describe tool behavior. It does not specify an MCP connection or server setup.

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/xmcp-dev/skills --skill create-tool

After installing, type/create-toolin Claude Code to confirm it loaded.

Bundled filesreferences/templates.md

Details

From the project README

Create xmcp Tool

You are helping the user create a new xmcp tool. Follow this interactive workflow.

Step 1: Gather Information

Before generating any code, ask the user these questions using AskUserQuestion:

  1. Tool name (if not provided as argument): What should the tool be named? (Use kebab-case)

  2. Handler type: Ask which handler type they need:

    • Standard - For data queries, calculations, API calls (returns string/JSON)
    • Template Literal (HTML) - For HTML widgets with external scripts
    • React Component - For interactive stateful widgets (.tsx file)
  3. Schema fields: What parameters should the tool accept? Ask for:

    • Parameter name
    • Type (string, number, boolean, enum, array, object)
    • Description
    • Whether it's optional
    • Any validation rules
  4. Annotations: Ask about behavior hints:

    • Is it read-only? (doesn't modify environment)
    • Is it destructive? (may delete or modify data)
    • Is it idempotent? (repeated calls have same effect)
    • Does it interact with external world? (openWorldHint)
  5. Widget support (if Template Literal or React): Ask if they need:

    • OpenAI tool invocation messages (invoking/invoked status)
    • Widget accessibility (widgetAccessible)
    • Widget-to-tool communication

Step 2: Generate the Tool

Create the tool file in src/tools/ with the appropriate extension:

  • .ts for Standard and Template Literal handlers
  • .tsx for React Component handlers
File Location
src/tools/{tool-name}.ts   # or .tsx for React

Tool Structure Reference

Every xmcp tool has three main exports:

// 1. Schema (optional) - Define parameters with Zod
export const schema = { /* ... */ };

// 2. Metadata (optional) - Tool configuration
export const metadata: ToolMetadata = { /* ... */ };

// 3. Handler (required) - Default export function
export default function handler(params) { /* ... */ }

Quick Reference

Essential Imports
import { z } from "zod";
import { type InferSchema, type ToolMetadata } from "xmcp";
Handler Types Summary
TypeUse CaseFile Extension
Standard (string)Simple queries, calculations.ts
Standard (async)API calls, database queries.ts
Template LiteralHTML widgets, iframes, scripts.ts
React ComponentInteractive stateful UIs.tsx
No ParametersTools that don't need input.ts
With Extra ArgsAuth/context-dependent tools.ts
Annotations Quick Reference
AnnotationUse When
readOnlyHint: trueTool doesn't modify environment
destructiveHint: trueTool may delete/modify data
idempotentHint: trueRepeated calls have same effect
openWorldHint: trueTool interacts with external world

Detailed Templates

For complete code templates including:

  • Schema patterns (simple, validation, enum, optional, object)
  • Metadata patterns (basic, annotations, OpenAI widgets, MCP Apps UI)
  • All handler type templates (A through G)
  • Return value patterns
  • Type imports reference

Read: references/templates.md


Checklist After Generation

  1. File created in src/tools/{tool-name}.ts (or .tsx)
  2. Schema uses .describe() for all parameters
  3. If using metadata, ensure it has descriptive name and description
  4. Appropriate annotations set based on tool behavior
  5. Handler matches the chosen type
  6. All imports are correct

Suggest running pnpm build to verify the tool compiles correctly.

Comments

Markdown supported