Skip to main content
Glama
wso2

FHIR MCP Server

by wso2

search

Query FHIR healthcare data by resource type and search parameters to find matching clinical records in a standardized format.

Instructions

Executes a standard FHIR search interaction on a given resource type, returning a bundle or list of matching resources. Use this when you need to query for multiple resources based on one or more search-parameters. Do not use this tool for create, update, or delete operations, and be aware that large result sets may be paginated by the FHIR server.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
typeYesThe FHIR resource type name. Must exactly match one of the resource types supported by the server
searchParamYesA mapping of FHIR search parameter names to their values. Only include parameters supported for the resource type, as listed by `get_capabilities`.

Implementation Reference

  • The `search` tool handler function, which takes a resource `type` and `searchParam` dictionary, and uses `fhirpy` to execute the FHIR search interaction.
    async def search(
        type: Annotated[
            str,
            Field(
                description="The FHIR resource type name. Must exactly match one of the resource types supported by the server",
                examples=["MedicationRequest", "Condition", "Procedure"],
            ),
        ],
        searchParam: Annotated[
            Dict[str, str | List[str]],
            Field(
                description=(
                    "A mapping of FHIR search parameter names to their values. "
                    "Only include parameters supported for the resource type, as listed by `get_capabilities`."
                ),
                examples=[
                    '{"family": "Smith"}',
                    '{"date": ["ge1970-01-01", "lt2000-01-01"]}',
                ],
            ),
        ],
    ) -> Annotated[
        list[Dict[str, Any]] | Dict[str, Any],
        Field(
            description="A dictionary containing the full FHIR resource instance matching the search criteria."
        ),
    ]:
        try:
            logger.debug(f"Invoked with type='{type}' and searchParam={searchParam}")
            if not type:
                logger.error(
                    "Unable to perform search operation: 'type' is a mandatory field."
                )
                return await get_operation_outcome_required_error("type")
    
            client: AsyncFHIRClient = await get_async_fhir_client()
            async_resources: list[Any] = (
                await client.resources(type).search(Raw(**searchParam)).fetch_raw()
            )
            logger.debug("Async resources fetched:", async_resources) 
            return async_resources
        except ValueError as ex:
            logger.exception(
                f"User does not have permission to perform FHIR '{type}' resource search operation. Caused by, ",
                exc_info=ex,
            )
            return await get_operation_outcome(
                code="forbidden",
                diagnostics=f"The user does not have the rights to perform search operation.",
            )
        except OperationOutcome as ex:
            logger.exception(
                f"FHIR server returned an OperationOutcome error while searching 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 search 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 describes key behaviors: it's a read-only operation (implied by 'search' and contrast with create/update/delete), may return paginated results for large datasets, and returns a bundle or list. However, it doesn't specify authentication requirements, rate limits, or error handling, leaving some gaps for a tool with no annotation support.

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 usage guidelines and behavioral notes in subsequent sentences. Each sentence adds clear value: defining the tool, specifying when to use it, warning against misuse, and noting pagination behavior. There is no redundant or wasted text.

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 no annotations and no output schema, the description does well to cover purpose, usage, and key behaviors like pagination. However, it lacks details on return values (bundle/list structure), error cases, or server-specific constraints, which would be helpful for a search tool with complex parameters. It's mostly complete but has minor gaps in output and error context.

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 fully documents the two parameters (type and searchParam). The description adds minimal semantic value beyond the schema—it mentions 'resource type' and 'search-parameters' but doesn't provide additional context like format examples or constraints not in the schema. 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's purpose: 'Executes a standard FHIR `search` interaction on a given resource type, returning a bundle or list of matching resources.' It specifies the verb ('search'), resource type ('FHIR resource'), and distinguishes it from siblings like create, update, delete, and read by explicitly mentioning it's for querying multiple resources based on search parameters.

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 need to query for multiple resources based on one or more search-parameters') and when not to use it ('Do not use this tool for create, update, or delete operations'). It also implies an alternative for single-resource retrieval (likely 'read') by contrasting with querying multiple resources, though it doesn't name specific siblings like 'read' directly.

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