Skip to main content
Glama

code_validate

Validate medical codes for accuracy, active status, and contextual appropriateness. Receive warnings and errors for invalid or mismatched codes.

Instructions

Validate a medical code for correctness, active status, and context. Returns warnings and errors.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesMedical code to validate
codeTypeNo
contextNo

Implementation Reference

  • Tool definition with Zod schema for code_validate: accepts 'code' (string), optional 'codeType' (icd10/cpt/hcpcs), and optional 'context.dateOfService' for temporal validation. Endpoint: /agent/v1/codes/validate, price: $0.005.
    {
      name: 'code_validate',
      description: 'Validate a medical code for correctness, active status, and context. Returns warnings and errors.',
      price: '$0.005',
      endpoint: '/agent/v1/codes/validate',
      schema: {
        code: z.string().describe('Medical code to validate'),
        codeType: z.enum(['icd10', 'cpt', 'hcpcs']).optional(),
        context: z.object({
          dateOfService: z.string().optional().describe('Date of service (YYYY-MM-DD) for temporal validation'),
        }).optional(),
      },
    },
  • src/index.js:19-61 (registration)
    Generic handler registration: code_validate (and all tools) are registered via MCP_TOOLS loop in createMcpServer(). Each tool's handler does an HTTP POST to the tool's endpoint with params, handles 402 (payment required), errors, and returns JSON response.
    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 };
        }
      });
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description must convey behavioral traits. It mentions 'returns warnings and errors' but does not elaborate on the nature of these, potential side effects, or requirements. Important aspects like how context affects validation or whether the tool modifies any state are omitted, leaving significant gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence, which is concise but at the expense of necessary detail. While it avoids fluff, it does not fully earn its place as it omits critical usage and parameter guidance. The structure is adequate but could be improved with additional clarity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (3 parameters including a nested object, no output schema, no annotations), the description is insufficient. It fails to explain the validation criteria, how codeType and context influence results, or what the warnings/errors entail. An agent would lack critical information to use the tool correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is only 33% (only 'code' has a description). The tool description adds no parameter information at all. For a low-coverage schema, the description must compensate, but it fails to explain 'codeType' or 'context', leaving their semantics ambiguous.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly identifies the tool as validating a medical code, specifying three aspects (correctness, active status, context) and the output (warnings and errors). This distinctly differentiates it from sibling tools like code_lookup or code_crossref, which serve different purposes.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description lacks any guidance on when to use this tool versus alternatives, such as code_lookup or code_suggest. No prerequisites, exclusions, or context for optimal use are provided, making it difficult for an agent to decide when this tool is appropriate.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/MyMedi-AI/mymedi-ai-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server