model_updateModelTemplates
Modify templates for an existing Anki flashcard model to update card layouts and formatting.
Instructions
Modifies the templates of an existing model by name.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| model | Yes | Model object. Must include 'name' (model name) and 'templates' (dict of template name to Front/Back definitions). |
Implementation Reference
- src/anki_mcp/model_service.py:97-110 (handler)Handler function for the 'model_updateModelTemplates' tool (prefixed during registration). Defines input schema via Pydantic Annotated and Field, and executes by calling AnkiConnect's updateModelTemplates.@model_mcp.tool( name="updateModelTemplates", description="Modifies the templates of an existing model by name.", ) async def update_model_templates_tool( model: Annotated[ Dict[str, Any], Field( description="Model object. Must include 'name' (model name) and 'templates' (dict of template name to Front/Back definitions)." ), ], ) -> None: return await anki_call("updateModelTemplates", model=model)
- src/anki_mcp/__init__.py:26-26 (registration)Registers the model_mcp server into the main anki_mcp, prefixing tool names with 'model_' (resulting in 'model_updateModelTemplates').await anki_mcp.import_server("model", model_mcp)
- src/anki_mcp/common.py:8-23 (helper)Helper function used by the handler to make HTTP calls to AnkiConnect API.async def anki_call(action: str, **params: Any) -> Any: async with httpx.AsyncClient() as client: payload = {"action": action, "version": 6, "params": params} result = await client.post(ANKICONNECT_URL, json=payload) result.raise_for_status() result_json = result.json() error = result_json.get("error") if error: raise Exception(f"AnkiConnect error for action '{action}': {error}") response = result_json.get("result") if "result" in result_json: return response return result_json
- src/anki_mcp/__init__.py:8-8 (registration)Imports the model_mcp instance containing the tool definitions.from .model_service import model_mcp