Fix JSON serialization to handle non-ASCII characters in _convert_to_…#495
Closed
detteiu0330 wants to merge 4 commits intomodelcontextprotocol:mainfrom
Closed
Fix JSON serialization to handle non-ASCII characters in _convert_to_…#495detteiu0330 wants to merge 4 commits intomodelcontextprotocol:mainfrom
detteiu0330 wants to merge 4 commits intomodelcontextprotocol:mainfrom
Conversation
Member
|
How can I reproduce this? Please share a snippet/what I need to run to reproduce. |
Author
|
I faced this issue when I used the below server code. from mcp.server import FastMCP
mcp = FastMCP("greeting")
@mcp.tool(
name="greet",
description="Greet a user with a personalized message",
)
def greet(name: str) -> str:
"""
Greet a user with a personalized message.
Args:
name (str): The name of the user to greet.
Returns:
str: A personalized greeting message.
"""
result = {
"message": f"こんにちは, {name}さん! 今日はどんなことをしたいですか?"
}
return result
if __name__ == "__main__":
mcp.run()For example, if response type is "dict", it is converted to json string by json.dumps but its contents converted to ascii at the same time.
It causes to exceed the limit of tokens, so it should be fixed, I think. |
Author
|
@Kludex |
9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…content
Fix JSON serialization to handle non-ASCII characters in _convert_to_content
Motivation and Context
Set ensure_ascii in json.dump of _convert_to_contect function to false to solve the problem that non-alphabetic characters are converted to ascii characters when trying to retrieve them.
How Has This Been Tested?
Tested using a server that retrieves chat history from slack's API.
Breaking Changes
Not necessary.
Types of changes
Checklist
Additional context