feat(mcp): advertise output schemas for data tools#89
Closed
felixgeelhaar wants to merge 1 commit into
Closed
Conversation
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
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. |
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
Adopts mcp-go's structured-output support (
OutputSchema+structuredContent) for the data-returning MCP tools in themcppackage. A typed struct return plus.OutputSchema(T{})makes mcp-go advertise anoutputSchemaintools/listand promote the marshaled result to typedstructuredContentalongside the existing text content.Adopted (7 tools)
list_machinesMachineListOutput{items, total}[]MachineInfosostructuredContentis a JSON objectget_stateStateOutputget_contextCtx(context object)get_machine_data*viz.VizMachinejson.RawMessageto the typed struct; identical JSON payloadvalidate_machineValidateOutput<prefix>.get_stateExposeStateOutputExposeInterpretersurface<prefix>.get_contextExposeContextOutput[C]{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'sstructuredContenta valid JSON object).get_machine_datamarshals to the same JSON as before.Guard test
OutputSchemarunsschema.Generateat registration and silently drops the tool if it errors. AddedTestOutputSchemasGenerateassertingschema.Generatesucceeds for every advertised output type (including the genericExposeContextOutput[C]with both map and struct contexts). Updated thelist_machinesandget_machine_datahandler tests for the new return shapes.Verification
gofmt -lon changed files: cleango build ./...: okgo vet ./mcp/...: cleango test ./... -count=1: all passgolangci-lint run ./mcp/: 0 issueshttps://claude.ai/code/session_01LCyhyAffdzBmzG3yPPqzTT