Principle:0xKoda WireMCP MCP Tool Interface
| Knowledge Sources | |
|---|---|
| Domains | MCP, API_Design |
| Last Updated | 2026-10-28 00:00 GMT |
Overview
Technique for exposing callable tools to LLM clients via the Model Context Protocol, using a structured registration and response envelope pattern.
Description
The MCP tool interface is a contract for exposing named, schema-validated functions to LLM clients over the Model Context Protocol. Each tool is registered with a name, description, a Zod schema defining its parameters, and an async handler. The handler receives validated arguments and must return a content envelope: `{ content: [{ type: 'text', text: <payload> }] }`. On failure, the handler returns the same envelope with `isError: true`. This contract allows LLMs to discover available tools, validate inputs, and interpret outputs uniformly.
Usage
Use this principle when building an MCP server that exposes tools for LLM-driven analysis. Register each tool with a clear description (used for LLM tool selection) and a Zod schema (used for input validation), and always return the standard content envelope.
Theoretical Basis
Pseudo-code Logic:
# Abstract algorithm (NOT real implementation)
def register_tool(server, name, description, schema, handler):
server.tools[name] = {
"description": description,
"schema": schema, # JSON Schema for validation
"handler": handler # async (args) -> content envelope
}
def call_tool(server, name, args):
tool = server.tools[name]
validated = validate(args, tool["schema"])
try:
result = tool["handler"](validated)
return {"content": [{"type": "text", "text": result}]}
except Exception as e:
return {"content": [{"type": "text", "text": str(e)}], "isError": True}
The content envelope is the key abstraction: it normalizes heterogeneous tool outputs (text, images, structured data) into a uniform format the MCP client can route to the LLM.