Model Context Protocol (MCP)
Overview
Model Context Protocol (MCP) is a mechanism that allows Faheem Code to communicate with external tool servers. These servers can provide additional functionality to the agent, such as specialized data processing, external API access, or custom tools. MCP is based on the open standard defined at modelcontextprotocol.io.
Supported MCPs
Faheem Code supports the following MCP transport protocols:
How MCP works
When Faheem Code starts, it:
- Reads the MCP configuration.
- Connects to any configured SSE and SHTTP servers.
- Starts any configured stdio servers.
- Registers the tools provided by these servers with the agent.
The agent can then use these tools just like any built-in tool. When the agent calls an MCP tool:
- Faheem Code routes the call to the appropriate MCP server.
- The server processes the request and returns a response.
- Faheem Code converts the response to an observation and presents it to the agent.
Configuration
MCP configuration can be defined in:
- The Faheem Code UI in the
Settings > MCPpage. - The
config.tomlfile under the[mcp]section if not using the UI.
Configuration options
SSE servers are configured using either a string URL or an object with the following properties:
-
url(required)- Type:
str - Description: The URL of the SSE server.
- Type:
-
api_key(optional)- Type:
str - Description: API key for authentication.
- Type:
SHTTP (Streamable HTTP) servers are configured using either a string URL or an object with the following properties:
-
url(required)- Type:
str - Description: The URL of the SHTTP server.
- Type:
-
api_key(optional)- Type:
str - Description: API key for authentication.
- Type:
-
timeout(optional)- Type:
int - Default:
60 - Range:
1-3600seconds (1 hour maximum) - Description: Timeout in seconds for tool execution. This prevents tool calls from hanging indefinitely.
- Use Cases:
- Short timeout (1-30s): For lightweight operations like status checks or simple queries.
- Medium timeout (30-300s): For standard processing tasks like data analysis or API calls.
- Long timeout (300-3600s): For heavy operations like file processing, complex calculations, or batch operations.
- Type:
Stdio servers are configured using an object with the following properties:
-
name(required)- Type:
str - Description: A unique name for the server. Accepted characters are letters, digits, underscores (
_), and hyphens (-). For example,integrations-hubis a valid name.
- Type:
-
command(required)- Type:
str - Description: The command to run the server.
- Type:
-
args(optional)- Type:
list of str - Default:
[] - Description: Command-line arguments to pass to the server.
- Type:
-
env(optional)- Type:
dict of str to str - Default:
{} - Description: Environment variables to set for the server process.
- Type:
When to use direct stdio
Direct stdio connections may still be appropriate in these scenarios:
- Development and testing: Quick prototyping of MCP servers.
- Simple, single-use tools: Tools that don't require high reliability or concurrent access.
- Local-only environments: When you don't want to manage additional proxy processes.
Configuration examples
For stdio-based MCP servers, we recommend using MCP proxy tools like
supergateway instead of direct stdio connections.
SuperGateway is a popular MCP proxy that converts stdio MCP servers to
HTTP/SSE endpoints.
Start the proxy servers separately:
# Terminal 1: Filesystem server proxy
supergateway --stdio "npx @modelcontextprotocol/server-filesystem /" --port 8080
# Terminal 2: Fetch server proxy
supergateway --stdio "uvx mcp-server-fetch" --port 8081
Then configure Faheem Code to use the HTTP endpoint:
[mcp]
# SSE Servers - Recommended approach using proxy tools
sse_servers = [
# Basic SSE server with just a URL
"http://example.com:8080/mcp",
# SuperGateway proxy for fetch server
"http://localhost:8081/sse",
# External MCP service with authentication
{url="https://api.example.com/mcp/sse", api_key="your-api-key"}
]
# SHTTP Servers - Modern streamable HTTP transport (recommended)
shttp_servers = [
# Basic SHTTP server with default 60s timeout
"https://api.example.com/mcp/shttp",
# Server with custom timeout for heavy operations
{
url = "https://files.example.com/mcp/shttp",
api_key = "your-api-key",
timeout = 1800 # 30 minutes for large file processing
}
]
[mcp]
# Direct stdio servers - use only for development/testing
stdio_servers = [
# Basic stdio server
{name="fetch", command="uvx", args=["mcp-server-fetch"]},
# Stdio server with environment variables
{
name="filesystem",
command="npx",
args=["@modelcontextprotocol/server-filesystem", "/"],
env={
"DEBUG": "true"
}
}
]
For production use, we recommend using proxy tools like SuperGateway.
Other options include:
- Custom FastAPI/Express servers: Build your own HTTP wrapper around stdio MCP servers.
- Docker-based proxies: Containerized solutions for better isolation.
- Cloud-hosted MCP services: Third-party services that provide MCP endpoints.
Manage installed servers
In Faheem Code, open Customize > MCP Servers to manage installed MCP servers. Use the control on an installed server card to disable it without deleting its configuration or saved credentials. Disabled servers are unavailable to new conversations until you enable them again.
Adding, editing, renaming, or deleting one server does not remove saved credentials for your other servers. Use the editor's delete action only when you want to remove that server configuration. Editing a disabled server does not enable it.
OAuth authentication
Some MCP servers (like Notion MCP) require OAuth authentication instead of API keys. Faheem Code supports OAuth-based MCP servers through the FastMCP library.
How OAuth works
When you configure an OAuth-enabled MCP server:
- First connection: When the agent first attempts to use tools from an OAuth-protected MCP server, Faheem Code initiates the OAuth flow
- Browser authentication: A browser window opens automatically for you to authorize access
- Token storage: After authorization, tokens are securely stored locally in
~/.fastmcp/oauth-mcp-client-cache/ - Automatic refresh: FastMCP automatically refreshes tokens as needed
Configuration
Use the --auth oauth flag when adding an MCP server:
faheemcode mcp add notion --transport http \
--auth oauth \
https://mcp.notion.com/mcp
This creates a configuration in ~/.faheem-code/mcp.json:
{
"mcpServers": {
"notion": {
"url": "https://mcp.notion.com/mcp",
"transport": "http",
"auth": "oauth"
}
}
}
Configure OAuth in your mcp_config:
mcp_config = {
"mcpServers": {
"notion": {
"url": "https://mcp.notion.com/mcp",
"auth": "oauth"
}
}
}
agent = Agent(llm=llm, tools=tools, mcp_config=mcp_config)
See the SDK MCP Guide for complete examples.
Add the auth field to your server configuration:
[mcp]
shttp_servers = [
{url = "https://mcp.notion.com/mcp", auth = "oauth"}
]