Skip to main content
Glama

delete_customer

Archive a customer record by ID using soft deletion. The customer data is retained but marked as inactive for compliance or recovery purposes.

Instructions

Soft-delete a customer by ID.

The customer record is archived but not permanently removed.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
customer_idYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The delete_customer handler function - decorated with @mcp.tool, takes customer_id and ctx parameters, performs a soft-delete by calling client.delete() on the /api/v2/consumers/{customer_id} endpoint, and handles StreamAPIError exceptions.
    @mcp.tool
    async def delete_customer(
        customer_id: str,
        ctx: Context = None,  # type: ignore[assignment]
    ) -> dict[str, Any]:
        """Soft-delete a customer by ID.
    
        The customer record is archived but not permanently removed.
        """
        client = await get_client(ctx)
        try:
            return await client.delete(f"{_BASE}/{customer_id}")
        except StreamAPIError as exc:
            return _err(exc)
  • The register() function that registers all customer tools including delete_customer with the FastMCP instance using the @mcp.tool decorator.
    def register(mcp: FastMCP) -> None:
        """Register all customer tools on *mcp*."""
    
        @mcp.tool
        async def create_customer(
            name: str,
            phone_number: str | None = None,
            email: str | None = None,
            external_id: str | None = None,
            iban: str | None = None,
            alias: str | None = None,
            comment: str | None = None,
            preferred_language: str | None = None,
            communication_methods: list[str] | None = None,
            ctx: Context = None,  # type: ignore[assignment]
        ) -> dict[str, Any]:
            """Create a new customer in Stream.
    
            Provide at least a *name*. Optionally include *phone_number*, *email*,
            *external_id*, *iban*, *alias*, *comment*, *preferred_language* (EN/AR),
            and *communication_methods* (WHATSAPP, EMAIL, SMS).
            """
            body = CreateCustomerRequest(
                name=name, phone_number=phone_number, email=email,
                external_id=external_id, iban=iban, alias=alias,
                comment=comment, preferred_language=preferred_language,
                communication_methods=communication_methods,
            )
            client = await get_client(ctx)
            try:
                return await client.post(_BASE, body.model_dump(exclude_none=True))
            except StreamAPIError as exc:
                return _err(exc)
    
        @mcp.tool
        async def list_customers(
            page: int = 1,
            limit: int = 20,
            ctx: Context = None,  # type: ignore[assignment]
        ) -> dict[str, Any]:
            """List / search customers with pagination.
    
            Returns a paginated list of customers.
            """
            params: dict[str, Any] = {"page": page, "limit": limit}
            client = await get_client(ctx)
            try:
                return await client.get(_BASE, params=params)
            except StreamAPIError as exc:
                return _err(exc)
    
        @mcp.tool
        async def get_customer(
            customer_id: str,
            ctx: Context = None,  # type: ignore[assignment]
        ) -> dict[str, Any]:
            """Get a single customer record by ID."""
            client = await get_client(ctx)
            try:
                return await client.get(f"{_BASE}/{customer_id}")
            except StreamAPIError as exc:
                return _err(exc)
    
        @mcp.tool
        async def update_customer(
            customer_id: str,
            name: str | None = None,
            phone_number: str | None = None,
            email: str | None = None,
            external_id: str | None = None,
            iban: str | None = None,
            alias: str | None = None,
            comment: str | None = None,
            preferred_language: str | None = None,
            communication_methods: list[str] | None = None,
            ctx: Context = None,  # type: ignore[assignment]
        ) -> dict[str, Any]:
            """Update fields on an existing customer.
    
            Only the fields you provide will be changed; others remain untouched.
            """
            body = UpdateCustomerRequest(
                name=name, phone_number=phone_number, email=email,
                external_id=external_id, iban=iban, alias=alias,
                comment=comment, preferred_language=preferred_language,
                communication_methods=communication_methods,
            )
            client = await get_client(ctx)
            try:
                return await client.put(
                    f"{_BASE}/{customer_id}",
                    body.model_dump(exclude_none=True),
                )
            except StreamAPIError as exc:
                return _err(exc)
    
        @mcp.tool
        async def delete_customer(
            customer_id: str,
            ctx: Context = None,  # type: ignore[assignment]
        ) -> dict[str, Any]:
            """Soft-delete a customer by ID.
    
            The customer record is archived but not permanently removed.
            """
            client = await get_client(ctx)
            try:
                return await client.delete(f"{_BASE}/{customer_id}")
            except StreamAPIError as exc:
                return _err(exc)
  • The _err helper function that formats StreamAPIError exceptions into a consistent error response dict with error, code, message, and details fields.
    def _err(exc: StreamAPIError) -> dict[str, Any]:
        return {"error": True, "code": exc.status_code, "message": str(exc), "details": exc.body}
  • The get_client async function that retrieves a StreamClient for the current request, supporting both local mode (shared client from lifespan context) and remote mode (per-user client with caching).
    async def get_client(ctx: "Context") -> StreamClient:
        """Return a :class:`StreamClient` for the current request.
    
        Resolution order:
    
        1. **Lifespan client** — used in local / stdio mode where a single
           ``STREAM_API_KEY`` is set as an environment variable.
        2. **Per-user client** — used in remote mode where each user passes
           their own API key as a Bearer token and (optionally) a custom
           base URL via the ``X-Stream-Base-URL`` header.
        """
        # ── 1. Local mode: shared client from server lifespan ─────────────
        shared_client = ctx.lifespan_context.get("client")
        if shared_client is not None:
            return shared_client
    
        # ── 2. Remote mode: per-user client from Bearer token ─────────────
        api_key = current_api_key.get()
        if not api_key:
            raise StreamError(
                "No Stream API key found. "
                "In local mode, set the STREAM_API_KEY env var. "
                "In remote mode, pass your key as a Bearer token in the Authorization header."
            )
    
        base_url = current_base_url.get() or settings.stream_base_url
        cache_key = f"{api_key}::{base_url}"
    
        if cache_key not in _client_cache:
            client = StreamClient(
                api_key=api_key,
                base_url=base_url,
                timeout=settings.stream_timeout,
                max_retries=settings.stream_max_retries,
            )
            await client.__aenter__()
            _client_cache[cache_key] = client
            logger.info(
                "Created cached StreamClient for remote user (key=…%s, base=%s)",
                api_key[-4:], base_url,
            )
    
        return _client_cache[cache_key]
  • The register_all_tools function that imports all tool modules and calls their register() functions, including customers.register(mcp) which registers the delete_customer tool.
    def register_all_tools(mcp: FastMCP) -> None:
        """Import every tool / resource module and call its ``register(mcp)``."""
        from stream_mcp.tools import (
            coupons,
            customers,
            docs,
            invoices,
            payment_links,
            payments,
            products,
        )
    
        payment_links.register(mcp)
        customers.register(mcp)
        products.register(mcp)
        payments.register(mcp)
        coupons.register(mcp)
        invoices.register(mcp)
        docs.register(mcp)
Behavior4/5

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

With no annotations provided, the description carries full burden and effectively discloses key behavioral traits: it specifies 'soft-delete' and clarifies that the record is 'archived but not permanently removed'. This informs the agent about the non-destructive nature, though it lacks details on permissions, reversibility, or side effects.

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

Conciseness5/5

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

The description is front-loaded with the core action in the first sentence and adds clarifying detail in the second. Both sentences earn their place by defining the operation and its archival effect, with zero wasted words.

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

Completeness4/5

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

Given the tool's complexity (a mutation with no annotations) and the presence of an output schema (which handles return values), the description is reasonably complete. It covers the soft-delete behavior adequately, though it could benefit from mentioning permissions or error conditions.

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

Parameters4/5

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

Schema description coverage is 0% with 1 parameter, so the description must compensate. It adds meaning by explaining that 'customer_id' is used to identify the customer for soft-deletion, though it does not specify format or constraints. This provides essential context beyond the bare schema.

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

Purpose5/5

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

The description clearly states the specific action ('soft-delete') and target resource ('a customer by ID'), distinguishing it from siblings like 'update_customer' or 'get_customer'. It precisely defines the operation as archival rather than permanent removal.

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

Usage Guidelines3/5

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

The description implies usage for archiving customers but does not explicitly state when to use this tool versus alternatives like 'update_customer' for deactivation or other deletion methods. No guidance on prerequisites or exclusions is provided.

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/streampayments/stream'

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