Skip to content

Instantly share code, notes, and snippets.

@ArcHound
Created May 4, 2025 09:20
Show Gist options
  • Save ArcHound/56ca99777c53f3dea1b35d44521bc384 to your computer and use it in GitHub Desktop.
Save ArcHound/56ca99777c53f3dea1b35d44521bc384 to your computer and use it in GitHub Desktop.
Transform MCP tool response into Mistral AI function call
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