|
16 | 16 | import os |
17 | 17 |
|
18 | 18 | 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