Skip to content

Commit d023307

Browse files
committed
strands agent for testing the registry
1 parent dd1f0dd commit d023307

File tree

7 files changed

+2501
-95
lines changed

7 files changed

+2501
-95
lines changed

README.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ The MCP Gateway & Registry solves these challenges by providing a unified platfo
2626

2727
You can deploy the gateway and registry on Amazon EC2 or Amazon EKS for production environments. Jump to [installation on EC2](#installation-on-ec2) or [installation on EKS](#installation-on-eks) for deployment instructions.
2828

29+
## What's New
30+
31+
* **Integration with [Strands Agents](https://github.com/strands-agents/sdk-python):** Enhanced agent capabilities with the Strands SDK
32+
* **Dynamic tool discovery and invocation:** User agents can discover new tools through the registry and have limitless capabilities
33+
* **[Installation on EKS](#installation-on-eks):** Deploy on Kubernetes for production environments
34+
2935
## Architecture
3036

3137
The Gateway works by using an [Nginx server](https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/) as a reverse proxy, where each MCP server is handled as a different _path_ and the Nginx reverse proxy sitting between the MCP clients (contained in AI Agents for example) and backend server forwards client requests to appropriate backend servers and returns the responses back to clients. The requested resources are then returned to the client.
@@ -229,16 +235,21 @@ The Gateway and the Registry are available as a Docker container. The package in
229235
The repo includes a test agent that can connect to the Registry to discover tools and invoke them to do interesting tasks. This functionality can be invoked either standalone or as part of a test suite.
230236
231237
```{.python}
232-
python agents\agent.py --mcp-registry-url http://localhost/mcpgw/sse --message "what is the current time in clarksburg, md"
238+
python agents/agent.py --mcp-registry-url http://localhost/mcpgw/sse --message "what is the current time in clarksburg, md"
239+
240+
# With Strands agent
241+
# python agents/strands_agent.py --mcp-registry-url http://localhost/mcpgw/sse --message "what is the current time in clarksburg, md"
233242
```
234243

235-
You can also run the full test suite and get a handy agent evaluation report. This test suite exercises the Registry functionality as well as tests the multiple built-in MCP servers provided by the Gateway.
244+
You can also run the full test suite and get a handy agent evaluation report. This test suite exercises the Registry functionality as well as tests the multiple built-in MCP servers provided by the Gateway.
236245

237-
```{.python}
238-
python agents/test_suite.py --mcp-registry-url http://localhost/mcpgw/sse
239-
```
246+
```{.python}
247+
python agents/test_suite.py --mcp-registry-url http://localhost/mcpgw/sse
248+
# With Strands agent
249+
# python agents/test_suite.py --mcp-registry-url http://localhost/mcpgw/sse --use-strands
250+
```
240251

241-
The result of the tests suites are available in the agents/test_results folder. It contains an accuracy.json, a summary.json, a logs folder and a raw_data folder that contains the verbose output from the agent. The test suite uses an LLM as a judge to evaluate the results for accuracy and tool usage quality.
252+
The result of the tests suites are available in the agents/test_results folder. It contains an accuracy.json, a summary.json, a logs folder and a raw_data folder that contains the verbose output from the agent. The test suite uses an LLM as a judge to evaluate the results for accuracy and tool usage quality.
242253

243254
#### Running the Gateway over HTTPS
244255

agents/agent.py

Lines changed: 24 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -145,59 +145,27 @@ async def invoke_mcp_tool(mcp_registry_url: str, server_name: str, tool_name: st
145145

146146
from datetime import datetime, UTC
147147
current_utc_time = str(datetime.now(UTC))
148-
SYSTEM_PROMPT_TEMPLATE = f"""
149-
<instructions>
150-
You are a highly capable AI assistant designed to solve a wide range of problems for users. You have access to a variety of built-in tools and can discover additional specialized tools as needed.
151148

152-
If there is a user question that requires understanding of the current time to answer it, for example
153-
it needs to determine a date range then remember that you know the current UTC datetime is {current_utc_time}
154-
and determine the date range based on that.
155-
MCP Registry URL: {{mcp_registry_url}}
156-
</instructions>
157-
158-
<capabilities>
159-
You can handle natural language requests across domains including data analysis, content creation, information retrieval, and problem-solving.
160-
You're able to break down complex requests into actionable steps.
161-
You can select the appropriate tools based on user needs.
162-
When you don't have an appropriate tool, you can discover one using the intelligent_tool_finder.
163-
</capabilities>
164-
165-
<available_tools>
166-
You have direct access to these built-in tools:
167-
- calculator: For performing mathematical calculations and arithmetic operations
168-
- invoke_mcp_tool: For invoking tools on MCP servers using the MCP Registry URL, server name, tool name, and arguments
169-
</available_tools>
170-
171-
<tool_discovery>
172-
When a user requests something that requires a specialized tool you don't have direct access to, use the intelligent_tool_finder tool.
173-
174-
How to use intelligent_tool_finder:
175-
1. When you identify that a task requires a specialized tool (e.g., image generation, specialized API access, etc.)
176-
2. Call the tool with a description of what you need: `intelligent_tool_finder("description of needed capability")`, Use admin/password for authentication.
177-
3. The tool will return the most appropriate specialized tool along with usage instructions
178-
4. You can then use the invoke_mcp_tool to invoke this discovered tool by providing the MCP Registry URL, server name, tool name, and required arguments
179-
180-
Example workflow:
181-
1. Discover a tool: result = intelligent_tool_finder("weather forecast")
182-
2. The result provides details about a weather_forecast tool on the "weather-server" MCP server.
183-
3. Always use the "service_path" path field for the server name while creating the arguments for the invoke_mcp_tool in the next step.
184-
4. Use invoke_mcp_tool to call it: invoke_mcp_tool("https://registry-url.com/mcpgw/sse", "/weather", "weather_forecast", {{{{"location": "New York", "days": 5}}}})
185-
</tool_discovery>
186-
187-
<workflow>
188-
1. Understand the user's request completely
189-
2. Determine if you can handle it with your primary tools
190-
3. If not, use intelligent_tool_finder to discover the appropriate specialized tool
191-
4. Use invoke_mcp_tool to call the discovered tool with the appropriate arguments
192-
5. Present results clearly to the user
193-
</workflow>
194-
195-
<guidelines>
196-
Always be transparent about what tools you're using. If you need to use the intelligent_tool_finder, briefly explain to the user that you're searching for the right capability.
197-
198-
Prioritize security and privacy. Never use tools to access, generate, or share harmful, illegal, or unethical content.
199-
</guidelines>
200-
"""
149+
def load_system_prompt():
150+
"""
151+
Load the system prompt template from the system_prompt.txt file.
152+
153+
Returns:
154+
str: The system prompt template
155+
"""
156+
try:
157+
with open("agents/system_prompt.txt", "r") as f:
158+
return f.read()
159+
except Exception as e:
160+
print(f"Error loading system prompt: {e}")
161+
# Provide a minimal fallback prompt in case the file can't be loaded
162+
return """
163+
<instructions>
164+
You are a highly capable AI assistant designed to solve problems for users.
165+
Current UTC time: {current_utc_time}
166+
MCP Registry URL: {mcp_registry_url}
167+
</instructions>
168+
"""
201169

202170
def print_agent_response(response_dict: Dict[str, Any]) -> None:
203171
"""
@@ -325,8 +293,10 @@ async def main():
325293
all_tools
326294
)
327295

328-
# Format the system prompt with the actual MCP registry URL
329-
system_prompt = SYSTEM_PROMPT_TEMPLATE.format(
296+
# Load and format the system prompt with the current time and MCP registry URL
297+
system_prompt_template = load_system_prompt()
298+
system_prompt = system_prompt_template.format(
299+
current_utc_time=current_utc_time,
330300
mcp_registry_url=args.mcp_registry_url
331301
)
332302

0 commit comments

Comments
 (0)