OpenClaw MCP Server Guide: Connect Any API in Under 10 Minutes
The Model Context Protocol (MCP) is the universal bridge between LLMs and your data. In OpenClaw, MCP servers are the primary way we give agents "hands" to interact with external APIs, databases, and local tools.
I've connected dozens of services to my personal fleetβfrom complex CRM APIs to simple local weather sensors. This guide shows you the fastest path to getting a new API connected and functional within your OpenClaw environment.
What is an MCP Server?
An MCP server is a small application that exposes "tools" to an MCP-compatible client (like OpenClaw). It handles the authentication and low-level API calls, presenting a standardized interface that the agent can understand and use.
Instead of writing custom logic for every agent, you write one MCP server (or use an existing one) and every agent in your fleet immediately knows how to use it.
Prerequisites
Before we start, ensure you have:
- OpenClaw installed and configured
- Node.js (v18+) or Python (3.10+) installed
- An API key for the service you want to connect
Step 1: Choose Your Server Type
You have three options for connecting an API:
- Pre-built Servers: Check the MCP Server Directory first. Most common APIs (GitHub, Google Maps, Slack) already have servers.
- MCPorter: Use OpenClaw's
mcportertool to bridge existing MCP servers. - Custom Implementation: Write a simple server in TypeScript or Python (takes ~5 minutes).
Step 2: Configuration via OpenClaw
The easiest way to add an MCP server to OpenClaw is through the openclaw.json configuration. OpenClaw supports both stdio and sse (HTTP) transports.
Example: Adding the Brave Search MCP Server
Edit your ~/.openclaw/openclaw.json (or the one in your workspace):
{
"mcp": {
"servers": {
"brave-search": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-brave-search"],
"env": {
"BRAVE_API_KEY": "your_key_here"
}
}
}
}
}Step 3: Verification
After updating the config, restart your OpenClaw gateway:
bash
openclaw gateway restart
Verify the server is active by asking your agent to list its tools:
bash
# In your chat interface
"What tools do you have available from the brave-search server?"
Step 4: Writing a Custom MCP Server (Fast Track)
If a server doesn't exist, use the Model Context Protocol SDK. Here's a minimal TypeScript implementation using the @modelcontextprotocol/sdk.
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
const server = new Server({
name: "my-custom-api",
version: "1.0.0",
}, {
capabilities: { tools: {} },
});
server.setRequestHandler(ListToolsRequestSchema, async () => ({
tools: [{
name: "fetch_data",
description: "Fetch data from my internal API",
inputSchema: {
type: "object",
properties: { id: { type: "string" } },
required: ["id"],
},
}],
}));
server.setRequestHandler(CallToolRequestSchema, async (request) => {
if (request.params.name === "fetch_data") {
const { id } = request.params.arguments as { id: string };
// Call your API here
return { content: [{ type: "text", text: `Data for ${id}: ...` }] };
}
throw new Error("Tool not found");
});
const transport = new StdioServerTransport();
await server.connect(transport);Advanced: Using mcporter for Ad-hoc Servers
OpenClaw includes mcporter, a skill designed to manage and call MCP servers dynamically without permanent configuration changes. This is perfect for testing.
bash
# Tell OpenClaw to use mcporter to call a remote server
openclaw exec "mcporter call --url http://localhost:3001/sse --tool get_balance --args '{\"user\": \"jkw\"}'"
Troubleshooting Common Issues
- Environment Variables: Ensure API keys are passed in the
envblock ofopenclaw.json, not just your shell. - Pathing: Use absolute paths for
commandifnpxorpythonisn't on the system path used by the daemon. - Timeouts: For long-running API calls, adjust the
timeoutMsin your server configuration.
FAQ
Q: Can I use Python for MCP servers?
A: Yes! The MCP Python SDK (mcp on PyPI) is first-class and works perfectly with OpenClaw's stdio transport.
Q: How many servers can I connect?
A: There is no hard limit, but keep an eye on total tool counts. If you have 100+ tools, agent performance may degrade. Use routing or sub-agents for large toolsets.
Q: Does OpenClaw support SSE/HTTP MCP?
A: Yes. In openclaw.json, use the url field instead of command/args for SSE transports.
Q: Is it secure to pass API keys in JSON?
A: openclaw.json should be chmod 600. For production, I recommend using the 1Password skill to inject secrets at runtime.
Q: How do I debug stdio servers?
A: Use openclaw gateway logs -f to see stderr from your MCP servers. Log to stderr in your code to avoid corrupting the stdio protocol.
Continue Learning
Ready to automate?
Connecting an API is just the first step. Learn how to combine MCP servers with AgentSkills to build fully autonomous workflows.
Ready to build?
Get the OpenClaw Starter Kit β config templates, 5 production-ready skills, deployment checklist. Go from zero to running in under an hour.
$14 $6.99
Get the Starter Kit βAlso in the OpenClaw store
Get the free OpenClaw quickstart guide
Step-by-step setup. Plain English. No jargon.