e15f284228
New Advanced page covering serving a card, publishing on a brand domain, static publishing, discovery and connect, ETag revalidation, and the security model (advisory cards, endpoint-keyed dedup, host scoped consent, SSRF policy defaults). Tutorials are pyright-checked docs_src modules proved against the real SDK by tests/docs_src/test_server_cards.py.
23 lines
867 B
Python
23 lines
867 B
Python
import httpx2
|
|
|
|
from mcp.client.experimental.server_card import create_server_card_request, parse_server_card_response
|
|
from mcp.shared.experimental.server_card import ServerCard
|
|
|
|
|
|
class CardStore:
|
|
"""Your host's cache. Anything that keeps a card and its ETag per URL works."""
|
|
|
|
def __init__(self) -> None:
|
|
self.cards: dict[str, ServerCard] = {}
|
|
self.etags: dict[str, str] = {}
|
|
|
|
|
|
async def refresh(store: CardStore, http: httpx2.AsyncClient, url: str) -> ServerCard:
|
|
request = create_server_card_request(url, if_none_match=store.etags.get(url))
|
|
response = await http.send(request)
|
|
if response.status_code != 304: # an unchanged card costs a 304
|
|
store.cards[url] = parse_server_card_response(response)
|
|
if "etag" in response.headers:
|
|
store.etags[url] = response.headers["etag"]
|
|
return store.cards[url]
|