# Agents 3 labs: MCP servers, skills and plugins

Three ways to extend Claude Code, each with a kit you can install and a checker that runs offline (Python
3.9+, stdlib only). Only `mcp_server/test_client.py --real` calls a model, and it is opt-in and capped.

| Lab | What you get | Docs |
|---|---|---|
| `mcp_server/` | `server.py`: a stdlib stdio MCP server (`lab-docs`, read-only) with two tools, four resources and one prompt, over the decision records in `mcp_server/docs/`. `test_client.py`: spawns it and checks every method, error kind and the stdout hygiene. It also prints the exact `claude mcp add` / `.mcp.json` install block, and `--real` runs one capped `claude -p` that can use only this server. | [MCP spec 2025-11-25](https://modelcontextprotocol.io/specification/2025-11-25), [Claude Code MCP](https://code.claude.com/docs/en/mcp) |
| `skill_lint.py` | Lints `SKILL.md` and `.claude/commands/*.md` against the documented rules: line-1 frontmatter, YAML that may not parse, unknown or misspelled fields, invocation control, the 1,536-character listing cap, `!` injection commands with no allow rule, `${CLAUDE_SKILL_DIR}` files, `$name` arguments, reserved and refused names, 500 lines. Samples are in `skills_sample/good` (clean) and `skills_sample/bad` (checked against `EXPECTED.json`). | [skills](https://code.claude.com/docs/en/skills), [permissions](https://code.claude.com/docs/en/permissions) |
| `plugin_kit/` + `plugin_validate.py` | `plugin_kit/kit/lab-review/`: a plugin with a skill (`/lab-review:review`), a subagent (`lab-review:test-auditor`) and a PostToolUse hook. The validator checks the manifest, path rules, `.claude-plugin/` contents, hooks.json, the fields plugin agents ignore and the skills (through skill_lint). It runs the hook on documented payloads, and compares the bad samples in `plugin_kit/bad/` against `EXPECTED.json`. | [manifest](https://code.claude.com/docs/en/plugins/manifest-reference), [create](https://code.claude.com/docs/en/plugins/create), [components](https://code.claude.com/docs/en/plugins/components), [hooks](https://code.claude.com/docs/en/hooks) |

## Run

```bash
cd labs
python3 agents-3/mcp_server/test_client.py          # 25 protocol checks + install block (-v prints every JSON-RPC line)
python3 agents-3/skill_lint.py                      # good + bad samples
python3 agents-3/skill_lint.py ~/code/myrepo        # your repo's .claude/skills and .claude/commands
python3 agents-3/plugin_validate.py                 # the kit + bad samples
python3 agents-3/plugin_validate.py --with-claude   # also `claude plugin validate` (local, no model call)

# optional extras
python3.13 agents-3/mcp_server/test_client.py --with-sdk    # interop with the official MCP Python SDK (pip install mcp)
python3 agents-3/mcp_server/test_client.py --real --model haiku --max-budget-usd 0.05   # costs money
```

## Install the MCP server in Claude Code

`test_client.py` prints the following with your absolute path filled in:

```bash
# local scope (default): only you, this project; stored in ~/.claude.json
claude mcp add --transport stdio lab-docs -- python3 /ABS/PATH/labs/agents-3/mcp_server/server.py
# project scope: writes .mcp.json at the repo root (teammates approve it on first interactive use)
claude mcp add --transport stdio --scope project lab-docs -- python3 /ABS/PATH/labs/agents-3/mcp_server/server.py
claude mcp get lab-docs          # ✔ Connected, or ⏸ Pending approval for a new .mcp.json server
```

Or commit a `.mcp.json` yourself and serve the repo's own records. Claude Code sets `CLAUDE_PROJECT_DIR` in the
server's environment, but `${VAR}` expansion in `.mcp.json` needs a default:

```json
{"mcpServers": {"lab-docs": {"type": "stdio", "command": "python3",
  "args": ["/ABS/PATH/labs/agents-3/mcp_server/server.py", "--docs", "${CLAUDE_PROJECT_DIR:-.}/docs/adr"]}}}
```

Pre-approve the two read-only tools in `.claude/settings.json`:
`{"permissions": {"allow": ["mcp__lab-docs__search_docs", "mcp__lab-docs__get_doc"]}}`.
In `claude -p`, Agent SDK and cloud sessions, `.mcp.json` servers load without the approval prompt. Use
`--strict-mcp-config --mcp-config <file>` for a run that loads only the servers you name.

## Install the plugin kit

```bash
claude --plugin-dir agents-3/plugin_kit/kit/lab-review     # this session only; writes nothing to settings
claude plugin validate agents-3/plugin_kit/kit/lab-review  # local check, no model call
```

Then `/lab-review:review` and `@agent-lab-review:test-auditor`; run `/reload-plugins` after editing the kit. The
hook runs in every session while the plugin is enabled, with your user permissions and outside the sandbox. To
share the kit, publish it through a marketplace (autonomy-2).

Copy the good skill samples into a repo with `cp -r agents-3/skills_sample/good/.claude <repo>/`. That adds
`/review-diff`, `/release-notes` and `/quick-check`.

## Output excerpts (offline)

`mcp_server/test_client.py` (abridged):

```
PASS  server/discover -> -32601, client falls back to initialize              Method not found: server/discover
PASS  initialize echoes 2025-11-25                                            2025-11-25
PASS  search_docs finds adr-0002 first                                        adr-0002-tax-after-discount, adr-0003-discount-codes
PASS  bad limit -> tool execution error (isError true), not a protocol error  limit must be an integer from 1 to 10 (got 50)
PASS  path-like id -> isError, nothing read outside docs/
PASS  unknown tool -> JSON-RPC error -32602                                   Unknown tool: delete_doc
PASS  unknown resource -> -32002 with data.uri
PASS  invalid JSON -> -32700 with id null
PASS  server exits 0 when stdin closes                                        exit 0
PASS  stdout carried only JSON-RPC messages                                   17 lines
PASS  unknown client version -> server answers its latest (2025-11-25)        2025-11-25

25/25 checks passed
```

`--with-sdk` against the official MCP Python SDK 2.3.0 client: its `auto` mode probed `server/discover`, got
-32601, and fell back to the handshake:

```
  official client negotiated 2025-11-25
  tools: search_docs, get_doc
  search_docs -> adr-0001-integer-cents: ADR-0001: Money is integer cents (score 12)
```

`skill_lint.py`, the bad samples (abridged):

```
  ERROR    /broken-yaml           yaml-error: the frontmatter may not parse; if Claude Code can't parse it, the skill loads with no fields set: line 2: ': ' inside an unquoted value; quote the value
  ERROR    /dead-end              uninvocable: disable-model-invocation: true and user-invocable: false together leave nobody able to invoke it
  WARNING  /fragile-inject        inject-unapproved: a ! command with no matching allow rule aborts the invocation outside auto mode: !`./scripts/check.sh $1`: ...
  ERROR    /fragile-inject        missing-file: a ${CLAUDE_SKILL_DIR} path that doesn't exist: rules/missing.md
  WARNING  /greedy                listing-truncated: description + when_to_use is truncated at 1,536 characters in the skill listing: 2,039 characters; everything after 1,536 is cut
  WARNING  /greedy                broad-allowed-tools: allowed-tools pre-approves broad access, and it isn't gated by workspace trust: Bash, Write
  ERROR    /late-frontmatter      frontmatter-not-line-1: the opening --- isn't line 1, so every field is ignored and the markers become skill text: line 1 is '<!-- Owner: platform team -->'
  WARNING  /typo-fields           unknown-field: Claude Code ignores unknown fields without an error: 'allowed_tools' (did you mean 'allowed-tools'?)
  WARNING  /with-paths            ignored-in-command: command files accept every skill field except name and paths: 'paths' in with-paths.md
  listing: ~2,094 characters of names + descriptions in context (≈838 tokens at ~2.5 chars/token); not listed (disable-model-invocation): /dead-end
```

`plugin_validate.py`, the kit and its hook (the `plugin:` line with the kit's absolute path is left out):

```
kit: plugin_kit/kit/lab-review
  skills: /lab-review:review
  agents: lab-review:test-auditor
  no findings
  hooks: PostToolUse[Edit|Write] -> python3 ${CLAUDE_PLUGIN_ROOT}/scripts/test_reminder.py

the kit's hook, run on documented PostToolUse payloads (common/hooks.py)
      payload                                  what Claude sees
────  ───────────────────────────────────────  ──────────────────────────────────────────────────────────────────────
PASS  Write tinyapp/pricing.py                 You changed pricing.py. Its tests are in tests/test_pricing.py: update
PASS  Write README.md                          success, no context (as expected)
PASS  Write tinyapp/pricing.py (cwd tinyapp/)  You changed pricing.py. Its tests are in tests/test_pricing.py: update
```

The third row is Claude after a `cd tinyapp`: the payload's `cwd` is a subfolder, and the hook still finds
`tests/` because it looks in the git root above `cwd`. It never uses `${CLAUDE_PROJECT_DIR}`, which stays at the
folder the session started in even after Claude enters a worktree (hooks page; worktrees page). The bad samples
list commands separately from skills: `bad/reserved` prints `commands: /claude-tools:today`.

## Real checks (2026-10-20, Claude Code v2.1.303)

**One capped model call:** `test_client.py --real --model haiku --max-budget-usd 0.05 --max-turns 4`, run in a temp copy of tiny-app with `--tools ""` (no built-ins), the two exact `mcp__lab-docs__*` allow rules, `--strict-mcp-config` and `--permission-mode dontAsk`. It cost $0.0016 (Claude Code's estimate):

```
init mcp_servers: [{"name": "lab-docs", "status": "connected", "source": "dynamic"}]
init tools: mcp__lab-docs__get_doc, mcp__lab-docs__search_docs
tool_use mcp__lab-docs__search_docs {"query": "tax discount interaction"}
  tool_result is_error=None '{"matches":[{"id":"adr-0002-tax-after-discount","title":"ADR-0002: Tax applies after the discount, r'
  outcome: success (terminal_reason=completed, stop_reason=end_turn)
  turns: 2
  model responses: 2 (3 assistant events)
  tool calls: 1 {'mcp__lab-docs__search_docs': 1}  errors=0
  cost (estimate): $0.001564
  usage: {'input_tokens': 4, 'output_tokens': 240, 'cache_creation_input_tokens': 10733, 'cache_read_input_tokens': 10247}
```

The shared `common/cc.print_summary` now prints the outcome line in the docs' order, stop_reason first ([ResultError](https://code.claude.com/docs/en/agent-sdk/python#resulterror)): for this run it reads `outcome: stop_reason=end_turn, terminal_reason=completed, subtype=success`.

What the call showed:
- **No `ToolSearch` call.** With `--tools ""` the MCP tools were listed directly in the init event, and Claude called `search_docs` without searching for tools first.
- **The tool result was the `structuredContent` JSON, not the text content block.** Because `search_docs` returns both, the model saw `{"matches": [...]}` as a string. Keep `structuredContent` model-readable, or leave it out.
- **`num_turns: 2`** for one tool call plus an answer, as in the common fixtures.
- **A saved transcript.** `--real` now also writes the transcript to `agents-3/out/mcp_real_run.jsonl`. Trace it with `python3 agents-1/loop_trace.py --transcript agents-3/out/mcp_real_run.jsonl`.

**Local `claude plugin validate`, no model call:**
- **The kit:** passes, including with `--strict`. The only output is an advisory about a marketplace install line in README.md.
- **Agreement on the bad samples:** Claude Code's validator reported the same manifest errors: `version` as a number, `author` as a string, an invalid `homepage`, `commands` without `./`, `agents` not ending in `.md`, `skills` with `..`, a missing hooks path, a hooks.json without `hooks`, an unknown event, the unquoted `${CLAUDE_PLUGIN_ROOT}` in shell form, and CLAUDE.md at the root. It flags the reserved name `claude-tools` once the schema errors are fixed.
- **Docs-based checks it didn't report on v2.1.303:**
  - a skill saved inside `.claude-plugin/`;
  - a plugin agent's ignored `permissionMode`, `hooks`, `mcpServers` and `initialPrompt`;
  - `${user_config.*}` in a shell-form command, which the hooks page says fails instead of running;
  - `if` on a `Stop` hook, which never runs;
  - a matcher on `UserPromptSubmit`, which is ignored;
  - a missing hook script.

  `plugin_validate.py` reports those from the docs.

## Notes

- **Protocol era.** The server speaks the 2025-11-25 handshake era (it also accepts 2025-06-18, 2025-03-26 and 2024-11-05). The 2026-07-28 revision replaces `initialize` with a per-request envelope and `server/discover`. Clients that support both eras fall back to `initialize` when `server/discover` returns -32601, as the official Python SDK client does in `--with-sdk`. Claude Code v2.1.303 connected to the server in the real run above (`status: connected`).
- **What the linters flag.** Both linters follow the docs. Where Claude Code's own parser is more lenient (an unclosed `[` in YAML frontmatter loads on v2.1.303, as the agents-4 author found), the message says "may not parse" rather than "won't load".
- **Defaults are hints, not proof.** The listing estimate uses ~2.5 characters per token (the course-wide ratio). For real numbers, use `/context`, which reports the Skills row, and `/doctor`.
