Serialize MCP-supplied object to string for JSON schema flags - #36
#36Serialize MCP-supplied object to string for JSON schema flags#36john-tipper wants to merge 2 commits intonjayp:mainnjayp/ophis:mainfrom john-tipper:fix/decode-flag-json-schemajohn-tipper/ophis:fix/decode-flag-json-schemaCopy head branch name to clipboard
Conversation
98c027b to
edae3f4
Compare
|
The same error occurred re GitHub Actions updating go.mod as for my last PR, not sure what happened there as the builds run on my machine. |
There was a problem hiding this comment.
The approach is correct and the tests are thorough. One docs typo to fix:
Typo in docs/schema.md — duplicate json:"foo" tag
The updated SomeJsonObject example has both Foo and Bar tagged with json:"foo":
Foo string `json:"foo" jsonschema:"..."`
Bar int `json:"foo" jsonschema:"..."` // should be json:"bar"Bar should be json:"bar". As-is the example would silently produce incorrect JSON, which is a confusing doc for users trying to learn the feature.
There was a problem hiding this comment.
The fix is correct and well-tested. One issue in docs/schema.md:
Bar int `json:"foo" jsonschema:"Description of Bar field"`The Bar field has json:"foo", which duplicates the tag from Foo. This should be json:"bar". Users who copy-paste this example will get a struct where two fields map to the same JSON key, causing silent unmarshaling bugs.
Also a minor note: globalFlagRegistry is shared global state with no cleanup between tests. The current tests happen to work because each case registers fresh metadata for the same tool name "foo" immediately before calling buildFlagArgs. If any test were added that doesn't set up its own registry entry before calling into code that reads it, it would silently inherit a previous test's state. Worth keeping in mind if the test suite grows.
What does this PR do?
When MCP supplies an object as a flag value into Ophis because that flag has a
jsonschemaannotation then Cobra needs that flag as a JSON string. This PR adds the missing part of the feature in #31, whereby Ophis converts the object into a JSON string.Related Issues
Fix #35
Checklist