Repository navigation
✨ Add serve mcp with tools declared by command annotations - #26
Merged
Merged
Conversation
Run an MCP server over stdio whose tools are the commands that carry `mcp` annotations. The list follows the run's `WS_*` settings and is read-only unless `WS_AI_MCP_ALLOW_WRITE` is set; `WS_AI_MCP_TOOLS` narrows it. Each call runs the command as a subprocess with a timeout and an output cap. The annotations are written to `commands.yaml` as an `mcp:` object. Move `--port` and `--bind` from the `serve` group onto `serve current` and `serve metrics`, so `serve mcp` takes no flags. Add `github.com/modelcontextprotocol/go-sdk` v1.8.0 and bump every other module to its latest release.
Drop the `mcp.description` annotation: a tool reads the command's long help again, reworded where it named a flag the tool does not expose, with the flag hints moved into the flags' own usage strings. Move the `[!]<group>.<prop>` condition and its evaluation from `internals/mcp` to `internals/config` as `Condition` and `Holds`. `cli.MCP` returns the command, so a tool is declared where its command is defined and the `init()` annotation blocks are gone.
Keep each behaviour of `serve mcp` asserted once, at the lowest layer that proves it: the in-memory server keeps only what needs the recorder, the literal tool table goes because `commands.yaml` already pins the surface, and the real-process tests keep the lifecycle, the signals, the warnings on stderr and one end-to-end settings check.
`serve mcp` prints a start banner and one log line per tool call on stderr, through the same `server.PrintStop` and `server.LogRequest` that `serve current` and `serve metrics` use. Stdout stays JSON-RPC only. New `internals/proc` holds the bounded subprocess runner (timeout, wait delay, process group) and the one self-exec seam. The MCP runner, `tempfile.Detach`, `config.GetExtensions` and the `nvidia-smi` call use it; `nvidia-smi` gains a 5 s timeout. Tool arguments are validated against the generated schema with `jsonschema-go`, and annotation lists are split by `config.ParseList`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
ws-cli serve mcpruns a Model Context Protocol server over stdio for AI agents inside the workspace.mcpannotations (cli.MCP):mcp(readorwrite),mcp.when(conditions on dotted env keys),mcp.flags(allow-list of exposed flags). The tool description is the command's long help.commands.yamlas anmcp:object per command.[!]<group>.<prop>condition lives ininternals/config(Condition,Holds), so later features can gate on the same settings.info,show,logs,feature list|info|store,editor diagnostics|list|selection,template list|show,seed ls) and 3 write (editor open,editor reveal,template apply).WS_AI_MCP_ALLOW_WRITEis set.WS_AI_MCP_TOOLSnarrows it to groups or tool names (comma-delimited,*means all).--flag=valueargs,--before positionals, empty stdin, no colour, 60 s timeout, 64 KiB output cap keeping the tail. Arguments are validated against the tool's schema withjsonschema-gobefore anything is spawned.serve mcpprints a start banner and one log line per tool call on stderr, in the style ofserve currentandserve metrics. Stdout carries only JSON-RPC.show_envexposes the key only, so it runs the mode that redactssecret: truevalues.info envandsecrets *are not tools.Also in this PR
--portand--bindmove from theservegroup ontoserve currentandserve metrics, soserve mcptakes no flags.serve --port X current(flag before the subcommand) no longer parses;serve metrics --port --collectorsis unchanged.github.com/modelcontextprotocol/go-sdkv1.8.0. It serves both the 2025-11-25 and the stateless 2026-07-28 protocol, which is why it is preferred over a stdlib implementation.internals/proc: one bounded subprocess runner (timeout, wait delay, process group) and one self-exec seam, used by the MCP runner,tempfile.Detach,config.GetExtensionsand thenvidia-smicall, which gains a 5 s timeout.internals/serverexportsPrintStopandLogRequest, shared by the threeservecommands.show env,logs,feature info,editor diagnostics,editor openandtemplate applyno longer names flags the tool does not expose; the hints moved to the flags' usage lines.Behaviour to know
aienv group is not in the workspace schema yet. Until it is, both variables are ignored with a warning and the server lists the read tools.WS_AI_MCP_TOOLSentry is ignored with a warning and never widens the list. A value that cannot be resolved serves no tools.mcp.whenandWS_AI_MCP_ALLOW_WRITEshape the tool list. They are not a privilege boundary.Verification
go vet ./...andgo test ./...pass.serve mcpprocess over stdio with 2025-11-25 and 2026-07-28 clients, call every listed tool with canary secrets planted, and pin the tool surface in a literal table.template_applywrote a file with writes enabled. Not tried: the editor chat and opencode.Follow-ups
envs.aitoenv.reference.yaml, bump thews-clidigest, add an integration test.