|
13 | 13 | from openhands.core.exceptions import AgentRuntimeUnavailableError
|
14 | 14 | from openhands.core.logger import OpenHandsLoggerAdapter
|
15 | 15 | from openhands.core.schema.agent import AgentState
|
16 |
| -from openhands.core.setup import create_mcp_agents |
17 | 16 | from openhands.events.action import ChangeAgentStateAction, MessageAction
|
18 | 17 | from openhands.events.event import Event, EventSource
|
19 | 18 | from openhands.events.stream import EventStream
|
20 | 19 | from openhands.integrations.provider import PROVIDER_TOKEN_TYPE, ProviderHandler
|
21 |
| -from openhands.mcp.mcp_agent import convert_mcp_agents_to_tools |
22 | 20 | from openhands.memory.memory import Memory
|
23 | 21 | from openhands.microagent.microagent import BaseMicroAgent
|
24 | 22 | from openhands.runtime import get_runtime_cls
|
@@ -115,69 +113,6 @@ async def start(
|
115 | 113 | finished = False # For monitoring
|
116 | 114 | runtime_connected = False
|
117 | 115 | try:
|
118 |
| - # Initialize MCP agents first before creating runtime and controller |
119 |
| - try: |
120 |
| - # Log MCP configuration to help with debugging |
121 |
| - self.logger.info(f'MCP SSE servers: {config.mcp.sse.mcp_servers}') |
122 |
| - self.logger.info(f'MCP stdio commands: {config.mcp.stdio.commands}') |
123 |
| - self.logger.info(f'MCP stdio args: {config.mcp.stdio.args}') |
124 |
| - |
125 |
| - # Check if MCP servers are available |
126 |
| - if not config.mcp.sse.mcp_servers and not config.mcp.stdio.commands: |
127 |
| - self.logger.warning( |
128 |
| - 'No MCP servers or commands configured. MCP integration will not work.' |
129 |
| - ) |
130 |
| - else: |
131 |
| - self.logger.info('Initializing MCP agents for server mode...') |
132 |
| - mcp_agents = await create_mcp_agents( |
133 |
| - config.mcp.sse.mcp_servers, |
134 |
| - config.mcp.stdio.commands, |
135 |
| - config.mcp.stdio.args, |
136 |
| - ) |
137 |
| - |
138 |
| - # Give some time for MCP connections to stabilize |
139 |
| - await asyncio.sleep(1) |
140 |
| - |
141 |
| - # For CodeActAgent and similar agents that use the tools attribute |
142 |
| - if hasattr(agent, 'tools'): |
143 |
| - try: |
144 |
| - # Convert MCP agents to tools format for CodeActAgent |
145 |
| - mcp_tools = convert_mcp_agents_to_tools(mcp_agents) |
146 |
| - self.logger.info( |
147 |
| - f"MCP tools created: {[tool.get('function', {}).get('name', '<unnamed>') for tool in mcp_tools]}" |
148 |
| - ) |
149 |
| - |
150 |
| - # If agent already has tools, extend them; otherwise create a new list |
151 |
| - if isinstance(agent.tools, list): |
152 |
| - agent.tools.extend(mcp_tools) |
153 |
| - else: |
154 |
| - agent.tools = mcp_tools |
155 |
| - |
156 |
| - self.logger.info( |
157 |
| - f'Agent now has {len(agent.tools)} tools including MCP tools' |
158 |
| - ) |
159 |
| - except Exception as e: |
160 |
| - self.logger.error( |
161 |
| - f'Error converting MCP agents to tools: {str(e)}', |
162 |
| - exc_info=True, |
163 |
| - ) |
164 |
| - |
165 |
| - # Log MCP agents status |
166 |
| - for idx, mcp_agent in enumerate(mcp_agents): |
167 |
| - self.logger.info( |
168 |
| - f'MCP Agent {idx} connection type: {mcp_agent.connection_type}' |
169 |
| - ) |
170 |
| - self.logger.info( |
171 |
| - f"MCP Agent {idx} available tools: {list(mcp_agent.mcp_clients.tool_map.keys()) if hasattr(mcp_agent, 'mcp_clients') and hasattr(mcp_agent.mcp_clients, 'tool_map') else 'No tools available'}" |
172 |
| - ) |
173 |
| - await mcp_agent.cleanup() |
174 |
| - |
175 |
| - self.logger.info( |
176 |
| - f'Successfully initialized {len(mcp_agents)} MCP agents' |
177 |
| - ) |
178 |
| - except Exception as e: |
179 |
| - self.logger.error(f'Error initializing MCP agents: {e}', exc_info=True) |
180 |
| - |
181 | 116 | self._create_security_analyzer(config.security.security_analyzer)
|
182 | 117 | runtime_connected = await self._create_runtime(
|
183 | 118 | runtime_name=runtime_name,
|
@@ -388,9 +323,9 @@ async def _create_runtime(
|
388 | 323 | return False
|
389 | 324 |
|
390 | 325 | if selected_repository and git_provider_tokens:
|
391 |
| - await self.runtime.clone_repo(git_provider_tokens, |
392 |
| - selected_repository, |
393 |
| - selected_branch) |
| 326 | + await self.runtime.clone_repo( |
| 327 | + git_provider_tokens, selected_repository, selected_branch |
| 328 | + ) |
394 | 329 | await call_sync_from_async(self.runtime.maybe_run_setup_script)
|
395 | 330 |
|
396 | 331 | self.logger.debug(
|
|
0 commit comments