Skip to main content
Glama
maheshbalan

FHIR MCP Server

by maheshbalan

get_loinc_codes

Find clinically relevant LOINC codes for an observation by name, returning only active codes sorted by popularity to support FHIR data interoperability.

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?

No annotations exist, so the description must reveal behavior. It discloses automatic STATUS='ACTIVE' filtering, COMMON_TEST_RANK sorting, popularity ordering, error key behavior, and authentication failure handling. This is rich and transparent.

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 lengthy and contains some redundancy (e.g., 'Don't automatically pick the first' appears in both Strategy and Rules). However, it is structured with headings and front-loaded with the core purpose. The length is mostly justified by the tool's complexity, but minor trimming would improve clarity.

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?

For a tool with no annotations and a multi-step usage pattern, the description covers purpose, behavior, error handling, parameter adjustment, and agent decision-making. It even discusses how to interpret results and select codes, making it complete for the intended use.

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 only names and defaults; the description adds meaning via an Args section: component_name example, max_codes as 'maximum number to return', max_fetch as 'maximum number to fetch from API'. It also explains how parameters interact (increase max_fetch progressively), fully compensating for 0% 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 opens with a clear, specific statement: 'Get the most relevant LOINC codes for a given observation name.' This identifies the verb, resource, and purpose. It further elaborates on automatic filtering and sorting, distinguishing it from sibling FHIR resource tools.

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?

Provides extensive guidance: a step-by-step strategy for selecting codes, handling errors, adjusting parameters, and when to suggest using the agent's own knowledge. It explicitly states when to stop (authentication errors) and suggests alternatives, exceeding the minimum for usage guidance.

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

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