Spell IPv6 hosts with `-` in the `MCP` capability's derived `id`
- Closes #12496
Agent(capabilities=[MCP('http://[::1]:8000/mcp')]) raised UserError: Capability id '::1' cannot contain a colon. The capability derives its default id from the URL hostname without the : to - spelling MCPToolset has used since #10791, and it passes that id to its local toolset and native MCPServerTool, so the toolset's spelling never applied.
MCP._derive_id now applies the same replacement, so the capability, its local toolset and its native tool all get --1. An explicit id= with a : is still rejected. The duplicate-host check keys off the raw hostname, so [::1] and a host named --1 still don't merge. Both now call one helper, host_derived_id in pydantic_ai/_utils.py, so the two ids can't drift apart again. It lives there because pydantic_ai.mcp imports fastmcp and the capability must work without it.
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
- PR title is fit for the release changelog.
Summary by cubic
Fixes the MCP capability deriving an invalid id for IPv6 hosts, so Agent(capabilities=[MCP('http://[::1]:8000/mcp')]) no longer raises UserError: Capability id '::1' cannot contain a colon.
MCPToolsetand the capability now share one helper in_utilsthat spells the hostname with:replaced by-, so the capability, its local toolset, and its native tool all derive--1from[::1].- An explicit
id=containing a:is still rejected, and duplicate-host detection still keys off the raw hostname.