You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The diagram illustrates how MCP serves as a standardised interface between different agent frameworks and LLM providers.The flow shows how users interact with the system by running a specific agent script, which then leverages MCP to communicate with LLM providers, while Logfire provides tracing and observability.
68
102
103
+
### Basic MCP Sequence Flow
104
+
105
+
```mermaid
106
+
sequenceDiagram
107
+
participant User
108
+
participant Agent as Agent Framework
109
+
participant MCP as Python MCP Server
110
+
participant LLM as LLM Provider
111
+
participant Tools as MCP Tools
112
+
participant Logfire as Logfire Tracing
113
+
114
+
Note over User,Logfire: Basic MCP Interaction Flow
115
+
116
+
User->>Agent: Run agent script with query
117
+
118
+
activate Agent
119
+
Agent->>Logfire: Start tracing
120
+
121
+
Agent->>MCP: Initialise connection
122
+
activate MCP
123
+
MCP-->>Agent: Connection established
124
+
125
+
Agent->>MCP: Send user query
126
+
127
+
MCP->>LLM: Generate response/action
128
+
activate LLM
129
+
130
+
loop Tool Use Cycle
131
+
LLM-->>MCP: Request tool execution
132
+
MCP->>Tools: Execute tool (e.g., add, get_time)
133
+
activate Tools
134
+
Tools-->>MCP: Return tool result
135
+
deactivate Tools
136
+
MCP->>LLM: Continue with tool result
137
+
end
138
+
139
+
LLM-->>MCP: Final response
140
+
deactivate LLM
141
+
142
+
MCP-->>Agent: Return response
143
+
deactivate MCP
144
+
145
+
Agent->>Logfire: Log completion
146
+
Agent->>User: Display final answer
147
+
deactivate Agent
148
+
149
+
Note over User,Logfire: End of interaction
150
+
```
151
+
152
+
The sequence diagram illustrates the temporal flow of interactions between the user, agent framework, MCP server, LLM provider, and tools. It highlights how the tool execution cycle operates within the MCP architecture.
This directory contains advanced examples demonstrating the integration of multiple Model Context Protocol (MCP) servers with agent frameworks.
5
4
6
-
Unlike the basic examples that use a single MCP server, these examples show how to connect to and coordinate between multiple specialized MCP servers simultaneously.
5
+
Unlike the basic examples that use a single MCP server, these examples show how to connect to and coordinate between multiple specialised MCP servers simultaneously.
6
+
7
+
8
+
## Quickstart
9
+
10
+
1. Configure `.env` and API keys following instructions in the [README.md](README.md)
11
+
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
14
+
15
+
4. Run an example script:
16
+
```bash
17
+
# Run the Pydantic-AI multi-MCP example
18
+
uv run agents_mcp_usage/multi_mcp/multi_mcp_use/pydantic_mcp.py
19
+
20
+
# Run the multi-MCP evaluation
21
+
uv run agents_mcp_usage/multi_mcp/eval_multi_mcp/evals_pydantic_mcp.py
22
+
```
23
+
24
+
5. Check the console output or Logfire for results.
25
+
7
26
8
27
### Multi-MCP Architecture
9
28
@@ -44,9 +63,105 @@ graph LR
44
63
45
64
LLM_Response[("Response")] --> User
46
65
LLMs --> LLM_Response
66
+
67
+
%% Node styling for better dark/light mode readability
This diagram illustrates how an agent can leverage multiple specialized MCP servers simultaneously, each providing distinct tools and resources.
89
+
This diagram illustrates how an agent can leverage multiple specialised MCP servers simultaneously, each providing distinct tools and resources.
90
+
91
+
### Multi-MCP Sequence Flow
92
+
93
+
```mermaid
94
+
sequenceDiagram
95
+
participant User
96
+
participant Agent as Pydantic-AI Agent
97
+
participant PyMCP as Python MCP Server
98
+
participant NodeMCP as Node.js MCP Server
99
+
participant LLM as LLM Provider
100
+
participant PyTools as Python Tools
101
+
participant NodeTools as Mermaid Validator
102
+
participant Logfire as Logfire Tracing
103
+
104
+
Note over User,Logfire: Multi-MCP Interaction Flow
105
+
106
+
User->>Agent: Run script with query
107
+
108
+
activate Agent
109
+
Agent->>Logfire: Start tracing session
110
+
111
+
par Connect to multiple MCP servers
112
+
Agent->>PyMCP: Initialise connection
113
+
activate PyMCP
114
+
PyMCP-->>Agent: Connection established
115
+
116
+
Agent->>NodeMCP: Initialise connection
117
+
activate NodeMCP
118
+
NodeMCP-->>Agent: Connection established
119
+
end
120
+
121
+
Agent->>LLM: Process user query
122
+
activate LLM
123
+
124
+
loop Tool Selection & Execution
125
+
alt Python MCP Tools Needed
126
+
LLM-->>Agent: Need Python tool
127
+
Agent->>PyMCP: Execute tool (e.g., add, get_time)
128
+
PyMCP->>PyTools: Call tool function
129
+
activate PyTools
130
+
PyTools-->>PyMCP: Return result
131
+
deactivate PyTools
132
+
PyMCP-->>Agent: Tool result
133
+
Agent->>LLM: Continue with tool result
134
+
else Node.js MCP Tools Needed
135
+
LLM-->>Agent: Need Mermaid validation
136
+
Agent->>NodeMCP: Validate Mermaid diagram
137
+
NodeMCP->>NodeTools: Process diagram
138
+
activate NodeTools
139
+
NodeTools-->>NodeMCP: Validation result
140
+
deactivate NodeTools
141
+
NodeMCP-->>Agent: Tool result
142
+
Agent->>LLM: Continue with tool result
143
+
end
144
+
end
145
+
146
+
LLM-->>Agent: Final response
147
+
deactivate LLM
148
+
149
+
Agent->>Logfire: Log completion
150
+
151
+
par Close MCP connections
152
+
Agent->>PyMCP: Close connection
153
+
deactivate PyMCP
154
+
Agent->>NodeMCP: Close connection
155
+
deactivate NodeMCP
156
+
end
157
+
158
+
Agent->>User: Display final answer
159
+
deactivate Agent
160
+
161
+
Note over User,Logfire: End of interaction
162
+
```
163
+
164
+
The sequence diagram shows how the agent coordinates between multiple specialised MCP servers. It highlights the parallel connection establishment, selective tool usage based on need, and proper connection management.
50
165
51
166
## Example Files
52
167
@@ -61,8 +176,8 @@ uv run agents_mcp_usage/multi_mcp/multi_mcp_use/pydantic_mcp.py
61
176
```
62
177
63
178
Key features:
64
-
- Connects to multiple specialized MCP servers simultaneously
65
-
-Organizes tools and resources by domain
179
+
- Connects to multiple specialised MCP servers simultaneously
180
+
-Organises tools and resources by domain
66
181
- Shows how to coordinate between different MCP servers
67
182
- Includes Logfire instrumentation for comprehensive tracing
68
183
@@ -77,34 +192,18 @@ uv run agents_mcp_usage/multi_mcp/eval_multi_mcp/evals_pydantic_mcp.py
77
192
```
78
193
79
194
Key features:
80
-
- Evaluates agent performance when using multiple specialized MCP servers
81
-
- Uses PydanticAI evaluation tools to measure outcomes
82
-
- Compares results with single-MCP approaches
195
+
- Evaluates agent performance when using multiple specialised MCP servers
196
+
- Uses PydanticAI Agent evaluation to measure success of outcomes
83
197
- Generates performance metrics viewable in Logfire
84
198
85
-
### Mermaid Diagrams Generator
86
-
87
-
**File:**`mermaid_diagrams.py`
88
-
89
-
A utility for generating Mermaid diagrams to visualize MCP architecture.
90
-
91
-
```bash
92
-
uv run agents_mcp_usage/multi_mcp/mermaid_diagrams.py
93
-
```
94
-
95
-
Key features:
96
-
- Creates visualization of MCP architectures
97
-
- Helps understand the flow between agents, MCP servers, and LLMs
98
-
- Customizable to represent different configurations
99
-
100
199
## Benefits of Multi-MCP Architecture
101
200
102
-
Using multiple specialized MCP servers offers several advantages:
201
+
Using multiple specialised MCP servers offers several advantages:
103
202
104
203
1.**Domain Separation**: Each MCP server can focus on a specific domain or set of capabilities.
105
204
2.**Modularity**: Add, remove, or update capabilities without disrupting the entire system.
106
205
3.**Scalability**: Distribute load across multiple servers for better performance.
107
-
4.**Specialization**: Optimize each MCP server for its specific use case.
206
+
4.**Specialisation**: Optimise each MCP server for its specific use case.
108
207
5.**Security**: Control access to sensitive tools or data through separate servers.
109
208
110
209
This approach provides a more flexible and maintainable architecture for complex agent systems.
0 commit comments