Skip to main content
Glama
the-momentum

FHIR MCP Server

by the-momentum

get_loinc_codes

Find LOINC codes for a clinical observation name, with active codes sorted by popularity to help identify relevant matches.

Instructions

Get the most relevant LOINC codes for a given observation name.

The function automatically:

  • Filters for STATUS="ACTIVE" codes only

  • Sorts by COMMON_TEST_RANK (lower rank = more commonly used)

  • Returns codes in popularity order (most common first)

Your job is to:

  1. Analyze returned codes for semantic relevance to the search query

  2. Balance clinical popularity with semantic matching

  3. Select codes that best match the intended observation

Strategy:

  1. Start with default parameters (max_codes=5, max_fetch=50)

  2. Check if result contains "Error" key in first element

  3. If "Authentication failed" or "Authorization" error:

    • STOP using this tool immediately.

    • Do not retry with different parameters.

    • Report the authentication error to the user.

    • Suggest they check their LOINC API credentials.

    • Ask the user if they want to use your knowledge to find a LOINC code and wait for the confirmation. Add warning that this may cause wrong results.

  4. If "No active LOINC codes found in current fetch":

    • Increase max_fetch progressively (50→100→200→RecordsFound).

    • Keep trying until max_fetch >= RecordsFound or you find active codes.

  5. If "No LOINC codes found": Try alternative search terms or report failure.

  6. If you get codes but they don't semantically match your query:

    • Increase max_codes to see more options.

    • Look for better matches in COMPONENT, SHORTNAME, LONG_COMMON_NAME fields.

Rules:

  • Function returns codes sorted by popularity - YOU decide which are most relevant.

  • Don't automatically pick the first (most common) codes.

  • Prioritize semantic relevance: exact matches in COMPONENT > SHORTNAME > partial matches.

  • Balance popularity with relevance (very rare codes might not be clinically useful).

  • Keep increasing max_fetch until you exhaust all available records (max_fetch >= RecordsFound).

  • Increase max_codes only when you need more options to find better semantic matches.

Args: component_name: The name of the observation to get the LOINC code for (i.e. "glucose"). max_codes: The maximum number of LOINC codes to return. max_fetch: The maximum number of LOINC codes to fetch from the API. Returns: LOINC codes sorted by popularity - you must select the most semantically relevant ones.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
max_codesNo
max_fetchNo
component_nameYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden. It discloses automatic behaviors (STATUS='ACTIVE' filter, COMMON_TEST_RANK sorting, popularity order) and error states ('Error' key, authentication failures, no active codes). This is exemplary transparency.

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 longer than average but well-structured with headings, bullet points, and numbered strategies. It front-loads the core purpose and automatic behaviors, then details a decision process. Some content (e.g., 'Your job is to...') is more agent instruction than tool description, but it remains organized and purposeful.

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

Completeness5/5

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

Given the output schema exists, the description does not need to explain return types. It covers all parameters, error handling, semantic selection strategy, and the balance between popularity and relevance. This makes it complete for a complex lookup tool with ambiguous result sets.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has zero parameter descriptions (0% coverage), so the description must compensate. It includes an 'Args' section defining all three parameters, including the distinction between max_codes and max_fetch, and the strategy section explains exactly how to tune them. This fully compensates for the missing schema documentation.

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 opens with a specific verb+resource: 'Get the most relevant LOINC codes for a given observation name.' This clearly distinguishes it from sibling tools that request FHIR resources (e.g., request_patient_resource) by focusing on terminology lookup.

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 'Strategy' section provides explicit guidance on when to adjust max_fetch and max_codes, and when to stop on authentication errors. It gives clear context for use, though it does not explicitly name alternative tools or exclusion scenarios. Still, it offers more usage direction than most tool descriptions.

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

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