Skip to content

feat: spec-conformant MCP server and CLI fixes - #16

Merged
9thLevelSoftware merged 1 commit into
feat/model-registry-doctorfrom
fix/mcp-cli-conformance
Oct 1, 2026
Merged

9thLevelSoftware merged 1 commit into
feat/model-registry-doctorfrom
fix/mcp-cli-conformance

Conversation

@9thLevelSoftware

Copy link
Copy Markdown
Owner

Summary

Stacked on #15 (PR 7 of the modernization plan).

Correction to my own plan: I had planned to remove the server's tasks/* methods as "non-spec". Checking the actual 2025-11-25 spec showed MCP does define an (experimental) Tasks utility. The real problems were the empty capability, non-spec result shapes ({id,status,result}), the wrong error code (-32004) and a non-spec tasks/update. So tasks are now implemented to spec rather than deleted.

MCP server (rewritten)

  • Protocol version negotiation; Tasks capability only for revisions that have it.
  • Spec Tasks: task-augmented clodex_build (execution.taskSupport: optional) + tasks/get, tasks/result (blocks, returns the tool result with related-task _meta), tasks/list (opaque cursors), tasks/cancel (-32602 for unknown / already-terminal). run_id is the task id. tasks/update removed.
  • JSON-RPC hygiene: errors keep the request id, notifications get no reply, ping, -32700/-32600, batch refused, exceptions → -32603 with the id.
  • Bad/missing tool arguments are tool-level errors (isError) so the model can self-correct; unknown tool = protocol error; workflow built lazily (a bad call no longer creates state).
  • Ordering: requests are handled in arrival order (clients may pipeline create → update → get); only long work (sync plan/build/audit, tasks/result waits) runs on a thread, so ping/poll/cancel never block. notifications/cancelled and EOF release a waiting tasks/result. (My first version ran everything on a pool and broke pipelined calls — caught by the existing tests.)
  • Repo root from CLODEX_REPO_ROOT or the git root; version from __version__; clodex_build exposes workspace/approval_profile; clodex_audit exposes base/commit.

CLI

  • audit --base REF | --commit SHA (+ --diff as the explicit default); empty diff → nothing-to-audit.
  • Plain-text output without --json (doctor shows [ok]/[FAIL]/[warn] + fixes); exit codes 0 ok / 1 blocked / 2 usage / 3 failed / 4 cancelled; unknown run ids and bad refs are one-line errors (CLODEX_DEBUG=1 for the traceback).
  • Every command finds the repo from any subdirectory instead of using the cwd.

Test plan

  • 269 tests pass locally (45 new; 4 SDK tests skip without mcp)
  • Official MCP SDK v2.2.0 client (speaks a newer revision) negotiates down to 2025-11-25 and parses capabilities, tool execution, ping, tool errors and unknown-tool errors
  • Every server message (handshake, tools, tasks incl. cancel, errors) validates against the SDK's _v2025_11_25 wire models. Note: SDK v2 deliberately has no high-level 2025-11-25 tasks/* client routing ("tasks/* deliberately absent" in its method table; the 2026-07-28 revision reworked them), so task messages are validated against its models directly. Supporting 2026-07-28 is not done here.
  • Real clodex audit --commit HEAD with real claude + codex (Claude approved, Codex raised a substantive finding → blocked, exit 1); bad ref → one-line error, exit 2; real doctor human output
  • CI matrix

🤖 Generated with Claude Code

MCP server (rewritten, protocol 2025-11-25):
- Negotiate the protocol version (echo a supported one, else our newest);
  advertise the Tasks capability only where the revision has it.
- Implement the spec's experimental Tasks utility instead of the ad-hoc
  methods: task-augmented `clodex_build` (execution.taskSupport), plus
  tasks/get, tasks/result (blocks, returns the tool result), tasks/list
  (opaque cursors) and tasks/cancel, with spec shapes and -32602 errors.
  `tasks/update` was never part of the spec and is removed.
- JSON-RPC hygiene: errors keep the request id, notifications and stray
  responses get no reply, ping, parse/invalid-request codes, batch refused,
  unexpected exceptions become -32603 with the id.
- Argument problems are tool-level errors (isError) so the model can fix
  them; an unknown tool is a protocol error; the workflow is built lazily
  so a bad call creates no state.
- Requests run in arrival order (clients may pipeline stateful calls); only
  long-running work (sync plan/build/audit, tasks/result waits) moves to a
  worker thread so ping/poll/cancel are never blocked. A cancelled-request
  notification or EOF releases a waiting tasks/result.
- Repo root from CLODEX_REPO_ROOT or the git root; version from
  __version__; clodex_build exposes workspace and approval_profile.
- Wire messages validated against the official SDK's 2025-11-25 schema
  models (optional `mcp` test extra; CI installs it).

CLI:
- `audit --base REF` / `--commit SHA` (and --diff as the explicit default);
  an empty diff reports nothing-to-audit instead of running reviewers.
- Plain-text output without --json (doctor shows [ok]/[FAIL]/[warn] lines
  with fixes); exit codes 0 ok / 1 blocked / 2 usage / 3 failed / 4
  cancelled; unknown run ids and bad refs are one-line errors
  (CLODEX_DEBUG=1 for the traceback).
- Every command finds the repo root from any subdirectory instead of
  using the cwd.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 1, 2026 03:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@9thLevelSoftware
9thLevelSoftware added this pull request to stack #21 October 1, 2026 04:41
@9thLevelSoftware
9thLevelSoftware merged commit acde030 into main Oct 1, 2026
8 checks passed
@9thLevelSoftware 9thLevelSoftware mentioned this pull request Oct 1, 2026
3 of 4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants