list_patients
Search for patients by name, email, or phone, and paginate results to manage your patient list efficiently.
Instructions
List or search for patients
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "list_patients"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| q | No | Search query (searches name, email, phone) | |
| page | No | Page number | |
| per_page | No | Results per page (max 100) |
Implementation Reference
- src/tools/patients.ts:31-60 (handler)The tool handler for 'list_patients'. Registers the tool via server.tool() with an input schema for q, page, per_page. Calls clinikoClient.listPatients() and formats the response.
server.tool('list_patients', { description: 'List or search for patients', inputSchema: { type: 'object', properties: { q: { type: 'string', description: 'Search query (searches name, email, phone)' }, page: { type: 'number', description: 'Page number' }, per_page: { type: 'number', description: 'Results per page (max 100)' } } }, }, async ({ q, page, per_page }: z.infer<typeof PatientSearchSchema>) => { try { const response = await client.listPatients({ q, page, per_page }); const patients = response.patients || []; return { content: [{ type: 'text', text: JSON.stringify({ patients, total_entries: response.total_entries, page: page || 1, has_more: !!response.links.next }, null, 2) }] }; } catch (error) { throw new Error(`Failed to list patients: ${error instanceof Error ? error.message : 'Unknown error'}`); } }); - src/tools/patients.ts:23-27 (schema)The PatientSearchSchema Zod schema that defines validation for the tool's input parameters (q, page, per_page).
const PatientSearchSchema = z.object({ q: z.string().optional().describe('Search query (searches name, email, phone)'), page: z.number().optional().describe('Page number'), per_page: z.number().optional().describe('Results per page (max 100)'), }); - src/tools/patients.ts:29-30 (registration)The registerPatientTools function which is called from src/index.ts to register the tool on the server. The tool named 'list_patients' is registered inside this function.
export function registerPatientTools(server: any, client: ClinikoClient) { // List/Search patients - src/index.ts:44-48 (registration)The toolRegistry helper used to register tools. The server.tool() call in patients.ts stores the schema and handler in a Map.
const toolRegistry = { tool(name: string, schema: any, handler: any) { tools.set(name, { schema, handler }); } }; - src/cliniko-client.ts:53-60 (helper)The ClinikoClient.listPatients() method that makes the actual API call to GET /patients with optional query params (page, per_page, q).
async listPatients(params?: { page?: number; per_page?: number; q?: string }): Promise<ClinikoListResponse<Patient>> { const searchParams = new URLSearchParams(); if (params?.page) searchParams.append('page', params.page.toString()); if (params?.per_page) searchParams.append('per_page', params.per_page.toString()); if (params?.q) searchParams.append('q', params.q); return this.request<ClinikoListResponse<Patient>>(`/patients${searchParams.toString() ? '?' + searchParams.toString() : ''}`); }