-
Notifications
You must be signed in to change notification settings - Fork 134
fix(mcp): rename wire fields to contract names before dispatch #3215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bjohas
wants to merge
2
commits into
superdoc-dev:main
Choose a base branch
from
OpenDevEd:fix/mcp-comment-id-rename
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+79
−1
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { describe, it, expect } from 'bun:test'; | ||
| import { applyParamRenames } from '../tools/param-renames.js'; | ||
|
|
||
| describe('applyParamRenames', () => { | ||
| it('renames id → commentId for comments.delete', () => { | ||
| expect(applyParamRenames('comments.delete', { id: 'c1' })).toEqual({ commentId: 'c1' }); | ||
| }); | ||
|
|
||
| it('renames id → commentId for comments.get', () => { | ||
| expect(applyParamRenames('comments.get', { id: 'c1' })).toEqual({ commentId: 'c1' }); | ||
| }); | ||
|
|
||
| it('renames id → commentId for comments.patch and preserves other fields', () => { | ||
| expect(applyParamRenames('comments.patch', { id: 'c1', text: 'updated', isInternal: true })).toEqual({ | ||
| commentId: 'c1', | ||
| text: 'updated', | ||
| isInternal: true, | ||
| }); | ||
| }); | ||
|
|
||
| it('renames parentId → parentCommentId for comments.create', () => { | ||
| expect(applyParamRenames('comments.create', { text: 'reply', parentId: 'c1' })).toEqual({ | ||
| text: 'reply', | ||
| parentCommentId: 'c1', | ||
| }); | ||
| }); | ||
|
|
||
| it('renames id → nodeId for getNodeById', () => { | ||
| expect(applyParamRenames('getNodeById', { id: 'n1' })).toEqual({ nodeId: 'n1' }); | ||
| }); | ||
|
|
||
| it('passes through unchanged for operations with no renames', () => { | ||
| expect(applyParamRenames('comments.list', { limit: 10 })).toEqual({ limit: 10 }); | ||
| expect(applyParamRenames('getText', {})).toEqual({}); | ||
| }); | ||
|
|
||
| it('does not strip non-renamed keys when a rename map exists', () => { | ||
| expect(applyParamRenames('comments.create', { text: 'top-level' })).toEqual({ text: 'top-level' }); | ||
| }); | ||
| }); |
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
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
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,37 @@ | ||||||||||
| /** | ||||||||||
| * Wire → contract field-name renames for intent tool dispatch. | ||||||||||
| * | ||||||||||
| * The MCP wire schema (apps/mcp/src/generated/catalog.ts) is generated from | ||||||||||
| * apps/cli/src/cli/operation-params.ts, where PARAM_FLAG_OVERRIDES rewrites | ||||||||||
| * a handful of contract field names to shorter CLI flag names (e.g. | ||||||||||
| * `commentId` → `id`, `parentCommentId` → `parentId`). The same renamed | ||||||||||
| * names end up in the MCP wire schema. Without an inverse translation at | ||||||||||
| * dispatch time, the contract validator rejects the input because it expects | ||||||||||
| * the canonical field names. | ||||||||||
| * | ||||||||||
| * The CLI applies the inverse rename in extractInvokeInput() | ||||||||||
| * (apps/cli/src/lib/invoke-input.ts PARAM_RENAMES). This module is the MCP | ||||||||||
| * mirror — kept in lockstep by hand. Three operations are affected today | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. count's off (map has 5 entries) and the em-dash trips our style rule.
Suggested change
|
||||||||||
| * (comments.delete, comments.get, comments.patch, plus comments.create's | ||||||||||
| * parentId and getNodeById's id), so duplication is small. | ||||||||||
| * | ||||||||||
| * Keys are bare operation IDs (no `doc.` prefix) to match the form | ||||||||||
| * executeOperation passes to api.invoke(). | ||||||||||
| */ | ||||||||||
| const PARAM_RENAMES: Record<string, Record<string, string>> = { | ||||||||||
| getNodeById: { id: 'nodeId' }, | ||||||||||
| 'comments.create': { parentId: 'parentCommentId' }, | ||||||||||
| 'comments.patch': { id: 'commentId' }, | ||||||||||
| 'comments.delete': { id: 'commentId' }, | ||||||||||
| 'comments.get': { id: 'commentId' }, | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| export function applyParamRenames(opId: string, input: Record<string, unknown>): Record<string, unknown> { | ||||||||||
| const renames = PARAM_RENAMES[opId]; | ||||||||||
| if (!renames) return input; | ||||||||||
| const renamed: Record<string, unknown> = {}; | ||||||||||
| for (const [key, value] of Object.entries(input)) { | ||||||||||
| renamed[renames[key] ?? key] = value; | ||||||||||
| } | ||||||||||
| return renamed; | ||||||||||
| } | ||||||||||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
input gets renamed (
id→commentId) but the response goes back as-is, so MCP clients seecommentIdin the body even though their input usesid. probably fine since the agent reads it as text, but is the asymmetry intentional? worth a line in the PR body, or a follow-up if it should be inverted on the way out too.