Search clinic protocol documents
search_protocolsSearch clinic protocols by keyword to obtain ranked snippets. Cite these snippets when answering to support accuracy and reference.
Instructions
Keyword search over the clinic's protocol library. Returns ranked snippets the model can cite when answering.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| clinic_id | Yes | ||
| query | Yes | ||
| limit | No |
Implementation Reference
- src/tools/search-protocols.ts:39-69 (handler)Main handler for the search_protocols tool. Parses input (clinic_id, query, limit), tokenizes query, scores protocol docs by TF in title (3x) and body (1x), returns top hits ranked by score.
export function searchProtocols( store: ClinicStore, raw: unknown, ): { hits: ProtocolHit[] } { const args = Args.parse(raw); const queryTerms = tokenize(args.query); if (queryTerms.length === 0) return { hits: [] }; const docs = store.listProtocolDocs(args.clinic_id); const scored: ProtocolHit[] = []; for (const doc of docs) { const titleTokens = tokenize(doc.title); const bodyTokens = tokenize(doc.body); let score = 0; for (const term of queryTerms) { score += titleTokens.filter((t) => t === term).length * 3; score += bodyTokens.filter((t) => t === term).length; } if (score === 0) continue; scored.push({ id: doc.id, title: doc.title, score, snippet: snippetAround(doc.body, queryTerms), }); } scored.sort((a, b) => b.score - a.score); return { hits: scored.slice(0, args.limit) }; } - src/tools/search-protocols.ts:4-8 (schema)Input schema for search_protocols: requires clinic_id (string) and query (1-500 chars), optional limit (1-20, default 5).
export const searchProtocolsInput = { clinic_id: z.string(), query: z.string().min(1).max(500), limit: z.number().int().min(1).max(20).default(5), }; - src/tools/search-protocols.ts:13-18 (schema)Output type for each protocol document hit: id, title, numeric score, and snippet.
export interface ProtocolHit { id: string; title: string; score: number; snippet: string; } - src/server.ts:83-92 (registration)Registration of 'search_protocols' tool in the MCP server with its title, description, input schema, and handler wrapper.
server.registerTool( "search_protocols", { title: "Search clinic protocol documents", description: "Keyword search over the clinic's protocol library. Returns ranked snippets the model can cite when answering.", inputSchema: searchProtocolsInput, }, wrap((args) => searchProtocols(store, args)), ); - src/store/index.ts:153-156 (helper)ClinicStore helper that returns protocol documents for a given clinic, used by searchProtocols to retrieve candidate docs.
listProtocolDocs(clinicId: string): ProtocolDoc[] { this.assertClinic(clinicId); return this.protocolDocs.filter((d) => d.clinic_id === clinicId); }