Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions autogpt_platform/backend/backend/copilot/prompting.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
# Shared technical notes that apply to both SDK and baseline modes
_SHARED_TOOL_NOTES = """\

### Tool priority: blocks before MCP
When a user asks for an integration (Google Sheets, Gmail, Slack, etc.), always
search for platform blocks first using `find_block` before considering MCP.
The platform has 480+ built-in blocks covering Google Workspace, social media,
databases, and more. Only fall back to `run_mcp_tool` when no matching blocks
exist and the service is in the known MCP servers list.

### Sharing files with the user
After saving a file to the persistent workspace with `write_workspace_file`,
share it with the user by embedding the `download_url` from the response in
Expand Down
19 changes: 18 additions & 1 deletion autogpt_platform/backend/backend/copilot/sdk/mcp_tool_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,24 @@ Use these URLs directly without asking the user:
| Cloudflare | `https://mcp.cloudflare.com/mcp` |
| Atlassian / Jira | `https://mcp.atlassian.com/mcp` |

For other services, search the MCP registry at https://registry.modelcontextprotocol.io/.
For other services, search the MCP registry API:
```
GET https://registry.modelcontextprotocol.io/v0/servers?q=<search_term>
```
Each result includes a `remotes` array with the exact server URL to use.

### Important: Check blocks first

Before using `run_mcp_tool`, always check if the platform already has blocks for the service
using `find_block`. The platform has hundreds of built-in blocks (Google Sheets, Google Docs,
Google Calendar, Gmail, etc.) that work without MCP setup.

Only use `run_mcp_tool` when:
- The service is in the known hosted MCP servers list above, OR
- You searched `find_block` first and found no matching blocks

**Never guess or construct MCP server URLs.** Only use URLs from the known servers list above
or from the `remotes[].url` field in MCP registry search results.

### Authentication

Expand Down
18 changes: 17 additions & 1 deletion autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
# HTTP status codes that indicate authentication is required
_AUTH_STATUS_CODES = {401, 403}

# Status codes where the URL almost certainly doesn't host an MCP server
_NOT_MCP_STATUS_CODES = {404, 405, 406}


def _service_name(host: str) -> str:
"""Strip the 'mcp.' prefix from an MCP hostname: 'mcp.sentry.dev' → 'sentry.dev'"""
Expand Down Expand Up @@ -185,9 +188,22 @@ async def _execute(
# Server requires auth and user has no stored credentials
return self._build_setup_requirements(server_url, session_id)
logger.warning("MCP HTTP error for %s: %s", server_host(server_url), e)

host = server_host(server_url)
if e.status_code in _NOT_MCP_STATUS_CODES:
error_msg = (
f"No MCP server found at {host} (HTTP {e.status_code}). "
"This URL does not appear to host an MCP server."
)
else:
error_msg = f"MCP server at {host} returned HTTP {e.status_code}."
return ErrorResponse(
message=f"MCP server returned HTTP {e.status_code}: {e}",
message=error_msg,
session_id=session_id,
# Raw HTTP detail goes in `error` so the frontend can
# render it in a collapsible/de-emphasised block instead
# of dumping the full body (which may be an HTML page).
error=f"HTTP {e.status_code}: {str(e)[:300]}",
)

except MCPClientError as e:
Expand Down
Loading