Skip to main content
Glama
Michaelzag

Migadu MCP Server

by Michaelzag

list_rewrites

Read-onlyIdempotent

Retrieve a list of rewrite rules for a domain to manage email routing and forwarding.

Instructions

List rewrite rules for a domain.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
domainNo

Implementation Reference

  • The 'list_rewrites' MCP tool handler – defined as an async function decorated with @migadu_tool. Resolves the domain and delegates to the RewriteService.list_rewrites() method. Registered via register_rewrite_tools().
    async def list_rewrites(ctx: Context, domain: str | None = None) -> dict[str, Any]:
        """List rewrite rules for a domain."""
        resolved = resolve_domain(domain)
        await ctx.info(f"📋 Listing rewrites for {resolved}")
        return await get_service_factory().rewrite_service().list_rewrites(resolved)
  • The RewriteService.list_rewrites() method – makes an HTTP GET request to the Migadu API endpoint /domains/{domain}/rewrites. This is the actual API call that fetches rewrite rules.
    async def list_rewrites(self, domain: str) -> dict[str, Any]:
        return await self.client.get(f"/domains/{domain}/rewrites")
  • Registration in initialize_server() – the function register_rewrite_tools(mcp) is called to register all rewrite tools (including list_rewrites) with the FastMCP server instance.
    def initialize_server() -> None:
        register_domain_tools(mcp)
        register_mailbox_tools(mcp)
        register_identity_tools(mcp)
        register_alias_tools(mcp)
        register_rewrite_tools(mcp)
        register_forwarding_tools(mcp)
  • The register_rewrite_tools() function that defines and registers all rewrite-related tools (including list_rewrites) with the FastMCP instance via the @migadu_tool decorator.
    def register_rewrite_tools(mcp: FastMCP) -> None:
        @migadu_tool(mcp, read_only=True, summarize_response=True)
        async def list_rewrites(ctx: Context, domain: str | None = None) -> dict[str, Any]:
            """List rewrite rules for a domain."""
            resolved = resolve_domain(domain)
            await ctx.info(f"📋 Listing rewrites for {resolved}")
            return await get_service_factory().rewrite_service().list_rewrites(resolved)
    
        @migadu_tool(mcp, read_only=True)
        async def get_rewrite(
            name: str, ctx: Context, domain: str | None = None
        ) -> dict[str, Any]:
            """Get rewrite rule details by slug/name."""
            resolved = resolve_domain(domain)
            await ctx.info(f"📋 Getting rewrite {name} for {resolved}")
            return await get_service_factory().rewrite_service().get_rewrite(resolved, name)
    
        @migadu_bulk_tool(mcp, RewriteCreateRequest, entity="rewrite", idempotent=False)
        async def create_rewrite(
            item: RewriteCreateRequest, ctx: Context
        ) -> dict[str, Any]:
            """Create rewrite rule(s). List of dicts with: name, local_part_rule (pattern), destinations, domain (optional), order_num (optional)."""
            domain = item.domain or resolve_domain(None)
            destinations = [str(d) for d in item.destinations]
            await ctx.info(f"📋 Creating rewrite {item.name} on {domain}")
            result = (
                await get_service_factory()
                .rewrite_service()
                .create_rewrite(
                    domain, item.name, item.local_part_rule, destinations, item.order_num
                )
            )
            return {"rewrite": result, "success": True}
    
        @migadu_bulk_tool(mcp, RewriteUpdateRequest, entity="rewrite")
        async def update_rewrite(
            item: RewriteUpdateRequest, ctx: Context
        ) -> dict[str, Any]:
            """Update rewrite rule(s). List of dicts with: name (required), and any of: new_name, local_part_rule, destinations, order_num, domain."""
            domain = item.domain or resolve_domain(None)
            destinations = (
                [str(d) for d in item.destinations] if item.destinations else None
            )
            await ctx.info(f"📋 Updating rewrite {item.name} on {domain}")
            result = (
                await get_service_factory()
                .rewrite_service()
                .update_rewrite(
                    domain,
                    item.name,
                    item.new_name,
                    item.local_part_rule,
                    destinations,
                    item.order_num,
                )
            )
            return {"rewrite": result, "success": True}
    
        @migadu_bulk_tool(mcp, RewriteDeleteRequest, entity="rewrite", destructive=True)
        async def delete_rewrite(
            item: RewriteDeleteRequest, ctx: Context
        ) -> dict[str, Any]:
            """Delete rewrite rule(s). DESTRUCTIVE. List of dicts with: name, domain (optional)."""
            domain = item.domain or resolve_domain(None)
            await ctx.warning(f"🗑️ Deleting rewrite {item.name}")
            await get_service_factory().rewrite_service().delete_rewrite(domain, item.name)
            return {"deleted": item.name, "success": True}
    
        _ = (list_rewrites, get_rewrite, create_rewrite, update_rewrite, delete_rewrite)
  • Alternative usage as an MCP resource – the 'rewrites://{domain}' resource also calls list_rewrites() internally, exposing the same data via the resource URI pattern.
    async def domain_rewrites(domain: str, ctx: Context) -> dict[str, Any]:
        await ctx.info(f"📋 Loading rewrites for {domain}")
        return await get_service_factory().rewrite_service().list_rewrites(domain)
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The description adds no behavioral context beyond what annotations already convey (readOnlyHint=true). It does not mention pagination, filtering behavior, or any side effects, leaving the agent to infer from the tool name alone.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence. However, it is arguably too terse, missing opportunities to add value without significant length increase.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with no output schema and minimal parameter info, the description is incomplete. It does not explain what 'rewrite rules' are, what the response looks like, or how the domain filter works when omitted. Essential context for proper invocation is lacking.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage, the description's phrase 'for a domain' provides some meaning for the 'domain' parameter, implying it filters results. However, it does not clarify that the parameter is optional or what the default behavior is, leaving ambiguity.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action (list) and the resource (rewrite rules) with a context (for a domain). However, it does not differentiate from other list tools like list_aliases or list_domains, which are similar in structure.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives, such as get_rewrite for a specific rule. The description does not explain when to omit the domain parameter or what happens if it's null.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Michaelzag/migadu-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server