provider_search
Find healthcare providers by name, specialty, or location using the NPI provider directory.
Instructions
Search the NPI provider directory. Find healthcare providers by name, specialty, or location.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| firstName | No | ||
| lastName | No | ||
| organizationName | No | ||
| taxonomy | No | Provider taxonomy/specialty code | |
| city | No | ||
| state | No | 2-letter state code | |
| limit | No | Max results (default 10, max 50) |
Implementation Reference
- src/index.js:19-61 (registration)The tool 'provider_search' is registered as an MCP tool inside the loop over MCP_TOOLS on line 20. Any tool in the MCP_TOOLS array, including provider_search, gets registered via s.tool().
for (const tool of MCP_TOOLS) { s.tool(tool.name, tool.description, tool.schema, async (params) => { const toolDef = getToolByName(tool.name); if (!toolDef) { return { content: [{ type: 'text', text: `Unknown tool: ${tool.name}` }], isError: true }; } try { const response = await fetch(`${API_BASE_URL}${toolDef.endpoint}`, { method: 'POST', headers: { 'Content-Type': 'application/json', ...(API_KEY && { 'X-API-Key': API_KEY }), 'X-Agent-ID': 'mcp-client', 'User-Agent': '@mymedi-ai/mcp-server/1.2.1', }, body: JSON.stringify(params), }); if (response.status === 402) { const paymentInfo = await response.json(); return { content: [{ type: 'text', text: JSON.stringify({ error: 'payment_required', message: `This tool costs ${toolDef.price} per call. Register at ${API_BASE_URL}/bot-marketplace/register for an API key with 10 free starter credits, or pay per call with on-chain USDC (no signup) via the x402 protocol.`, price: toolDef.price, register: `${API_BASE_URL}/bot-marketplace/register`, ...paymentInfo, }, null, 2) }], isError: true, }; } if (!response.ok) { const error = await response.json().catch(() => ({ message: response.statusText })); return { content: [{ type: 'text', text: JSON.stringify({ error: true, status: response.status, ...error }, null, 2) }], isError: true }; } const data = await response.json(); const creditsSpent = response.headers.get('X-Credits-Spent'); const creditsRemaining = response.headers.get('X-Credits-Remaining'); if (creditsSpent) { data._billing = { creditsSpent: parseInt(creditsSpent, 10), creditsRemaining: creditsRemaining ? parseInt(creditsRemaining, 10) : undefined, priceUSD: toolDef.price }; } return { content: [{ type: 'text', text: JSON.stringify(data, null, 2) }] }; } catch (err) { return { content: [{ type: 'text', text: JSON.stringify({ error: true, message: err.message, hint: 'Ensure MCP_API_BASE_URL and MCP_API_KEY environment variables are set.' }, null, 2) }], isError: true }; } }); } - src/index.js:20-61 (handler)The handler for provider_search is the generic async function in the s.tool() call. It fetches POST to the tool's endpoint (/agent/v1/providers/search) and returns the JSON result.
s.tool(tool.name, tool.description, tool.schema, async (params) => { const toolDef = getToolByName(tool.name); if (!toolDef) { return { content: [{ type: 'text', text: `Unknown tool: ${tool.name}` }], isError: true }; } try { const response = await fetch(`${API_BASE_URL}${toolDef.endpoint}`, { method: 'POST', headers: { 'Content-Type': 'application/json', ...(API_KEY && { 'X-API-Key': API_KEY }), 'X-Agent-ID': 'mcp-client', 'User-Agent': '@mymedi-ai/mcp-server/1.2.1', }, body: JSON.stringify(params), }); if (response.status === 402) { const paymentInfo = await response.json(); return { content: [{ type: 'text', text: JSON.stringify({ error: 'payment_required', message: `This tool costs ${toolDef.price} per call. Register at ${API_BASE_URL}/bot-marketplace/register for an API key with 10 free starter credits, or pay per call with on-chain USDC (no signup) via the x402 protocol.`, price: toolDef.price, register: `${API_BASE_URL}/bot-marketplace/register`, ...paymentInfo, }, null, 2) }], isError: true, }; } if (!response.ok) { const error = await response.json().catch(() => ({ message: response.statusText })); return { content: [{ type: 'text', text: JSON.stringify({ error: true, status: response.status, ...error }, null, 2) }], isError: true }; } const data = await response.json(); const creditsSpent = response.headers.get('X-Credits-Spent'); const creditsRemaining = response.headers.get('X-Credits-Remaining'); if (creditsSpent) { data._billing = { creditsSpent: parseInt(creditsSpent, 10), creditsRemaining: creditsRemaining ? parseInt(creditsRemaining, 10) : undefined, priceUSD: toolDef.price }; } return { content: [{ type: 'text', text: JSON.stringify(data, null, 2) }] }; } catch (err) { return { content: [{ type: 'text', text: JSON.stringify({ error: true, message: err.message, hint: 'Ensure MCP_API_BASE_URL and MCP_API_KEY environment variables are set.' }, null, 2) }], isError: true }; } }); } - src/tools.js:209-223 (schema)The schema and tool definition for provider_search. Defines Zod validation for optional input parameters (firstName, lastName, organizationName, taxonomy, city, state, limit) and the API endpoint /agent/v1/providers/search.
{ name: 'provider_search', description: 'Search the NPI provider directory. Find healthcare providers by name, specialty, or location.', price: '$0.005', endpoint: '/agent/v1/providers/search', schema: { firstName: z.string().optional(), lastName: z.string().optional(), organizationName: z.string().optional(), taxonomy: z.string().optional().describe('Provider taxonomy/specialty code'), city: z.string().optional(), state: z.string().optional().describe('2-letter state code'), limit: z.number().optional().describe('Max results (default 10, max 50)'), }, }, - src/tools.js:255-257 (helper)Helper function used by the handler to look up the tool definition (including endpoint and price) by name.
export function getToolByName(name) { return MCP_TOOLS.find((t) => t.name === name); }