Skip to main content
Glama
wso2

FHIR MCP Server

by wso2

update

Replace an existing FHIR resource's content entirely with new data to correct or complete records, using the resource's logical ID. Supports conditional updates and validation operations.

Instructions

Performs a FHIR update interaction by replacing an existing resource instance's content with the provided payload. Use it when you need to overwrite a resource's data in its entirety, such as correcting or completing a record, and you already know the resource's logical id. Optionally, you can include searchParam for conditional updates (e.g., only update if the resource matches certain criteria) or specify a custom operation (e.g., $validate to run validation before updating) The tool returns the updated resource or an OperationOutcome detailing any errors.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
typeYesThe FHIR resource type name. Must exactly match one of the resource types supported by the server.
idYesThe logical ID of a specific FHIR resource instance.
payloadYesThe complete JSON representation of the FHIR resource, containing all required elements and any optional data. Servers replace the existing resource with this exact content, so the payload must include all mandatory fields defined by the resource's profile and any previous data you wish to preserve.
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 'update' tool handler in the FHIR MCP server, which performs a FHIR PUT operation using the provided resource type, ID, and payload.
    async def update(
        type: Annotated[
            str,
            Field(
                description="The FHIR resource type name. Must exactly match one of the resource types supported by the server.",
                examples=["Location", "Organization", "Coverage"],
            ),
        ],
        id: Annotated[
            str,
            Field(description="The logical ID of a specific FHIR resource instance."),
        ],
        payload: Annotated[
            Dict[str, Any],
            Field(
                description=(
                    "The complete JSON representation of the FHIR resource, containing all required elements and any optional data. "
                    "Servers replace the existing resource with this exact content, so the payload must include all mandatory fields "
                    "defined by the resource's profile and any previous data you wish to preserve."
                )
            ),
        ],
        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=['{"patient":"Patient/54321","relationship":["father"]}'],
            ),
        ] = {},
        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=["$lastn"],
            ),
        ] = "",
    ) -> Annotated[
        Dict[str, Any],
        Field(description="A dictionary containing the updated FHIR resource"),
    ]:
        try:
            logger.debug(
                f"Invoked with type='{type}', id={id}, payload={payload}, searchParam={searchParam}, and operation={operation}"
            )
            if not type:
                logger.error(
                    "Unable to perform update operation: 'type' is a mandatory field."
                )
                return await get_operation_outcome_required_error("type")
    
            client: AsyncFHIRClient = await get_async_fhir_client()
            bundle: dict = await client.resource(resource_type=type, id=id).execute(
                operation=operation or "",
                method="PUT",
                data={**payload, "id": id},
                params=searchParam,
            )
            return await get_bundle_entries(bundle=bundle)
        except ValueError as ex:
            logger.exception(
                f"User does not have permission to perform FHIR '{type}' resource update operation. Caused by, ",
                exc_info=ex,
            )
            return await get_operation_outcome(
                code="forbidden",
                diagnostics=f"The user does not have the rights to perform update operation.",
            )
        except OperationOutcome as ex:
            logger.exception(
                f"FHIR server returned an OperationOutcome error while updating 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 update operation for resource: '{type}'. Caused by, ",
                exc_info=ex,
            )
        return await get_operation_outcome_exception()
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 destructive write operation ('replacing an existing resource instance's content'), mentions that the payload must include all required fields and any data to preserve, describes optional conditional updates and custom operations, and notes the return value includes either the updated resource or error details. It doesn't cover rate limits or authentication requirements, but provides substantial operational context.

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 appropriately sized at three sentences, front-loaded with the core purpose, followed by usage guidance, and ending with return value information. Every sentence adds value, though it could be slightly more concise by combining some concepts about optional parameters.

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 mutation tool with 5 parameters, no annotations, and no output schema, the description does well by explaining the destructive nature, parameter interactions, and return values. It covers the essential context needed to use the tool correctly, though could benefit from mentioning authentication or error handling specifics.

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?

With 100% schema description coverage, the baseline is 3. The description adds meaningful context beyond the schema by explaining the purpose of each parameter: 'type' identifies the FHIR resource, 'id' is the logical ID, 'payload' must contain complete resource data for replacement, 'searchParam' enables conditional updates, and 'operation' allows custom operations. This provides practical guidance on how parameters work together.

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 performs a FHIR 'update' interaction by replacing an existing resource's content with a provided payload. It specifies the verb ('replacing'), resource ('FHIR resource instance'), and distinguishes it from siblings by mentioning it's for overwriting entire resources when you know the logical ID, unlike create (new resources) or read/search (retrieval operations).

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

Usage Guidelines5/5

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

The description explicitly states when to use this tool ('when you need to overwrite a resource's data in its entirety, such as correcting or completing a record, and you already know the resource's logical id') and mentions conditional updates and custom operations as optional use cases. It distinguishes from siblings by implying this is for full replacements rather than partial updates or other operations.

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