provider_enrich
Retrieve comprehensive provider intelligence, including practice details, specialties, affiliations, and market context, by inputting a 10-digit NPI number.
Instructions
AI-enriched provider intelligence from NPI number. Returns practice details, specialties, affiliations, and market context.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| npi | Yes | 10-digit NPI number |
Implementation Reference
- src/tools.js:224-232 (schema)Tool definition for 'provider_enrich' including name, description, price ($0.05), endpoint (/agent/v1/providers/enrich), and Zod schema requiring a 10-digit NPI number.
{ name: 'provider_enrich', description: 'AI-enriched provider intelligence from NPI number. Returns practice details, specialties, affiliations, and market context.', price: '$0.05', endpoint: '/agent/v1/providers/enrich', schema: { npi: z.string().describe('10-digit NPI number'), }, }, - src/index.js:17-62 (registration)Generic tool registration loop (s.tool()) that registers all tools from MCP_TOOLS including 'provider_enrich'. The handler proxies requests to the external API endpoint.
function createMcpServer() { const s = new McpServer({ name: 'mymedi-ai', version: '1.2.1' }); 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 }; } }); } return s; - src/index.js:20-60 (handler)Generic async handler for all tools including 'provider_enrich'. Calls the external REST API at /agent/v1/providers/enrich with the npi parameter, handles 402 payment responses, error responses, and billing headers.
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:255-257 (helper)getToolByName helper function that looks up a tool definition by name from the MCP_TOOLS array.
export function getToolByName(name) { return MCP_TOOLS.find((t) => t.name === name); }