MCP Builder Skill
Build Model Context Protocol (MCP) servers to extend OpenClaw with custom tools and integrations.
When to Use
- •Creating new skills for OpenClaw
- •Connecting external APIs and services
- •Building agent-to-agent communication protocols
- •Extending AI capabilities with custom tools
Quick Start
Create a new MCP server:
bash
npx @anthropic-ai/mcp init my-skill cd my-skill npm install
Core Concepts
Tools
Tools are functions that the AI can call:
typescript
server.tool("search_web", {
query: z.string()
}, async ({ query }) => {
const results = await search(query);
return { content: [{ type: "text", text: results }] };
});
Resources
Resources provide data to the AI:
typescript
server.resource("docs", "docs://{path}", async (uri, { path }) => {
const content = await readFile(path);
return { contents: [{ uri: uri.href, mimeType: "text/markdown", text: content }] };
});
Best Practices
- •Always validate inputs with Zod schemas
- •Return structured, parseable responses
- •Handle errors gracefully
- •Document all tools and resources
- •Test thoroughly before deployment
Examples
Weather API Tool
typescript
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}`
}]
};
});
File Resource
typescript
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)
}]
};
});
Deployment
- •Test locally with
mcp dev - •Build for production:
npm run build - •Deploy to your infrastructure
- •Configure in OpenClaw:
openclaw config set skills.entries.my-skill.enabled true