list_models
Retrieve a list of Odoo models filtered by name. Use this tool to explore available models in your Odoo instance.
Instructions
List Odoo models with optional name filtering
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | No | ||
| limit | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/odoo_mcp/server.py:1765-1808 (registration)The `list_models` tool is registered via @mcp.tool decorator on the `list_models` function. It is the MCP tool definition with description, annotations (READ_ONLY_TOOL), structured output, and the handler logic that queries Odoo models with optional name filtering.
@mcp.tool( description="List Odoo models with optional name filtering", annotations=READ_ONLY_TOOL, structured_output=True, ) def list_models( ctx: Context, query: Optional[str] = None, limit: int = 100, ) -> Dict[str, Any]: """ List available Odoo model technical names and display names. Prefer this read-only tool over execute_method when discovering models. """ odoo = ctx.request_context.lifespan_context.odoo try: limit = clamp_limit(limit, maximum=500) models = odoo.get_models() if "error" in models: return {"success": False, "error": models["error"]} model_names = models.get("model_names", []) models_details = models.get("models_details", {}) if query: query_lower = query.lower() model_names = [ model_name for model_name in model_names if query_lower in model_name.lower() or query_lower in str(models_details.get(model_name, {}).get("name", "")).lower() ] records = [ { "model": model_name, "name": models_details.get(model_name, {}).get("name", ""), } for model_name in model_names[:limit] ] return {"success": True, "count": len(records), "result": records} except Exception as e: return {"success": False, "error": str(e)} - src/odoo_mcp/server.py:1766-1768 (schema)Tool annotations: READ_ONLY_TOOL (readOnlyHint=True, destructiveHint=False, idempotentHint=True, openWorldHint=True) and structured_output=True. Parameters: ctx (Context), query (Optional[str]), limit (int=100). Returns Dict[str, Any].
description="List Odoo models with optional name filtering", annotations=READ_ONLY_TOOL, structured_output=True, - src/odoo_mcp/odoo_client.py:394-438 (helper)The `OdooClient.get_models()` method is the underlying helper that fetches model names and details from the Odoo instance. It is called by the `list_models` handler via `odoo.get_models()`.
def get_models(self) -> dict[str, Any]: """ Get a list of all available models in the system Returns: List of model names Examples: >>> client = OdooClient(url, db, username, password) >>> models = client.get_models() >>> print(len(models)) 125 >>> print(models[:5]) ['res.partner', 'res.users', 'res.company', 'res.groups', 'ir.model'] """ try: # First search for model IDs model_ids = self._execute("ir.model", "search", []) if not model_ids: return { "model_names": [], "models_details": {}, "error": "No models found", } # Then read the model data with only the most basic fields # that are guaranteed to exist in all Odoo versions result = self._execute("ir.model", "read", model_ids, ["model", "name"]) # Extract and sort model names alphabetically models = sorted([rec["model"] for rec in result]) # For more detailed information, include the full records models_info = { "model_names": models, "models_details": { rec["model"]: {"name": rec.get("name", "")} for rec in result }, } return models_info except Exception as e: print(f"Error retrieving models: {str(e)}", file=sys.stderr) return {"model_names": [], "models_details": {}, "error": str(e)} - src/odoo_mcp/diagnostics.py:765-783 (helper)In `_recommended_fit_gap_calls`, `list_models` is referenced as a recommended next tool call to suggest model discovery after a fit/gap classification.
def _recommended_fit_gap_calls( requirement: str, classification: str ) -> list[dict[str, Any]]: calls = [ { "tool": "list_models", "arguments": { "query": requirement.split()[0] if requirement.split() else None }, } ] if classification in {"studio", "custom_module", "unknown"}: calls.append( { "tool": "inspect_model_relationships", "arguments": {"model": "res.partner", "use_live_metadata": True}, } ) return calls - src/odoo_mcp/agent_tools.py:487-489 (helper)In `business_pack_report`, `list_models` is referenced as a recommended next call for unpacking expected model prefixes when models are missing.
{"tool": "list_models", "arguments": {"query": model.split(".")[0]}} for model in expected_models[:3] ],