MCP Integration
What is MCP?
Model Context Protocol (MCP) is Anthropic's open standard for connecting AI models to external tools, data sources, and services.
Why MCP?
| Benefit | Description |
|---|
| Standardized | One protocol for all tools |
| Ecosystem | Growing library of servers |
| Type-safe | Validated schemas |
| Composable | Mix and match servers |
Architecture
┌─────────────────────────────────────────────────────────────────────┐
│ MCP IN VIBE AI │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ VIBE AGENT │
│ ┌───────────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ AgentRunner │ │
│ │ │ │ │
│ │ ▼ │ │
│ │ ┌─────────────┐ │ │
│ │ │ToolManager │ │ │
│ │ └─────────────┘ │ │
│ │ │ │ │
│ │ ├─────────────────┬─────────────────┐ │ │
│ │ ▼ ▼ ▼ │ │
│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │
│ │ │ Native │ │ MCP │ │Composio │ │ │
│ │ │ Tools │ │Executor │ │ Handler │ │ │
│ │ └─────────┘ └─────────┘ └─────────┘ │ │
│ │ │ │ │
│ └─────────────────────────┼──────────────────────────────────────┘ │
│ │ │
│ MCP SERVERS ▼ │
│ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │
│ │Filesystem│ │ GitHub │ │ Slack │ │ Custom │ │
│ │ Server │ │ Server │ │ Server │ │ Server │ │
│ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────┘
Configuration
Adding MCP Servers
# Agent MCP configuration
mcp_servers:
# Filesystem access
- name: "filesystem"
type: "stdio"
command: "npx"
args: ["-y", "@modelcontextprotocol/server-filesystem", "/allowed/path"]
# GitHub integration
- name: "github"
type: "stdio"
command: "npx"
args: ["-y", "@modelcontextprotocol/server-github"]
env:
GITHUB_TOKEN: "${GITHUB_TOKEN}"
# Slack integration
- name: "slack"
type: "stdio"
command: "npx"
args: ["-y", "@modelcontextprotocol/server-slack"]
env:
SLACK_BOT_TOKEN: "${SLACK_BOT_TOKEN}"
# Custom server (SSE)
- name: "custom"
type: "sse"
url: "https://my-mcp-server.com/sse"
headers:
Authorization: "Bearer ${CUSTOM_TOKEN}"
Server Types
| Type | Protocol | Use Case |
|---|
stdio | Standard I/O | Local processes |
sse | Server-Sent Events | Remote servers |
http | HTTP | REST APIs |
Available Servers
Official Servers
| Server | Description | Tools |
|---|
server-filesystem | File operations | read, write, list |
server-github | GitHub API | repos, issues, PRs |
server-slack | Slack messaging | send, read, react |
server-google-drive | Google Drive | upload, download |
server-postgres | PostgreSQL | query, execute |
server-memory | KV store | get, set, delete |
Community Servers
| Server | Description |
|---|
server-brave-search | Brave search API |
server-puppeteer | Browser automation |
server-sqlite | SQLite database |
server-fetch | HTTP requests |
Creating Custom MCP Server
Server Template
# my_mcp_server.py
from mcp.server import Server
from mcp.types import Tool, TextContent
app = Server("my-server")
@app.list_tools()
async def list_tools():
return [
Tool(
name="my_tool",
description="Does something useful",
inputSchema={
"type": "object",
"properties": {
"input": {"type": "string"}
},
"required": ["input"]
}
)
]
@app.call_tool()
async def call_tool(name: str, arguments: dict):
if name == "my_tool":
result = process(arguments["input"])
return [TextContent(type="text", text=result)]
raise ValueError(f"Unknown tool: {name}")
if __name__ == "__main__":
import asyncio
asyncio.run(app.run())
Running Custom Server
# In VIBE AI agent config
mcp_servers:
- name: "my_server"
type: "stdio"
command: "python"
args: ["my_mcp_server.py"]
Tool Discovery
Automatic Discovery
When MCP servers connect, their tools are automatically discovered:
# VIBE AI automatically discovers tools
async def discover_mcp_tools(server_config):
connection = await connect_mcp(server_config)
# List available tools
tools = await connection.list_tools()
# Convert to VIBE tool format
for tool in tools:
vibe_tool = convert_mcp_to_vibe(tool)
tool_manager.register(vibe_tool)
Tool Schema Conversion
# MCP schema
{
"name": "read_file",
"description": "Read file contents",
"inputSchema": {
"type": "object",
"properties": {
"path": {"type": "string"}
}
}
}
# Converted to VIBE OpenAPI schema
{
"type": "function",
"function": {
"name": "mcp_filesystem_read_file",
"description": "Read file contents",
"parameters": {
"type": "object",
"properties": {
"path": {"type": "string"}
}
}
}
}
Best Practices
Security
mcp_servers:
- name: "filesystem"
type: "stdio"
command: "npx"
args: [
"-y",
"@modelcontextprotocol/server-filesystem",
"/allowed/path" # Restrict to specific directory
]
# Additional security
security:
sandbox: true
timeout: 30
max_memory: "256MB"
Error Handling
async def call_mcp_tool(server: str, tool: str, args: dict):
try:
result = await mcp_executor.call(server, tool, args)
return ToolResult.success(result)
except MCPConnectionError:
return ToolResult.fail("MCP server unavailable")
except MCPTimeoutError:
return ToolResult.fail("Tool execution timed out")
except MCPValidationError as e:
return ToolResult.fail(f"Invalid arguments: {e}")
Performance
mcp_settings:
# Connection pooling
connection_pool_size: 5
# Caching
cache_tool_schemas: true
cache_ttl: 3600
# Timeouts
connection_timeout: 10
execution_timeout: 30
Resources
Next: DeFi Integrations →