Skip to content

feat(mcp): advertise output schemas for data tools#89

Closed
felixgeelhaar wants to merge 1 commit into
mainfrom
feat/mcp-structured-output
Closed

feat(mcp): advertise output schemas for data tools#89
felixgeelhaar wants to merge 1 commit into
mainfrom
feat/mcp-structured-output

Conversation

@felixgeelhaar

Copy link
Copy Markdown
Collaborator

What

Adopts mcp-go's structured-output support (OutputSchema + structuredContent) for the data-returning MCP tools in the mcp package. A typed struct return plus .OutputSchema(T{}) makes mcp-go advertise an outputSchema in tools/list and promote the marshaled result to typed structuredContent alongside the existing text content.

Adopted (7 tools)

Tool Output type Note
list_machines MachineListOutput{items, total} enveloped the bare []MachineInfo so structuredContent is a JSON object
get_state StateOutput already an object
get_context Ctx (context object) already an object
get_machine_data *viz.VizMachine refactored return from json.RawMessage to the typed struct; identical JSON payload
validate_machine ValidateOutput already an object
<prefix>.get_state ExposeStateOutput ExposeInterpreter surface
<prefix>.get_context ExposeContextOutput[C] generic wrapper {context: ...}

Skipped (with reasons)

  • create_machine, send_event, reset_machine, delete_machine, <prefix>.send_event — mutations, not read/query tools.
  • export_machine — returns a formatted string (json / mermaid / ascii), not a typed object.
  • <prefix>.matches — returns a scalar boolean predicate {matches: bool}, not genuine structured data.

Behavior preserved

Text content for every tool is unchanged except list_machines, whose result is now the envelope object {items, total} (the sanctioned technique for making a list tool's structuredContent a valid JSON object). get_machine_data marshals to the same JSON as before.

Guard test

OutputSchema runs schema.Generate at registration and silently drops the tool if it errors. Added TestOutputSchemasGenerate asserting schema.Generate succeeds for every advertised output type (including the generic ExposeContextOutput[C] with both map and struct contexts). Updated the list_machines and get_machine_data handler tests for the new return shapes.

Verification

  • gofmt -l on changed files: clean
  • go build ./...: ok
  • go vet ./mcp/...: clean
  • go test ./... -count=1: all pass
  • golangci-lint run ./mcp/: 0 issues

https://claude.ai/code/session_01LCyhyAffdzBmzG3yPPqzTT

Adopt mcp-go structured-output support so data-returning MCP tools emit
typed structuredContent alongside their text content. A typed struct
return plus .OutputSchema(T{}) makes mcp-go promote the marshaled result
to structuredContent (a JSON object) and advertise outputSchema in
tools/list.

Adopted (7 tools):
- list_machines: enveloped []MachineInfo into MachineListOutput
  {items, total} so the result is a JSON object.
- get_state: StateOutput.
- get_context: Ctx (arbitrary context object).
- get_machine_data: refactored return from json.RawMessage to the typed
  *viz.VizMachine (same JSON payload) and advertised viz.VizMachine.
- validate_machine: ValidateOutput.
- <prefix>.get_state / <prefix>.get_context (ExposeInterpreter):
  ExposeStateOutput and generic ExposeContextOutput[C].

Skipped (with reasons): create/send_event/reset/delete and
<prefix>.send_event are mutations; export_machine returns a formatted
string (json/mermaid/ascii); <prefix>.matches returns a scalar boolean
predicate.

Added a guard test asserting schema.Generate succeeds for every
advertised output type, since OutputSchema silently drops a tool when
generation fails. Updated list_machines and get_machine_data handler
tests for the new return shapes.

Claude-Session: https://claude.ai/code/session_01LCyhyAffdzBmzG3yPPqzTT
@felixgeelhaar

Copy link
Copy Markdown
Collaborator Author

Closing — per maintainer decision, statekit doesn't need an MCP server, so this structured-output enhancement is moot. See follow-up on whether to remove the MCP package entirely.

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.

1 participant