Skip to main content
Glama

list_models

Retrieve and filter data models from APIs via pagination, property counts, required fields, and tags. Use to explore and analyze OpenAPI schemas efficiently without full context loading.

Instructions

List all data models in an API

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
apiYesAPI name or direct URL
has_required_fieldsNoFilter by presence of required fields
include_detailsNoInclude detailed information about models
max_propertiesNoMaximum number of properties
min_propertiesNoMinimum number of properties
pageNoPage number (1-based)
page_sizeNoItems per page (max 100)
tags_excludeNoExclude models with these tags
tags_includeNoInclude models with these tags
typesNoFilter by model types (e.g., ['object', 'array', 'string'])

Implementation Reference

  • ListModelsTool class implementing the MCP tool 'list_models': sets name/description, provides tool definition with input schema, handles calls by validating API, extracting pagination/filters, calling explorer.list_models_paginated, formatting paginated model list response.
    class ListModelsTool(APITool, ToolDefinitionMixin): """Tool for listing API data models.""" def __init__(self, config_manager, explorer): super().__init__( name="list_models", description="List all data models in an API", config_manager=config_manager, explorer=explorer, ) def get_tool_definition(self) -> Tool: return Tool( name=self.name, description=self.description, inputSchema=self.create_paginated_model_input_schema(), ) async def handle_call(self, arguments: Dict[str, Any]) -> List[TextContent]: try: self._validate_api_identifier(arguments["api"]) pagination = self.extract_pagination_params(arguments) filters = self.extract_model_filter_params(arguments) include_details = arguments.get("include_details", False) paginated_result = await self.explorer.list_models_paginated( arguments["api"], pagination, filters ) result = self._format_paginated_model_response( paginated_result, filters, include_details ) return self._create_text_response(result) except Exception as e: return self._create_error_response(e) def _format_paginated_model_response( self, paginated_result, filters, include_details ) -> str: """Format paginated model response.""" result = "" filter_display = filters.format_display() if filter_display: result += filter_display + "\n\n" if filters and any( [ filters.types, filters.min_properties is not None, filters.max_properties is not None, filters.has_required_fields is not None, filters.tags_include, filters.tags_exclude, ] ): result += ( f"Total Results: {paginated_result.total_count} models (filtered)\n\n" ) else: result += f"Total Results: {paginated_result.total_count} models\n\n" if paginated_result.items: for model in paginated_result.items: result += model.format_display(detailed=include_details) + "\n" else: result += "No models found\n" result += "\n" + paginated_result.format_navigation() return result
  • create_paginated_model_input_schema static method: defines the JSON schema for 'list_models' input, including required 'api', optional pagination (page, page_size), model filters (types, min/max_properties, etc.), and include_details flag.
    def create_paginated_model_input_schema() -> Dict[str, Any]: """Create input schema for paginated model operations.""" schema = ToolDefinitionMixin.create_api_input_schema() schema["properties"].update(ToolDefinitionMixin.create_pagination_properties()) schema["properties"].update( ToolDefinitionMixin.create_model_filter_properties() ) schema["properties"]["include_details"] = { "type": "boolean", "description": "Include detailed information about models", "default": False, } return schema
  • _register_tools method in ToolRegistry: instantiates and registers ListModelsTool instance among other tools into the tools dict for MCP server dispatching.
    def _register_tools(self) -> None: """Register all available 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}")
  • list_models_paginated method in OpenAPIExplorer: fetches all models via list_models, applies filters if provided, applies pagination, returns PaginationResult used by the tool handler.
    async def list_models_paginated( self, api_identifier: str, pagination: PaginationParams, filters: Optional[ModelFilterParams] = None, ) -> PaginationResult[ModelInfo]: """List models with pagination and filtering.""" all_models = await self.list_models(api_identifier) if filters: filtered_models = [ model for model in all_models if model.matches_filters(filters) ] else: filtered_models = all_models total_count = len(filtered_models) start_idx = pagination.get_offset() end_idx = start_idx + pagination.get_limit() paginated_models = filtered_models[start_idx:end_idx] logger.info( f"Paginated models for API {api_identifier}: " f"page {pagination.page}, showing {len(paginated_models)} of {total_count}" ) return PaginationResult.create(paginated_models, total_count, pagination)
  • list_models method: extracts ModelInfo objects from OpenAPI components.schemas, used as base for pagination and filtering in list_models_paginated.
    async def list_models(self, api_identifier: str) -> List[ModelInfo]: """List all data models in an API.""" url, headers = self.config_manager.get_api_config(api_identifier) schema = await self.cache.get_schema(url, headers) models = [] components = schema.get("components", {}) schemas = components.get("schemas", {}) for name, model_schema in schemas.items(): tags = [] if "x-tags" in model_schema: tags = model_schema["x-tags"] elif "tags" in model_schema: tags = model_schema["tags"] model = ModelInfo( name=name, type=model_schema.get("type", "object"), properties=model_schema.get("properties", {}), required=model_schema.get("required", []), description=model_schema.get("description"), tags=tags, ) models.append(model) logger.info(f"Found {len(models)} models for API {api_identifier}") return models

Other Tools

Related Tools

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