Skip to main content
Glama
rkirkendall

Medplum MCP Server

by rkirkendall

createMedication

Generate medication resources in Medplum FHIR servers by specifying medication codes, names, and forms for accurate healthcare data management.

Instructions

Creates a new medication resource. Requires medication code or identifier.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesThe code identifying the medication (e.g., RxNorm, SNOMED CT).
displayNoThe display name of the medication.
formNoThe form of the medication (e.g., tablet, capsule, liquid).

Implementation Reference

  • The primary handler function that executes the 'createMedication' tool logic. It takes CreateMedicationArgs, validates the code, builds a FHIR Medication resource, creates it using the Medplum client, and returns the created resource or an OperationOutcome on error.
    export async function createMedication(
      args: CreateMedicationArgs,
      client?: MedplumClient, // Restore optional client
    ): Promise<Medication | OperationOutcome> {
      const medplumClient = client || medplum;
      await ensureAuthenticated();
      try {
        if (!args.code || !args.code.coding || args.code.coding.length === 0) {
          throw new Error('Medication code with at least one coding is required.');
        }
    
        const medicationResource: Medication = {
          resourceType: 'Medication',
          code: args.code,
          status: args.status,
          manufacturer: args.manufacturer,
          form: args.form,
          identifier: args.identifier,
        };
    
        Object.keys(medicationResource).forEach(
          (key) =>
            (medicationResource as any)[key] === undefined && delete (medicationResource as any)[key],
        );
    
        const createdMedication = (await medplumClient.createResource(
          medicationResource,
        )) as Medication;
        console.log('Medication created successfully:', createdMedication);
        return createdMedication;
      } catch (error: any) {
        console.error('Error creating Medication:', error);
        const outcome: OperationOutcome = {
          resourceType: 'OperationOutcome',
          issue: [
            {
              severity: 'error',
              code: 'exception',
              diagnostics: `Error creating Medication: ${error.message || 'Unknown error'}`,
            },
          ],
        };
        if (error.outcome) {
          console.error('Server OperationOutcome:', JSON.stringify(error.outcome, null, 2));
          return error.outcome as OperationOutcome;
        }
        return outcome;
      }
    }
  • TypeScript interface defining the input arguments for the createMedication handler, including required code and optional fields like status, manufacturer, form, and identifiers.
    export interface CreateMedicationArgs {
      code: CodeableConcept;
      status?: MedicationStatus;
      manufacturer?: Reference<Organization>; // Corrected to Reference<Organization>
      form?: CodeableConcept;
      identifier?: Identifier[];
    }
  • Detailed JSON schema definition for the 'createMedication' tool input, providing structured properties for code, status, manufacturer, form, and identifiers to guide LLM usage.
    {
      name: 'createMedication',
      description: 'Creates a new Medication resource. Requires at least a code system and code value.',
      input_schema: {
        type: 'object',
        properties: {
          code_coding_system: {
            type: 'string',
            description: "The system for the medication code (e.g., 'http://www.nlm.nih.gov/research/umls/rxnorm').",
          },
          code_coding_code: {
            type: 'string',
            description: 'The value for the medication code (e.g., \'313782\').',
          },
          code_coding_display: {
            type: 'string',
            description: 'Optional display text for the medication code (e.g., \'Amoxicillin 250mg Oral Tablet\').',
          },
          code_text: {
            type: 'string',
            description: 'Optional fallback text for the overall medication code concept.',
          },
          status: {
            type: 'string',
            description: "The status of the medication. Optional.",
            enum: ['active', 'inactive', 'entered-in-error'],
          },
          manufacturer_reference: {
            type: 'string',
            description: 'Optional reference to the manufacturer Organization (e.g., \"Organization/123\").',
          },
          form_coding_system: {
            type: 'string',
            description: "Optional: The system for the medication form code (e.g., 'http://snomed.info/sct').",
          },
          form_coding_code: {
            type: 'string',
            description: "Optional: The value for the medication form code (e.g., \'385055001\').",
          },
          form_coding_display: {
            type: 'string',
            description: "Optional: Display text for the medication form code (e.g., \'Oral tablet\').",
          },
          form_text: {
            type: 'string',
            description: 'Optional: Fallback text for the overall medication form concept.',
          },
          identifier_system: {
            type: 'string',
            description: "Optional: System for a medication identifier (e.g., 'http://hl7.org/fhir/sid/ndc').",
          },
          identifier_value: {
            type: 'string',
            description: 'Optional: Value for the medication identifier.',
          },
        },
        required: ['code_coding_system', 'code_coding_code'],
      },
    },
  • src/index.ts:976-988 (registration)
    Tool registration in the MCP server: imported at line 51, defined in mcpTools array (lines 655-677 with inputSchema), and mapped in toolMapping object for execution handling.
      createMedication,
      getMedicationById,
      searchMedications,
      createEpisodeOfCare,
      getEpisodeOfCareById,
      updateEpisodeOfCare,
      searchEpisodesOfCare,
      createCondition,
      getConditionById,
      updateCondition,
      searchConditions,
      generalFhirSearch,
    };
  • src/index.ts:655-677 (registration)
    MCP tool definition in mcpTools array, including name, description, and simplified inputSchema used by the MCP server for tool listing and validation.
    {
      name: "createMedication",
      description: "Creates a new medication resource. Requires medication code or identifier.",
      inputSchema: {
        type: "object",
        properties: {
          code: {
            type: "string",
            description: "The code identifying the medication (e.g., RxNorm, SNOMED CT).",
          },
          display: {
            type: "string",
            description: "The display name of the medication.",
          },
          form: {
            type: "string",
            description: "The form of the medication (e.g., tablet, capsule, liquid).",
          },
        },
        required: ["code"],
      },
    },
    {
Behavior2/5

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

With no annotations provided, the description carries full burden but only states it 'Creates a new medication resource' and requires a code. It lacks details on permissions needed, whether this is a write operation (implied but not explicit), error handling, or response format. This is inadequate for a mutation tool with zero annotation coverage.

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 concise with two short sentences, front-loading the main action. However, it could be more structured by explicitly separating purpose from requirements, but it avoids unnecessary verbosity.

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 this is a mutation tool with no annotations and no output schema, the description is incomplete. It doesn't cover behavioral aspects like authentication needs, potential side effects, or what the response contains, leaving significant gaps for an AI agent to understand tool usage fully.

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 the schema fully documents parameters like 'code' and 'display'. The description adds minimal value by mentioning 'medication code or identifier,' which aligns with the schema but doesn't provide additional context or examples beyond what's already in the schema 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') and resource ('medication resource'), making the purpose understandable. However, it doesn't differentiate this tool from other 'create' siblings like createPatient or createObservation beyond the resource type, missing specific distinctions about what makes medication creation unique.

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 minimal guidance with 'Requires medication code or identifier,' which hints at a prerequisite but doesn't explain when to use this tool versus alternatives like createMedicationRequest or generalFhirSearch. No explicit when/when-not scenarios or comparisons to sibling tools are provided.

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