fix(mcp): accept canonical resource names in path params and keep error results schema-valid#6108
Merged
boojack merged 2 commits intoJul 23, 2026
Conversation
The API returns names like "memos/abc123", but path substitution placed
the value into "/api/v1/memos/{memo}" verbatim, so round-tripping a
returned name produced "/api/v1/memos/memos/abc123" and a 404 on every
get/update/delete/comment call. Strip the collection prefix when the
placeholder directly follows its collection segment; bare IDs, foreign
prefixes, and multi-segment values pass through unchanged.
Error results carried structuredContent {"error": ...}, which cannot
conform to the success outputSchema each tool declares. Spec-strict
clients reject the result with a schema-validation error, masking the
real message. Report errors through isError and text content only.
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
WalkthroughMCP path substitution now accepts canonical resource names by removing collection prefixes before URL-escaping path identifiers. Tests cover bare IDs, canonical names, nested routes, and reserved characters. Tool errors now return text content with 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Fixes #6107
Problem
The MCP tools substitute path parameters directly into the REST route, so
memo_get_memowithmemo: "memos/abc123"requests/api/v1/memos/memos/abc123and 404s. Butmemos/abc123is exactly what the API returns asnamein every memo object — an MCP client that round-trips the name it received frommemo_create_memo/memo_list_memosgets a 404 on every follow-up call, and formemo_update_memothe edit is silently lost.The failure is then hidden by a second issue: on REST errors the tools return
structuredContent: {"error": ...}, which doesn't conform to the tool's declaredoutputSchema(e.g. requiredstate/content/visibility). Spec-strict clients (Claude Code, LiteLLM, the ChatGPT connector) reject the response with a schema-validation error, masking the underlying 404.Changes
substitutePathParametersnow routes values throughtrimResourceNamePrefix: when a path parameter's placeholder directly follows its collection segment (/api/v1/memos/{memo}) and the value carries that collection prefix (memos/abc123), the prefix is stripped. Bare IDs pass through unchanged; foreign prefixes and multi-segment values are left untouched. Works generically for{memo},{attachment}, and any future path parameter.newToolErrorResultno longer attachesstructuredContent. Error results report throughisError: trueand text content, per the spec's structured-content guidance —structuredContentis only meaningful when it conforms to the declared output schema. As a bonus, clients now see the real error message (404 Not Found: memo not found) instead of a validation failure.Testing
TestBuildAPIRequestAcceptsResourceNamesForPathParameterscovering canonical names, bare IDs, nested routes, attachment names, and the two left-untouched cases; updated error-shape assertions inadapter_test.goandservice_test.go.go test ./server/router/mcp/...passes;go build ./...clean;golangci-lint runreports 0 issues.memos/<id>names (update verified persisted), and a nonexistent-memo call returnsisError: truewith nostructuredContentand the real 404 message.