Skip to main content
Glama
rkirkendall

Medplum MCP Server

by rkirkendall

searchMedicationRequests

Retrieve medication requests using criteria such as patient ID, medication reference, practitioner ID, or status within the Medplum MCP Server.

Instructions

Searches for medication requests based on criteria like patient ID or medication.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
medicationReferenceNoThe medication reference to filter by. Optional.
patientIdNoThe patient ID to search medication requests for. Optional.
practitionerIdNoThe practitioner ID to search medication requests for. Optional.
statusNoThe medication request status to filter by. Optional.

Implementation Reference

  • The core handler function that builds FHIR search parameters from input args and executes the search using medplum.searchResources.
    export async function searchMedicationRequests(args: SearchMedicationRequestsArgs): Promise<MedicationRequest[]> {
      await ensureAuthenticated();
      const searchCriteria: string[] = [];
    
      if (Object.keys(args).length === 0) {
        console.warn('MedicationRequest search called with no specific criteria. This might return a large number of results or be inefficient.');
      }
    
      if (args.patientId) {
        searchCriteria.push(`patient=Patient/${args.patientId}`);
      }
      if (args.status) {
        searchCriteria.push(`status=${args.status}`);
      }
      if (args.intent) {
        searchCriteria.push(`intent=${args.intent}`);
      }
      if (args.code) {
        searchCriteria.push(`code=${args.code}`);
      }
      if (args.authoredon) {
        searchCriteria.push(`authoredon=${args.authoredon}`);
      }
      if (args.requester) {
        searchCriteria.push(`requester=${args.requester}`);
      }
      if (args.identifier) {
        searchCriteria.push(`identifier=${args.identifier}`);
      }
      if (args._lastUpdated) {
        searchCriteria.push(`_lastUpdated=${args._lastUpdated}`);
      }
    
      if (searchCriteria.length === 0 && Object.keys(args).length > 0) {
        console.warn('MedicationRequest search arguments provided but did not map to any known search parameters:', args);
        return [];
      }
      
      // Only search if there are criteria or if no arguments were provided (search all)
      if (searchCriteria.length > 0 || Object.keys(args).length === 0) {
          const queryString = searchCriteria.join('&');
          return medplum.searchResources('MedicationRequest', queryString);
      } else {
          return []; // Should be caught by the warning above, but as a fallback
      }
    } 
  • TypeScript interface defining the input arguments for the searchMedicationRequests function.
    export interface SearchMedicationRequestsArgs {
      patientId?: string; // Searches for subject=Patient/[patientId]
      status?: MedicationRequest['status'];
      intent?: MedicationRequest['intent'];
      code?: string; // Searches by medicationCodeableConcept.coding.code
      codeSystem?: string; // System for the medication code
      authoredon?: string; // Date search for authoredOn, supports prefixes like eq, gt, le
      requester?: string; // FHIR style search param: Practitioner/XYZ or Organization/XYZ
      identifier?: string; // Search by identifier value (e.g. value or system|value)
      _lastUpdated?: string;
      // Add other common search parameters
    }
  • src/index.ts:627-653 (registration)
    MCP tool registration in the mcpTools array, including name, description, and inputSchema.
    {
      name: "searchMedicationRequests",
      description: "Searches for medication requests based on criteria like patient ID or medication.",
      inputSchema: {
        type: "object",
        properties: {
          patientId: {
            type: "string",
            description: "The patient ID to search medication requests for. Optional.",
          },
          medicationReference: {
            type: "string",
            description: "The medication reference to filter by. Optional.",
          },
          practitionerId: {
            type: "string",
            description: "The practitioner ID to search medication requests for. Optional.",
          },
          status: {
            type: "string",
            description: "The medication request status to filter by. Optional.",
            enum: ["active", "on-hold", "cancelled", "completed", "entered-in-error", "stopped", "draft", "unknown"],
          },
        },
        required: [],
      },
    },
  • src/index.ts:950-988 (registration)
    Mapping of tool name to handler function for execution in the MCP server.
    const toolMapping: Record<string, (...args: any[]) => Promise<any>> = {
      createPatient,
      getPatientById, 
      updatePatient,
      searchPatients,
      searchPractitionersByName,
      createPractitioner,
      getPractitionerById,
      updatePractitioner,
      searchPractitioners,
      createOrganization,
      getOrganizationById,
      updateOrganization,
      searchOrganizations,
      createEncounter,
      getEncounterById,
      updateEncounter,
      searchEncounters,
      createObservation,
      getObservationById,
      updateObservation,
      searchObservations,
      createMedicationRequest,
      getMedicationRequestById,
      updateMedicationRequest,
      searchMedicationRequests,
      createMedication,
      getMedicationById,
      searchMedications,
      createEpisodeOfCare,
      getEpisodeOfCareById,
      updateEpisodeOfCare,
      searchEpisodesOfCare,
      createCondition,
      getConditionById,
      updateCondition,
      searchConditions,
      generalFhirSearch,
    };
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' but doesn't clarify if it's read-only, what permissions are needed, how results are returned (e.g., pagination, format), or any rate limits. For a search tool with zero annotation coverage, this leaves significant gaps in understanding its behavior.

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 front-loads the core purpose without unnecessary details. It's appropriately sized for a search tool, though it could be slightly more structured by explicitly listing all criteria or usage scenarios.

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 complexity of a search tool with 4 parameters, no annotations, and no output schema, the description is incomplete. It lacks behavioral context (e.g., how results are handled), doesn't explain the relationship with sibling tools, and provides minimal guidance on parameter use. For a tool in this context, more comprehensive information is needed.

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 input schema has 100% description coverage, so parameters are well-documented there. The description mentions 'criteria like patient ID or medication,' which loosely maps to 'patientId' and 'medicationReference' but doesn't add meaningful semantics beyond what the schema provides. Since schema coverage is high, the 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: 'Searches for medication requests based on criteria like patient ID or medication.' It specifies the verb ('searches'), resource ('medication requests'), and key criteria, making the intent unambiguous. However, it doesn't explicitly differentiate from sibling tools like 'searchMedications' or 'getMedicationRequestById', which would be needed for a perfect 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 mentions criteria like patient ID or medication but doesn't compare it to siblings such as 'generalFhirSearch' (for broader searches) or 'getMedicationRequestById' (for specific IDs). Without this context, an agent might struggle 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