处理工具调用 / Handle tool calls
(name: str, arguments: dict)
| 89 | |
| 90 | @app.call_tool() |
| 91 | async def handle_call_tool(name: str, arguments: dict) -> list[types.TextContent]: |
| 92 | """ |
| 93 | 处理工具调用 / Handle tool calls |
| 94 | """ |
| 95 | try: |
| 96 | if name == "execute_commands": |
| 97 | return await execute_command_batch( |
| 98 | arguments.get("commands", ""), arguments.get("working_directory", ".") |
| 99 | ) |
| 100 | elif name == "execute_single_command": |
| 101 | return await execute_single_command( |
| 102 | arguments.get("command", ""), arguments.get("working_directory", ".") |
| 103 | ) |
| 104 | else: |
| 105 | raise ValueError(f"未知工具 / Unknown tool: {name}") |
| 106 | |
| 107 | except Exception as e: |
| 108 | return [ |
| 109 | types.TextContent( |
| 110 | type="text", |
| 111 | text=f"工具执行错误 / Error executing tool {name}: {str(e)}", |
| 112 | ) |
| 113 | ] |
| 114 | |
| 115 | |
| 116 | async def execute_command_batch( |
nothing calls this directly
no test coverage detected