Skip to content

Cut a tool's link fields and a vendor's refusal between characters, not inside an emoji - #919

Open
kevin9327 wants to merge 1 commit into
CopilotKit:mainfrom
kevin9327:fix/mcp-link-cut-between-characters
Open

kevin9327 wants to merge 1 commit into
CopilotKit:mainfrom
kevin9327:fix/mcp-link-cut-between-characters

Conversation

@kevin9327

Copy link
Copy Markdown
Contributor

What this changes

Two cuts in server/src/plugins/mcp.ts still sliced by UTF-16 units:

  • resourceLinkText bounds a resource_link's title, name and description to 400 with value.slice(0, 400) + "…".
  • trimmed bounds the reason a vendor gives in a refused (403) request to 400 the same way.

When the cut landed between the two halves of an emoji, the text ended in a lone high surrogate, so the Bot (or the operator reading the refusal) was handed �…, a character that was never in the source.

Both now use cutAtCodeUnits from channels/text.ts, which resultText's own 20,000-character cut in the same file already uses. It drops the half character, so nothing gets longer than before.

Where it runs

  • New state that outlives a request? None.
  • What happens on the second replica? Nothing new.
  • Anything serialised? The tool result text and the failure message, as before; they are now always valid Unicode.
  • Anything fanned out to a browser? Nothing new.
  • New listener, port, or schedule? None.

Boundary and audit

  • Every acting call still goes through the gateway. Untouched; only display text is cut.
  • New refusals and new failures each write a row. None added.
  • Nothing new is trusted from the client.

Changelog

  • A section in CHANGELOG.md under Unreleased; happy to rebase if it conflicts.

Proof

New case in server/tests/mcp-result.test.ts (a description of 399 characters followed by emoji). On unmodified main:

(fail) a result with something in it > cuts a resource_link's long field between characters, not inside an emoji

With the change, bun test tests/mcp-result.test.ts passes (25 pass). vendorFailure's 403 path has no direct test hook, so trimmed is covered by the same helper rather than a new test. biome format and biome lint --error-on-warnings on the changed files are clean.

AI assistance: I used an AI coding assistant to find and write this change, and reviewed and tested it myself.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-31T03:26:18.984440Z
We couldn’t complete this review. Comment @codex review to try again.
25fc82d PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

This branch has not been deployed

No deployments
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.

1 participant