Skip to content

Commit 1ecf45f

Browse files
authored
Feature/mcp support (#74)
* feat: Implement MCP server integration with navigation and tool execution capabilities - Added mcp_server.py to define basic math tools and server file retrieval. - Introduced mcp_servers.json for server configuration. - Updated poetry.lock to include MCP and related dependencies. - Enhanced test feature to validate MCP server connection and calculations. - Implemented MCP Navigation Agent for executing tools and managing resources. - Developed MCP tools for server communication and tool execution, including connection management and error handling. - Configured environment variables for MCP integration in BaseConfigManager. * working mcp client * bug fix * deps update * removed unwanted file * update gitignore * feat: Enhance MCP support with detailed documentation and configuration - Added MCP integration section in README.md, including quick start guide and example usage. - Introduced MCP Integration details in environment_variables.md, outlining configuration options. - Created MCP_Usage.md to provide comprehensive guidance on connecting Hercules to MCP servers and executing tools. - Updated simple_hercules.py to ensure MCP agents are properly set up. - Refactored mcp_tools.py for improved organization and clarity in MCP server communication.
1 parent 6eac026 commit 1ecf45f

File tree

13 files changed

+1052
-55
lines changed

13 files changed

+1052
-55
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ share/python-wheels/
2626
.installed.cfg
2727
*.egg
2828
MANIFEST
29+
mcp_servers.json
2930

3031
# PyInstaller
3132
# Usually these files are written by a python script from a template

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,50 @@ To configure Hercules in detail:
494494
cp .env-example .env
495495
```
496496

497+
## 🔌 MCP Support
498+
499+
Hercules includes an MCP Navigation Agent that can connect to MCP servers over `stdio`, `sse`, and `streamable-http`. It works out of the box with Composio-generated MCP servers.
500+
501+
- Quick start guide: see `docs/MCP_Usage.md`
502+
- Composio docs: https://docs.composio.dev/docs/mcp-developers
503+
504+
Minimal setup:
505+
506+
1) Create `mcp_servers.json` at the repo root:
507+
508+
```
509+
{
510+
"mcpServers": {
511+
"server_name": {
512+
"transport": "streamable-http",
513+
"url": "https://mcp.composio.dev/composio/server/<SERVER_UUID>/mcp?user_id=<USER_EMAIL>"
514+
}
515+
}
516+
}
517+
```
518+
519+
2) In `.env`:
520+
521+
```
522+
MCP_ENABLED=true
523+
MCP_SERVERS=mcp_servers.json
524+
MCP_TIMEOUT=30
525+
```
526+
527+
Then, run Hercules as usual; the MCP agent will initialize and expose tools from the configured server.
528+
529+
### Example Testcase (Simple)
530+
```
531+
Feature: Read emails from Gmail
532+
533+
Scenario: Retrieve OTP from Gmail using MCP
534+
Given Gmail is configured using MCP
535+
When I connect to Gmail
536+
And I read the email with OTP
537+
```
538+
For more testcases visit [MCP-Docs](/docs/MCP_Usage.md)
539+
540+
---
497541
- Hercules is capable of running in two configuration forms:
498542

499543
1. **Using single LLM for all work**

docs/MCP_Usage.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Using MCP with Hercules
2+
3+
This guide explains how to connect Hercules to an MCP server and execute tools, with Composio as a ready-to-use provider.
4+
5+
## Overview
6+
- Hercules ships with an MCP Navigation Agent and MCP tooling.
7+
- Supports `stdio`, `sse`, and `streamable-http` transports.
8+
- Optimized for servers that expose tools but may not expose resources.
9+
10+
## Pre-requisites
11+
- Hercules installed and running (PyPI, Docker, or source).
12+
- A valid MCP server URL. For Composio, use the generated server URL which embeds user scoping.
13+
- Pattern: `https://mcp.composio.dev/composio/server/<SERVER_UUID>/mcp?user_id=<USER_EMAIL>`
14+
- Composio docs: https://docs.composio.dev/docs/mcp-developers
15+
16+
## Configure Hercules
17+
18+
1) Create `mcp_servers.json` in the repository root:
19+
20+
```json
21+
{
22+
"mcpServers": {
23+
"server_name": {
24+
"transport": "streamable-http",
25+
"url": "https://mcp.composio.dev/composio/server/<SERVER_UUID>/mcp?user_id=<USER_EMAIL>"
26+
}
27+
}
28+
}
29+
```
30+
31+
- `server_name`: Logical name used to reference this server in tools.
32+
- `transport`: Use `streamable-http` for Composio’s HTTP streaming transport. `stdio` and `sse` are also supported if your server provides them.
33+
- `url`: Your server URL; replace placeholders with your actual values.
34+
35+
2) Enable MCP in your environment (e.g., `.env`):
36+
37+
```
38+
MCP_ENABLED=true
39+
MCP_SERVERS=mcp_servers.json
40+
# Optional timeout in seconds
41+
MCP_TIMEOUT=30
42+
```
43+
44+
45+
46+
Hercules manages client contexts and sessions, and registers MCP tools for the agent to call.
47+
48+
## Transport Notes
49+
- `streamable-http`: Recommended for Composio; avoids websocket restrictions and supports streaming.
50+
- `sse`: Use if your server provides an SSE endpoint.
51+
- `stdio`: Use for local MCP servers launched as subprocesses.
52+
53+
## Troubleshooting
54+
- “Method not found” during connect
55+
- Cause: Server doesn’t implement resource endpoints.
56+
- Resolution: Hercules initializes the MCP toolkit with resources disabled by default and tools enabled. Ensure you are on a version with this behavior.
57+
- `Server not found in connected toolkits`
58+
- Ensure `MCP_ENABLED=true`, `MCP_SERVERS` points to `mcp_servers.json`, and `initialize_mcp_connections` has been called.
59+
- `Connection failed`
60+
- Verify the URL (UUID, user email) and that the server is reachable over HTTPS.
61+
62+
## Security Notes
63+
- Do not commit user emails or tokens. Keep server URLs and environment in private configuration.
64+
- Composio server URLs handle authentication and tool access based on your server configuration.
65+
66+
## References
67+
- Composio MCP: https://docs.composio.dev/docs/mcp-developers
68+
69+
## Example Testcase (Simple)
70+
71+
```gherkin
72+
Feature: Read emails from Gmail
73+
74+
Scenario: Retrieve OTP from Gmail using MCP
75+
Given Gmail is configured using MCP
76+
When I connect to Gmail
77+
And I read the email with OTP
78+
```
79+
80+
## Concrete OTP Retrieval Scenario
81+
82+
The following example demonstrates a full flow using MCP tools to search, fetch, and extract an OTP from an email. Replace tool names and fields to match your MCP server’s tool schema.
83+
84+
```gherkin
85+
Feature: Retrieve OTP via MCP Gmail
86+
87+
Background:
88+
Given MCP is enabled and the "mail" server is configured
89+
And I initialize MCP connections
90+
And MCP server "mail" is connected
91+
92+
Scenario: Read OTP from most recent email
93+
When I execute MCP tool "GMAIL_FETCH_EMAILS" on "mail" with:
94+
"""
95+
{"query": "subject:(OTP OR verification code) newer_than:15m", "max_results": 5}
96+
"""
97+
Then I store the first result's "id" as "message_id"
98+
99+
When I execute MCP tool "GMAIL_FETCH_MESSAGE_BY_MESSAGE_ID" on "mail" with:
100+
"""
101+
{"id": "${message_id}"}
102+
"""
103+
Then I read OTP from the email body
104+
And I should see an OTP
105+
```
106+
107+
Notes:
108+
- Typical tool names on Composio MCP servers:
109+
- 'GMAIL_FETCH_EMAILS'
110+
- 'GMAIL_FETCH_MESSAGE_BY_MESSAGE_ID'
111+
- 'GMAIL_FETCH_MESSAGE_BY_THREAD_ID',
112+
- Typical request fields:
113+
- For search: query, max_results
114+
- For get message: id or message_id

docs/environment_variables.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ This document provides a comprehensive guide to all environment variables and co
2727
- [Advanced Configuration](#advanced-configuration)
2828
- [Cache and Performance](#cache-and-performance)
2929
- [Portkey Integration](#portkey-integration)
30+
- [MCP Integration](#mcp-integration)
3031
- [Telemetry and Monitoring](#telemetry-and-monitoring)
3132
- [Additional Features](#additional-features)
3233
- [Configuration Priority](#configuration-priority)
@@ -335,6 +336,26 @@ LLM Parameters:
335336
- Default: `30.0`
336337
- Implementation: Controls how long Portkey waits for a response before timing out
337338

339+
### MCP Integration
340+
- `MCP_ENABLED`: Enable MCP integration
341+
- Values: `true`, `false`
342+
- Default: `false`
343+
- Implementation: Toggles MCP agent and tooling. When enabled, Hercules can connect to configured MCP servers.
344+
345+
- `MCP_SERVERS`: MCP server configuration
346+
- Values: Path to a `.json` file or a JSON string
347+
- Example (file path): `mcp_servers.json`
348+
- Example (JSON string): `{"mcpServers": {"server_name": {"transport": "streamable-http", "url": "https://mcp.composio.dev/composio/server/<SERVER_UUID>/mcp?user_id=<USER_EMAIL>"}}}`
349+
- Implementation: If a path ending with `.json` is provided, Hercules attempts to load it from:
350+
- The current working directory
351+
- Relative to `testzeus_hercules/`
352+
- Relative to `testzeus_hercules/config.py` location
353+
Otherwise, it treats the value as a JSON string.
354+
355+
- `MCP_TIMEOUT`: MCP read timeout in seconds
356+
- Default: `30`
357+
- Implementation: Used to set `ClientSession` read timeouts during MCP interactions.
358+
338359
### Telemetry and Monitoring
339360
- `ENABLE_TELEMETRY`: Enable usage telemetry
340361
- Values: `0`, `1`

mcp_servers.example.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"mcpServers": {
3+
"server_name":{
4+
"transport": "streamable-http",
5+
"url": "https://mcp.composio.dev/composio/server/<UUID>/mcp?user_id=user123@example.com"
6+
}
7+
}
8+
}

0 commit comments

Comments
 (0)