Skip to content

Improve Handling of MCP Tool Call Arguments #3127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 28, 2025

Conversation

danielholanda
Copy link
Contributor

@danielholanda danielholanda commented May 28, 2025

Description

This PR handles two issues as described below.

Handle empty MCP tool call arguments

Some OpenAI-compatible providers may generate tool calls with empty arguments represented by an empty JSON object "{}" instead of None. This PR addresses that corner case.

Avoid argument duplication

The code aggregates tool call chunks by index. The first if checks if it's the first chunk and initializes final_tool_calls[tool_call.index] with the current tool_call, including its arguments. The second if appends arguments regardless, causing duplication on the first chunk. Changing the second if to elif ensures arguments are only appended for subsequent chunks, not during initialization.

Copy link
Contributor

@Wauplin Wauplin left a comment

Choose a reason for hiding this comment

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

Sounds good to me but let's wait for @hanouticelina 's review

@Wauplin
Copy link
Contributor

Wauplin commented May 28, 2025

@bot /style

Copy link
Contributor

Style fixes have been applied. View the workflow run here.

@Wauplin
Copy link
Contributor

Wauplin commented May 28, 2025

@danielholanda I'm curious about how you are using the MCP Tool. What have been your use case and how did it go so far? (trying to gather feedback from early adopters 🤗)

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Contributor

@hanouticelina hanouticelina left a comment

Choose a reason for hiding this comment

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

looks good to me, thanks @danielholanda for fixing this!

@Wauplin Wauplin merged commit aa4e9c9 into huggingface:main May 28, 2025
1 check passed
@danielholanda
Copy link
Contributor Author

Hi @Wauplin and @hanouticelina. Congrats on the great work on huggingface_hub and thanks for reviewing and approving this PR.

My team and I own an open-source LLM serving framework called Lemonade (repo created 2 weeks ago). Our focus is local LLMs and we are doing cool things like streaming tool calls tageting onnx-runtime-genai, which afaik others are not doing yet.

We are planning on hopefully publishing a Blog on AMD's developer's page on TinyAgents MCP + Lemonade in the next week or so. If you find that interesting and would like to participate or get some additional info there feel free to send me an email (see bio) so we can schedule something. :)

@julien-c
Copy link
Member

looks very cool!

image

hanouticelina pushed a commit that referenced this pull request May 30, 2025
* Handle empty MCP tool call arguments

* Apply style fixes

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
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.

5 participants