Skip to content

Navigation Menu

Sign in
Appearance settings
Sign up
Appearance settings

Serialize MCP-supplied object to string for JSON schema flags - #36

#36
Open
john-tipper wants to merge 2 commits into
njayp:mainnjayp/ophis:mainfrom
john-tipper:fix/decode-flag-json-schemajohn-tipper/ophis:fix/decode-flag-json-schemaCopy head branch name to clipboard
Open

Serialize MCP-supplied object to string for JSON schema flags#36
john-tipper wants to merge 2 commits into
njayp:mainnjayp/ophis:mainfrom
john-tipper:fix/decode-flag-json-schemajohn-tipper/ophis:fix/decode-flag-json-schemaCopy head branch name to clipboard

Conversation

@john-tipper

Copy link
Copy Markdown
Contributor

What does this PR do?

When MCP supplies an object as a flag value into Ophis because that flag has a jsonschema annotation 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

  • Tests added or updated
  • Docs added or updated

@github-actions
github-actions Bot requested a review from njayp December 8, 2025 23:40
@john-tipper
john-tipper force-pushed the fix/decode-flag-json-schema branch from 98c027b to edae3f4 Compare December 8, 2025 23:46
@john-tipper

Copy link
Copy Markdown
Contributor Author

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.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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.

Serialize MCP-supplied flag into string for JSON schema flags

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.