Skip to main content
Glama
wso2

FHIR MCP Server

by wso2

read

Retrieve a specific FHIR healthcare resource by its type and unique ID, with optional search parameters or custom operations to refine the response.

Instructions

Performs a FHIR read interaction to retrieve a single resource instance by its type and resource ID, optionally refining the response with search parameters or custom operations. Use it when you know the exact resource ID and require that one resource; do not use it for bulk queries. If additional query-level parameters or operations are needed (e.g., _elements or $validate), include them in searchParam or operation.

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.
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 resource must match one of the operation names returned by `get_capabilities`.

Implementation Reference

  • The `read` function is the handler for the 'read' MCP tool. It takes resource type and ID, and performs a FHIR GET request using an AsyncFHIRClient.
    async def read(
        type: Annotated[
            str,
            Field(
                description="The FHIR resource type name. Must exactly match one of the resource types supported by the server.",
                examples=["DiagnosticReport", "AllergyIntolerance", "Immunization"],
            ),
        ],
        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=['{"device-name": "glucometer", "identifier": ["12345"]}'],
            ),
        ] = {},
        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=["$everything"],
            ),
        ] = "",
    ) -> Annotated[
        Dict[str, Any],
        Field(
            description="A dictionary containing the single FHIR resource instance of the requested type and id."
        ),
    ]:
        try:
            logger.debug(
                f"Invoked with type='{type}', id={id}, searchParam={searchParam}, and operation={operation}"
            )
            if not type:
                logger.error(
                    "Unable to perform read 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="GET", params=searchParam
            )
    
            return await get_bundle_entries(bundle=bundle)
        except ResourceNotFound as ex:
            logger.error(
                f"Resource of type '{type}' with id '{id}' not found. Caused by, ",
                exc_info=ex,
            )
            return await get_operation_outcome(
                code="not-found",
                diagnostics=f"The resource of type '{type}' with id '{id}' was not found.",
            )
        except ValueError as ex:
            logger.exception(
                f"User does not have permission to perform FHIR '{type}' resource read operation. Caused by, ",
                exc_info=ex,
            )
            return await get_operation_outcome(
                code="forbidden",
                diagnostics=f"The user does not have the rights to perform read operation.",
            )
        except OperationOutcome as ex:
            logger.exception(
                f"FHIR server returned an OperationOutcome error while reading 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 read operation for resource: '{type}'. Caused by, ",
                exc_info=ex,
            )
        return await get_operation_outcome_exception()
Behavior3/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 explains the tool's purpose and constraints (single resource retrieval, not for bulk queries) but lacks details on error handling, rate limits, authentication requirements, or response format. It does mention that search parameters must match those from 'get_capabilities', adding some context, but overall behavioral traits are minimally covered.

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 efficiently structured in two sentences: the first states the purpose and scope, and the second provides usage guidelines and parameter context. It's front-loaded with key information and avoids redundancy, though it could be slightly more concise by integrating the parameter details more seamlessly.

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?

Given the tool's moderate complexity (4 parameters, nested objects, no output schema, and no annotations), the description is adequate but has gaps. It covers purpose and usage well but lacks details on behavioral aspects like error handling or response format. Without annotations or an output schema, the description doesn't fully compensate for these missing elements, leaving some context incomplete.

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 marginal value by explaining that search parameters 'refine the response' and operations are 'custom FHIR operations', but it doesn't provide additional syntax or format details beyond what the schema specifies. This meets the baseline for 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 tool performs a FHIR 'read' interaction to retrieve a single resource instance by type and ID, distinguishing it from bulk query tools like 'search' and other CRUD operations like 'create', 'update', and 'delete'. It specifies the exact verb ('retrieve'), resource ('single resource instance'), and scope ('by its type and resource ID').

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 provides explicit guidance on when to use this tool ('when you know the exact resource ID and require that one resource') and when not to use it ('do not use it for bulk queries'). It also mentions alternatives implicitly by contrasting with bulk queries, though it doesn't name specific sibling tools like 'search' directly. The inclusion of 'If additional query-level parameters or operations are needed...' further clarifies usage scenarios.

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