model_modelFieldAdd
Adds a custom field to an existing Anki flashcard model, enabling enhanced data organization and flexibility in card creation.
Instructions
Adds a new field to an existing model.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| fieldName | Yes | Name of the new field to add. | |
| index | No | Optional 0-based index to insert the field at. | |
| modelName | Yes | Name of the model to modify. |
Implementation Reference
- src/anki_mcp/model_service.py:127-142 (handler)Handler function implementing the tool logic for modelFieldAdd (exposed as model_modelFieldAdd), which constructs parameters and calls AnkiConnect's modelFieldAdd via anki_call.@model_mcp.tool( name="modelFieldAdd", description="Adds a new field to an existing model." ) async def add_model_field_tool( modelName: Annotated[str, Field(description="Name of the model to modify.")], fieldName: Annotated[str, Field(description="Name of the new field to add.")], index: Annotated[ Optional[int], Field(description="Optional 0-based index to insert the field at."), ] = None, ) -> None: params: Dict[str, Any] = {"modelName": modelName, "fieldName": fieldName} if index is not None: params["index"] = index return await anki_call("modelFieldAdd", **params)
- src/anki_mcp/__init__.py:26-26 (registration)Registers the model_mcp FastMCP instance under the 'model' prefix, making tools like modelFieldAdd available as model_modelFieldAdd in the main AnkiConnectMCP server.await anki_mcp.import_server("model", model_mcp)
- src/anki_mcp/common.py:8-23 (helper)Helper function used by the handler to perform HTTP POST requests to AnkiConnect API, handling errors and returning results.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