create_identity
Set up email identities on Migadu MCP Server by specifying target addresses, mailboxes, names, passwords, and optional domains in a structured format.
Instructions
Create email identities. List of dicts with: target, mailbox, name, password (required), domain (optional).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| identities | Yes |
Input Schema (JSON Schema)
{
"properties": {
"identities": {
"items": {
"additionalProperties": true,
"type": "object"
},
"title": "Identities",
"type": "array"
}
},
"required": [
"identities"
],
"type": "object"
}
Implementation Reference
- The primary handler function for the 'create_identity' MCP tool. It processes a list of identity dictionaries using a bulk processor, logs the operation, and returns the results.annotations={ "readOnlyHint": False, "destructiveHint": False, "idempotentHint": False, "openWorldHint": True, }, ) async def create_identity( identities: List[Dict[str, Any]], ctx: Context ) -> Dict[str, Any]: """Create email identities. List of dicts with: target, mailbox, name, password (required), domain (optional).""" count = len(list(ensure_iterable(identities))) await log_bulk_operation_start(ctx, "Creating", count, "identity") result = await process_create_identity(identities, ctx) await log_bulk_operation_result(ctx, "Identity creation", result, "identity") return result
- migadu_mcp/utils/schemas.py:189-197 (schema)Pydantic BaseModel schema defining the input structure for creating an identity, validated by the bulk processor used in the tool handler.class IdentityCreateRequest(BaseModel): """Request schema for creating an identity""" target: str = Field(..., description="Local part of identity address") mailbox: str = Field(..., description="Username of mailbox that owns this identity") name: str = Field(..., description="Display name for identity") password: str = Field(..., description="Password for SMTP authentication") domain: Optional[str] = Field(None, description="Domain name")
- Helper function decorated with bulk_processor_with_schema that handles the actual creation of a single identity, including domain resolution, logging, and service call.@bulk_processor_with_schema(IdentityCreateRequest) async def process_create_identity( validated_item: IdentityCreateRequest, ctx: Context ) -> Dict[str, Any]: """Process a single identity creation""" # Get domain if not provided domain = validated_item.domain if domain is None: from migadu_mcp.config import get_config config = get_config() domain = config.get_default_domain() if not domain: raise ValueError("No domain provided and MIGADU_DOMAIN not configured") email_address = format_email_address(domain, validated_item.target) await log_operation_start( ctx, "Creating identity", f"{email_address} for {validated_item.mailbox}" ) service = get_service_factory().identity_service() result = await service.create_identity( domain, validated_item.mailbox, validated_item.target, validated_item.name, validated_item.password, ) await log_operation_success(ctx, "Created identity", email_address) return {"identity": result, "email_address": email_address, "success": True}
- migadu_mcp/main.py:22-22 (registration)The call to register_identity_tools(mcp) in the main server initialization, which defines and registers the create_identity tool along with other identity tools.register_identity_tools(mcp)
- Backend service method that performs the actual API request to create an identity via the MigaduClient.async def create_identity( self, domain: str, mailbox: str, local_part: str, name: str, password: str ) -> Dict[str, Any]: """Create a new identity for a mailbox""" data = {"local_part": local_part, "name": name, "password": password} return await self.client.request( "POST", f"/domains/{domain}/mailboxes/{mailbox}/identities", json=data )