Build Model Context Protocol (MCP) servers to extend OpenClaw with custom tools and integrations. Use when creating new skills, connecting external APIs, or building agent-to-agent protocols.
Build Model Context Protocol (MCP) servers to extend OpenClaw with custom tools and integrations.
Create a new MCP server:
npx @anthropic-ai/mcp init my-skill
cd my-skill
npm install
Tools are functions that the AI can call:
server.tool("search_web", {
query: z.string()
}, async ({ query }) => {
const results = await search(query);
return { content: [{ type: "text", text: results }] };
});
Resources provide data to the AI:
server.resource("docs", "docs://{path}", async (uri, { path }) => {
const content = await readFile(path);
return { contents: [{ uri: uri.href, mimeType: "text/markdown", text: content }] };
});
server.tool("get_weather", {
location: z.string(),
units: z.enum(["celsius", "fahrenheit"]).default("celsius")
}, async ({ location, units }) => {
const weather = await fetchWeather(location, units);
return {
content: [{
type: "text",
text: `Weather in ${location}: ${weather.temperature}°${units === 'celsius' ? 'C' : 'F'}, ${weather.condition}`
}]
};
});
server.resource("config", "config://app", async (uri) => {
const config = await readConfig();
return {
contents: [{
uri: uri.href,
mimeType: "application/json",
text: JSON.stringify(config, null, 2)
}]
};
});
mcp devnpm run buildopenclaw config set skills.entries.my-skill.enabled true