drug_enrich
Enrich drug information by querying OpenFDA to obtain drug details, indications, interactions, and AI-powered analysis for any brand or generic drug.
Instructions
Drug information enrichment via OpenFDA. Returns drug details, indications, interactions, and AI analysis.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| drugName | Yes | Drug name (brand or generic, min 2 chars) | |
| searchField | No | Search by brand or generic name |
Implementation Reference
- src/tools.js:233-242 (registration)Tool registration for 'drug_enrich' in MCP_TOOLS array. Defines name, description, price ($0.03), endpoint (/agent/v1/drugs/enrich), and Zod schema (drugName required, searchField optional enum of brand_name/generic_name).
{ name: 'drug_enrich', description: 'Drug information enrichment via OpenFDA. Returns drug details, indications, interactions, and AI analysis.', price: '$0.03', endpoint: '/agent/v1/drugs/enrich', schema: { drugName: z.string().describe('Drug name (brand or generic, min 2 chars)'), searchField: z.enum(['brand_name', 'generic_name']).optional().describe('Search by brand or generic name'), }, }, - src/index.js:19-62 (handler)Generic MCP tool handler in createMcpServer() that iterates over MCP_TOOLS including drug_enrich. Each tool's handler makes an HTTP POST to the configured API base URL with the tool's endpoint and user's params, returning JSON responses or error/payment info.
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;