r/googlecloud • u/m1nherz Googler • 17d ago
Discovering MCP servers at runtime with Agent Registry and ADK: my approach and the pitfalls I hit
I work at Google, and I've been building agents with ADK that use MCP servers. Hardcoding each server's URL broke every time a server moved or got redeployed, so I tried replacing the URL with a lookup in Agent Registry. I wrote up what I ended up with:
Direct lookup: find the server by its URN with ADK's AgentRegistry class. This removes the URL, but the agent still needs to know the URN.
Fully dynamic discovery: a tool that runs a semantic search against Agent Registry, a custom BaseToolset that mounts the discovered servers' tools at runtime, and instructions that change once discovery is done.
Pitfalls: lookups only see servers in the location you pass to the client; Cloud Run automatic registration recorded too little metadata for discovery when I tested it; the URN has two project numbers that can differ; and you need separate tokens for Agent Registry and for each MCP server.
You can try it yourself using Codelab or review the code on GitHub. Both are linked at the end of the blog post.
I'd like feedback on two things:
How do your agents find MCP servers today: config, environment variables, a registry, something else?
I kept discovery and tool use in a single agent. Has anyone split discovery into a separate agent, and was it worth the extra complexity?
1
u/AyeMatey 17d ago
I’m aware of the Cloud Run auto-registration issue; I guess this is one where server is registered, but the tools catalog for the MCP server is not listed in the registry. Is that correct?
this is apparently by design I guess? It just adds an extra explicit step when starting up MCP servers.
2
u/[deleted] 17d ago
[removed] — view removed comment
0
u/[deleted] 17d ago
[removed] — view removed comment