Skip to main content
Glama

archive_product

Archive a product to prevent further sales while retaining its historical record for reference.

Instructions

Archive a product so it can no longer be sold.

This is a soft-delete; the product record is retained for history.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
product_idYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The archive_product tool handler decorated with @mcp.tool. It takes a product_id and Context, then makes a DELETE request to /api/v2/products/{product_id} via the StreamClient. Handles StreamAPIError exceptions using the _err helper.
    @mcp.tool
    async def archive_product(
        product_id: str,
        ctx: Context = None,  # type: ignore[assignment]
    ) -> dict[str, Any]:
        """Archive a product so it can no longer be sold.
    
        This is a soft-delete; the product record is retained for history.
        """
        client = await get_client(ctx)
        try:
            return await client.delete(f"{_BASE}/{product_id}")
        except StreamAPIError as exc:
            return _err(exc)
  • Error handler helper function _err that converts StreamAPIError into a standardized error dict with error flag, status code, message, and details.
    def _err(exc: StreamAPIError) -> dict[str, Any]:
        return {"error": True, "code": exc.status_code, "message": str(exc), "details": exc.body}
  • Registration call: products.register(mcp) is invoked in register_all_tools to register all product tools including archive_product.
    products.register(mcp)
  • The get_client helper function that retrieves a StreamClient for the current request, supporting both local (shared from lifespan) and remote (per-user from Bearer token) modes.
    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 function that contains all product tool definitions including archive_product. This function is called by register_all_tools to register all product tools on the FastMCP instance.
    def register(mcp: FastMCP) -> None:
        """Register all product tools on *mcp*."""
    
        @mcp.tool
        async def create_product(
            name: str,
            type: Literal["ONE_OFF", "RECURRING", "METERED"] = "ONE_OFF",
            price: float = 1.0,
            currency: str = "SAR",
            description: str | None = None,
            is_price_inclusive_of_vat: bool = True,
            is_price_exempt_from_vat: bool = False,
            recurring_interval: str | None = None,
            recurring_interval_count: int = 1,
            ctx: Context = None,  # type: ignore[assignment]
        ) -> dict[str, Any]:
            """Create a new product or service in Stream.
    
            *type* is ``ONE_OFF``, ``RECURRING``, or ``METERED``.
            For recurring products, specify *recurring_interval* (WEEK, MONTH, SEMESTER, YEAR).
            """
            prices = [ProductPriceInlineCreate(
                currency=currency,
                amount=price,
                is_price_inclusive_of_vat=is_price_inclusive_of_vat,
                is_price_exempt_from_vat=is_price_exempt_from_vat,
            )]
            body = CreateProductRequest(
                name=name,
                type=type,
                description=description,
                prices=prices,
                recurring_interval=recurring_interval,
                recurring_interval_count=recurring_interval_count,
            )
            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_products(
            page: int = 1,
            limit: int = 20,
            type: str | None = None,
            active: bool | None = None,
            currency: str | None = None,
            ctx: Context = None,  # type: ignore[assignment]
        ) -> dict[str, Any]:
            """List products with optional filters.
    
            *type* can be ``ONE_OFF``, ``RECURRING``, or ``METERED``.
            *active* filters by active/inactive status.
            """
            params: dict[str, Any] = {"page": page, "limit": limit}
            if type:
                params["type"] = type
            if active is not None:
                params["active"] = active
            if currency:
                params["currency"] = currency
            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_product(
            product_id: str,
            ctx: Context = None,  # type: ignore[assignment]
        ) -> dict[str, Any]:
            """Get a single product by ID."""
            client = await get_client(ctx)
            try:
                return await client.get(f"{_BASE}/{product_id}")
            except StreamAPIError as exc:
                return _err(exc)
    
        @mcp.tool
        async def update_product(
            product_id: str,
            name: str | None = None,
            description: str | None = None,
            is_active: bool | None = None,
            ctx: Context = None,  # type: ignore[assignment]
        ) -> dict[str, Any]:
            """Update an existing product's name, description, or active status.
    
            Only the fields you provide will be changed.
            """
            body = UpdateProductRequest(
                name=name, description=description, is_active=is_active,
            )
            client = await get_client(ctx)
            try:
                return await client.put(
                    f"{_BASE}/{product_id}",
                    body.model_dump(exclude_none=True),
                )
            except StreamAPIError as exc:
                return _err(exc)
    
        @mcp.tool
        async def archive_product(
            product_id: str,
            ctx: Context = None,  # type: ignore[assignment]
        ) -> dict[str, Any]:
            """Archive a product so it can no longer be sold.
    
            This is a soft-delete; the product record is retained for history.
            """
            client = await get_client(ctx)
            try:
                return await client.delete(f"{_BASE}/{product_id}")
            except StreamAPIError as exc:
                return _err(exc)
Behavior4/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively explains that this is a 'soft-delete' operation, retaining the product record for history, which clarifies the mutation's nature and permanence. However, it lacks details on permissions, side effects, or response format.

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 purpose in the first sentence, followed by a clarifying detail. Both sentences earn their place by adding value, with no wasted words, making it highly efficient and well-structured.

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), the description adequately covers the soft-delete behavior, but lacks details on permissions or error cases. The presence of an output schema reduces the need to explain return values, making it mostly complete for basic use.

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?

The schema has 0% description coverage for its single parameter 'product_id', but the description compensates by implicitly defining it as the product to archive. It adds meaning beyond the bare schema, though it could specify format or constraints. With one parameter, the baseline is high.

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 ('Archive a product') and resource ('product'), distinguishing it from siblings like 'delete_customer' (hard delete) or 'update_product' (modify). It precisely communicates the tool's function without being tautological.

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 when a product should be removed from sale but retained for history, but it does not explicitly state when to use this tool versus alternatives like 'delete_customer' (hard delete) or 'update_product' to modify status. No exclusions or prerequisites are mentioned.

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