MCP Protocol Introduction
Model Context Protocol (MCP) is an open protocol for connecting AI models with external tools and data sources. OpenClaw acts as an MCP Client, connecting to multiple MCP Servers so the AI assistant can access databases, file systems, APIs, and more.
View MCP Connections
openclaw mcp list
Add MCP Servers
Stdio Transport
{
"mcp": {
"servers": {
"filesystem": {
"transport": "stdio",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/allowed/dir"]
}
}
}
}
SSE Transport
{
"mcp": {
"servers": {
"remote-tools": {
"transport": "sse",
"url": "https://mcp-server.example.com/sse",
"headers": {
"Authorization": "Bearer {{MCP_SERVER_TOKEN}}"
}
}
}
}
}
Common MCP Server Configurations
PostgreSQL Database
{
"mcp": {
"servers": {
"postgres": {
"transport": "stdio",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-postgres"],
"env": { "POSTGRES_URL": "{{DATABASE_URL}}" }
}
}
}
}
GitHub
{
"mcp": {
"servers": {
"github": {
"transport": "stdio",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": { "GITHUB_TOKEN": "{{GITHUB_TOKEN}}" }
}
}
}
}
Web Search (Brave)
{
"mcp": {
"servers": {
"brave-search": {
"transport": "stdio",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-brave-search"],
"env": { "BRAVE_API_KEY": "{{BRAVE_API_KEY}}" }
}
}
}
}
Assign MCP Tools to Channels
{
"channels": {
"telegram-main": {
"mcpServers": ["filesystem", "brave-search"],
"tools": ["mcp:filesystem:read_file", "mcp:brave-search:search"]
}
}
}
Security Configuration
{
"mcp": {
"security": {
"requireApproval": ["write_file", "delete_file", "execute_query"],
"blockedTools": ["drop_table"],
"maxCallsPerMinute": 30,
"timeout": 10000
}
}
}
Tools in the requireApproval list prompt for user confirmation before execution.
Develop Custom MCP Servers
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
const server = new Server({
name: "my-tools",
version: "1.0.0"
}, {
capabilities: { tools: {} }
});
server.setRequestHandler("tools/list", async () => ({
tools: [{
name: "get_time",
description: "Get the current time",
inputSchema: { type: "object", properties: {} }
}]
}));
server.setRequestHandler("tools/call", async (request) => {
if (request.params.name === "get_time") {
return { content: [{ type: "text", text: new Date().toISOString() }] };
}
});
const transport = new StdioServerTransport();
await server.connect(transport);
Summary
MCP provides a standardized tool extension mechanism for OpenClaw. By connecting various MCP Servers, the AI assistant can access file systems, databases, external APIs, and more -- truly achieving the powerful combination of "AI + Tools."