π OpenHands: AI-Driven Development
(Hotfix): make sure MCP tool error observations are surfaced to agent (#8894)
Rohit Malhotrad30c6ff7201f
diff --git a/openhands/integrations/github/github_service.py b/openhands/integrations/github/github_service.pyindex f1adfed34b..4cf5279abd 100644--- a/openhands/integrations/github/github_service.py+++ b/openhands/integrations/github/github_service.py@@ -483,35 +483,33 @@ class GitHubService(BaseGitService, GitService):- PR URL when successful- Error message when unsuccessful"""- try:- url = f'{self.BASE_URL}/repos/{repo_name}/pulls'-- # Set default body if none provided- if not body:- body = f'Merging changes from {source_branch} into {target_branch}'-- # Prepare the request payload- payload = {- 'title': title,- 'head': source_branch,- 'base': target_branch,- 'body': body,- 'draft': draft,- }-- # Make the POST request to create the PR- response, _ = await self._make_request(- url=url, params=payload, method=RequestMethod.POST- )- # Return the HTML URL of the created PR- if 'html_url' in response:- return response['html_url']- else:- return f'PR created but URL not found in response: {response}'+ url = f'{self.BASE_URL}/repos/{repo_name}/pulls'++ # Set default body if none provided+ if not body:+ body = f'Merging changes from {source_branch} into {target_branch}'++ # Prepare the request payload+ payload = {+ 'title': title,+ 'head': source_branch,+ 'base': target_branch,+ 'body': body,+ 'draft': draft,+ }++ # Make the POST request to create the PR+ response, _ = await self._make_request(+ url=url, params=payload, method=RequestMethod.POST+ )++ # Return the HTML URL of the created PR+ if 'html_url' in response:+ return response['html_url']+ else:+ return f'PR created but URL not found in response: {response}'- except Exception as e:- return f'Error creating pull request: {str(e)}'github_service_cls = os.environ.get(diff --git a/openhands/integrations/gitlab/gitlab_service.py b/openhands/integrations/gitlab/gitlab_service.pyindex 5d9f17dd8c..28b2182505 100644--- a/openhands/integrations/gitlab/gitlab_service.py+++ b/openhands/integrations/gitlab/gitlab_service.py@@ -476,38 +476,37 @@ class GitLabService(BaseGitService, GitService):- MR URL when successful- Error message when unsuccessful"""- try:- # Convert string ID to URL-encoded path if needed- project_id = str(id).replace('/', '%2F') if isinstance(id, str) else id- url = f'{self.BASE_URL}/projects/{project_id}/merge_requests'-- # Set default description if none provided- if not description:- description = (- f'Merging changes from {source_branch} into {target_branch}'- )- # Prepare the request payload- payload = {- 'source_branch': source_branch,- 'target_branch': target_branch,- 'title': title,- 'description': description,- }+ # Convert string ID to URL-encoded path if needed+ project_id = str(id).replace('/', '%2F') if isinstance(id, str) else id+ url = f'{self.BASE_URL}/projects/{project_id}/merge_requests'- # Make the POST request to create the MR- response, _ = await self._make_request(- url=url, params=payload, method=RequestMethod.POST+ # Set default description if none provided+ if not description:+ description = (+ f'Merging changes from {source_branch} into {target_branch}')- # Return the web URL of the created MR- if 'web_url' in response:- return response['web_url']- else:- return f'MR created but URL not found in response: {response}'+ # Prepare the request payload+ payload = {+ 'source_branch': source_branch,+ 'target_branch': target_branch,+ 'title': title,+ 'description': description,+ }++ # Make the POST request to create the MR+ response, _ = await self._make_request(+ url=url, params=payload, method=RequestMethod.POST+ )++ # Return the web URL of the created MR+ if 'web_url' in response:+ return response['web_url']+ else:+ return f'MR created but URL not found in response: {response}'+- except Exception as e:- return f'Error creating merge request: {str(e)}'gitlab_service_cls = os.environ.get(diff --git a/openhands/integrations/service_types.py b/openhands/integrations/service_types.pyindex 3e7dea4d79..11ed113eb3 100644--- a/openhands/integrations/service_types.py+++ b/openhands/integrations/service_types.py@@ -167,11 +167,11 @@ class BaseGitService(ABC):return RateLimitError('GitHub API rate limit exceeded')logger.warning(f'Status error on {self.provider} API: {e}')- return UnknownException('Unknown error')+ return UnknownException(f'Unknown error: {e}')def handle_http_error(self, e: HTTPError) -> UnknownException:logger.warning(f'HTTP error on {self.provider} API: {type(e).__name__} : {e}')- return UnknownException(f'HTTP error {type(e).__name__}')+ return UnknownException(f'HTTP error {type(e).__name__} : {e}')class GitService(Protocol):diff --git a/openhands/server/routes/mcp.py b/openhands/server/routes/mcp.pyindex 780824174a..7bc8d93ee8 100644--- a/openhands/server/routes/mcp.py+++ b/openhands/server/routes/mcp.py@@ -2,6 +2,7 @@ import refrom typing import Annotatedfrom fastmcp import FastMCP+from fastmcp.exceptions import ToolErrorfrom fastmcp.server.dependencies import get_http_requestfrom pydantic import Field@@ -19,7 +20,7 @@ from openhands.server.user_auth import ()from openhands.storage.data_models.conversation_metadata import ConversationMetadata-mcp_server = FastMCP('mcp', stateless_http=True, dependencies=get_dependencies())+mcp_server = FastMCP('mcp', stateless_http=True, dependencies=get_dependencies(), mask_error_details=True)async def save_pr_metadata(user_id: str, conversation_id: str, tool_result: str@@ -96,7 +97,8 @@ async def create_pr(await save_pr_metadata(user_id, conversation_id, response)except Exception as e:- response = str(e)+ error = f"Error creating pull request: {e}"+ raise ToolError(str(error))return response@@ -151,6 +153,7 @@ async def create_mr(await save_pr_metadata(user_id, conversation_id, response)except Exception as e:- response = str(e)+ error = f"Error creating merge request: {e}"+ raise ToolError(str(error))return response