Created
May 4, 2025 09:20
-
-
Save ArcHound/56ca99777c53f3dea1b35d44521bc384 to your computer and use it in GitHub Desktop.
Transform MCP tool response into Mistral AI function call
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
from mcp.types import Tool | |
def tool_mcp_to_mistral(tool: Tool): | |
json_tool = vars(tool) | |
mistral_tool = dict() | |
# might as well throw an exception if we don't have a name and a description | |
mistral_tool["name"] = json_tool["name"] | |
mistral_tool["description"] = json_tool["description"] | |
# inputSchema maps to parameters, but there are optional fields | |
mistral_tool["parameters"] = dict() | |
mistral_tool["parameters"]["properties"] = json_tool["inputSchema"].get("properties", {}) | |
mistral_tool["parameters"]["required"] = json_tool["inputSchema"].get("required",[]) | |
return {"type": "function", "function": mistral_tool} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment