Repository navigation
2026 11 27 skill read labels
History. Written 2026-11-27 for Dr K. It is the plan of record for #77, built in #78 on
issue-77, which merges intomain. It rewrites telemetry TEL-21 and adds a sentence to TEL-16. It builds on telemetry reports itself, whose TEL-21 labelled a skill's file by its own URI.
For agentic workers: REQUIRED SUB-SKILL: Use skill://superpowers/subagent-driven-development/SKILL.md (recommended) or skill://superpowers/executing-plans/SKILL.md to implement this plan task-by-task. Steps use checkbox (
- [ ]) syntax for tracking.
Goal: a resources/read of anything the plugin layer serves is recorded on
mcp.server.operation.duration under a fixed pattern, a library and a plugin, so the series grow
with the plugins served, never with the files read.
Architecture: the plugin layer answers from the request's pinned build. Each build gets an
owners map (a skill's root URI, or a prompt or agent folder's URI, to its Plugin), and a pure
function _labels(build, uri) classifies the URI. _ReadObserver asks the layer first, and falls
back to TEL-21's template lookup only when the layer says the URI isn't its own. Two more fields ride
the existing _Matched holder into _Labelled.record.
Tech Stack: Python 3.11–3.14, FastMCP 4.2 (>=4.2,<5), OpenTelemetry SDK, pytest, ruff.
Spec: #77's notes and Dr K's ruling on the issue (2026-11-27T02:48Z, spec approved). There's no
separate design file: this plan is the record, and Task 3 writes the rows into
docs/superpowers/specs/telemetry.md.
Dr K's rulings aren't to be reopened:
- the library label holds the library, the namespace's first segment (
grafana), and the plugin label holds the plugin's name (grafana-k6), never the joined namespace; - the exact URI stays on the span (
mcp.resource.uri); metrics never carry a URI the layer serves; - template reads are unchanged;
- mcp-kb's own
skill://<library>/_index.mdandskill://<library>/<plugin>/_index.mdstay labelled by URI. The spec notes it as kb's to change, and nothing is filed.
Where the notes left a detail open, the choice made here is marked (settled here).
-
The attributes (settled here).
kubed.plugin.libraryandkubed.plugin.name, which Prometheus shows askubed_plugin_libraryandkubed_plugin_name. OpenTelemetry asks a non-standard attribute for a vendor prefix, andmcp.*belongs to the OpenTelemetry MCP conventions.-
kubed.plugin.libraryisplugin.namespace.partition("/")[0]. -
kubed.plugin.nameisplugin.name. - A skill's name is never a label.
-
-
The patterns (settled here), the exact values of
mcp.resource.template.{path}stands for every segment between the library and the file's own name, none included:A read of mcp.resource.templatea skill's SKILL.mdskill://{library}/{path}/SKILL.mda skill's _manifestskill://{library}/{path}/_manifesta skill folder's index, the root's included skill://{library}/{path}/_index.md,skill://{library}/{path}/_index.jsonany other file of a skill skill://{library}/{path}a prompt or agent file prompts://{library}/{path},agents://{library}/{path}a prompt or agent folder's index prompts://{library}/{path}/_index.md,…/_index.json, the same foragents://Only the root's
SKILL.mdand_manifesttake their own patterns. ASKILL.mdor_manifestin a subfolder is any other file, as SKL treats it. -
Whose URI it is, and whose plugin.
-
A served prompt or agent file, by its exact URI in
build.files: its own plugin,material.served.plugin. A renamed agent (<name>@<plugin>.md, PLUG-64) is its own plugin's. -
Otherwise, a URI strictly below an owned URI, longest owner first:
- a skill's root (
skills._root(key)), owned by the plugin whose catalogue holds the key; - a prompt or agent folder, owned by the first admitted plugin with a file in it, PLUG-68's rule
for an index's
Site.
- a skill's root (
- Anything else isn't the layer's. That covers another scheme, a skill's root URI itself, a folder above every namespace, and mcp-kb's library indexes.
- Whether the file exists doesn't matter (settled here). A missing file below a skill's root, or below a served folder, takes the pattern of its last segment. So a failed read keeps a bounded label, and the lookup never checks a skill's files.
-
A served prompt or agent file, by its exact URI in
-
The owners are made with the build.
_Build.owners: Mapping[str, Plugin]is filled in both branches ofPlugins._make:- skills from the build's own catalogue, so a skill a rewriter failed isn't owned;
- folders from
_folders_inof each material, in build order, keeping the first plugin.
The lookup reads
build.filesandbuild.ownersonly, never a file and never a skill's file list. -
The order of the lookups.
_ReadObserverasks the layer first, aftercall_nextreturns or raises.- The layer answers: label, library and plugin are the layer's, success or failure.
-
It doesn't: TEL-21 as before. On success, the template's
uri_template, else the URI. On failure, the template's, else no label. - The layer's lookup never raises (TEL-6): a failure, a pin that failed included, counts as "not the layer's".
-
No plugin served: a server with no plugin served (
not plugins.current) skips the layer and never pins. - Timing: both lookups count in the read's duration.
-
What reaches the histogram.
_Labelled.recordchanges only where it already acts, on a point that hasmcp.resource.template. There it also setskubed.plugin.libraryandkubed.plugin.namewhen the holder has them. A point UsageMiddleware has taken the name off, a routing error, carries none of the three, as before. Tool and prompt points are untouched. -
Prompts are unchanged.
gen_ai.prompt.nameis bounded by the prompts served, a plugin's prefixed name (PLUG-63) included, and unknown names are already left off. TEL-16 says so, and a prompt point gets no library or plugin label.
-
from __future__ import annotationsstays at the top of every module.kubed/gets no__init__.py. -
No public name changes.
_ReadLabels,_labels,Plugins._read_labelsand_Build.ownersare private._CallMetrics.observeand_ReadObserverare private and change signature freely. -
_metrics.pyis still imported only whenotelis on._builtins.pyandtelemetry.pystay FastMCP-free at module level._metrics.pyimportsPluginsonly underTYPE_CHECKING. -
_Matched(label)still builds positionally:test_the_call_metrics_copy_and_still_labelcalls_Matched("data://items/{id}"). - TEL-6: the observer never raises anything but the read's own error, and a lookup failure is never logged per read.
-
Tests: no network beyond localhost. Every server is built with
config=. -
Checks, as CI runs them (
lint.yml, andtest.ymlafterpip install -e .[test,tasks]):ruff check .andpytest. -
The wiki. Edits are left in the
docs/checkout. The job commits them on the wiki branchissue-77and moves the pointer here. No git runs insidedocs/, and the wiki'smasteris never pushed. Spec text is in the present tense, with no issue numbers.
-
A server with no plugin. Its static and template reads keep TEL-21's labels, and the observer
never pins (Task 2,
test_a_server_without_plugins_never_pins_for_a_label). -
A read whose pin fails, from a view that raises. The read fails with the view's error, the
observer adds no error of its own, and the point carries none of the layer's labels (Task 2,
test_a_read_whose_pin_fails_falls_back_to_the_template_lookup). -
A rewritten build. Its indexes come from
build.indexes, not rendered per read, and they label the same as an unrewritten build's (Task 1,test_an_index_labels_the_same_rewritten_or_not). -
Two plugins in one namespace (PLUG-18). A shared prompts folder's index is the first plugin's,
and each file is its own plugin's (Task 1,
test_a_shared_folder_is_its_first_plugins). -
A renamed agent at
agents://<ns>/<name>@<plugin>.mdis the renaming plugin's, not the plain name's owner (Task 1,test_a_renamed_agent_is_its_own_plugins).
Files:
- Modify:
kubed/mcp/plugins.py:- new
_ReadLabels,_owners,_patternand_labelsnear_Build; -
_Build.owners, filled in both branches ofPlugins._make; - new
Plugins._read_labels.
- new
- Create:
tests/test_read_labels.py.
Interfaces:
-
Consumes:
_Build,_Material,_folders_in,skills._root,skills.INDEX_MD,skills.INDEX_JSON,skills.ENTRY,skills.MANIFEST,Plugins.pinned. -
Produces:
-
@dataclass(frozen=True) class _ReadLabels: pattern: str; library: str; plugin: str; -
_Build.owners: Mapping[str, Plugin], defaulting to an emptyMappingProxyType; -
_owners(admitted: Iterable[_Served], catalogue: Mapping[str, skills.Skill], materials: Iterable[_Material]) -> Mapping[str, Plugin]; -
_labels(build: _Build, uri: str) -> _ReadLabels | None; -
async def Plugins._read_labels(self, uri: str) -> _ReadLabels | None: None whennot self.current, else_labels((await self.pinned()).build, uri). It may raise whatpinnedraises: Task 2's caller catches it.
-
-
Step 1: Write the failing tests
tests/test_read_labels.py builds real servers with QuickMCP(name, config={}), write from
tests/plugin_server.py, and KIT_TREE from tests/gateway_server.py. The plugin folder is kit, so
the plugin's name is kit. Off a request, await mcp._plugins.pinned() makes a fresh pin, and the
tests call _labels(pin.build, uri).
TREE = {**KIT_TREE, "skills/guide/references/b.md": "# B\n"}
async def labels(mcp, uri):
return _labels((await mcp._plugins.pinned()).build, uri)
@pytest.mark.parametrize(("uri", "pattern"), [
("skill://lib/guide/SKILL.md", "skill://{library}/{path}/SKILL.md"),
("skill://lib/guide/_manifest", "skill://{library}/{path}/_manifest"),
("skill://lib/guide/_index.md", "skill://{library}/{path}/_index.md"),
("skill://lib/guide/references/_index.json", "skill://{library}/{path}/_index.json"),
("skill://lib/guide/references/a.md", "skill://{library}/{path}"),
("skill://lib/guide/references/missing.md", "skill://{library}/{path}"),
("prompts://lib/ask.md", "prompts://{library}/{path}"),
("agents://lib/scout.md", "agents://{library}/{path}"),
("prompts://lib/_index.md", "prompts://{library}/{path}/_index.md"),
("agents://lib/_index.json", "agents://{library}/{path}/_index.json"),
])
async def test_each_kind_of_read_has_its_pattern(tmp_path, uri, pattern):
mcp = QuickMCP("labels", config={})
mcp.add_plugin(write(tmp_path / "kit", TREE), namespace="lib")
assert await labels(mcp, uri) == _ReadLabels(pattern, "lib", "kit")
async def test_two_files_of_one_skill_label_alike(tmp_path):
# a.md and b.md: the same _ReadLabels
async def test_the_library_is_the_namespaces_first_segment(tmp_path):
# add_plugin(write(tmp_path / "grafana-k6", TREE), namespace="grafana/grafana-k6")
# skill://grafana/grafana-k6/guide/SKILL.md -> ("skill://{library}/{path}/SKILL.md", "grafana", "grafana-k6")
@pytest.mark.parametrize("uri", [
"skill://lib/guide", # a skill's root itself
"skill://lib/_index.md", # above every skill: a server's own (mcp-kb's library index)
"skill://other/x/SKILL.md", # no such skill
"prompts://elsewhere/ask.md",
"data://items/1",
"not a uri",
])
async def test_what_the_layer_doesnt_serve_is_none(tmp_path, uri):
# -> None
async def test_a_shared_folder_is_its_first_plugins(tmp_path):
# plugin "first" with commands/a.md, then "second" with commands/b.md, both namespace="grafana"
# prompts://grafana/_index.md -> plugin "first"; prompts://grafana/b.md -> plugin "second"
async def test_a_renamed_agent_is_its_own_plugins(tmp_path):
# "one" and "two" both serve agents/scout.md under namespace "lib"
# agents://lib/scout.md -> "one"; agents://lib/scout@two.md -> "two", pattern "agents://{library}/{path}"
@pytest.mark.parametrize("rewritten", [False, True])
async def test_an_index_labels_the_same_rewritten_or_not(tmp_path, rewritten):
# rewritten: mcp.add_rewriter(lambda site, text: text)
# skill://lib/guide/_index.md and prompts://lib/_index.md label as in the table above
async def test_a_skill_a_rewriter_fails_is_not_the_layers(tmp_path):
# a rewriter that raises on the guide skill's SKILL.md text leaves the skill out of the
# build (PLUG-59): skill://lib/guide/SKILL.md -> None, prompts://lib/ask.md still labelled
async def test_a_server_without_plugins_has_no_labels_and_never_pins(monkeypatch):
mcp = QuickMCP("bare", config={})
async def boom(self): raise AssertionError("pinned")
monkeypatch.setattr(Plugins, "pinned", boom)
assert await mcp._plugins._read_labels("skill://lib/guide/SKILL.md") is NoneA rewriter that fails a skill is written as tests/test_rewriters.py writes one. Check that
Plugins._make drops the failed skill from the build's catalogue before writing the assertion.
- Step 2: Run the tests to verify they fail
Run: pytest tests/test_read_labels.py -v
Expected: collection fails with ImportError: cannot import name '_ReadLabels'.
- Step 3: Implement design items 1 to 4 in
kubed/mcp/plugins.py
_labels checks build.files first for prompts:// and agents://. Then it walks the URI's
ancestors from the longest down, the URI itself excluded, and stops at the first one in
build.owners. _pattern(scheme, rel) is decided by rel, the segments below the owner:
- its last segment an index name gives that index's pattern;
- otherwise, for
skill,rel == [ENTRY]orrel == [MANIFEST]gives that pattern; - otherwise it's the scheme's plain
{path}pattern.
_Build's docstring gains a line on owners.
- Step 4: Run the tests to verify they pass
Run: pytest tests/test_read_labels.py tests/test_rewriters.py tests/test_prompt_and_agent_resources.py tests/test_plugin_views.py -v
Expected: PASS.
- Step 5: Checks and commit
Run: ruff check . && pytest
Expected: all pass.
git add kubed/mcp/plugins.py tests/test_read_labels.py
git commit -m "feat(plugins): a build names each read's pattern, library and plugin"Files:
- Modify:
kubed/mcp/_metrics.py:-
_LIBRARY = "kubed.plugin.library"and_PLUGIN = "kubed.plugin.name"; -
_Matchedgainslibrary: str | None = Noneandplugin: str | None = None, afterlabel; -
_Labelled.record,_CallMetrics.observeand_ReadObserver; - the module docstring.
-
- Modify:
kubed/mcp/_builtins.py:146:metrics.observe(mcp.server, mcp._plugins). - Test:
tests/test_telemetry.py, section# -- resource reads (TEL-21).
Interfaces:
-
Consumes:
Plugins._read_labels(uri) -> _ReadLabels | None(Task 1). -
Produces:
-
_CallMetrics.observe(self, server: FastMCP, plugins: Plugins) -> None; -
_ReadObserver(server: FastMCP, plugins: Plugins).
-
-
Step 1: Write the failing tests
Change the two prefix tests to the layer's labels. Add a helper beside reads:
def labelled(points):
"""Each resources/read point's (template, library, plugin), with its count."""
return [((p.attributes.get("mcp.resource.template"), p.attributes.get("kubed.plugin.library"),
p.attributes.get("kubed.plugin.name")), p.count)
for p in points if p.attributes["mcp.method.name"] == "resources/read"]
# test_a_plugin_skill_read_under_a_prefix_is_labelled_without_it: reads a.md and SKILL.md under kb+:
assert sorted(labelled(duration_points(metered, "kit-reads"))) == [
(("skill://{library}/{path}", "lib", "kit"), 1),
(("skill://{library}/{path}/SKILL.md", "lib", "kit"), 1),
]
# test_a_plugin_file_read_under_a_prefix_is_labelled_without_it:
assert labelled(...) == [((f"{scheme}://{{library}}/{{path}}", "lib", "kit"), 1)]
async def test_many_files_of_one_skill_are_one_series(metered, tmp_path):
# TREE with references/b.md; read a.md, b.md, a.md
assert labelled(...) == [(("skill://{library}/{path}", "lib", "kit"), 3)]
async def test_an_index_and_a_manifest_read_are_labelled_by_the_layer(metered, tmp_path):
# skill://lib/guide/_index.md, skill://lib/guide/_manifest, prompts://lib/_index.md: one point each,
# with the patterns of Task 1's table and ("lib", "kit")
async def test_no_point_carries_a_served_uri(metered, tmp_path):
# after the reads above, no attribute value of any resources/read point starts with "skill://lib/",
# "prompts://lib/" or "agents://lib/"
async def test_the_span_keeps_the_exact_uri(metered, spans, tmp_path):
# read skill://lib/guide/references/a.md
(span,) = [s for s in spans.get_finished_spans()
if s.attributes.get("mcp.method.name") == "resources/read"]
assert span.attributes["mcp.resource.uri"] == "skill://lib/guide/references/a.md"
async def test_a_failed_read_of_a_missing_skill_file(metered, tmp_path):
# read skill://lib/guide/references/missing.md, pytest.raises(MCPError)
# its point: ("skill://{library}/{path}", "lib", "kit"), and rpc.status_code as FastMCP gives it
async def test_a_template_read_beside_plugins_is_unchanged(metered, tmp_path):
# resourced("beside") plus the kit plugin: data://items/1 -> (("data://items/{id}", None, None), 1)
async def test_a_server_without_plugins_never_pins_for_a_label(metered, monkeypatch):
# monkeypatch Plugins.pinned to raise AssertionError; resourced("unpinned") reads data://about
# and data://items/1: [("data://about", None, None)], [("data://items/{id}", None, None)]
async def test_a_read_whose_pin_fails_falls_back_to_the_template_lookup(metered, tmp_path):
# kit plugin; mcp.plugin_view(a view fn that raises RuntimeError("view"))
# reading skill://lib/guide/SKILL.md raises MCPError; its point has none of the three attributestest_a_failed_read_of_a_missing_skill_file: if Step 4 shows UsageMiddleware takes the name off this
error (a routing error, design item 6), the point carries none of the three. Pin that instead, and say
so in the pull request. Either way no attribute holds the URI.
test_a_read_through_the_tool_is_a_call_and_a_read gains a read of skill://lib/guide/SKILL.md
through the tool. Its point is labelled by the layer, so the nested read shares the pin.
test_the_call_metrics_copy_and_still_label gains a case: with
_Matched("skill://{library}/{path}", "lib", "kit"), the recorded point is
{_TEMPLATE: "skill://{library}/{path}", _LIBRARY: "lib", _PLUGIN: "kit"}. A point without _TEMPLATE
gets neither new key.
- Step 2: Run the tests to verify they fail
Run: pytest tests/test_telemetry.py -v -k "read or series or span_keeps or pins or label"
Expected: the new and changed tests fail on the URI label. test_a_template_read_beside_plugins_is_unchanged
and test_a_server_without_plugins_never_pins_for_a_label may pass already.
- Step 3: Implement design items 5 and 6
_ReadObserver._layer(uri) -> _ReadLabels | None wraps plugins._read_labels(uri) in
except Exception: return None, as _template does. _label(matched, context, uri, failed: bool) sets
the holder:
- the layer's three when
_layeranswers; - else the template's
uri_template; - else the URI when
failedis false; - else nothing.
A cancellation still passes through unlabelled. The module docstring gains two sentences: the layer is asked first, from the pinned build's maps; and why, since a skill's files are static resources that would otherwise each be a series.
- Step 4: Run the tests to verify they pass
Run: pytest tests/test_telemetry.py tests/test_read_labels.py tests/test_facade.py -v
Expected: PASS, test_call_metrics_are_outermost_with_otel_on and test_otel_off_imports_no_sdk
included.
- Step 5: Checks and commit
Run: ruff check . && pytest
Expected: all pass.
git add kubed/mcp/_metrics.py kubed/mcp/_builtins.py tests/test_telemetry.py
git commit -m "feat(telemetry): a plugin read is charted by pattern, library and plugin, never its URI"Files:
-
Modify:
docs/superpowers/specs/telemetry.md(the wiki): TEL-16 and TEL-21. -
Modify:
CHANGELOG.md,[Unreleased]. -
Step 1: TEL-16 keeps its text. After "Unknown component names are left off, so the series stay bounded." it adds: "A prompt render is labelled by the prompt's name, bounded by the prompts served, a plugin's prefixed name (PLUG-63) included, and carries no plugin label."
-
Step 2: TEL-21 reads:
TEL-21. Call metrics (TEL-16) also record
resources/readonmcp.server.operation.duration, labelledmcp.resource.template.
The plugin layer labels a read first, from the request's build. A read of a served prompt or agent file, or of a URI below a served skill's root or below a folder of prompt or agent files, is labelled by a pattern and two more attributes, never by its URI:
kubed.plugin.library: the first segment of the plugin's namespace,grafanaforgrafana/grafana-k6;kubed.plugin.name: the plugin'sname,grafana-k6.In Prometheus these are
mcp_resource_template,kubed_plugin_libraryandkubed_plugin_name. A skill's name is never a label.The plugin is the file's own, the skill's, or for a folder's index the first admitted plugin with a file in the folder (PLUG-68).
{path}is every segment between the library and the file's name:(the table of design item 2)
The root's
SKILL.mdand_manifesttake their own patterns. ASKILL.mdor_manifestin a subfolder is any other file.Whether the file is there doesn't matter: a failed read below a skill's root keeps the layer's labels. The lookup reads the build, never a file, and a server with no plugin served skips it.
Every other read is labelled from the template lookup. A read whose URI matches a template is labelled by that template's
uri_template, a static resource included when its URI also matches a template. A successful read that matches no template is labelled by its static URI. A server's own resources underskill://are such reads, mcp-kb'sskill://<library>/_index.mdamong them, and are the server's to label.The URI is the one the server's providers saw: never with a gateway prefix (GW-4), and never a templated URI's values, so the series stay bounded.
A failed read whose URI matches a template keeps that template's label. A failed read that is neither the layer's nor a template's, a static resource's included, carries no label, only the error attributes the other methods get.
The read's span keeps the exact URI as
mcp.resource.uri.The recorded duration of a read includes the lookups that label it.
A read through the
read_resourcetool records both atools/calland aresources/readpoint.
If Task 2 found that a routing error takes the name off, the failed-read bullet adds: "A read FastMCP counts as a routing error carries none of the three."
- Step 3: The CHANGELOG, under
[Unreleased],### Changed:
- Skill, prompt and agent file reads are charted by pattern, library and plugin, not one series per file.- Step 4: Checks
Run: ruff check . && pytest
Expected: all pass. The wiki and the CHANGELOG are left for the job to commit, as Global Constraints
says.
git add CHANGELOG.md
git commit -m "docs: TEL-21 labels a plugin read by pattern, library and plugin"These pages describe what is on main; the spec says what is built and what is only proposed.
kubed-mcp · MIT