Skip to main content
Glama
rkirkendall

Medplum MCP Server

by rkirkendall

searchConditions

Search for patient conditions using Medplum MCP Server by entering patient ID, clinical status, category, or code. Filter and retrieve condition data efficiently.

Instructions

Searches for conditions based on patient and other criteria. Requires a patient ID.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
categoryNoFilter by category, e.g., "encounter-diagnosis" or "problem-list-item".
clinical-statusNoFilter by clinical status.
codeNoA code to filter by, e.g., "http://snomed.info/sct|44054006". Optional.
patientIdYesThe ID of the patient whose conditions are being searched.

Implementation Reference

  • The primary handler function that performs a FHIR search for Condition resources using the Medplum client. It constructs search criteria from input arguments (patient/subject, category, clinical-status, code, asserter.identifier) and returns matching Conditions or an OperationOutcome on error.
    export async function searchConditions(
      args: ConditionSearchArgs,
      client?: MedplumClient,
    ): Promise<Condition[] | OperationOutcome> {
      const medplumClient = client || medplum;
      await ensureAuthenticated();
      try {
        const searchCriteria: string[] = [];
        const patientId = args.subject || args.patient;
    
        if (patientId) {
          // Medplum search needs the full reference, but the arg might just be an ID
          searchCriteria.push(`subject=${patientId.startsWith('Patient/') ? patientId : `Patient/${patientId}`}`);
        }
        if (args.category) {
          searchCriteria.push(`category=${args.category}`);
        }
        if (args['clinical-status']) {
          searchCriteria.push(`clinical-status=${args['clinical-status']}`);
        }
        if (args.code) {
          searchCriteria.push(`code=${args.code}`);
        }
        if(args['asserter.identifier']){
          searchCriteria.push(`asserter.identifier=${args['asserter.identifier']}`);
        }
    
        if (searchCriteria.length === 0) {
          return {
            resourceType: 'OperationOutcome',
            issue: [
              {
                severity: 'error',
                code: 'invalid',
                diagnostics:
                  'At least one search criterion (subject, patient, category, clinical-status, or code) must be provided.',
              },
            ],
          };
        }
    
        const query = searchCriteria.join('&');
        console.log('Searching conditions with query:', query);
    
        const searchResult = await medplumClient.searchResources('Condition', query);
        const conditions = searchResult as Condition[];
    
        console.log(`Found ${conditions.length} conditions.`);
        return conditions;
      } catch (error: any) {
        console.error('Error searching Conditions:', error);
        const outcome: OperationOutcome = {
          resourceType: 'OperationOutcome',
          issue: [
            {
              severity: 'error',
              code: 'exception',
              diagnostics: `Error searching Conditions: ${error.message || 'Unknown error'}`,
            },
          ],
        };
        if (error.outcome) {
          console.error('Server OperationOutcome:', JSON.stringify(error.outcome, null, 2));
          return error.outcome as OperationOutcome;
        }
        return outcome;
      }
    } 
  • Input schema definition for the searchConditions tool, specifying parameters like patientId (required), code, clinical-status, and category.
    {
      name: 'searchConditions',
      description: 'Searches for conditions based on patient and other criteria. Requires a patient ID.',
      input_schema: {
        type: 'object',
        properties: {
          patientId: {
            type: 'string',
            description: "The ID of the patient whose conditions are being searched.",
          },
          code: {
            type: 'string',
            description: 'A code to filter by, e.g., "http://snomed.info/sct|44054006". Optional.',
          },
          'clinical-status': {
            type: 'string',
            description: 'Filter by clinical status.',
            enum: ['active', 'recurrence', 'relapse', 'inactive', 'remission', 'resolved'],
          },
          category: {
            type: 'string',
            description: 'Filter by category, e.g., "encounter-diagnosis" or "problem-list-item".',
          },
        },
        required: ['patientId'],
      },
    },
  • src/index.ts:893-919 (registration)
    Registration of the searchConditions tool in the MCP server's tool list (mcpTools array), including its schema for the listTools handler.
    {
      name: "searchConditions",
      description: "Searches for conditions based on patient and other criteria. Requires a patient ID.",
      inputSchema: {
        type: "object",
        properties: {
          patientId: {
            type: "string",
            description: "The ID of the patient whose conditions are being searched.",
          },
          code: {
            type: "string",
            description: "A code to filter by, e.g., \"http://snomed.info/sct|44054006\". Optional.",
          },
          "clinical-status": {
            type: "string",
            description: "Filter by clinical status.",
            enum: ["active", "recurrence", "relapse", "inactive", "remission", "resolved"],
          },
          category: {
            type: "string",
            description: "Filter by category, e.g., \"encounter-diagnosis\" or \"problem-list-item\".",
          },
        },
        required: ["patientId"],
      },
    },
  • src/index.ts:1060-1066 (registration)
    Special dispatching logic in the MCP callTool handler that maps 'patientId' from arguments to 'subject' for the searchConditions function call.
    } else if (toolName === 'searchConditions') {
      // Special handling for searchConditions
      const { patientId, ...searchArgs } = args;
      if (patientId) {
        searchArgs.subject = patientId;
      }
      result = await toolFunction(searchArgs);
  • TypeScript interface defining the input arguments for the searchConditions function.
    export interface ConditionSearchArgs {
      subject?: string; // Patient ID
      patient?: string; // Patient ID (alternative to subject)
      category?: string; // e.g., 'encounter-diagnosis'
      'clinical-status'?: string; // e.g., 'active'
      code?: string; // e.g., 'http://snomed.info/sct|44054006'
      'asserter.identifier'?: string;
    }
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 only mentions the patient ID requirement, missing critical details like whether this is a read-only operation (implied by 'searches' but not explicit), pagination behavior, error handling, or rate limits. For a search tool with zero annotation coverage, this leaves significant gaps in understanding how it behaves.

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 two short sentences that are front-loaded with the core purpose. It avoids unnecessary words, though it could be slightly more structured by separating prerequisites from the main action. Overall, it's efficient with no wasted space.

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 tool's complexity (search with 4 parameters), lack of annotations, and no output schema, the description is incomplete. It doesn't explain what the search returns (e.g., list of conditions, format), error cases, or behavioral constraints. For a search operation in a medical context, more detail is needed to ensure safe and effective use.

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 all four parameters. The description adds minimal value beyond the schema by mentioning 'patient and other criteria' and the patient ID requirement, but doesn't provide additional context about parameter interactions or usage examples. This meets the baseline for high schema coverage.

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 verb ('searches') and resource ('conditions') with the scope 'based on patient and other criteria', making the purpose understandable. However, it doesn't explicitly differentiate from sibling tools like 'getConditionById' or 'generalFhirSearch', which would require more specific language about filtering capabilities.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage by stating 'Requires a patient ID' as a prerequisite, which provides some context for when to use it. However, it lacks explicit guidance on when to choose this tool over alternatives like 'getConditionById' (for single conditions) or 'generalFhirSearch' (for broader searches), and doesn't mention exclusions or complementary tools.

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