Skip to main content
Glama
rkirkendall

Medplum MCP Server

by rkirkendall

searchEncounters

Search and filter healthcare encounters by patient ID, practitioner ID, or status on the Medplum MCP Server. Retrieve relevant encounter data efficiently for improved care coordination.

Instructions

Searches for encounters based on criteria like patient ID or status.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
patientIdNoThe patient ID to search encounters for. Optional.
practitionerIdNoThe practitioner ID to search encounters for. Optional.
statusNoThe encounter status to filter by. Optional.

Implementation Reference

  • The core handler function that executes the FHIR search for Encounter resources using Medplum's searchResources method, building query parameters from input arguments.
    export async function searchEncounters(searchArgs: EncounterSearchArgs): Promise<Encounter[]> {
      await ensureAuthenticated();
      
      const searchCriteria: string[] = [];
    
      if (searchArgs.patientId) {
        searchCriteria.push(`subject=Patient/${searchArgs.patientId}`);
      }
      if (searchArgs.practitionerId) {
        const practitionerRef = searchArgs.practitionerId.startsWith('Practitioner/') 
          ? searchArgs.practitionerId 
          : `Practitioner/${searchArgs.practitionerId}`;
        searchCriteria.push(`participant=${practitionerRef}`);
      }
      if (searchArgs.organizationId) {
        searchCriteria.push(`service-provider=Organization/${searchArgs.organizationId}`);
      }
      if (searchArgs.status) {
        searchCriteria.push(`status=${searchArgs.status}`);
      }
      if (searchArgs.classCode) {
        searchCriteria.push(`class=${searchArgs.classCode}`);
      }
      if (searchArgs.date) {
        searchCriteria.push(`date=${searchArgs.date}`);
      }
      if (searchArgs.identifier) {
        searchCriteria.push(`identifier=${searchArgs.identifier}`);
      }
      if (searchArgs._lastUpdated) {
        searchCriteria.push(`_lastUpdated=${searchArgs._lastUpdated}`);
      }
    
      if (searchCriteria.length === 0) {
        console.warn('Encounter search called with no specific criteria. This might return a large number of results or be inefficient.');
        return []; // Return empty array if no criteria are provided
      }
    
      const queryString = searchCriteria.join('&');
      return medplum.searchResources('Encounter', queryString);
    } 
  • MCP tool schema definition including input schema validation for the searchEncounters tool.
    {
      name: "searchEncounters",
      description: "Searches for encounters based on criteria like patient ID or status.",
      inputSchema: {
        type: "object",
        properties: {
          patientId: {
            type: "string",
            description: "The patient ID to search encounters for. Optional.",
          },
          status: {
            type: "string",
            description: "The encounter status to filter by. Optional.",
            enum: ["planned", "arrived", "triaged", "in-progress", "onleave", "finished", "cancelled"],
          },
          practitionerId: {
            type: "string",
            description: "The practitioner ID to search encounters for. Optional.",
          },
        },
        required: [],
      },
    },
  • src/index.ts:36-36 (registration)
    Import of the searchEncounters handler function from encounterUtils for registration in the MCP server.
    searchEncounters,
  • src/index.ts:967-967 (registration)
    Registration of searchEncounters in the toolMapping object used by the MCP CallToolRequest handler.
    searchEncounters,
  • Type definition for input arguments to the searchEncounters function.
    export interface EncounterSearchArgs {
      patientId?: string;
      subject?: string; // Added for FHIR-style search: Patient/123
      practitionerId?: string;
      participant?: string; // Added for FHIR-style search: Practitioner/456
      organizationId?: string;
      date?: string;
      status?: string;
      classCode?: string;
      typeCode?: string;
      typeSystem?: string; // Added for use with typeCode
      identifier?: string;
      _lastUpdated?: string; // Added for FHIR-style search
      // Add other common search parameters as needed
    }
Behavior2/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 states the tool searches based on criteria but doesn't cover key aspects like whether it's read-only, how results are returned (e.g., pagination, format), rate limits, or authentication needs. This leaves significant gaps for a search operation.

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, efficient sentence that directly states the tool's function without unnecessary words. It's front-loaded and appropriately sized, though it could be slightly more informative without losing conciseness.

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 (search with 3 optional parameters), no annotations, and no output schema, the description is incomplete. It covers the basic purpose but lacks details on behavior, output format, and usage context, making it adequate but with clear gaps for an agent to rely on.

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 patient ID or status, which aligns with some parameters, but the input schema has 100% coverage with detailed descriptions and an enum for status. Since the schema already documents all parameters well, the description adds minimal value beyond restating schema information, meeting the baseline score.

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 ('encounters'), and mentions criteria like patient ID or status. However, it doesn't explicitly differentiate from sibling tools like 'getEncounterById' or 'generalFhirSearch', which also retrieve encounter data, so it doesn't reach the highest score.

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. It doesn't mention sibling tools like 'getEncounterById' for single encounters or 'generalFhirSearch' for broader FHIR searches, nor does it specify prerequisites or exclusions, leaving the agent with minimal usage context.

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