Overview
The MCP (Model Context Protocol) tool proxy connects to external MCP servers, discovers their tools, and wraps them as Grip tool instances. Supports stdio (subprocess) and HTTP/SSE transports with OAuth authentication.Installation
MCP support requires the optionalmcp dependency group:
Configuration
MCP servers are configured ingrip.toml under [tools.mcp_servers]:
Transport Types
Stdio Transport
Spawns a subprocess and communicates via stdin/stdout. Configuration:- Local MCP servers (Python, Node.js, etc.)
- Command-line tools wrapped as MCP servers
- Servers that don’t need network access
HTTP/SSE Transport
Connects to a remote MCP server via HTTP with Server-Sent Events. Configuration:sse— Server-Sent Events (default, most common)http— Streamable HTTP transport (newer)
- Cloud-hosted MCP servers
- Third-party MCP services (GitHub, Supabase, etc.)
- Shared team MCP servers
OAuth Authentication
For MCP servers that require OAuth (e.g. Supabase with dynamic client registration): Configuration:- Run
grip mcp login supabase(or use/mcpcommand in chat) - Browser opens for authorization
- User approves access
- Token stored in
~/.grip/tokens/supabase.json - Token auto-refreshes when expired
Tool Discovery
When Grip starts, the MCP manager:- Connects to all enabled MCP servers in parallel
- Calls
list_tools()on each server - Wraps discovered tools as Grip
MCPWrappedToolinstances - Registers them in the tool registry with
mcp_[server]_[tool]naming
search_repositories tool:
Tool Execution
When an agent calls an MCP tool:- Tool parameters are validated against the MCP tool’s input schema
- Parameters are passed to the MCP server via
call_tool() - MCP server executes the tool and returns content blocks
- Text content is extracted and returned to the agent
- Errors are caught and returned as error messages
asyncio.run_coroutine_threadsafe() to avoid deadlocks.
Example: Filesystem MCP Server
Install:mcp_filesystem_read_file— Read file contentsmcp_filesystem_write_file— Write to filemcp_filesystem_list_directory— List directory contentsmcp_filesystem_search_files— Search for files by pattern
Example: GitHub MCP Server
Configure:mcp_github_search_repositories— Search for reposmcp_github_get_file_contents— Read file from repomcp_github_create_issue— Open new issuemcp_github_create_pull_request— Create PR
Connection Status
Check MCP server connection status:Reconnection
MCP servers can be reconnected manually:- Updating OAuth tokens
- Changing server configuration
- Recovering from connection failures
Error Handling
MCP Package Not Installed
OAuth Login Required
Connection Timeout
Tool Execution Error
Best Practices
- Use stdio for local servers — faster and no network overhead
- Use SSE for remote servers — most compatible with existing MCP services
- Set appropriate timeouts for slow servers (default 30s)
- Store OAuth tokens securely — never commit to version control
- Test servers individually before enabling all
- Monitor connection status periodically to catch failures
- Use environment variables for API keys in stdio servers
Limitations
- No resource support — MCP resources not yet implemented
- No prompt support — MCP prompts not exposed to agents
- No sampling support — MCP sampling requests not implemented
- No progress updates — long-running MCP tools don’t report progress
- Single connection per server — no connection pooling
- No automatic reconnection — failed connections require manual intervention
Implementation
Defined ingrip/tools/mcp.py. Uses:
mcp.ClientSessionfor MCP protocol handlingmcp.client.stdio.stdio_clientfor subprocess transportmcp.client.sse.sse_clientfor Server-Sent Events transportmcp.client.streamable_http.streamablehttp_clientfor HTTP transportasyncio.run_coroutine_threadsafe()for cross-loop execution- OAuth token storage and refresh via
grip/security/token_store.py MCPManagerfor connection lifecycle management