fix: warm FastMCP's state store before serving, and measure GC per generation (#97)
QuickMCP's lifespan reads FastMCP's private _state_store once, after the
components start and before the server's own lifespan (APP-5 step 4), so
the beartype-instrumented key_value.aio import lands in startup instead of
on a session's first request. A FastMCP without the store, or a warm-up
that raises, is one warning on kubed.mcp.config, by type only.
With otel on, kubed.mcp._gc records cpython.gc.collections and
cpython.gc.duration per generation (TEL-23), and warns of a pass of 0.5 s
or more with the trace id of the span it stalled. The gc callback only
reads the clock and the span context and queues the pass; a task on the
loop drains the queue every second, under an empty context. It starts and
stops with OpenTelemetry, first to stop, with one last drain.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Agent: done
docs: a programmatic stop waits up to graceful_timeout for listen streams (#83)
The stop hook wraps uvicorn's handle_exit, so a stop made by setting
should_exit directly leaves open listen streams to uvicorn, which waits
out the full graceful_timeout. APP-15, CMP-4's serving text and
ServingSettings.graceful_timeout's description now say so: a stop by
signal ends listen streams at once; a programmatic stop waits up to
graceful_timeout for them.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fix(app): open listen streams end cleanly when the server stops, with serving.graceful_timeout (#54)
On HTTP, run() wraps uvicorn.Server.handle_exit while it serves and puts
the listen-ender first in the middleware: when a stop signal lands, each
open subscriptions/listen stream gets a disconnect and a complete response,
so uvicorn no longer cancels it at FastMCP's 2 s and logs an ERROR and a
traceback per listen. Every other request keeps serving.graceful_timeout
(15 s, GRACEFUL_TIMEOUT, --graceful-timeout) to finish, passed as
uvicorn_config['timeout_graceful_shutdown'], which run() now refuses from
the caller. APP-7, APP-8, APP-10, the new APP-15, CMP-4 and config.md say
so. A loopback subprocess test holds it on 3.11 and 3.14.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Agent: done
docs: CFG-11 and CFG-18, APP-2/3, CMP-2, FAC-11, the config page and the changelog
The spec now says a config loads once, in QuickMCP or before it in
load_config(), and CFG-18 sets out the loader: what LoadedConfig holds,
that QuickMCP(loaded=...) reads nothing again, what it refuses beside
loaded=, and that one load builds one server. The config page shows a
server reading its config before building itself, and the changelog
gets its line.
From the whole-branch review: tests for the lifespan running inside the
components, for QuickMCP's None defaults, and for a register that raises
leaving the load claimed; the register loop's comment back above it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Agent: done
fix(app): building the HTTP app fixes mcp.auth, as FastMCP reads it there
mcp.server.http_app() read auth=None and a provider set after it was accepted but
never enforced. The instance's http_app is wrapped in __init__ so building the app,
by hand or through FastMCP's own HTTP run, counts as serving started. APP-2 says so.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Agent: done
docs: CMP-2 to 6 and TEL-20 built; the app, config, telemetry, delivery and facade rows; README and changelog
The spec rows say what was built, the components page gains the built-ins'
tables and a component example, and [Unreleased] gains the Added lines and
the BREAKING ones. The whole-branch review's fixes come with them: run()
refuses serving keys in its options, LOG_LEVEL is read case-insensitively,
the telemetry line never shows userinfo however the address is written, a
clash with a built-in's name suggests hooking it, and the runtime masking
and cancellation paths are tested.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Agent: done
docs: CFG-7 to 10 and 12 to 14, the config page's operator and author sections, APP-2/3, FAC-11, the README and the changelog
The config rows lose (proposed) and say what the code does: literal env and
flag names refused at composition when malformed, duplicated, reserved or
unreadable; sensitive means a secret type; one YAML file, env vars and flags
merged deep over the defaults; provenance and the boot line; every load error
at once, with no value quoted by quick-mcp or pydantic. The config page gains
"Setting the config" for an operator and "Writing a server's config" for an
author. The README passes argv=sys.argv[1:], and [Unreleased] says what a
server writes now.
The whole-branch review's fixes: an error path matches every key a field
accepts, so a secret behind AliasChoices or by-name validation prints no key
below it, and env=/arg= on a field with a non-str alias is refused; a
default_factory model is merged over like a default instance; every YAML
failure and a self-referencing mapping are "is not valid YAML"; tokens after
-- are positionals; the boot line is built only when INFO is on. The plan's
design items 5 and 7 and its Global Constraints record the rules settled.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Agent: done
docs: the config rows, APP-2/3/8, DI-12, FAC-11, the README and the changelog
The config core's rows lose (proposed) and read as built: sections by key,
one composed strict config, loaded at construction, injected by section, and
one schema written without FastMCP. APP-2/3/8, DI-12 and FAC-11 follow, and
the changelog gets the Added and BREAKING lines.
The whole-branch review's fixes come with it: a sensitive field is kept out
of the repr, today's call shapes are tested through QuickMCP(...),
sections=None and a nested RootModel get errors that say what to do, the
schema warning that printed a default is suppressed, and pydantic's floor
is 2.12, as FastMCP already requires.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Agent: done
Merge wiki master (0.2.0) into issue-12
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
# superpowers/specs/facade.md
feat(delivery): instructions per request, and the handshake echoes what it resolved
mcp.instructions(fn) is called with the request's Resolved once per
initialize and once per server/discover; its string is the result's
instructions, written with the gateway prefix. None, a raise or a
non-string keeps the built instructions, the last two logged at error.
Every QuickMCP server's initialize and server/discover result carries
_meta["io.kubed/delivery"] (resources, listed, via, prefix), merged into
any _meta there: the one change to the handshake's bytes. FastMCP 4.2
runs server/discover through the public Middleware.on_discover, so
_handshake._Describe touches no private.
Resolved.extensions is the extension ids the client declares, from
initialize's capabilities or the session's. Resolved.resources and
Resolved.via are Literal types, and the resolver asserts that Via's and
Listed's levels line up.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Agent: done
feat(delivery): a client's default from its clientInfo, and VS Code's built in
mcp.delivery_default(fn) answers each request's inputs at level 4 of
DLV-3, from the client's clientInfo: initialize's params, else the
request's _meta["io.modelcontextprotocol/clientInfo"], else the
session's. kubed-mcp's table of known clients is level 6, matched by
the longest case-sensitive prefix of the name: Visual Studio Code gets
resources off. A server's own settings beat the table.
Every input with a Delivery attribute has every level, so Via and
Listed stay aligned and a Via from delivery_default or the table puts
its preset at that level. An fn that raises, or answers with no
Delivery, is logged at error and gives nothing.
The default-mode client stamps its own clientInfo into each request's
_meta, so the malformed-_meta tests send a raw tools/call on a legacy
session.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
feat(delivery): list_resources and read_resource for clients that cannot read resources
A server with a plugin now serves two read-only tools, list_resources
and read_resource, over every resource it has. They show in tools/list
under X-MCP-Resources: off and are always callable by name.
list_resources returns the request's resources/list rows, less ui://,
with each row's uri written under the gateway prefix. read_resource
reads through the server's middleware, as resources/read does:
- images come back as image content;
- UTF-8 text/* and SVG blobs come back as text;
- other binaries come back as a JSON description, with the pointer
mcp.binary_pointer(fn) gives;
- ui:// is refused;
- a miss carries resources/read's message.
A server's own list_resources or read_resource tool now refuses the
first add_plugin or serve, and mcp.tool, now QuickMCP's own method,
refuses either name once there is a plugin. Both messages name the
plugin layer's replacement.
From the whole-branch review: gateway.prefix() in a custom route reads
the server's own prefix header, a tool miss logs at info, the tools'
JSON keeps non-ASCII, and the Via parts of DLV-2, DLV-4 and DLV-16
are tagged (proposed). DLV-6 and DLV-7 are built; APP-4 and APP-12
follow.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Agent: done
feat(delivery): read every input under the server's own header prefix
QuickMCP(..., header_prefix="Kb") makes every header input read as
Kb-<Name> first, then the shared X-MCP-<Name> alias, then the query
parameter. A bad Kb-* value falls to the alias with one warning naming
it. A background task's worker on the server reads its own headers too.
A prefix that is not a header-name token, or X-MCP itself, is refused
with a ValueError before anything is built. DLV-16 is built; APP-2,
GW-1 and GW-2 follow.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
feat(plugins): reserve prompts:// and agents:// for the plugins
Once a server has a plugin, mcp.resource refuses a resource or template
under prompts:// or agents://, the scheme compared in lowercase. A server
that already has its own resource under either scheme cannot serve its
first plugin: add_plugin, staging.add and mcp.serve refuse it (PLUG-72).
The check reads FastMCP's local store, which is private: if a later
release renames it, the check is skipped with a warning, and a test fails
CI on that bump.
mcp.resource is now a method, with FastMCP's signature and docs (APP-4).
PLUG-72 is no longer proposed. The design records step 4 built, and the
plan records Task 4 as built.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Agent: done
docs(telemetry): the call metrics ship: TEL-16, TEL-17, PKG-22 and APP-6 (#15)
Task 4 of the plan, and the whole-branch review's fixes. TEL-16,
TEL-17 and PKG-22 lose their tag, APP-6 puts the call metrics ahead
of QuickMCP's own middleware, and the design and the plan record
what shipped. TEL-13 and TEL-17 now say that a process that set only
its own tracer provider gets no meter provider, so the call metrics
record nowhere until it sets one. The Prometheus test's scrape of
localhost never goes through a proxy, and the order test checks that
the call metrics come first.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Agent: done
telemetry: record each tool call and prompt render with FastMCP's call metrics (#15)
Task 1 of the plan. With telemetry.otel on, QuickMCP puts FastMCP's
UsageMiddleware(user_id="omit") first in the server's middleware,
ahead of the call scope, so mcp.server.operation.duration records what
the client received, a transient's teardown error included. The
middleware is imported only when otel is on, and a failure to build
it is one error by type: the server serves without it.
This also merges issue-12 for the dependency audit of the telemetry
extra, and brings #14's wiki commit into the wiki branch, so TEL-1 to
TEL-15 read as built here too.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs: app: websocket_route (APP-13), get_tool (APP-14); facade: request_values(request) (FAC-10)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Spec: plugins area (PLUG-1 to PLUG-35), APP-12, PKG-9; the design's History and namespace rule
The namespace defaults to the server's name; namespace="" is the root.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Spec: DI-17 singleton instances, APP-4 add_transform and custom_route, Serving without log_level
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Spec: APP-11, run() never passes log_level to FastMCP
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Spec: app, container and facade areas; the design is built
app.md (APP), container.md (DI) and facade.md (FAC) hold what QuickMCP,
its container, Inject[T], the facade and request_values() now do, with
kubed.mcp.skills as FAC-7, proposed. PKG-9 moves the pin to
fastmcp>=4.2,<5 with the tasks extra, and PKG-21 is the py.typed marker.
The design's History header says what shipped and what was overtaken.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>