Skip to content

Prevent duplicate MCP server registration in Google ADK tooling extension#168

Merged
JesuTerraz merged 3 commits intousers/jterrazas/google-adk-supportfrom
copilot/sub-pr-156
Feb 6, 2026
Merged

Prevent duplicate MCP server registration in Google ADK tooling extension#168
JesuTerraz merged 3 commits intousers/jterrazas/google-adk-supportfrom
copilot/sub-pr-156

Conversation

Copy link
Contributor

Copilot AI commented Feb 6, 2026

The add_tool_servers_to_agent() method unconditionally appended servers on each invocation, causing duplicate tools in agent.tools, duplicate _connected_servers entries, and multiple cleanup attempts for the same server.

Changes

  • De-duplicate by server URL: Collect existing server URLs from agent.tools before processing new servers. Skip servers already present.
  • Performance optimization: Use set for URL tracking (O(1) lookup vs O(n) list scan).
  • Conditional modification: Only update agent.tools when new servers are added.

Implementation

# Collect existing URLs (set for O(1) lookup)
existing_server_urls = set()
for tool in agent.tools:
    if hasattr(tool, "connection_params") and hasattr(tool.connection_params, "url"):
        existing_server_urls.add(tool.connection_params.url)

# Skip duplicates during processing
for server_config in mcp_server_configs:
    if server_config.url in existing_server_urls:
        continue
    # Create and add new toolset
    existing_server_urls.add(server_config.url)  # Prevent intra-batch duplicates

Pattern follows OpenAI extension implementation. Prevents duplicate tools, duplicate cleanup attempts, and unnecessary processing on repeated calls.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits February 6, 2026 19:42
Co-authored-by: JesuTerraz <96103167+JesuTerraz@users.noreply.github.com>
Co-authored-by: JesuTerraz <96103167+JesuTerraz@users.noreply.github.com>
Copilot AI changed the title [WIP] WIP Address feedback on New Google ADK Tooling Extension PR Prevent duplicate MCP server registration in Google ADK tooling extension Feb 6, 2026
Copilot AI requested a review from JesuTerraz February 6, 2026 19:47
@JesuTerraz JesuTerraz marked this pull request as ready for review February 6, 2026 19:50
@JesuTerraz JesuTerraz requested a review from a team as a code owner February 6, 2026 19:50
@JesuTerraz JesuTerraz merged commit 76aa10b into users/jterrazas/google-adk-support Feb 6, 2026
1 check passed
@JesuTerraz JesuTerraz deleted the copilot/sub-pr-156 branch February 6, 2026 19:50
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.

2 participants