[Feat]: Git mcp server to open PRs (#8348)

Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: Xingyao Wang <xingyao@all-hands.dev>
Co-authored-by: Robert Brennan <accounts@rbren.io>
This commit is contained in:
Rohit Malhotra
2025-05-21 11:48:02 -04:00
committed by GitHub
parent 7305c8fb31
commit 890796cc9d
18 changed files with 2663 additions and 2158 deletions

View File

@@ -25,7 +25,11 @@ class MCPClient(BaseModel):
arbitrary_types_allowed = True
async def connect_sse(
self, server_url: str, api_key: str | None = None, timeout: float = 30.0
self,
server_url: str,
api_key: str | None = None,
conversation_id: str | None = None,
timeout: float = 30.0,
) -> None:
"""Connect to an MCP server using SSE transport.
@@ -41,9 +45,14 @@ class MCPClient(BaseModel):
try:
# Use asyncio.wait_for to enforce the timeout
async def connect_with_timeout():
headers = {'Authorization': f'Bearer {api_key}'} if api_key else {}
if conversation_id:
headers['X-OpenHands-Conversation-ID'] = conversation_id
streams_context = sse_client(
url=server_url,
headers={'Authorization': f'Bearer {api_key}'} if api_key else None,
headers=headers if headers else None,
timeout=timeout,
)
streams = await self.exit_stack.enter_async_context(streams_context)

View File

@@ -44,7 +44,7 @@ def convert_mcp_clients_to_tools(mcp_clients: list[MCPClient] | None) -> list[di
async def create_mcp_clients(
sse_servers: list[MCPSSEServerConfig],
sse_servers: list[MCPSSEServerConfig], conversation_id: str | None = None
) -> list[MCPClient]:
mcp_clients: list[MCPClient] = []
# Initialize SSE connections
@@ -56,7 +56,11 @@ async def create_mcp_clients(
client = MCPClient()
try:
await client.connect_sse(server_url.url, api_key=server_url.api_key)
await client.connect_sse(
server_url.url,
api_key=server_url.api_key,
conversation_id=conversation_id,
)
# Only add the client to the list after a successful connection
mcp_clients.append(client)
logger.info(f'Connected to MCP server {server_url} via SSE')
@@ -155,6 +159,7 @@ async def add_mcp_tools_to_agent(
"""
Add MCP tools to an agent.
"""
from openhands.runtime.impl.action_execution.action_execution_client import (
ActionExecutionClient, # inline import to avoid circular import
)