Skip to main content
Glama
rkirkendall

Medplum MCP Server

by rkirkendall

createMedicationRequest

Generate medication requests (prescriptions) by specifying patient ID, medication reference, prescriber, status, and intent using the Medplum MCP Server.

Instructions

Creates a new medication request (prescription). Requires patient ID, medication reference, and prescriber.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
intentYesThe intent of the medication request.
medicationReferenceYesReference to the medication being prescribed.
patientIdYesThe ID of the patient this prescription is for.
practitionerIdYesThe ID of the practitioner prescribing the medication.
statusYesThe status of the medication request.

Implementation Reference

  • The async handler function that validates input, constructs a FHIR MedicationRequest resource, and creates it via the Medplum client.
    export async function createMedicationRequest(args: CreateMedicationRequestArgs): Promise<MedicationRequest> {
      await ensureAuthenticated();
    
      if (!args.status) {
        throw new Error('MedicationRequest status is required.');
      }
      if (!args.intent) {
        throw new Error('MedicationRequest intent is required.');
      }
      if (!args.medicationCodeableConcept) { // Add || !args.medicationReference if that's supported
        throw new Error('Medication (medicationCodeableConcept or medicationReference) is required.');
      }
      if (!args.subjectId) {
        throw new Error('Subject (Patient ID) is required to create a MedicationRequest.');
      }
    
      const medicationRequestResource: MedicationRequest = {
        resourceType: 'MedicationRequest',
        status: args.status,
        intent: args.intent,
        medicationCodeableConcept: args.medicationCodeableConcept,
        // medicationReference: args.medicationReference,
        subject: { reference: `Patient/${args.subjectId}` },
        authoredOn: args.authoredOn || new Date().toISOString(),
        dosageInstruction: args.dosageInstruction,
      };
    
      if (args.encounterId) {
        medicationRequestResource.encounter = { reference: `Encounter/${args.encounterId}` };
      }
      if (args.requesterId) {
        medicationRequestResource.requester = { reference: `Practitioner/${args.requesterId}` };
      }
      if (args.note) {
        medicationRequestResource.note = [{ text: args.note }];
      }
      if (args.identifier) {
        medicationRequestResource.identifier = [{ system: args.identifier.system, value: args.identifier.value }];
      }
    
      return medplum.createResource<MedicationRequest>(medicationRequestResource);
    }
  • TypeScript interface defining the input parameters expected by the createMedicationRequest handler.
    export interface CreateMedicationRequestArgs {
      status: MedicationRequest['status'];
      intent: MedicationRequest['intent'];
      medicationCodeableConcept?: CodeableConcept;
      // medicationReference?: Reference; // TODO: Add if direct reference to Medication resource is needed
      subjectId: string; // Convenience for Patient reference
      encounterId?: string; // Convenience for Encounter reference
      authoredOn?: string;
      requesterId?: string; // Convenience for Practitioner reference
      dosageInstruction?: Dosage[];
      note?: string;
      identifier?: { system?: string; value: string };
      // Add other relevant fields like dispenseRequest, category, priority, etc. as needed
    }
  • MCP tool schema defining the input validation for createMedicationRequest tool calls.
    {
      name: "createMedicationRequest",
      description: "Creates a new medication request (prescription). Requires patient ID, medication reference, and prescriber.",
      inputSchema: {
        type: "object",
        properties: {
          patientId: {
            type: "string",
            description: "The ID of the patient this prescription is for.",
          },
          medicationReference: {
            type: "string",
            description: "Reference to the medication being prescribed.",
          },
          practitionerId: {
            type: "string",
            description: "The ID of the practitioner prescribing the medication.",
          },
          status: {
            type: "string",
            description: "The status of the medication request.",
            enum: ["active", "on-hold", "cancelled", "completed", "entered-in-error", "stopped", "draft", "unknown"],
          },
          intent: {
            type: "string",
            description: "The intent of the medication request.",
            enum: ["proposal", "plan", "order", "original-order", "reflex-order", "filler-order", "instance-order", "option"],
          },
        },
        required: ["patientId", "medicationReference", "practitionerId", "status", "intent"],
      },
  • src/index.ts:44-49 (registration)
    Import statement registering the createMedicationRequest function from medicationRequestUtils.
    import {
      createMedicationRequest,
      getMedicationRequestById,
      updateMedicationRequest,
      searchMedicationRequests,
    } from './tools/medicationRequestUtils.js';
  • src/index.ts:972-972 (registration)
    Entry in toolMapping object that maps the tool name to its handler function for execution.
    createMedicationRequest,
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states this is a creation operation but doesn't mention permissions needed, whether this is a draft or active prescription by default, side effects, or what happens on success/failure. For a write operation with medical implications, this is insufficient 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 a single, efficient sentence that states the core purpose and key requirements. It's appropriately brief given the comprehensive schema documentation, though it could be slightly more informative about the tool's role in the broader FHIR workflow.

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?

For a medication prescription creation tool with no annotations and no output schema, the description is inadequate. It doesn't explain what constitutes a successful creation, what data is returned, error conditions, or how this fits into clinical workflows. The schema handles parameter documentation well, but the description fails to provide necessary operational context.

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?

Schema description coverage is 100%, so parameters are well-documented in the schema. The description mentions three required parameters (patient ID, medication reference, prescriber) but omits 'intent' and 'status' which are also required. It adds minimal value beyond the schema's parameter descriptions.

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 action ('Creates a new medication request') and the resource ('prescription'), with specific required parameters mentioned. It distinguishes from sibling tools like 'createMedication' by focusing on prescriptions rather than medication definitions, but doesn't explicitly contrast with 'updateMedicationRequest' or search tools.

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 like 'updateMedicationRequest' or 'searchMedicationRequests'. It mentions required parameters but doesn't indicate prerequisites, constraints, or typical workflow contexts for creating prescriptions versus other operations.

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