Model Context Protocol Integration
AgentOS includes a Model Context Protocol (MCP) client that allows agents to connect to external MCP servers and use their tools. MCP provides a standardized way to extend LLM capabilities with external data sources, APIs, and services.Overview
Implemented insrc/mcp-client.ts:1, the MCP integration provides:
- Stdio and SSE transports for connecting to MCP servers
- Tool discovery via the
tools/listRPC method - Tool invocation with automatic request/response handling
- Connection management with automatic cleanup
- MCP server mode - Expose AgentOS functions as MCP tools
What is MCP?
Model Context Protocol is a standard for connecting AI assistants to external tools and data sources. An MCP server exposes:- Tools - Functions the LLM can call
- Resources - Data sources the LLM can read
- Prompts - Pre-built prompt templates
Available Integrations
Fromworkspace/source/integrations/, AgentOS includes 25+ pre-configured MCP integrations:
GitHub
Repository management, PRs, issues
GitLab
Project management, pipelines, merge requests
Slack
Send messages, read channels
Discord
Bot integration, channel management
Jira
Issue tracking, project management
Linear
Issue tracking, roadmap planning
Notion
Knowledge base, database queries
Google Drive
File access, document management
Gmail
Email sending, inbox reading
Google Calendar
Event creation, schedule management
AWS
S3, EC2, Lambda management
Azure
Azure resource management
GCP
Google Cloud operations
PostgreSQL
Database queries, schema inspection
MongoDB
Document queries, collection management
Redis
Cache operations, pub/sub
Elasticsearch
Search, indexing, analytics
SQLite
Local database access
Sentry
Error tracking, issue management
Dropbox
File storage, sharing
Brave Search
Web search API
Exa Search
Semantic search
Bitbucket
Repository management
Microsoft Teams
Chat, channel management
Todoist
Task management
Connecting to an MCP Server
Connect via Stdio
For MCP servers that run as local processes:From
src/mcp-client.ts:138-163, this:- Validates the command for security
- Spawns the process with stripped environment variables
- Parses stdout for JSON-RPC messages
- Calls
initializeto negotiate capabilities - Calls
tools/listto discover available tools
Connect via SSE
For MCP servers that expose HTTP endpoints:Note: SSE transport is defined but not fully implemented in the current version.
Calling MCP Tools
src/mcp-client.ts:277-304, the client:
- Validates the server connection exists
- Checks the tool is available
- Sends
tools/callRPC to the MCP server - Logs the invocation to security audit
- Returns the result
Managing Connections
List Active Connections
src/mcp-client.ts:313-325, this returns:
- Connection ID
- Server name
- Transport type
- Tool count
- Connection timestamp
- Uptime in milliseconds
Disconnect from a Server
src/mcp-client.ts:212-244, this:
- Terminates the child process (SIGTERM)
- Removes the connection from the map
- Deletes state storage
- Rejects all pending RPC requests
MCP Server Mode
Expose AgentOS functions as MCP tools to external clients:Start the MCP server
src/mcp-client.ts:328-433, this:- Registers a handler function for MCP JSON-RPC requests
- Handles
initialize,tools/list, andtools/callmethods - Maps tool calls to AgentOS trigger invocations
- Exposes an HTTP endpoint at
/mcp/rpc
Real-World Example: GitHub Integration
JSON-RPC Implementation
Fromsrc/mcp-client.ts:60-99, the client implements JSON-RPC 2.0:
src/mcp-client.ts:101-109).
Security
Command Validation
Command Validation
From
src/mcp-client.ts:140, all MCP commands are validated with validateMcpCommand() to prevent command injection.Environment Stripping
Environment Stripping
Child processes run with stripped environment variables (
stripSecretsFromEnv()) to prevent credential leakage.Authentication Required
Authentication Required
All MCP endpoints require authentication via
requireAuth() (see src/mcp-client.ts:118).Audit Logging
Audit Logging
All MCP operations are logged to the security audit trail:
mcp_connect- Connection establishedmcp_disconnect- Connection closedmcp_tool_call- Tool invocation
HTTP API Endpoints
CLI Commands
From the README:MCP Protocol Specification
AgentOS implements MCP protocol version2024-11-05 with:
- Initialize:
{ protocolVersion, capabilities, clientInfo } - Tools/List: Returns array of
{ name, description, inputSchema } - Tools/Call:
{ name, arguments }→{ content: [...] }
Best Practices
One Connection per Integration
Don’t create multiple connections to the same MCP server
Handle Connection Failures
MCP processes can crash. Monitor and reconnect as needed
Namespace Tools
Tools are automatically namespaced as
mcp_{server}_{tool}Clean Up Connections
Disconnect when done to free resources
Troubleshooting
Connection timeout
Connection timeout
The MCP server process may not be starting. Check that the command and args are correct, and that required packages are installed.
Tool not found
Tool not found
Use
mcp::list_tools to see what tools are actually available. Tool names must match exactly.RPC timeout
RPC timeout
The MCP server isn’t responding. Check if the process is still running and hasn’t crashed.
Environment variables missing
Environment variables missing
Many MCP servers need API tokens. Pass them via args or ensure they’re in the environment before starting AgentOS.
Related Features
- A2A Protocol - Connect AgentOS instances together
- SkillKit - Alternative to MCP for extending agent capabilities
- Tools - Built-in AgentOS tools