Repository navigation
outputSchema on 68 of 78 tools, generated by the type checker - #286
Merged
Merged
Conversation
A client may validate a result against its tool's outputSchema, so a wrong one is worse than none. internal/apisurface/outputschema reads dispatch for each tool's handler, follows every return through Result and the handlers it delegates to, and writes a schema only for a tool that always answers with one concrete type, saying why for the other ten. The schema follows encoding/json. make api runs it; api-check fails when it is stale. A test holds every schema to empty and filled values of its type, and fails on a corrupted one; live results from 29 tool calls on the Android 15 emulator validated with jsonschema, none invalid.
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.
MCP tools may declare
outputSchema: the shape of theirstructuredContent. Clients increasingly validate results against it and may refuse one that doesn't match, so a wrong schema is worse than none.How it's made
internal/apisurface/outputschematype-checksinternal/agentwithgo/types(standard library only):dispatchfor each tool's handler.Result(text, v)tov's static type, and through theHandlersmethods it delegates to.app_screenshotanswers with an image andapp_logswith one of two shapes.The schema follows
encoding/json: field names from JSON tags;omitemptyfields optional and the rest required; pointers, slices, maps and interfaces nullable; a customMarshalJSONtype accepts anything. Extra keys are allowed, becausereportHandledandreportIdleadd notes to results.make apiruns it intointernal/agent/outputschema_gen.go, andapi-check(inmake ci) fails when that file is stale.Checked
TestEveryOutputSchemaHoldsItsTypesValues: every schema accepts its type's empty value (nil slices and pointers) and a filled one (every field set, every slice holding one element). Corrupting one schema's integer type fails it.TestTheValidatorRefuses: the test's validator rejects a missing required field and a wrong type.mobium mcpresults from 29 tool calls validated against the schemas its owntools/listserved, using Python'sjsonschema4.26, an independent validator. 29 valid, 0 invalid. Not checked: three platform refusals, andapp_find, which has no schema.Docs: the MCP guide's section 3 explains the schemas. It also fixes the read-only count there: 22 tools, not 19.
make cigreen.