Skip to main content
Glama
wso2

FHIR MCP Server

by wso2

create

Add new healthcare data to a FHIR server by submitting a complete JSON resource. Specify the resource type and payload to create records like Patient or Observation entries.

Instructions

Executes a FHIR create interaction to persist a new resource of the specified type. It is required to supply the full resource payload in JSON form. Use this tool when you need to add new data (e.g., a new Patient or Observation). Note that servers may reject resources that violate profiles or mandatory bindings.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
typeYesThe FHIR resource type name. Must exactly match one of the resource types supported by the server.
payloadYesA JSON object representing the full FHIR resource body to be created. It must include all required elements of the resource's profile.
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 'create' tool handler function that executes a FHIR create interaction.
    @mcp.tool(
        description=(
            "Executes a FHIR `create` interaction to persist a new resource of the specified type. "
            "It is required to supply the full resource payload in JSON form. "
            "Use this tool when you need to add new data (e.g., a new Patient or Observation). "
            "Note that servers may reject resources that violate profiles or mandatory bindings."
        )
    )
    async def create(
        type: Annotated[
            str,
            Field(
                description="The FHIR resource type name. Must exactly match one of the resource types supported by the server.",
                examples=["Device", "CarePlan", "Goal"],
            ),
        ],
        payload: Annotated[
            Dict[str, Any],
            Field(
                description=(
                    "A JSON object representing the full FHIR resource body to be created. "
                    "It must include all required elements of the resource's profile."
                )
            ),
        ],
        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=['{"address-city": "Boston", "address-state": ["NY"]}'],
            ),
        ] = {},
        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=["$evaluate"],
            ),
        ] = "",
    ) -> Annotated[
        Dict[str, Any],
        Field(
            description=(
                "A dictionary containing the newly created FHIR resource, including server-assigned fields "
                "(id, meta.versionId, meta.lastUpdated, and any server-added extensions). Reflects exactly what was persisted."
            )
        ),
    ]:
        try:
            logger.debug(
                f"Invoked with type='{type}', payload={payload}, searchParam={searchParam}, and operation={operation}"
            )
            if not type:
                logger.error(
                    "Unable to perform create 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).execute(
                operation=operation or "", data=payload, 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 create operation. Caused by, ",
                exc_info=ex,
            )
            return await get_operation_outcome(
                code="forbidden",
                diagnostics=f"The user does not have the rights to perform create operation.",
            )
        except OperationOutcome as ex:
            logger.exception(
                f"FHIR server returned an OperationOutcome error while creating 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 create 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 and does well by disclosing key behavioral traits: it specifies that servers may reject resources for profile violations or mandatory binding issues, which is crucial for a write operation. However, it doesn't mention other potential behaviors like rate limits, authentication needs, or response formats.

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 and front-loaded, with the first sentence stating the core purpose. The second sentence adds required input details, and the third provides usage context and behavioral notes. Every sentence earns its place, though it could be slightly more streamlined.

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

Completeness3/5

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

For a mutation tool with 4 parameters, no annotations, and no output schema, the description is adequate but has gaps. It covers the purpose and some behavioral aspects (server rejections), but lacks details on prerequisites, error handling, or return values. Given the complexity, it should do more to compensate for missing structured data.

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 minimal value beyond the schema by mentioning 'full resource payload in JSON form' and 'specified type,' but it doesn't provide additional semantic context or usage examples for parameters. Baseline 3 is appropriate given high schema coverage.

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 ('Executes a FHIR `create` interaction'), the resource involved ('new resource of the specified type'), and distinguishes it from siblings by specifying it's for adding new data rather than reading, updating, or deleting. The examples (Patient, Observation) further clarify the purpose.

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 add new data'), but it doesn't explicitly mention when not to use it or name specific alternatives among the sibling tools (e.g., use 'update' for existing resources, 'read' for retrieval). The guidance is helpful but lacks sibling differentiation.

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