49b9bb6724
Deploy Docs / deploy-docs (push) Failing after 1s
Conformance Tests / client-conformance (push) Failing after 3s
Conformance Tests / server-conformance (push) Failing after 1s
GitHub Actions Security Analysis / zizmor (push) Failing after 1s
CI / checks (push) Failing after 59m20s
CI / all-green (push) Waiting to run
2.1 KiB
2.1 KiB
resources
Expose data by URI: a static resource (config://app) and an RFC-6570
template (greeting://{name}). One @mcp.resource() decorator handles both —
the SDK infers static-vs-template from whether the URI contains {...}. The
client lists resources, lists templates, then reads each.
Run it
# stdio (default — the client spawns the server as a subprocess)
uv run python -m stories.resources.client
# HTTP — the client self-hosts the server on a free port, runs, then tears it down
uv run python -m stories.resources.client --http
# same, against the lowlevel-API server variant
uv run python -m stories.resources.client --http --server server_lowlevel
What to look at
client.pyasync with Client(target, mode=mode) as client:— the one line every client example exists to teach.targetis anythingClient()accepts (an in-process server, a transport, or an HTTP URL) andmode=is always explicit; the rest of the story is the body of thatasync with.server.pyapp_configvsgreeting— a URI with no{}registers a static resource (appears inresources/list); a URI with{name}registers a template (appears only inresources/templates/list) and the placeholder must match the function parameter name.server_lowlevel.pyread_resource— withoutMCPServeryou own the URI dispatch yourself, including raisingMCPError(code=INVALID_PARAMS, ...)for unknown URIs (matches whatMCPServersends).client.pyisinstance(entry, TextResourceContents)—contentsis a list ofTextResourceContents | BlobResourceContents; narrow before reading.text.
Not shown here
Subscriptions. Per-URI resources/subscribe is a 2025-era RPC being replaced
by subscriptions/listen in 2026-07-28; neither is shown in this story. See
stickynotes/ for list_changed notifications.
Spec
See also
stickynotes/ (list-changed notifications), pagination/ (cursor over a long
resource list).