Skip to main content
Glama
rkirkendall

Medplum MCP Server

by rkirkendall

getMedicationById

Retrieve specific medication details by entering its unique ID to access accurate healthcare data from the Medplum MCP Server.

Instructions

Retrieves a medication by its unique ID.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
medicationIdYesThe unique ID of the medication to retrieve.

Implementation Reference

  • The core handler function that implements the getMedicationById tool. It uses MedplumClient to read the Medication resource by ID, handles authentication, not-found cases (returns null), and errors (returns OperationOutcome).
    /**
     * Retrieves a Medication resource by its ID.
     * @param medicationId The ID of the Medication to retrieve.
     * @returns The Medication resource or null if not found, or an OperationOutcome on error.
     */
    export async function getMedicationById(
      medicationId: string,
      client?: MedplumClient,
    ): Promise<Medication | null | OperationOutcome> {
      const medplumClient = client || medplum;
      await ensureAuthenticated();
      try {
        if (!medicationId) {
          throw new Error('Medication ID is required.');
        }
        const medication = (await medplumClient.readResource(
          'Medication',
          medicationId,
        )) as Medication | null;
        console.log('Medication retrieved:', medication);
        return medication;
      } catch (error: any) {
        if (error.outcome && error.outcome.issue && error.outcome.issue[0]?.code === 'not-found') {
          console.log(`Medication with ID "${medicationId}" not found.`);
          return null;
        }
        console.error(`Error retrieving Medication with ID "${medicationId}":`, error);
        const outcome: OperationOutcome = {
          resourceType: 'OperationOutcome',
          issue: [
            {
              severity: 'error',
              code: 'exception',
              diagnostics: `Error retrieving 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;
      }
    }
  • MCP tool schema definition for getMedicationById, specifying input as medicationId string.
      name: "getMedicationById",
      description: "Retrieves a medication by its unique ID.",
      inputSchema: {
        type: "object",
        properties: {
          medicationId: {
            type: "string",
            description: "The unique ID of the medication to retrieve.",
          },
        },
        required: ["medicationId"],
      },
    },
  • src/index.ts:950-988 (registration)
    Registration of the getMedicationById handler function in the toolMapping object used by the MCP server to dispatch tool calls.
    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,
    };
  • src/index.ts:51-54 (registration)
    Import statement bringing the getMedicationById function into index.ts for registration.
      createMedication,
      getMedicationById,
      searchMedications,
    } from './tools/medicationUtils.js';
  • Alternative or legacy schema definition for getMedicationById tool (note: input_schema vs inputSchema, may not be actively used).
      name: 'getMedicationById',
      description: 'Retrieves a Medication resource by its unique ID.',
      input_schema: {
        type: 'object',
        properties: {
          medicationId: { type: 'string', description: 'The unique ID of the Medication to retrieve.' },
        },
        required: ['medicationId'],
      },
    },
Behavior2/5

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

No annotations are provided, so the description carries full burden for behavioral disclosure. It states this is a retrieval operation, implying read-only behavior, but doesn't mention error handling (e.g., what happens if the ID is invalid), authentication requirements, rate limits, or response format. For a 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.

Conciseness5/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 words. Every part of the sentence ('Retrieves a medication by its unique ID') contributes directly to understanding the tool's function.

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 retrieval tool. It doesn't explain what data is returned (e.g., medication details in FHIR format), error scenarios, or how it fits into the broader context of sibling tools like 'createMedication' or 'searchMedications'. This leaves the agent with insufficient information to use the tool effectively.

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%, with the single parameter 'medicationId' clearly documented in the schema as 'The unique ID of the medication to retrieve.' The description adds no additional meaning beyond this, such as ID format examples or constraints, but the schema provides adequate baseline documentation.

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 ('Retrieves') and resource ('a medication by its unique ID'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'getMedicationRequestById' or 'searchMedications', which would require specifying this is for retrieving medication resources specifically rather than medication requests or search results.

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 'searchMedications' or 'getMedicationRequestById'. It doesn't mention prerequisites (e.g., needing a valid medication ID) or contextual factors (e.g., use this for direct lookup vs. search for filtering).

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