Overview
Model Context Protocol (MCP) is a standardized protocol for AI agents to interact with external tools and services. Nanobot’s MCP integration:- Connects to MCP servers via stdio, SSE, or HTTP transports
- Wraps MCP tools as native nanobot tools
- Handles authentication and configuration
- Provides timeout and error handling
Configuration
MCP servers are configured in~/.nanobot/config.json:
Transport Types
stdio (Standard Input/Output)
Runs an MCP server as a subprocess and communicates via stdin/stdout.- Local MCP server processes
- Node.js packages (via
npx) - Python modules
- Binary executables
command is specified without type, stdio is assumed.
SSE (Server-Sent Events)
Connects to an MCP server over HTTP using Server-Sent Events for streaming.- Remote MCP servers
- Cloud-hosted tools
- Services requiring authentication
/sse automatically use SSE transport.
streamableHttp (Streamable HTTP)
Connects to an MCP server over HTTP with bidirectional streaming.- REST-style MCP servers
- APIs with custom headers
- Services requiring special authentication
/sse automatically use streamableHttp transport.
Tool Naming
MCP tools are prefixed with the server name to avoid conflicts: MCP Server:filesystemMCP Tool:
read_fileNanobot Tool:
mcp_filesystem_read_file
This allows multiple MCP servers to provide tools with the same name.
Tool Schema
MCPToolWrapper Properties
- name:
mcp_{server_name}_{tool_name} - description: From MCP tool definition
- parameters: JSON Schema from
inputSchema - execute: Async method calling MCP server
Example Tool
Given this MCP tool definition:Usage Example
Once configured, agents can use MCP tools like any other tool:- Routes the call to the correct MCP server
- Sends the request with proper formatting
- Waits for the response (with timeout)
- Returns the result as a string
Timeout Handling
Each tool call has a configurable timeout:Connection Lifecycle
Error Handling
Connection Failed
Tool Timeout
tool_timeout or optimize the server.
Invalid Response
Unknown Transport
stdio, sse, or streamableHttp.
Response Format
MCP tools can return multiple content blocks:Authentication
Headers
Pass authentication headers in the configuration:Environment Variables
Pass environment variables to stdio servers:Best Practices
Server Naming
Use descriptive, unique names: ✅ Good:Tool Timeouts
Set appropriate timeouts based on expected response times:- Fast APIs: 10-30 seconds
- Database queries: 30-60 seconds
- Long-running operations: 60-300 seconds
Error Handling
Check logs for connection issues:Environment Variables
Store secrets in environment variables, not config files:export API_KEY=your-secret-key
Available MCP Servers
Popular MCP servers:- @modelcontextprotocol/server-filesystem - File operations
- @modelcontextprotocol/server-github - GitHub API
- @modelcontextprotocol/server-postgres - PostgreSQL queries
- @modelcontextprotocol/server-brave-search - Brave Search API
- @modelcontextprotocol/server-google-maps - Google Maps API
Implementation
Seenanobot/agent/tools/mcp.py for the implementation:
- MCPToolWrapper: line 14
- connect_mcp_servers: line 56
Related
- Tool Registry - Tool registration system
- Configuration - Configuring MCP servers
- MCP Protocol - Official MCP documentation