model_createModel
Create custom note types in Anki by defining fields and card templates to organize flashcards according to your learning needs.
Instructions
Creates a new model (note type). Returns the created model object.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| modelName | Yes | The name for the new model. | |
| inOrderFields | Yes | List of field names in order. | |
| cardTemplates | Yes | List of card template definitions. Each dict needs 'Name', 'Front', 'Back'. | |
| css | No | Optional CSS for the model. | |
| isCloze | No | Set to true if this is a Cloze model. | |
| modelId | No | Optional model ID to use. |
Implementation Reference
- src/anki_mcp/model_service.py:59-94 (handler)Handler function executing the logic for tool 'model_createModel' by calling AnkiConnect's 'createModel' API.@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)Registers the 'model_mcp' FastMCP server (containing the createModel tool) into the main 'anki_mcp' with 'model_' prefix, resulting in 'model_createModel'.await anki_mcp.import_server("model", model_mcp)
- src/anki_mcp/model_service.py:8-8 (registration)Creates the 'model_mcp' FastMCP instance where the 'createModel' tool is registered (later prefixed).model_mcp = FastMCP(name="AnkiModelService")
- src/anki_mcp/common.py:8-23 (helper)Utility function that performs HTTP POST to AnkiConnect API, used by the handler to invoke 'createModel'.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