Skip to content

fix(agent_registry): source MCP destination ID from RuntimeReference.uri - #7197

Open
chelsealong wants to merge 1 commit into
google:mainfrom
chelsealong:fix-7196-mcp-destination-id
Open

chelsealong wants to merge 1 commit into
google:mainfrom
chelsealong:fix-7196-mcp-destination-id

Conversation

@chelsealong

Copy link
Copy Markdown
Contributor

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

Problem:
AgentRegistry.get_mcp_toolset() stamps the gcp.mcp.server.destination.id
span attribute (used by the Agent Platform Topology view to draw a
connection from an agent to the MCP server it calls) from the Agent
Registry API's mcpServerId field, a urn:mcp:... value. The Topology
view's connection matcher resolves against the App Hub resource-name URI
form instead (//agentregistry.googleapis.com/projects/<number>/locations/ <region>/services/<name>), which the same API response already returns,
unused, under
attributes["agentregistry.googleapis.com/system/RuntimeReference"]["uri"].
Because the two identifier forms never match, no topology connection is
ever drawn for an MCP server reached through AgentRegistry /
AgentRegistrySingleMcpToolset, regardless of correct registration.

Solution:
In get_mcp_toolset(), source destination_resource_id from
attributes["agentregistry.googleapis.com/system/RuntimeReference"]["uri"]
when present, falling back to mcpServerId only if that attribute is
absent. mcpServerId itself is left untouched everywhere else in the file
(e.g. _resolve_auth_provider_scheme, which matches it against IAM
binding targets and still expects the urn form) — this is a one-field,
single-call-site change.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Added test_get_mcp_toolset_prefers_runtime_reference_uri to
tests/unittests/integrations/agent_registry/test_agent_registry.py,
which mocks an MCP server response containing both mcpServerId and
attributes["agentregistry.googleapis.com/system/RuntimeReference"]["uri"]
and asserts the tool's custom_metadata[GCP_MCP_SERVER_DESTINATION_ID]
is the RuntimeReference.uri value, not mcpServerId.

Confirmed the new test fails without the fix (reverting only
agent_registry.py via git stash) with:

AssertionError: assert 'urn:mcp:goog...obal:bigquery' == '//agentregis...ices/bigquery'

- //agentregistry.googleapis.com/projects/1234/locations/global/services/bigquery
+ urn:mcp:googleapis.com:projects:1234:locations:global:bigquery

Full suite for the touched module, with the fix applied:

$ pytest tests/unittests/integrations/agent_registry/ -q
55 passed, 13 warnings in 2.73s

pre-commit run --files src/google/adk/integrations/agent_registry/agent_registry.py tests/unittests/integrations/agent_registry/test_agent_registry.py
passes (ruff, isort, pyink, addlicense, compliance checks, codespell).

Manual End-to-End (E2E) Tests:

Not performed — this requires a live Google Cloud Agent Registry
deployment with a registered MCP server and OTLP export to
telemetry.googleapis.com, which is unavailable in this environment.
Covered instead by the unit test above, which reproduces the exact
API response shape from the issue report (both mcpServerId and
RuntimeReference.uri present) and asserts the observable output
(custom_metadata[GCP_MCP_SERVER_DESTINATION_ID]).

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have added tests that prove my fix is effective.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end (see note above).

Additional context

This change was written with AI assistance (Claude Code), with all
changes reviewed and verified by the human account opening this PR.

Fixes #7196

get_mcp_toolset() stamped gcp.mcp.server.destination.id on tools using
mcpServerId, a urn:mcp:... value. The Agent Platform Topology view's
connection matcher resolves against the App Hub resource-name URI form
instead, which the Agent Registry API returns in the same response under
attributes["agentregistry.googleapis.com/system/RuntimeReference"]["uri"].
Since the two never matched, no topology connection was ever drawn for an
MCP server reached through AgentRegistry.

Prefer RuntimeReference.uri for the destination span attribute, falling
back to mcpServerId when the attribute is absent. mcpServerId is left
unchanged everywhere else (e.g. IAM binding resolution), which still
expects the urn form.

Fixes google#7196
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AgentRegistry.get_mcp_toolset() reads the wrong field for gcp.mcp.server.destination.id — breaks Agent Platform Topology view

1 participant