1
1
# Model Context Protocol (MCP) Agent Frameworks Demo
2
2
3
3
This repository demonstrates the usage of Model Context Protocol (MCP) servers with several frameworks:
4
- - Google Agent Development Toolkit (ADK)
4
+ - Google Agent Development Kit (ADK)
5
5
- LangGraph Agents
6
6
- OpenAI Agents
7
7
- Pydantic-AI Agents
@@ -18,15 +18,15 @@ Tracing is done through Pydantic Logfire.
18
18
` cp .env.example .env `
19
19
- Add ` GEMINI_API_KEY ` and/or ` OPENAI_API_KEY `
20
20
- Individual scripts can be adjusted to use models from any provider supported by the specific framework
21
- - By default only [ basic_mcp_use/oai-agent_mcp.py] ( basic_mcp_use/oai-agent_mcp.py ) requires ` OPENAI_API_KEY `
21
+ - By default only [ basic_mcp_use/oai-agent_mcp.py] ( agents_mcp_usage/basic_mcp/ basic_mcp_use/oai-agent_mcp.py) requires ` OPENAI_API_KEY `
22
22
- All other scripts require ` GEMINI_API_KEY ` (Free tier key can be created at https://aistudio.google.com/apikey )
23
23
- [ Optional] Add ` LOGFIRE_TOKEN ` to visualise evaluations in Logfire web ui
24
24
25
25
Run an Agent framework script e.g.:
26
- - ` uv run basic_mcp_use/pydantic_mcp.py `
26
+ - ` uv run agents_mcp_usage/basic_mcp/ basic_mcp_use/pydantic_mcp.py `
27
27
- Requires ` GEMINI_API_KEY ` by default
28
28
29
- - ` uv run basic_mcp_use/oai-agent_mcp.py `
29
+ - ` uv run agents_mcp_usage/basic_mcp/ basic_mcp_use/oai-agent_mcp.py `
30
30
- Requires ` OPENAI_API_KEY ` by default
31
31
32
32
Check console or Logfire for output
@@ -35,34 +35,185 @@ Check console or Logfire for output
35
35
36
36
This project aims to teach:
37
37
1 . How to use MCP with multiple LLM Agent frameworks
38
- - Agent using a single MCP server
39
- - Agent using multi- MCP servers
38
+ - Agent using a single MCP server ( [ basic_mcp ] ( #basic-mcp-single-server-usage ) )
39
+ - Agent using multiple MCP servers ( [ multi_mcp ] ( #multi-mcp-advanced-usage ) )
40
40
2 . How to see traces LLM Agents with Logfire
41
41
3 . How to evaluate LLMs with PydanticAI evals
42
42
43
43
![ Logfire UI] ( docs/images/logfire_ui.png )
44
44
45
45
## Repository Structure
46
46
47
- - ** agents_mcp_usage/basic_mcp/basic_mcp_use/** - Contains basic examples of single MCP usage:
48
- - ` adk_mcp.py ` - Example of using MCP with Google's Agent Development Kit (ADK)
49
- - ` langgraph_mcp.py ` - Example of using MCP with LangGraph
50
- - ` oai-agent_mcp.py ` - Example of using MCP with OpenAI Agents
51
- - ` pydantic_mcp.py ` - Example of using MCP with Pydantic-AI
47
+ - ** [ agents_mcp_usage/basic_mcp/] ( agents_mcp_usage/basic_mcp/ ) ** - Single MCP server integration examples
48
+ - ** basic_mcp_use/** - Contains basic examples of single MCP usage:
49
+ - ` adk_mcp.py ` - Example of using MCP with Google's Agent Development Kit (ADK)
50
+ - ` langgraph_mcp.py ` - Example of using MCP with LangGraph
51
+ - ` oai-agent_mcp.py ` - Example of using MCP with OpenAI Agents
52
+ - ` pydantic_mcp.py ` - Example of using MCP with Pydantic-AI
52
53
53
- - ** agents_mcp_usage/basic_mcp/ eval_basic_mcp_use/** - Contains evaluation examples for single MCP usage:
54
- - ` evals_adk_mcp.py ` - Evaluation of MCP with Google's ADK
55
- - ` evals_langchain_mcp.py ` - Evaluation of MCP with LangGraph
56
- - ` evals_pydantic_mcp.py ` - Evaluation of MCP with Pydantic-AI
54
+ - ** eval_basic_mcp_use/** - Contains evaluation examples for single MCP usage:
55
+ - ` evals_adk_mcp.py ` - Evaluation of MCP with Google's ADK
56
+ - ` evals_langchain_mcp.py ` - Evaluation of MCP with LangGraph
57
+ - ` evals_pydantic_mcp.py ` - Evaluation of MCP with Pydantic-AI
57
58
58
- - ** agents_mcp_usage/multi_mcp/** - Contains advanced examples of multi-MCP usage:
59
- - ` multi_mcp_use/pydantic_mcp.py ` - Example of using multiple MCP servers with Pydantic-AI
60
- - ` eval_multi_mcp/evals_pydantic_mcp.py ` - Example of evaluating the use of multiple MCP servers with Pydantic-AI
61
- - ` mermaid_diagrams.py ` - Generates Mermaid diagrams for visualizing MCP architecture
59
+ - ** [ agents_mcp_usage/multi_mcp/] ( agents_mcp_usage/multi_mcp/ ) ** - Advanced multi-MCP server integration examples
60
+ - ** multi_mcp_use/** - Contains examples of using multiple MCP servers simultaneously:
61
+ - ` pydantic_mcp.py ` - Example of using multiple MCP servers with Pydantic-AI Agent
62
+ - ** eval_multi_mcp/** - Contains evaluation examples for multi-MCP usage:
63
+ - ` evals_pydantic_mcp.py ` - Example of evaluating the use of multiple MCP servers with Pydantic-AI
62
64
63
65
- ** Demo Python MCP Server**
64
66
- ` run_server.py ` - Simple MCP server that runs locally, implemented in Python
65
67
68
+ ## Basic MCP: Single Server Usage
69
+
70
+ The ` basic_mcp ` module demonstrates how to integrate a single MCP server with different agent frameworks. Each example follows a similar pattern:
71
+
72
+ 1 . ** Environment Setup** : Loading environment variables and configuring logging
73
+ 2 . ** Server Connection** : Establishing a connection to the local MCP server
74
+ 3 . ** Agent Configuration** : Setting up an agent with the appropriate model
75
+ 4 . ** Execution** : Running the agent with a query and handling the response
76
+
77
+ The MCP server in these examples provides:
78
+ - An addition tool (` add(a, b) ` )
79
+ - A time tool (` get_current_time() ` )
80
+ - A dynamic greeting resource (` greeting://{name} ` )
81
+
82
+ ### Basic MCP Architecture
83
+
84
+ ``` mermaid
85
+ graph LR
86
+ User((User)) --> |"Run script<br>(e.g., pydantic_mcp.py)"| Agent
87
+
88
+ subgraph "Agent Frameworks"
89
+ Agent[Agent]
90
+ ADK["Google ADK<br>(adk_mcp.py)"]
91
+ LG["LangGraph<br>(langgraph_mcp.py)"]
92
+ OAI["OpenAI Agents<br>(oai-agent_mcp.py)"]
93
+ PYD["Pydantic-AI<br>(pydantic_mcp.py)"]
94
+
95
+ Agent --> ADK
96
+ Agent --> LG
97
+ Agent --> OAI
98
+ Agent --> PYD
99
+ end
100
+
101
+ subgraph "Python MCP Server"
102
+ MCP["Model Context Protocol Server<br>(run_server.py)"]
103
+ Tools["Tools<br>- add(a, b)<br>- get_current_time()"]
104
+ Resources["Resources<br>- greeting://{name}"]
105
+ MCP --- Tools
106
+ MCP --- Resources
107
+ end
108
+
109
+ subgraph "LLM Providers"
110
+ OAI_LLM["OpenAI Models"]
111
+ GEM["Google Gemini Models"]
112
+ OTHER["Other LLM Providers..."]
113
+ end
114
+
115
+ Logfire[("Logfire<br>Tracing")]
116
+
117
+ ADK --> MCP
118
+ LG --> MCP
119
+ OAI --> MCP
120
+ PYD --> MCP
121
+
122
+ MCP --> OAI_LLM
123
+ MCP --> GEM
124
+ MCP --> OTHER
125
+
126
+ ADK --> Logfire
127
+ LG --> Logfire
128
+ OAI --> Logfire
129
+ PYD --> Logfire
130
+
131
+ LLM_Response[("Response")] --> User
132
+ OAI_LLM --> LLM_Response
133
+ GEM --> LLM_Response
134
+ OTHER --> LLM_Response
135
+ ```
136
+
137
+ #### Try the Basic MCP Examples:
138
+
139
+ ``` bash
140
+ # Google ADK example
141
+ uv run agents_mcp_usage/basic_mcp/basic_mcp_use/adk_mcp.py
142
+
143
+ # LangGraph example
144
+ uv run agents_mcp_usage/basic_mcp/basic_mcp_use/langgraph_mcp.py
145
+
146
+ # OpenAI Agents example
147
+ uv run agents_mcp_usage/basic_mcp/basic_mcp_use/oai-agent_mcp.py
148
+
149
+ # Pydantic-AI example
150
+ uv run agents_mcp_usage/basic_mcp/basic_mcp_use/pydantic_mcp.py
151
+ ```
152
+
153
+ More details on basic MCP implementation can be found in the [ basic_mcp README] ( agents_mcp_usage/basic_mcp/README.md ) .
154
+
155
+ ## Multi-MCP: Advanced Usage
156
+
157
+ The ` multi_mcp ` module demonstrates advanced techniques for connecting to and coordinating between multiple specialized MCP servers simultaneously. This approach offers several advantages:
158
+
159
+ 1 . ** Domain Separation** : Each MCP server can focus on a specific domain or set of capabilities
160
+ 2 . ** Modularity** : Add, remove, or update capabilities without disrupting the entire system
161
+ 3 . ** Scalability** : Distribute load across multiple servers for better performance
162
+ 4 . ** Specialization** : Optimize each MCP server for its specific use case
163
+
164
+ ### Multi-MCP Architecture
165
+
166
+ ``` mermaid
167
+ graph LR
168
+ User((User)) --> |"Run script<br>(e.g., pydantic_mcp.py)"| Agent
169
+
170
+ subgraph "Agent Framework"
171
+ Agent["Pydantic-AI Agent<br>(pydantic_mcp.py)"]
172
+ end
173
+
174
+ subgraph "MCP Servers"
175
+ PythonMCP["Python MCP Server<br>(run_server.py)"]
176
+ NodeMCP["Node.js MCP Server<br>(mermaid-validator)"]
177
+
178
+ Tools["Tools<br>- add(a, b)<br>- get_current_time()"]
179
+ Resources["Resources<br>- greeting://{name}"]
180
+ MermaidValidator["Mermaid Diagram<br>Validation Tools"]
181
+
182
+ PythonMCP --- Tools
183
+ PythonMCP --- Resources
184
+ NodeMCP --- MermaidValidator
185
+ end
186
+
187
+ subgraph "LLM Providers"
188
+ LLMs["PydanticAI LLM call"]
189
+ end
190
+
191
+ Logfire[("Logfire<br>Tracing")]
192
+
193
+ Agent --> PythonMCP
194
+ Agent --> NodeMCP
195
+
196
+ PythonMCP --> LLMs
197
+ NodeMCP --> LLMs
198
+
199
+ Agent --> Logfire
200
+
201
+ LLM_Response[("Response")] --> User
202
+ LLMs --> LLM_Response
203
+ ```
204
+
205
+ #### Try the Multi-MCP Examples:
206
+
207
+ ``` bash
208
+ # Run the Pydantic-AI multi-MCP example
209
+ uv run agents_mcp_usage/multi_mcp/multi_mcp_use/pydantic_mcp.py
210
+
211
+ # Run the multi-MCP evaluation
212
+ uv run agents_mcp_usage/multi_mcp/eval_multi_mcp/evals_pydantic_mcp.py
213
+ ```
214
+
215
+ More details on multi-MCP implementation can be found in the [ multi_mcp README] ( agents_mcp_usage/multi_mcp/README.md ) .
216
+
66
217
## What is MCP?
67
218
68
219
The Model Context Protocol allows applications to provide context for LLMs in a standardised way, separating the concerns of providing context from the actual LLM interaction.
@@ -88,15 +239,7 @@ A key advantage highlighted is flexibility; MCP allows developers to more easily
88
239
GEMINI_API_KEY=your_gemini_api_key
89
240
OPENAI_API_KEY=your_openai_api_key
90
241
```
91
- 4 . Run any of the sample scripts to see a simple MCP server being used via an Agent framework
92
- - Google Agent Development Kit (ADK)
93
- - [ basic_mcp_use/adk_mcp.py] ( basic_mcp_use/adk_mcp.py )
94
- - LangGraph Agents
95
- - [ basic_mcp_use/langgraph_mcp.py] ( basic_mcp_use/langgraph_mcp.py )
96
- - OpenAI Agents
97
- - [ basic_mcp_use/oai-agent_mcp.py] ( basic_mcp_use/oai-agent_mcp.py )
98
- - Pydantic-AI Agents
99
- - [ basic_mcp_use/pydantic_mcp.py] ( basic_mcp_use/pydantic_mcp.py )
242
+ 4 . Run any of the sample scripts as shown in the examples above
100
243
101
244
## About Logfire
102
245
0 commit comments