Skip to content

Commit 6a48db8

Browse files
authored
Merge pull request #4 from andrewginns/add-levels-of-eval-difficulty
2 parents 3eb1d03 + 5620aa6 commit 6a48db8

File tree

12 files changed

+63
-53
lines changed

12 files changed

+63
-53
lines changed

README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ Both single and multiple MCP server examples are demonstrated
1111
- [Agent with multiple MCP servers](agents_mcp_usage/multi_mcp/README.md)
1212
- Also includes Agent evaluations
1313

14-
The repo also includes a Python MCP Server [`run_server.py`](run_server.py) based on [MCP Python SDK Quickstart](https://github.com/modelcontextprotocol/python-sdk/blob/b4c7db6a50a5c88bae1db5c1f7fba44d16eebc6e/README.md?plain=1#L104)
15-
- Modified to include a datetime tool and run as a server invoked by Agents
14+
The repo also includes Python MCP Servers:
15+
- [`example_server.py`](mcp_servers/example_server.py) based on [MCP Python SDK Quickstart](https://github.com/modelcontextprotocol/python-sdk/blob/b4c7db6a50a5c88bae1db5c1f7fba44d16eebc6e/README.md?plain=1#L104) - Modified to include a datetime tool and run as a server invoked by Agents
16+
- [`mermaid_validator.py`](mcp_servers/mermaid_validator.py) - Mermaid diagram validation server using mermaid-cli
1617

1718
Tracing is done through Pydantic Logfire.
1819

@@ -67,8 +68,9 @@ This project aims to teach:
6768
- **eval_multi_mcp/** - Contains evaluation examples for multi-MCP usage:
6869
- `evals_pydantic_mcp.py` - Example of evaluating the use of multiple MCP servers with Pydantic-AI
6970

70-
- **Demo Python MCP Server**
71-
- `run_server.py` - Simple MCP server that runs locally, implemented in Python
71+
- **Demo Python MCP Servers**
72+
- `mcp_servers/example_server.py` - Simple MCP server that runs locally, implemented in Python
73+
- `mcp_servers/mermaid_validator.py` - Mermaid diagram validation MCP server, implemented in Python
7274

7375
## Basic MCP: Single Server Usage
7476

@@ -104,7 +106,7 @@ graph LR
104106
end
105107
106108
subgraph "Python MCP Server"
107-
MCP["Model Context Protocol Server<br>(run_server.py)"]
109+
MCP["Model Context Protocol Server<br>(mcp_servers/example_server.py)"]
108110
Tools["Tools<br>- add(a, b)<br>- get_current_time()"]
109111
Resources["Resources<br>- greeting://{name}"]
110112
MCP --- Tools
@@ -177,16 +179,16 @@ graph LR
177179
end
178180
179181
subgraph "MCP Servers"
180-
PythonMCP["Python MCP Server<br>(run_server.py)"]
181-
NodeMCP["Node.js MCP Server<br>(mermaid-validator)"]
182+
PythonMCP["Python MCP Server<br>(mcp_servers/example_server.py)"]
183+
MermaidMCP["Python Mermaid MCP Server<br>(mcp_servers/mermaid_validator.py)"]
182184
183185
Tools["Tools<br>- add(a, b)<br>- get_current_time()"]
184186
Resources["Resources<br>- greeting://{name}"]
185187
MermaidValidator["Mermaid Diagram<br>Validation Tools"]
186188
187189
PythonMCP --- Tools
188190
PythonMCP --- Resources
189-
NodeMCP --- MermaidValidator
191+
MermaidMCP --- MermaidValidator
190192
end
191193
192194
subgraph "LLM Providers"
@@ -196,10 +198,10 @@ graph LR
196198
Logfire[("Logfire<br>Tracing")]
197199
198200
Agent --> PythonMCP
199-
Agent --> NodeMCP
201+
Agent --> MermaidMCP
200202
201203
PythonMCP --> LLMs
202-
NodeMCP --> LLMs
204+
MermaidMCP --> LLMs
203205
204206
Agent --> Logfire
205207

agents_mcp_usage/basic_mcp/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ graph LR
4545
end
4646
4747
subgraph "Python MCP Server"
48-
MCP["Model Context Protocol Server<br>(run_server.py)"]
48+
MCP["Model Context Protocol Server<br>(mcp_servers/example_server.py)"]
4949
Tools["Tools<br>- add(a, b)<br>- get_current_time()"]
5050
Resources["Resources<br>- greeting://{name}"]
5151
MCP --- Tools
@@ -229,7 +229,7 @@ The examples are designed to be as similar as possible, allowing you to compare
229229

230230
## MCP Server
231231

232-
All examples connect to the same MCP server defined in `run_server.py` at the project root. This server provides:
232+
All examples connect to the same MCP server defined in `mcp_servers/example_server.py`. This server provides:
233233

234234
- An addition tool (`add(a, b)`)
235235
- A time tool (`get_current_time()`)

agents_mcp_usage/basic_mcp/basic_mcp_use/adk_mcp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async def main(query: str = "Greet Andrew and give him the current time") -> Non
2929
# Set up MCP server connection
3030
server_params = StdioServerParameters(
3131
command="uv",
32-
args=["run", "run_server.py", "stdio"],
32+
args=["run", "mcp_servers/example_server.py", "stdio"],
3333
)
3434

3535
tools, exit_stack = await MCPToolset.from_server(connection_params=server_params)

agents_mcp_usage/basic_mcp/basic_mcp_use/langgraph_mcp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# Create server parameters for stdio connection
2222
server = StdioServerParameters(
2323
command="uv",
24-
args=["run", "run_server.py", "stdio"],
24+
args=["run", "mcp_servers/example_server.py", "stdio"],
2525
)
2626

2727
model = ChatGoogleGenerativeAI(

agents_mcp_usage/basic_mcp/basic_mcp_use/oai-agent_mcp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ async def main(query: str = "Greet Andrew and give him the current time") -> Non
2424
async with MCPServerStdio(
2525
params={
2626
"command": "uv",
27-
"args": ["run", "run_server.py", "stdio"],
27+
"args": ["run", "mcp_servers/example_server.py", "stdio"],
2828
}
2929
) as server:
3030
# Initialise the agent with the server

agents_mcp_usage/basic_mcp/basic_mcp_use/pydantic_mcp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
command="uv",
1717
args=[
1818
"run",
19-
"run_server.py",
19+
"mcp_servers/example_server.py",
2020
"stdio",
2121
],
2222
)

agents_mcp_usage/multi_mcp/README.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ Agents utilising multiple MCP servers can be dramatically more complex than an A
99

1010
1. Configure `.env` and API keys following instructions in the [README.md](README.md)
1111

12-
3. Ensure the Node.js MCP server can be used:
13-
- Install the Node.js MCP server (mermaid-validator) locally, run `make install` if you haven't already
12+
3. Ensure the Python MCP servers can be used:
13+
- The Python MCP servers (example_server.py and mermaid_validator.py) are included in the repository
1414

1515
4. Run an example script:
1616
```bash
@@ -38,16 +38,16 @@ graph LR
3838
end
3939
4040
subgraph "MCP Servers"
41-
PythonMCP["Python MCP Server<br>(run_server.py)"]
42-
NodeMCP["Node.js MCP Server<br>(mermaid-validator)"]
41+
PythonMCP["Python MCP Server<br>(mcp_servers/example_server.py)"]
42+
MermaidMCP["Python Mermaid MCP Server<br>(mcp_servers/mermaid_validator.py)"]
4343
4444
Tools["Tools<br>- add(a, b)<br>- get_current_time()"]
4545
Resources["Resources<br>- greeting://{name}"]
4646
MermaidValidator["Mermaid Diagram<br>Validation Tools"]
4747
4848
PythonMCP --- Tools
4949
PythonMCP --- Resources
50-
NodeMCP --- MermaidValidator
50+
MermaidMCP --- MermaidValidator
5151
end
5252
5353
subgraph "LLM Providers"
@@ -57,10 +57,10 @@ graph LR
5757
Logfire[("Logfire<br>Tracing")]
5858
5959
Agent --> PythonMCP
60-
Agent --> NodeMCP
60+
Agent --> MermaidMCP
6161
6262
PythonMCP --> LLMs
63-
NodeMCP --> LLMs
63+
MermaidMCP --> LLMs
6464
6565
Agent --> Logfire
6666
@@ -82,7 +82,7 @@ graph LR
8282
class User userNode;
8383
class Agent agentNode;
8484
class PythonMCP pythonMcpNode;
85-
class NodeMCP nodeMcpNode;
85+
class MermaidMCP nodeMcpNode;
8686
class Tools,Resources,MermaidValidator toolNode;
8787
class LLMs llmNode;
8888
class LLM_Response outputNode;
@@ -98,10 +98,10 @@ sequenceDiagram
9898
participant User
9999
participant Agent as Pydantic-AI/ADK Agent
100100
participant PyMCP as Python MCP Server
101-
participant NodeMCP as Node.js MCP Server
101+
participant MermaidMCP as Python Mermaid MCP Server
102102
participant LLM as LLM Provider
103103
participant PyTools as Python Tools
104-
participant NodeTools as Mermaid Validator
104+
participant MermaidTools as Mermaid Validator
105105
participant Logfire as Logfire Tracing
106106
107107
Note over User,Logfire: Multi-MCP Interaction Flow
@@ -116,9 +116,9 @@ sequenceDiagram
116116
activate PyMCP
117117
PyMCP-->>Agent: Connection established
118118
119-
Agent->>NodeMCP: Initialise connection
120-
activate NodeMCP
121-
NodeMCP-->>Agent: Connection established
119+
Agent->>MermaidMCP: Initialise connection
120+
activate MermaidMCP
121+
MermaidMCP-->>Agent: Connection established
122122
end
123123
124124
Agent->>LLM: Process user query
@@ -134,14 +134,14 @@ sequenceDiagram
134134
deactivate PyTools
135135
PyMCP-->>Agent: Tool result
136136
Agent->>LLM: Continue with tool result
137-
else Node.js MCP Tools Needed
137+
else Mermaid MCP Tools Needed
138138
LLM-->>Agent: Need Mermaid validation
139-
Agent->>NodeMCP: Validate Mermaid diagram
140-
NodeMCP->>NodeTools: Process diagram
141-
activate NodeTools
142-
NodeTools-->>NodeMCP: Validation result
143-
deactivate NodeTools
144-
NodeMCP-->>Agent: Tool result
139+
Agent->>MermaidMCP: Validate Mermaid diagram
140+
MermaidMCP->>MermaidTools: Process diagram
141+
activate MermaidTools
142+
MermaidTools-->>MermaidMCP: Validation result
143+
deactivate MermaidTools
144+
MermaidMCP-->>Agent: Tool result
145145
Agent->>LLM: Continue with tool result
146146
end
147147
end
@@ -154,8 +154,8 @@ sequenceDiagram
154154
par Close MCP connections
155155
Agent->>PyMCP: Close connection
156156
deactivate PyMCP
157-
Agent->>NodeMCP: Close connection
158-
deactivate NodeMCP
157+
Agent->>MermaidMCP: Close connection
158+
deactivate MermaidMCP
159159
end
160160
161161
Agent->>User: Display final answer
@@ -210,7 +210,7 @@ uv run agents_mcp_usage/multi_mcp/multi_mcp_use/adk_mcp.py
210210

211211
Key features:
212212
- Uses Google's ADK framework with Gemini model
213-
- Connects to both Python MCP server and Node.js Mermaid validator
213+
- Connects to both Python MCP server and Python Mermaid validator
214214
- Demonstrates proper connection management with contextlib.AsyncExitStack
215215
- Shows how to handle asynchronous MCP tool integration
216216
- Uses a simple test case that utilizes both MCP servers in a single query

agents_mcp_usage/multi_mcp/eval_multi_mcp/evals_pydantic_mcp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
command="uv",
3737
args=[
3838
"run",
39-
"run_server.py",
39+
"mcp_servers/example_server.py",
4040
"stdio",
4141
],
4242
)

agents_mcp_usage/multi_mcp/mermaid_diagrams.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# MCP Server
2121
subgraph "MCP"
2222
direction TD
23-
MCP["Model Context Protocol Server<br>(run_server.py)"]
23+
MCP["Model Context Protocol Server<br>(mcp_servers/example_server.py)"]
2424
Tools["Tools<br>- add(a, b)<br>- get_current_time() e.g. {current_time}"]
2525
Resources["Resources<br>- greeting://{{name}}"]
2626
MCP --- Tools
@@ -86,7 +86,7 @@
8686
# MCP Server
8787
subgraph "MCP"
8888
direction TB
89-
MCP["Model Context Protocol Server<br>(run_server.py)"]
89+
MCP["Model Context Protocol Server<br>(mcp_servers/example_server.py)"]
9090
Tools["Tools<br>- add(a, b)<br>- get_current_time() e.g. {current_time}"]
9191
Resources["Resources<br>- greeting://{{name}}"]
9292
MCP --- Tools
@@ -150,7 +150,7 @@
150150
%% MCP Server
151151
subgraph "MCP Server"
152152
direction TB
153-
MCP["Model Context Protocol Server<br>(run_server.py)"]
153+
MCP["Model Context Protocol Server<br>(mcp_servers/example_server.py)"]
154154
Tools["Tools<br>- add(a, b)<br>- get_current_time() e.g. {current_time}"]
155155
Resources["Resources<br>- greeting://{{name}}"]
156156
MCPs --- Tools
@@ -214,7 +214,7 @@
214214
%% MCP Server
215215
subgraph "MCP Server"
216216
direction TB
217-
MCP["Model Context Protocol Server<br>(run_server.py)"]
217+
MCP["Model Context Protocol Server<br>(mcp_servers/example_server.py)"]
218218
Tools["Tools<br>- add(a, b)<br>- get_current_time() e.g. {current_time}"]
219219
Resources["Resources<br>- greeting://{{name}}"]
220220
MCP --- Tools

agents_mcp_usage/multi_mcp/multi_mcp_use/adk_mcp.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
22
import contextlib
33
import os
4+
import time
45

56
import logfire
67
from dotenv import load_dotenv
@@ -35,16 +36,16 @@ async def get_tools_async():
3536
command="uv",
3637
args=[
3738
"run",
38-
"run_server.py",
39+
"mcp_servers/example_server.py",
3940
"stdio",
4041
],
4142
)
4243

4344
mermaid_server = StdioServerParameters(
44-
command="npx",
45+
command="uv",
4546
args=[
46-
"-y",
47-
"@rtuin/mcp-mermaid-validator@latest",
47+
"run",
48+
"mcp_servers/mermaid_validator.py",
4849
],
4950
)
5051

@@ -123,6 +124,13 @@ async def main(query: str = "Hi!", request_limit: int = 5) -> None:
123124
await exit_stack.aclose()
124125
print("Cleanup complete.")
125126

127+
# Give Logfire time to complete any pending exports
128+
print("Shutting down Logfire...")
129+
logfire.shutdown()
130+
# Small delay to ensure export completes
131+
time.sleep(0.5)
132+
print("Logfire shutdown complete.")
133+
126134

127135
if __name__ == "__main__":
128136
query = f"Add the current time and fix the mermaid diagram syntax using the validator: {invalid_mermaid_diagram_easy}. Return only the fixed mermaid diagram between backticks."

0 commit comments

Comments
 (0)