Skip to main content
Glama

search_patients

Find patients in athenahealth using name, date of birth, phone number, or email address to support clinical workflows and data access.

Instructions

Search for patients by name, DOB, phone, or email

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
firstnameNoPatient first name
lastnameNoPatient last name
dobNoDate of birth (YYYY-MM-DD)
phoneNoPhone number
emailNoEmail address
limitNoMaximum number of results

Implementation Reference

  • The main MCP tool handler for search_patients. Validates input parameters, calls the AthenaHealthClient to search patients, handles errors, logs activity, and formats the response as MCP content.
    async handleSearchPatients(args: any) {
      try {
        // Validate that at least one search parameter is provided
        const searchFields = ['firstname', 'lastname', 'dob', 'departmentid', 'phone', 'email'];
        const hasSearchParam = searchFields.some(field => args[field]);
    
        if (!hasSearchParam) {
          return {
            content: [
              {
                type: 'text' as const,
                text: JSON.stringify({
                  error: 'At least one search parameter is required',
                  message: 'Please provide at least one of: firstname, lastname, dob, departmentid, phone, or email',
                  example: {
                    firstname: 'John',
                    lastname: 'Doe',
                    limit: 10
                  }
                }, null, 2),
              },
            ],
          };
        }
    
        const patients = await this.client.searchPatients(args);
    
        // Log the actual response for debugging
        console.error('Patient search raw response:', JSON.stringify(patients, null, 2));
        console.error('Response type:', typeof patients);
        console.error('Is array:', Array.isArray(patients));
    
        auditLog('PATIENT_SEARCH', { result: 'success' });
    
        if (!patients || typeof patients.length !== 'number') {
          return {
            content: [
              {
                type: 'text' as const,
                text: JSON.stringify({
                  error: 'Patient search failed',
                  message: 'The API returned an unexpected response.',
                  suggestion: 'Try using list_departments first to get department IDs, then use list_patients_by_department to list patients.',
                  api_response: patients,
                  response_type: typeof patients,
                  is_array: Array.isArray(patients),
                }, null, 2),
              },
            ],
          };
        }
    
        return {
          content: [
            {
              type: 'text' as const,
              text: JSON.stringify(patients, null, 2),
            },
          ],
        };
      } catch (error: any) {
        console.error('handleSearchPatients caught error:', error);
        return {
          content: [
            {
              type: 'text' as const,
              text: JSON.stringify({
                error: 'Patient search exception',
                message: error.message || 'Unknown error occurred',
                error_type: error.error || 'Unknown',
                details: error.details || error.message,
                detailcode: error.detailcode,
              }, null, 2),
            },
          ],
        };
      }
    }
  • Input schema and metadata definition for the search_patients tool, used for MCP tool listing and validation.
    {
      name: 'search_patients',
      description: 'Search for patients by name, DOB, phone, or email',
      inputSchema: {
        type: 'object',
        properties: {
          firstname: { type: 'string', description: 'Patient first name' },
          lastname: { type: 'string', description: 'Patient last name' },
          dob: { type: 'string', description: 'Date of birth (YYYY-MM-DD)' },
          phone: { type: 'string', description: 'Phone number' },
          email: { type: 'string', description: 'Email address' },
          limit: { type: 'number', description: 'Maximum number of results', default: 10 },
        },
        required: [],
      },
    },
  • Registers the tool definitions (including search_patients) for MCP's listTools request handler.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => {
      return { tools: toolDefinitions };
    });
  • Dispatches incoming search_patients tool calls to the ToolHandlers.handleSearchPatients method.
    case 'search_patients':
      return await this.toolHandlers.handleSearchPatients(args);
  • Core service method that makes the actual AthenaHealth API GET request to /patients with search parameters and normalizes the response.
    async searchPatients(params: {
      firstname?: string;
      lastname?: string;
      dob?: string;
      phone?: string;
      email?: string;
      limit?: number;
    }): Promise<Patient[]> {
      try {
        const queryParams: any = {};
    
        if (params.firstname) queryParams.firstname = params.firstname;
        if (params.lastname) queryParams.lastname = params.lastname;
        if (params.dob) queryParams.dob = params.dob;
        if (params.phone) queryParams.phone = params.phone;
        if (params.email) queryParams.email = params.email;
        if (params.limit) queryParams.limit = params.limit;
    
        const response = await this.makeRequest<any>(
          `${this.config.practice_id}/patients`,
          {
            method: 'GET',
            params: queryParams,
          }
        );
    
        if (response.patients && Array.isArray(response.patients)) {
          return response.patients;
        }
    
        if (Array.isArray(response)) {
          return response;
        }
    
        if (response.data && Array.isArray(response.data)) {
          return response.data;
        }
    
        console.error('Unexpected patients response structure, returning empty array');
        return [];
      } catch (error: any) {
        console.error('Search patients error:', error.message);
        throw error;
      }
    }
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, requires authentication, has rate limits, returns partial matches, or handles errors. For a search tool with zero annotation coverage, this leaves critical behavioral traits unspecified.

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 functionality. It wastes no words and directly communicates the tool's purpose without redundancy or fluff, making it easy for an agent to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (6 parameters, no output schema, no annotations), the description is adequate but incomplete. It covers the basic search scope but lacks details on behavioral traits, usage context, and output expectations. This leaves gaps that could hinder an agent's 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%, with each parameter clearly documented in the input schema. The description adds minimal value by listing searchable fields (name, DOB, phone, email) but doesn't explain parameter interactions, optionality, or the 'limit' parameter. Baseline 3 is appropriate since the schema does the heavy lifting.

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: 'Search for patients by name, DOB, phone, or email.' It specifies the verb ('search') and resource ('patients'), and lists searchable fields. However, it doesn't explicitly distinguish this from potential sibling search tools (though none exist in the provided list), keeping it from 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 doesn't mention prerequisites, limitations, or how it compares to other patient-related tools like 'get_patient_encounters' or 'create_patient'. Without such context, an agent might struggle to choose appropriately.

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

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/ophydami/Athenahealth-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server