Skip to main content
Glama

get_model_schema

Retrieve detailed schema information for specific API models to analyze data structures and endpoints without loading entire OpenAPI specifications.

Instructions

Get detailed schema for a specific model

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
apiYesAPI name or direct URL
model_nameYesName of the model

Implementation Reference

  • Core handler function that retrieves the detailed schema for a specific model from the OpenAPI components.schemas section.
    async def get_model_schema(
        self, api_identifier: str, model_name: str
    ) -> Dict[str, Any]:
        """Get detailed schema for a specific model."""
        url, headers = self.config_manager.get_api_config(api_identifier)
        schema = await self.cache.get_schema(url, headers)
    
        components = schema.get("components", {})
        schemas = components.get("schemas", {})
    
        if model_name not in schemas:
            raise ValueError(f"Model '{model_name}' not found")
    
        logger.info(f"Retrieved schema for model {model_name}")
        return {"name": model_name, "schema": schemas[model_name]}
  • Defines the JSON Schema for the tool's input parameters, requiring 'api' and 'model_name'.
    def create_model_schema_input_schema() -> Dict[str, Any]:
        """Create input schema for model schema operations."""
        return {
            "type": "object",
            "properties": {
                "api": {"type": "string", "description": "API name or direct URL"},
                "model_name": {
                    "type": "string",
                    "description": "Name of the model",
                },
            },
            "required": ["api", "model_name"],
        }
  • Registers the GetModelSchemaTool instance in the tool registry along with other tools.
    tools = [
        # API Management Tools
        AddApiTool(self.config_manager),
        ListSavedApisTool(self.config_manager),
        RemoveApiTool(self.config_manager),
        # API Exploration Tools
        GetApiInfoTool(self.config_manager, self.explorer),
        ListEndpointsTool(self.config_manager, self.explorer),
        SearchEndpointsTool(self.config_manager, self.explorer),
        GetEndpointDetailsTool(self.config_manager, self.explorer),
        ListModelsTool(self.config_manager, self.explorer),
        GetModelSchemaTool(self.config_manager, self.explorer),
    ]
    
    for tool in tools:
        self._tools[tool.name] = tool
        logger.debug(f"Registered tool: {tool.name}")
  • MCP tool handler that validates arguments, calls the explorer service, formats the response, and handles errors.
    async def handle_call(self, arguments: Dict[str, Any]) -> List[TextContent]:
        try:
            self._validate_api_identifier(arguments["api"])
            schema = await self.explorer.get_model_schema(
                arguments["api"], arguments["model_name"]
            )
            result = self.explorer.format_model_schema(schema)
            return self._create_text_response(result)
        except Exception as e:
            return self._create_error_response(e)
  • Helper function to format the model schema data into a readable text response.
    def format_model_schema(self, schema_data: Dict[str, Any]) -> str:
        """Format model schema for display."""
        result = f"Model: {schema_data['name']}\n\n"
        result += f"Schema:\n{json.dumps(schema_data['schema'], indent=2)}"
        return result

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/nyudenkov/openapi-mcp-proxy'

If you have feedback or need assistance with the MCP directory API, please join our Discord server