Skip to content

lm-studio (beta) is missing a parameter from the tool schema #82

Description

@oderwat

To make lm-studio (current beta) work as a backend with my setup I had to modify the code:

from mcp import Tool
from lmos_openai_types import ChatCompletionTool

def mcp2openai(mcp_tool: Tool) -> ChatCompletionTool:
    """Convert a MCP Tool to an OpenAI ChatCompletionTool."""
    # Start with the input schema or default to empty object schema
    parameters = mcp_tool.inputSchema.copy() if mcp_tool.inputSchema else {"type": "object"}
    
    # Ensure OpenAI compatibility for object types
    if parameters.get("type") == "object":
        if "properties" not in parameters:
            parameters["properties"] = {}
        # Optionally ensure 'required' field exists as empty array if not present
        if "required" not in parameters:
            parameters["required"] = []
    
    return ChatCompletionTool(
        type="function",
        function={
            "name": mcp_tool.name,
            "description": mcp_tool.description,
            "parameters": parameters,
            "strict": False,
        },
    )

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions