Skip to content

Commit ec6a4e1

Browse files
committed
Add MCP support
1 parent a284f1d commit ec6a4e1

File tree

12 files changed

+1682
-205
lines changed

12 files changed

+1682
-205
lines changed

README.md

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,25 @@ Copy the `.env.example` file to `.env` and update with your specific configurati
106106

107107
```env
108108
LITELLM_CONFIG_PATH=model.config.toml
109+
# Optional: Path to your MCP server configuration file
110+
# MCP_CONFIG_PATH=mcp.toml
109111
110112
# Redis configuration
111113
REDIS_HOST=localhost
112114
REDIS_PORT=6379
113115
114-
# Optional for research functionality
115-
JINA_API_KEY=your-jina-api-key
116+
# JINA API Key
117+
# JINA_API_KEY=your-jina-api-key # Uncomment and set if using deep research
116118
117119
# For image processing
118-
AZURE_VISION_ENDPOINT=your-azure-vision-endpoint
119-
AZURE_VISION_KEY=your-azure-vision-key
120+
# AZURE_VISION_ENDPOINT=your-azure-vision-endpoint # Uncomment and set if using Azure vision
121+
# AZURE_VISION_KEY=your-azure-vision-key # Uncomment and set if using Azure vision
120122
121123
# For web search functionality
122-
SERPAPI_API_KEY=your-serpapi-api-key
124+
# SERPAPI_API_KEY=your-serpapi-api-key # Uncomment and set for Google Search via SerpAPI
125+
# SERPER_API_KEY=your-serper-api-key # Uncomment and set for Google Search via Serper
126+
127+
SENDER_EMAIL=ai-assistant@mxtoai.com
123128
```
124129

125130
This project supports load balancing and routing across multiple models, so you can define as many models as you'd like. Copy `model.config.example.toml` to a toml file and update it with your preferred configuration. Update `.env` with the path your toml relative to root.
@@ -257,6 +262,34 @@ The system now supports:
257262
- Fallback responses for partial failures
258263
- Comprehensive error logging
259264

265+
### MCP Server Integration (Optional)
266+
267+
The system supports integration with Model Context Protocol (MCP) servers, allowing the EmailAgent to leverage additional tools and data sources.
268+
269+
**Configuration:**
270+
271+
1. Create or copy `mcp.toml.example` to `mcp.toml` in the project root.
272+
2. Edit `mcp.toml` to define your MCP server configurations. Refer to the comments within `mcp.toml.example` for detailed instructions and examples for both Stdio and SSE based servers.
273+
3. Ensure each server configuration you want to use has `enabled = true`.
274+
4. You can specify a custom path for this configuration file by setting the `MCP_CONFIG_PATH` environment variable in your `.env` file.
275+
276+
**Example `mcp.toml` entry:**
277+
```toml
278+
[mcp_servers.my_filesystem_reader]
279+
type = "stdio"
280+
command = "npx"
281+
args = [
282+
"-y",
283+
"@modelcontextprotocol/server-filesystem",
284+
"/path/to/readable/directory"
285+
]
286+
env = { "SOME_VAR" = "some_value" }
287+
enabled = true
288+
```
289+
290+
**Security Note:**
291+
Using MCP servers, especially Stdio-based ones, involves running external commands and code. The system uses `trust_remote_code=True` when loading these tools via `smolagents`, which is often necessary for their functionality but carries inherent security risks. **Only configure and enable MCP servers from sources you explicitly trust.**
292+
260293
## Load Testing
261294

262295
The project uses Locust for load testing various email processing scenarios.

mcp.toml.example

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# mcp.toml.example
2+
# Configuration file for Model Context Protocol (MCP) servers.
3+
#
4+
# This file allows the EmailAgent to connect to various MCP servers
5+
# and utilize the tools they provide.
6+
#
7+
# Security Warning:
8+
# Enabling MCP servers, especially Stdio-based ones, involves running external commands
9+
# and potentially arbitrary code. The `trust_remote_code=True` flag is used when loading
10+
# these tools with smolagents, which is necessary for their operation but carries inherent risks.
11+
# ALWAYS ENSURE YOU TRUST THE SOURCE AND IMPLEMENTATION OF ANY MCP SERVER YOU CONFIGURE.
12+
# For Stdio-based servers, the commands are executed on the machine where the agent is running.
13+
# For SSE-based servers, while the server itself runs remotely, ensure the endpoint is trusted.
14+
15+
# [[mcp_servers]] # Use a list of tables for multiple servers of the same type or for clarity
16+
# name = "filesystem_example"
17+
# type = "stdio" # "stdio" or "sse"
18+
# command = "npx"
19+
# args = [
20+
# "-y",
21+
# "@modelcontextprotocol/server-filesystem",
22+
# "/path/to/your/Desktop", # Replace with actual accessible paths
23+
# "/path/to/your/Downloads" # Replace with actual accessible paths
24+
# ]
25+
# # Optional environment variables for the command
26+
# # env = { "SOME_VARIABLE" = "some_value" }
27+
28+
# [[mcp_servers]]
29+
# name = "github_stdio_example"
30+
# type = "stdio"
31+
# command = "npx"
32+
# args = [
33+
# "-y",
34+
# "@modelcontextprotocol/server-github"
35+
# ]
36+
# env = { GITHUB_PERSONAL_ACCESS_TOKEN = "<YOUR_GITHUB_PERSONAL_ACCESS_TOKEN>" } # Replace with your token
37+
38+
# [[mcp_servers]]
39+
# name = "github_docker_example"
40+
# type = "stdio"
41+
# command = "docker"
42+
# args = [
43+
# "run",
44+
# "-i", # For interactive processes
45+
# "--rm", # Automatically remove the container when it exits
46+
# "-e", "GITHUB_PERSONAL_ACCESS_TOKEN", # Pass the environment variable to the container
47+
# "mcp/github" # The Docker image for the GitHub MCP server
48+
# ]
49+
# env = { GITHUB_PERSONAL_ACCESS_TOKEN = "<YOUR_DOCKER_GITHUB_TOKEN>" } # Replace with your token
50+
51+
# [[mcp_servers]]
52+
# name = "remote_sse_example"
53+
# type = "sse"
54+
# url = "http://127.0.0.1:8000/sse" # Replace with the actual URL of your SSE MCP server
55+
# # Optional: any other parameters required by the mcp.client.sse.sse_client
56+
# # extra_params = { "some_other_sse_param" = "value" }
57+
58+
59+
# More structured way using TOML tables:
60+
# Each key under [mcp_servers] will be treated as a server configuration.
61+
# The name of the server will be the key itself (e.g., "filesystem", "github_service").
62+
63+
[mcp_servers.filesystem]
64+
type = "stdio" # "stdio" or "sse"
65+
command = "npx"
66+
args = [
67+
"-y",
68+
"@modelcontextprotocol/server-filesystem",
69+
"/path/to/your/Desktop", # IMPORTANT: Replace with actual, accessible paths
70+
"/path/to/your/Downloads" # IMPORTANT: Replace with actual, accessible paths
71+
]
72+
# Optional environment variables for the command
73+
# env = { "SOME_VARIABLE" = "some_value" }
74+
# enabled = true # Optional: defaults to true if not specified. Set to false to disable.
75+
76+
[mcp_servers.github_stdio]
77+
type = "stdio"
78+
command = "npx"
79+
args = [
80+
"-y",
81+
"@modelcontextprotocol/server-github"
82+
]
83+
env = { GITHUB_PERSONAL_ACCESS_TOKEN = "<YOUR_GITHUB_PERSONAL_ACCESS_TOKEN>" } # IMPORTANT: Replace with your token
84+
# enabled = true
85+
86+
[mcp_servers.github_docker]
87+
type = "stdio"
88+
command = "docker"
89+
args = [
90+
"run",
91+
"-i", # For interactive processes
92+
"--rm", # Automatically remove the container when it exits
93+
"-e", "GITHUB_PERSONAL_ACCESS_TOKEN", # Pass the environment variable to the container
94+
"mcp/github" # The Docker image for the GitHub MCP server
95+
]
96+
env = { GITHUB_PERSONAL_ACCESS_TOKEN = "<YOUR_DOCKER_GITHUB_TOKEN>" } # IMPORTANT: Replace with your token
97+
# enabled = true
98+
99+
[mcp_servers.pubmed_example]
100+
type = "stdio"
101+
command = "uvx" # Using uvx as per smolagents documentation example
102+
args = ["--quiet", "pubmedmcp@0.1.3"]
103+
env = {"UV_PYTHON" = "3.12"} # Ensure this matches your environment if needed, os.environ will be merged.
104+
# enabled = true
105+
106+
[mcp_servers.remote_sse_service]
107+
type = "sse"
108+
url = "http://127.0.0.1:8000/sse" # IMPORTANT: Replace with the actual URL of your SSE MCP server
109+
# Optional: any other parameters required by the mcp.client.sse.sse_client for SSE connections
110+
# extra_params = { "some_other_sse_param" = "value" }
111+
# enabled = true

0 commit comments

Comments
 (0)