Skip to content

Conversation

@pvzheroes125
Copy link
Collaborator

@pvzheroes125 pvzheroes125 commented Jan 26, 2026

Filter the $schema field in tool parameters of kosong genai provider so that kimi-cli can work properly when using gemini models with third-party mcp. (Tool parameters is a BaseModel with extra=forbid in genai sdk while TypedDict in anthropic and openai sdk)

Related Issue

Resolve #(issue_number)

Description

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked the related issue, if any.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have run make gen-changelog to update the changelog.
  • I have run make gen-docs to update the user documentation.

Open with Devin

…r so that kimi-cli can work properly when using gemini models with third-party mcp. (Tool parameters is a `BaseModel` with `extra=forbid` in genai sdk while `TypedDict` in anthropic and openai sdk)
Copy link

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

View issue and 1 additional flag in Devin Review.

Open in Devin Review

Comment on lines 358 to 359
if '$schema' in tool.parameters:
del tool.parameters['$schema']

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Mutation of shared tool.parameters dict removes $schema field permanently

The tool_to_google_genai function directly mutates the tool.parameters dictionary by deleting the $schema key, which permanently modifies the original Tool object.

Click to expand

How the bug is triggered

The Tool object is a Pydantic BaseModel that is typically reused across multiple API calls. When tool_to_google_genai is called:

if '$schema' in tool.parameters:
    del tool.parameters['$schema']

This directly modifies the original tool.parameters dict. Since the same Tool instance is returned by toolset.tools (see kosong/tooling/simple.py:89-90), subsequent uses of this tool will have the $schema field missing.

Actual vs Expected behavior

Actual: The $schema field is permanently removed from the original tool object after the first call to tool_to_google_genai.

Expected: The function should create a copy of the parameters dict before modifying it, leaving the original tool object unchanged.

Impact

  1. If the same tool is used with multiple providers (e.g., OpenAI and Google GenAI), the $schema field will be missing for subsequent provider calls.
  2. If the tool's parameters dict is used elsewhere in the application (e.g., for validation, logging, or serialization), it will be missing the $schema field.
  3. This violates the principle of least surprise - a conversion function should not have side effects on its input.

Recommendation: Create a shallow copy of the parameters dict before modifying it:

parameters = tool.parameters.copy()
if '$schema' in parameters:
    del parameters['$schema']
return Tool(
    function_declarations=[
        FunctionDeclaration(
            name=tool.name,
            description=tool.description,
            parameters=parameters,
        )
    ]
)
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@pvzheroes125 pvzheroes125 force-pushed the fix/genai_extra_field_in_tool_parameters branch from 2c7074a to 08500b2 Compare January 26, 2026 13:45
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.

2 participants