ner_extract
Extract medical named entities from clinical text, including ICD-10, CPT codes, medications, and dates with confidence scores.
Instructions
Extract medical named entities from clinical text. Identifies ICD-10 codes, CPT codes, dates, medications, and 12 entity types with confidence scores.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | Clinical text to extract entities from | |
| entityTypes | No | Filter to specific entity types |
Implementation Reference
- src/tools.js:71-80 (schema)Zod schema definition and tool metadata for ner_extract. Defines the tool name, description, price, endpoint '/agent/v1/ner/extract', and input schema (text: required string, entityTypes: optional array of strings).
{ name: 'ner_extract', description: 'Extract medical named entities from clinical text. Identifies ICD-10 codes, CPT codes, dates, medications, and 12 entity types with confidence scores.', price: '$0.02', endpoint: '/agent/v1/ner/extract', schema: { text: z.string().describe('Clinical text to extract entities from'), entityTypes: z.array(z.string()).optional().describe('Filter to specific entity types'), }, }, - src/index.js:19-61 (registration)Registration of the ner_extract tool as an MCP tool via server.tool(). The generic handler fetches the external REST API at the tool's endpoint. ner_extract is registered as part of the MCP_TOOLS loop at line 19.
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:66-73 (registration)Sandbox registration of ner_extract in createSandboxServer(), returning 'sandbox' placeholder responses.
export function createSandboxServer() { const sandboxServer = new McpServer({ name: 'mymedi-ai', version: '1.2.1' }); for (const tool of MCP_TOOLS) { sandboxServer.tool(tool.name, tool.description, tool.schema, async () => ({ content: [{ type: 'text', text: 'sandbox' }] })); } return sandboxServer; }