e3536df3c9
- Replace build_server_card() with the ServerCard.from_server() classmethod, matching the SDK's from_* alternate-constructor idiom; the _ServerIdentity protocol moves to mcp.shared.experimental.server_card alongside it. - Make DiscoveryResult iterable over its listings (__iter__/__len__), so 'for listing in result:' works without the .listings attribute hop. - Remove the client-side server_card_url() helper: card URLs must come from an AI Catalog entry per the discovery spec, never be constructed by the client. fetch_server_card's docstring now says so. - Explain the RFC 6598 shared address space constant in the SSRF guard and rename it _CGNAT_NETWORK -> _SHARED_ADDRESS_SPACE; ipaddress reports these addresses as neither private nor global, so the guard names them explicitly. All symbols are experimental (no deprecation cycle), so the removals are clean.
20 lines
555 B
Python
20 lines
555 B
Python
from mcp.server import MCPServer
|
|
from mcp.server.experimental.server_card import mount_discovery
|
|
from mcp.shared.experimental.server_card import Remote, ServerCard
|
|
|
|
mcp = MCPServer(
|
|
name="weather",
|
|
version="1.4.0",
|
|
description="Hourly forecasts.",
|
|
website_url="https://example.com",
|
|
)
|
|
|
|
card = ServerCard.from_server(
|
|
mcp,
|
|
name="com.example/weather",
|
|
remotes=[Remote(type="streamable-http", url="https://mcp.example.com/mcp")],
|
|
)
|
|
|
|
app = mcp.streamable_http_app()
|
|
mount_discovery(app, card, public_url="https://mcp.example.com")
|