DocsBuilding ToolsCreating a New Tool

Creating a New Tool

Use the Starter Kit

We strongly recommend using our Toolserver Starter repository. It has everything you need to create, run, and deploy an MCP server with optional token gating.

  1. Clone the Starter

    git clone https://github.com/<your-organization>/toolserver-starter.git
    cd toolserver-starter
    npm install
  2. Choose Your Entry Point

    • src/index.ts: A simple, open-access example (“echo” service).
    • src/index-gated.ts: A token-gated variant that checks if the caller holds a minimum token balance before serving requests.
  3. Run Locally

    npx tsx src/index.ts

    or

    npx tsx src/index-gated.ts

    Then open another terminal:

    npx @wong2/mcp-cli --sse http://localhost:3000/sse

    You’ll see the service is discoverable via MCP.

  4. Set Environment Variables (for token gating)

    • RPC_URL: Your chain’s RPC endpoint (e.g., Base, Sepolia, or mainnet).
    • STRAWBERRY_NETWORK_ID: Numeric chain ID.
    • LOCALHOST_TOKEN: Address of the ERC-20 token that gates usage.

Expand the Example

From here, you can add multiple tools under one server, or create more sophisticated routes in your src/index(-gated).ts file. For instance, you might add an image-processing API that accepts a base64 string and returns the processed image.

Key Steps:

  • Edit server.setRequestHandler(ListToolsRequestSchema, ...) to list new tools.
  • Implement your logic in server.setRequestHandler(CallToolRequestSchema, ...) for each tool.
  • If you need a more advanced gating model (pay-per-call), see Advanced Topics → Metered Billing.