fix(mcp): type edit_frontmatter operations for OpenAI schema compatibility#38
Open
brndnblck wants to merge 1 commit into
Open
fix(mcp): type edit_frontmatter operations for OpenAI schema compatibility#38brndnblck wants to merge 1 commit into
brndnblck wants to merge 1 commit into
Conversation
34616a6 to
30f70aa
Compare
Replace `Vec<serde_json::Value>` with typed `FrontmatterOpInput` struct and `FrontmatterOpKind` enum for the `edit_frontmatter` tool's `operations` parameter. This causes schemars to emit a proper object schema instead of `"items": true`, which OpenAI's function-calling API rejects at tool registration time. Changes: - Add `FrontmatterOpKind` enum with serde rename_all = snake_case - Add `FrontmatterOpInput` struct with typed op/key/value fields - Update `EditFrontmatterParams` and `EditFrontmatterBody` to use the new types - Simplify `parse_frontmatter_ops` in both serve.rs and http.rs to match on the enum instead of raw JSON strings - Add regression test asserting operations.items is an object schema - Add deserialization round-trip and unknown-variant rejection tests Fixes devwhodevs#32
30f70aa to
1bdd8be
Compare
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.
Summary
Fixes #32.
OpenAI's function-calling API rejects
edit_frontmatterat tool registration because theoperationsparameter schema has"items": trueinstead of a proper object schema. This happens becauseoperationswas typed asVec<serde_json::Value>, and schemars mapsserde_json::Valueto the JSON Schematrue(any value).Changes
FrontmatterOpKindenum with#[serde(rename_all = "snake_case")]andDeserialize + JsonSchemaderivesFrontmatterOpInputstruct with typedop,key,valuefieldsEditFrontmatterParams(MCP) andEditFrontmatterBody(HTTP) to useVec<FrontmatterOpInput>parse_frontmatter_opsin bothserve.rsandhttp.rsto match on the typed enumoperations.itemsis an object schema (nottrue)Generated schema (after fix)
Where
FrontmatterOpInputdefinesopas an enum with the 6 allowed values.Wire format
Unchanged.
{"op": "set", "key": "status", "value": "done"}works identically.Testing
cargo fmt --check-- cleancargo clippy -- -D warnings-- cleancargo test --lib-- 461 passed (458 existing + 3 new)