8000 update mcp agent to use latest toolset interface · aphraz/adk-python@8c78945 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8c78945

Browse files
seanzhougooglecopybara-github
authored andcommitted
update mcp agent to use latest toolset interface
PiperOrigin-RevId: 756613972
1 parent 7dffb59 commit 8c78945

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

contributing/samples/mcp_agent/agent.py

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,26 @@
1616
import os
1717

1818
from google.adk.agents.llm_agent import LlmAgent
19-
from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset, StdioServerParameters
20-
21-
22-
async def create_agent():
23-
"""Gets tools from MCP Server."""
24-
tools, exit_stack = await MCPToolset.from_server(
25-
connection_params=StdioServerParameters(
26-
command='npx',
27-
args=[
28-
'-y', # Arguments for the command
29-
'@modelcontextprotocol/server-filesystem',
30-
os.path.dirname(os.path.abspath(__file__)),
31-
],
32-
)
33-
)
34-
35-
agent = LlmAgent(
36-
model='gemini-2.0-flash',
37-
name='enterprise_assistant',
38-
instruction='Help user accessing their file systems',
39-
tools=tools,
40-
)
41-
return agent, exit_stack
42-
43-
44-
root_agent = create_agent()
19+
from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset
20+
from google.adk.tools.mcp_tool.mcp_toolset import StdioServerParameters
21+
22+
root_agent = LlmAgent(
23+
model='gemini-2.0-flash',
24+
name='enterprise_assistant',
25+
instruction='Help user accessing their file systems',
26+
tools=[
27+
MCPToolset(
28+
connection_params=StdioServerParameters(
29+
command='npx',
30+
args=[
31+
'-y', # Arguments for the command
32+
'@modelcontextprotocol/server-filesystem',
33+
os.path.dirname(os.path.abspath(__file__)),
34+
],
35+
),
36+
# don't want agent to do write operation
37+
tool_predicate=lambda tool, ctx=None: tool.name
38+
not in ('write_file', 'edit_file', 'create_directory', 'move_file'),
39+
)
40+
],
41+
)

0 commit comments

Comments
 (0)
0