Skip to main content
Glama
wso2

FHIR MCP Server

by wso2

delete

Remove a specific FHIR resource instance by its ID or conditionally delete resources matching search criteria. Supports custom FHIR operations like $expunge for targeted deletion operations.

Instructions

Execute a FHIR delete interaction on a specific resource instance. Use this tool when you need to remove a single resource identified by its logical ID or optionally filtered by search parameters. The optional id parameter must match an existing resource instance when present. If you include searchParam, the server will perform a conditional delete, deleting the resource only if it matches the given criteria. If you supply operation, it will execute the named FHIR operation (e.g., $expunge) on the resource. This tool returns a FHIR OperationOutcome describing success or failure of the deletion.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
typeYesThe FHIR resource type name. Must exactly match one of the resource types supported by the server.
idNoThe logical ID of a specific FHIR resource instance.
searchParamNoA mapping of FHIR search parameter names to their desired values. These parameters refine queries for operation-specific query qualifiers. Only parameters exposed by `get_capabilities` for that resource type are valid.
operationNoThe name of a custom FHIR operation or extended query defined for the resourceMust match one of the operation names returned by `get_capabilities`.

Implementation Reference

  • The `delete` function is the handler that implements the FHIR delete interaction for the MCP server. It validates the input type, ID/search parameters, executes the deletion using an asynchronous FHIR client, and returns an OperationOutcome or resource bundle.
    async def delete(
        type: Annotated[
            str,
            Field(
                description="The FHIR resource type name. Must exactly match one of the resource types supported by the server.",
                examples=["ServiceRequest", "Appointment", "HealthcareService"],
            ),
        ],
        id: Annotated[
            str,
            Field(description="The logical ID of a specific FHIR resource instance."),
        ] = "",
        searchParam: Annotated[
            Dict[str, str | List[str]],
            Field(
                description=(
                    "A mapping of FHIR search parameter names to their desired values. "
                    "These parameters refine queries for operation-specific query qualifiers. "
                    "Only parameters exposed by `get_capabilities` for that resource type are valid. "
                ),
                examples=['{"category": "laboratory", "status": ["active"]}'],
            ),
        ] = {},
        operation: Annotated[
            str,
            Field(
                description=(
                    "The name of a custom FHIR operation or extended query defined for the resource"
                    "Must match one of the operation names returned by `get_capabilities`."
                ),
                examples=["$expand"],
            ),
        ] = "",
    ) -> Annotated[
        Dict[str, Any],
        Field(
            description="A dictionary containing the confirmation of deletion or details on why deletion failed."
        ),
    ]:
        try:
            logger.debug(
                f"Invoked with type='{type}', id={id}, searchParam={searchParam}, and operation={operation}"
            )
            if not type:
                logger.error(
                    "Unable to perform delete operation: 'type' is a mandatory field."
                )
                return await get_operation_outcome_required_error("type")
            if not id and not searchParam:
                logger.error(
                    "Unable to perform delete operation: 'id' or 'searchParam' is required."
                )
                return await get_operation_outcome_required_error("id")
    
            client: AsyncFHIRClient = await get_async_fhir_client()
            bundle = await client.resource(resource_type=type, id=id).execute(
                operation=operation or "", method="DELETE", params=searchParam
            )
            if isinstance(bundle, Dict):
                return await get_bundle_entries(bundle=bundle)
            return await get_operation_outcome(
                severity="information",
                code="SUCCESSFUL_DELETE",
                diagnostics="Successfully deleted resource(s).",
            )
        except ValueError as ex:
            logger.exception(
                f"User does not have permission to perform FHIR '{type}' resource delete operation. Caused by, ",
                exc_info=ex,
            )
            return await get_operation_outcome(
                code="forbidden",
                diagnostics=f"The user does not have the rights to perform delete operation.",
            )
        except OperationOutcome as ex:
            logger.exception(
                f"FHIR server returned an OperationOutcome error while deleting the resource: '{type}', Caused by,",
                exc_info=ex,
            )
            return ex.resource["issue"] or await get_operation_outcome_exception()
        except Exception as ex:
            logger.exception(
                f"An unexpected error occurred during the FHIR delete operation for resource: '{type}'. Caused by, ",
                exc_info=ex,
            )
        return await get_operation_outcome_exception()
  • The `delete` tool is registered using the `@mcp.tool` decorator, which defines its documentation and metadata for the MCP server.
    @mcp.tool(
        description=(
            "Execute a FHIR `delete` interaction on a specific resource instance. "
            "Use this tool when you need to remove a single resource identified by its logical ID or optionally filtered by search parameters. "
            "The optional `id` parameter must match an existing resource instance when present. "
            "If you include `searchParam`, the server will perform a conditional delete, deleting the resource only if it matches the given criteria. "
            "If you supply `operation`, it will execute the named FHIR operation (e.g., `$expunge`) on the resource. "
            "This tool returns a FHIR `OperationOutcome` describing success or failure of the deletion."
        )
    )
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 does well. It discloses that this is a destructive operation ('remove a single resource'), explains conditional behavior ('deleting the resource only if it matches the given criteria'), mentions server validation ('must match an existing resource instance'), and describes the return type ('FHIR OperationOutcome'). It doesn't cover rate limits or authentication needs.

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 appropriately sized and front-loaded. The first sentence states the core purpose, followed by specific usage scenarios and parameter interactions. Every sentence adds value with no wasted words, and the structure logically progresses from general to specific details.

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?

For a complex destructive operation with 4 parameters, no annotations, and no output schema, the description does well. It explains the tool's behavior, parameter interactions, and return type. However, it doesn't mention prerequisites like authentication or potential side effects, which would be helpful given the destructive nature.

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?

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds some semantic context by explaining how parameters interact (e.g., 'If you include searchParam, the server will perform a conditional delete'), but doesn't provide significant additional meaning beyond what's in the schema descriptions.

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 tool's purpose: 'Execute a FHIR `delete` interaction on a specific resource instance.' It specifies the verb ('delete'), resource ('FHIR resource'), and distinguishes from siblings like 'create', 'read', 'update', and 'search' by focusing on removal operations.

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool: 'when you need to remove a single resource identified by its logical ID or optionally filtered by search parameters.' It explains conditional deletion and operation execution scenarios. However, it doesn't explicitly state when not to use it or name alternatives among siblings.

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/wso2/fhir-mcp-server'

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