Skip to main content
Glama
rkirkendall

Medplum MCP Server

by rkirkendall

searchPatients

Search for patients in the Medplum MCP Server by criteria such as name, birth date, or gender to efficiently manage healthcare data and streamline patient retrieval.

Instructions

Searches for patients based on criteria like name or birth date.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
birthdateNoThe patient's birth date in YYYY-MM-DD format.
familyNoThe patient's family (last) name.
genderNoThe patient's gender.
givenNoThe patient's given (first) name.

Implementation Reference

  • Core handler function for the 'searchPatients' tool. Builds FHIR search parameters from input args and performs the search using Medplum's searchResources method on Patient resources.
    export async function searchPatients(args: PatientSearchArgs): Promise<Patient[]> {
      await ensureAuthenticated();
      const searchCriteria: string[] = [];
    
      if (args.firstName) searchCriteria.push(`given:contains=${args.firstName}`);
      if (args.lastName) searchCriteria.push(`family:contains=${args.lastName}`);
      if (args.givenName) searchCriteria.push(`given:contains=${args.givenName}`);
      if (args.familyName) searchCriteria.push(`family:contains=${args.familyName}`);
      if (args.birthDate) searchCriteria.push(`birthdate=${args.birthDate}`);
      if (args.mrn) searchCriteria.push(`identifier=${args.mrn}`); // Assumes MRN is a primary identifier
      if (args.email) searchCriteria.push(`email=${args.email}`);
      if (args.telecom) searchCriteria.push(`telecom=${args.telecom}`);
      if (args.identifier) searchCriteria.push(`identifier=${args.identifier}`);
      if (args._lastUpdated) searchCriteria.push(`_lastUpdated=${args._lastUpdated}`);
    
      // Handle additional test fields
      if (args.family) searchCriteria.push(`family:contains=${args.family}`);
      if (args.given) searchCriteria.push(`given:contains=${args.given}`);
      if (args.birthdate) searchCriteria.push(`birthdate=${args.birthdate}`);
    
      if (searchCriteria.length === 0) {
        // Consider if this should throw an error, return all, or return empty.
        // Returning empty for now if no specific criteria are provided.
        return [];
      }
    
      const queryString = searchCriteria.join('&');
      return medplum.searchResources('Patient', queryString);
    }
  • TypeScript interface defining the input parameters accepted by the searchPatients handler function.
    export interface PatientSearchArgs {
      firstName?: string;
      lastName?: string;
      birthDate?: string;
      mrn?: string;
      email?: string;
      telecom?: string;
      familyName?: string; // Added for more specific name search
      givenName?: string;  // Added for more specific name search
      identifier?: string; // General identifier search (e.g. system|value or just value)
      _lastUpdated?: string;
      // Add fields that tests expect
      family?: string;
      given?: string;
      birthdate?: string; // Alternative spelling used in tests
    }
  • MCP protocol input schema definition for the searchPatients tool, including properties for given name, family name, birthdate, and gender.
    {
      name: "searchPatients",
      description: "Searches for patients based on criteria like name or birth date.",
      inputSchema: {
        type: "object",
        properties: {
          given: {
            type: "string",
            description: "The patient's given (first) name.",
          },
          family: {
            type: "string", 
            description: "The patient's family (last) name.",
          },
          birthdate: {
            type: "string",
            description: "The patient's birth date in YYYY-MM-DD format.",
          },
          gender: {
            type: "string",
            description: "The patient's gender.",
            enum: ["male", "female", "other", "unknown"],
          },
        },
        required: [],
      },
    },
  • src/index.ts:27-31 (registration)
    Import of the searchPatients handler function into the main index file for tool registration.
      createPatient,
      getPatientById,
      updatePatient,
      searchPatients,
    } from './tools/patientUtils.js';
  • src/index.ts:954-954 (registration)
    Registration of the 'searchPatients' tool name mapped to its handler function in the toolMapping object used by the MCP server.
    searchPatients,
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool searches based on criteria but doesn't explain key behaviors like whether it returns partial matches, supports pagination, requires authentication, or has rate limits. For a search tool with no annotations, this leaves significant gaps in understanding how it operates.

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 a single, clear sentence that efficiently conveys the core purpose without unnecessary details. It's front-loaded and wastes no words, though it could be slightly more informative to improve completeness without sacrificing conciseness.

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

Completeness2/5

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

Given the lack of annotations and output schema, the description is incomplete for a search tool. It doesn't explain the return format, error handling, or how multiple criteria interact (e.g., AND/OR logic). For a tool with 4 parameters and no structured behavioral hints, more context is needed to guide effective usage.

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?

The description mentions criteria like 'name or birth date', which loosely maps to parameters such as 'given', 'family', and 'birthdate'. However, with 100% schema description coverage, the schema already fully documents all 4 parameters, including their types and the 'gender' enum. The description adds minimal value beyond what's in the schema, so a baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/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 with a specific verb ('Searches') and resource ('patients'), and mentions criteria like name or birth date. However, it doesn't explicitly distinguish this from sibling tools like 'searchPractitionersByName' or 'generalFhirSearch', which might also search for patients or other resources, leaving some ambiguity about its unique role.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. For example, it doesn't mention when to choose 'searchPatients' over 'getPatientById' for retrieving patient data, or how it differs from 'generalFhirSearch' in the context of FHIR searches. This lack of context makes it harder for an agent to select the right tool.

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

Related 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/rkirkendall/medplum-mcp'

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