Skip to main content
Glama

list_models

Retrieve and filter data models from an API specification to understand available structures and properties for integration planning.

Instructions

List all data models in an API

Input Schema

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

Implementation Reference

  • ListModelsTool class implementing the 'list_models' MCP tool, including the handle_call handler, tool definition (schema), and formatting logic.
    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
  • ToolRegistry._register_tools method where ListModelsTool is instantiated and added to the tools dictionary for MCP server registration.
    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}") logger.info(f"Registered {len(self._tools)} tools")
  • OpenAPIExplorer.list_models_paginated helper method that performs the core logic of listing and paginating models, invoked 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)
  • OpenAPIExplorer.list_models helper method that extracts all models from the OpenAPI schema.
    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

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