model_createModel
Create custom note types in Anki by defining field names, card templates, and optional CSS. Use this tool to design tailored flashcard models for enhanced learning content.
Instructions
Creates a new model (note type). Returns the created model object.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cardTemplates | Yes | List of card template definitions. Each dict needs 'Name', 'Front', 'Back'. | |
| css | No | Optional CSS for the model. | |
| inOrderFields | Yes | List of field names in order. | |
| isCloze | No | Set to true if this is a Cloze model. | |
| modelId | No | Optional model ID to use. | |
| modelName | Yes | The name for the new model. |
Implementation Reference
- src/anki_mcp/model_service.py:59-94 (handler)Handler function for the 'createModel' tool in the model_mcp FastMCP server. Constructs parameters and calls AnkiConnect's 'createModel' action via anki_call. This becomes the 'model_createModel' tool when model_mcp is imported into the main server.@model_mcp.tool( name="createModel", description="Creates a new model (note type). Returns the created model object.", ) async def create_model_tool( modelName: Annotated[str, Field(description="The name for the new model.")], inOrderFields: Annotated[ List[str], Field(description="List of field names in order.") ], cardTemplates: Annotated[ List[Dict[str, Any]], Field( description="List of card template definitions. Each dict needs 'Name', 'Front', 'Back'." ), ], css: Annotated[ Optional[str], Field(description="Optional CSS for the model.") ] = None, isCloze: Annotated[ Optional[bool], Field(description="Set to true if this is a Cloze model.") ] = False, modelId: Annotated[ Optional[int], Field(description="Optional model ID to use.") ] = None, ) -> Dict[str, Any]: params: Dict[str, Any] = { "modelName": modelName, "inOrderFields": inOrderFields, "cardTemplates": cardTemplates, "isCloze": isCloze, } if css is not None: params["css"] = css if modelId is not None: params["modelId"] = modelId return await anki_call("createModel", **params)
- src/anki_mcp/__init__.py:26-26 (registration)Imports the model_mcp server into the main anki_mcp server with the 'model' prefix, registering all model tools (including 'createModel' as 'model_createModel').await anki_mcp.import_server("model", model_mcp)
- src/anki_mcp/model_service.py:63-83 (schema)Pydantic-based input schema definition for the tool parameters using Annotated and Field, including descriptions for model name, fields, templates, CSS, cloze flag, and model ID.async def create_model_tool( modelName: Annotated[str, Field(description="The name for the new model.")], inOrderFields: Annotated[ List[str], Field(description="List of field names in order.") ], cardTemplates: Annotated[ List[Dict[str, Any]], Field( description="List of card template definitions. Each dict needs 'Name', 'Front', 'Back'." ), ], css: Annotated[ Optional[str], Field(description="Optional CSS for the model.") ] = None, isCloze: Annotated[ Optional[bool], Field(description="Set to true if this is a Cloze model.") ] = False, modelId: Annotated[ Optional[int], Field(description="Optional model ID to use.") ] = None, ) -> Dict[str, Any]:
- src/anki_mcp/common.py:8-23 (helper)Utility function that performs HTTP POST to AnkiConnect API endpoint, used by all service handlers including model_createModel to invoke the underlying 'createModel' action.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