get_model_json_schema
Retrieve JSON schema for Vizro models like Card, Dashboard, or Page to validate structure and ensure proper configuration.
Instructions
Get the JSON schema for the specified Vizro model. Server Vizro version: 0.1.50
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| model_name | Yes | Name of the Vizro model to get schema for (e.g., 'Card', 'Dashboard', 'Page') |
Implementation Reference
- The core handler function for the 'get_model_json_schema' tool, decorated with @mcp.tool() for registration. It retrieves the JSON schema for a given Vizro model name, handling special cases for modified, deprecated, and layout models.@mcp.tool(description=f"Get the JSON schema for the specified Vizro model. Server Vizro version: {vizro.__version__}") def get_model_json_schema( model_name: str = Field( description="Name of the Vizro model to get schema for (e.g., 'Card', 'Dashboard', 'Page')" ), ) -> ModelJsonSchemaResults: """Get the JSON schema for the specified Vizro model. Returns: JSON schema of the requested Vizro model """ if not hasattr(vm, model_name): return ModelJsonSchemaResults( model_name=model_name, json_schema={}, additional_info=f"Model '{model_name}' not found in vizro.models", ) modified_models = { "Graph": GraphEnhanced, "AgGrid": AgGridEnhanced, "Table": AgGridEnhanced, "Figure": FigureEnhanced, } if model_name in modified_models: return ModelJsonSchemaResults( model_name=model_name, json_schema=modified_models[model_name].model_json_schema(schema_generator=NoDefsGenerateJsonSchema), additional_info="""LLM must remember to replace `$ref` with the actual config. Request the schema of that model if necessary. Do NOT forget to call `validate_dashboard_config` after each iteration.""", ) deprecated_models = {"filter_interaction": "set_control", "Layout": "Grid"} if model_name in deprecated_models: return ModelJsonSchemaResults( model_name=model_name, json_schema={}, additional_info=f"Model '{model_name}' is deprecated. Use {deprecated_models[model_name]} instead.", ) model_class = getattr(vm, model_name) if model_name in {"Grid", "Flex"}: return ModelJsonSchemaResults( model_name=model_name, json_schema=model_class.model_json_schema(schema_generator=NoDefsGenerateJsonSchema), additional_info=LAYOUT_INSTRUCTIONS, ) return ModelJsonSchemaResults( model_name=model_name, json_schema=model_class.model_json_schema(schema_generator=NoDefsGenerateJsonSchema), additional_info="""LLM must remember to replace `$ref` with the actual config. Request the schema of that model if necessary. Do NOT forget to call `validate_dashboard_config` after each iteration.""", )
- Dataclass defining the structured output for the get_model_json_schema tool, including model name, JSON schema, and additional info.@dataclass class ModelJsonSchemaResults: """Results of the get_model_json_schema tool.""" model_name: str json_schema: dict[str, Any] additional_info: str
- vizro-mcp/src/vizro_mcp/server.py:107-107 (registration)The @mcp.tool decorator registers the get_model_json_schema function as an MCP tool.@mcp.tool(description=f"Get the JSON schema for the specified Vizro model. Server Vizro version: {vizro.__version__}")