Skip to content

🐛 Bug: Tool Names Violate Gemini API Function Calling Rules #37

@darraghh1

Description

@darraghh1

🐛 Bug: Tool Names Violate Gemini API Function Calling Rules

🔗 Issue Summary

The @21st-dev/magic@latest Model Context Protocol (MCP) server causes client applications using the Gemini API (such as the Gemini CLI) to fail initialization due to invalid function names starting with a digit. This is a compatibility issue with the Gemini API's strict validation rules for tool function declarations.

🔬 Environment & Configuration

  • MCP Server: @21st-dev/magic@latest
  • Client: Gemini CLI (using the standard Google Generative Language API)
  • Client Behavior: Fails immediately upon startup when attempting to aggregate tools.

Relevant settings.json Snippet:

"magic": {
  "type": "stdio",
  "command": "cmd",
  "args": [
    "/c",
    "npx",
    "-y",
    "@21st-dev/magic@latest"
  ],
  "env": {
    "API_KEY": "..." // Key redacted, but present in configuration
  }
}

🛑 Error Description & Evidence

When the Gemini CLI starts, it receives a 400 Bad Request error. The Gemini API requires function names to follow the pattern: ^[a-zA-Z_][a-zA-Z0-9_]*$, meaning they cannot start with a digit (like '2').

API Error Message (from CLI debug output):

[API Error: [{
  "error": {
    "code": 400,
    "message": "The GenerateContentRequest proto is invalid:\n * tools[0].function_declarations[41].name: [FIELD_INVALID] Invalid function name. Must start with a letter or an underscore. Must be a-z, A-Z, 0-9, or contain underscores, dots and dashes, with a maximum length of 64.",
...
"status": "INVALID_ARGUMENT"
}]

Tools Exposed by magic Server (Verified via /mcp):

The following tools are exposed, and the ones starting with '2' are the source of the error:

  1. 21st_magic_component_builder ❌ (Invalid: Starts with '2')
  2. logo_search ✅ (Compliant)
  3. 21st_magic_component_inspiration ❌ (Invalid: Starts with '2')
  4. 21st_magic_component_refiner ❌ (Invalid: Starts with '2')

✅ Workaround

A temporary fix for users of the Gemini CLI is to explicitly exclude the non-compliant tools in their settings.json file:

"magic": {
  // ... existing config ...
  "exclude-tools": [
    "21st_magic_component_builder",
    "21st_magic_component_inspiration",
    "21st_magic_component_refiner"
  ]
}

💡 Proposed Solution

Please rename the affected tool functions within the @21st-dev/magic@latest package to be compliant with the Gemini API rules. A simple fix would be to prepend them with a non-digit character, for example: magic_21st_component_builder or _21st_magic_component_builder.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions