$ ssh clawdbot.space --loading...
$ ssh clawdbot.space --loading...
Create custom Model Context Protocol servers to give your agent superpowers — APIs, databases, IoT, and more.
MCP (Model Context Protocol) servers let your OpenClaw agent interact with external services through standardized tools. Instead of prompt-hacking API calls, you build a clean server that exposes typed tools the agent can call reliably. This guide walks you through building your first MCP server from scratch.
MCP defines a JSON-RPC protocol for LLM-to-tool communication. Your agent discovers available tools, understands their parameters, and calls them with type safety.
Build servers in Python (FastMCP), TypeScript (MCP SDK), or any language that speaks JSON-RPC over stdio or HTTP.
Each MCP server handles one domain. Combine multiple servers: one for email, one for calendar, one for smart home.
Install FastMCP framework
pip install fastmcp
Create a minimal MCP server
# server.py
from fastmcp import FastMCP
mcp = FastMCP("weather")
@mcp.tool()
def get_weather(city: str) -> str:
"""Get current weather for a city."""
# Your API logic here
return f"Weather in {city}: 22°C, sunny"
if __name__ == "__main__":
mcp.run()Register in OpenClaw config
# openclaw.config.yaml
mcp_servers:
weather:
command: python
args: [server.py]Test the tool
openclaw mcp list weather get_weather --city Tokyo
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";
const server = new McpServer({ name: "weather", version: "1.0.0" });
server.tool("get_weather",
{ city: z.string().describe("City name") },
async ({ city }) => ({
content: [{ type: "text", text: `Weather in ${city}: 22°C` }]
})
);
const transport = new StdioServerTransport();
await server.connect(transport);Wrap REST APIs (GitHub, Jira, Slack) with typed tool definitions. Handle auth, pagination, rate limiting.
get_issues, create_pr, send_messageExpose read-only SQL queries. Always use parameterized queries. Never expose write access without approval.
query_customers, get_order_statusControl smart home devices via MQTT or HTTP. Include safety constraints (temperature limits, lock confirmations).
set_thermostat, toggle_lightsPDF parsing, image analysis, data transformation. Process files and return structured results.
parse_invoice, extract_table