Skip to content
This repository was archived by the owner on Jun 2, 2026. It is now read-only.

fix: ensure MCP tool name prefix starts with a letter for Gemini compatibility#961

Open
octo-patch wants to merge 2 commits into
voideditor:mainfrom
octo-patch:fix/issue-874-gemini-invalid-function-name
Open

fix: ensure MCP tool name prefix starts with a letter for Gemini compatibility#961
octo-patch wants to merge 2 commits into
voideditor:mainfrom
octo-patch:fix/issue-874-gemini-invalid-function-name

Conversation

@octo-patch

Copy link
Copy Markdown

Fixes #874

Problem

_addUniquePrefix generates a 6-character random base-36 string via
Math.random().toString(36).slice(2, 8). Base-36 uses digits 0–9 and
letters a–z, so the string frequently starts with a digit (e.g. 4fzyo8).

The resulting tool name (4fzyo8_read_file) is then sent to Gemini as a
FunctionDeclaration.name. Gemini enforces:

Must start with a letter or an underscore. Must be alphanumeric
(a-z, A-Z, 0-9), underscores, dots or dashes, with a maximum length of 64.

This causes a 400 Bad Request / INVALID_ARGUMENT error for every Gemini
request when MCP tools are registered.

Solution

Prepend the fixed character m to the random segment so the prefix always
starts with a letter:

// Before
return `${Math.random().toString(36).slice(2, 8)}_${base}`;

// After
return `m${Math.random().toString(36).slice(2, 8)}_${base}`;

This is the minimal change needed: uniqueness is unchanged (the random part
still contributes 6 random base-36 chars), removeMCPToolNamePrefix still
works correctly (it splits on _ and drops the first segment), and all other
providers are unaffected.

Testing

  • Verified that m${Math.random().toString(36).slice(2, 8)} always produces a
    string starting with m (a letter), satisfying Gemini's constraint.
  • removeMCPToolNamePrefix('m4fzyo8_read_file')'read_file'
octo-patch added 2 commits April 18, 2026 09:53
…ixes voideditor#925)

The .chat-dnd-overlay element uses position:absolute to cover the chat
panel during drag-and-drop, but its parent .interactive-session lacked
a positioning context (position:relative). This caused the overlay to
be positioned relative to a wrong ancestor, making it appear off-screen
or in an incorrect location with no visual feedback during drag operations.
…atibility (fixes voideditor#874)

Math.random().toString(36) can produce strings starting with a digit (e.g.
'4fzyo8'), causing Gemini to reject the request with INVALID_ARGUMENT.
Gemini requires function names to start with a letter or underscore.

Prepend 'm' to the random prefix so generated names always start with a
letter, satisfying Gemini's constraint while preserving uniqueness.
@andrewpareles andrewpareles force-pushed the main branch 11 times, most recently from 360390b to b3166e7 Compare June 2, 2026 22:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

1 participant