Skip to main content
Glama
backworkai
by backworkai

search_policies

Search Medicare coverage policies (LCDs, NCDs, Articles) to find coverage rules for procedures, conditions, or specific medical questions using keyword or semantic search.

Instructions

Search Medicare coverage policies (LCDs, NCDs, Articles). Use this to find policies related to procedures, conditions, or coverage questions. Supports keyword and semantic search modes.

Examples:

  • search_policies("ultrasound guidance") - find policies about ultrasound

  • search_policies("diabetes CGM") - find continuous glucose monitor policies

  • search_policies("", { policy_type: "NCD" }) - list all National Coverage Determinations

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryNoSearch query - leave empty to browse
modeNoSearch mode: keyword (exact) or semantic (conceptual)keyword
policy_typeNoFilter by policy type
jurisdictionNoMAC jurisdiction code (e.g., JM, JH, JK)
payerNoFilter by payer name
statusNoPolicy status filteractive
limitNoResults per page
cursorNoPagination cursor from previous response
includeNoAdditional data: 'summary', 'criteria', 'codes'

Implementation Reference

  • src/index.ts:289-362 (registration)
    Registration of the 'search_policies' MCP tool, including description, input schema using Zod, and inline async handler function that queries the Verity API /policies endpoint and formats results.
    server.registerTool(
      "search_policies",
      {
        description: `Search Medicare coverage policies (LCDs, NCDs, Articles).
    Use this to find policies related to procedures, conditions, or coverage questions.
    Supports keyword and semantic search modes.
    
    Examples:
    - search_policies("ultrasound guidance") - find policies about ultrasound
    - search_policies("diabetes CGM") - find continuous glucose monitor policies
    - search_policies("", { policy_type: "NCD" }) - list all National Coverage Determinations`,
        inputSchema: {
          query: z.string().max(500).optional().describe("Search query - leave empty to browse"),
          mode: z.enum(["keyword", "semantic"]).default("keyword").describe("Search mode: keyword (exact) or semantic (conceptual)"),
          policy_type: z
            .enum(["LCD", "Article", "NCD", "PayerPolicy", "Medical Policy", "Drug Policy"])
            .optional()
            .describe("Filter by policy type"),
          jurisdiction: z.string().max(10).optional().describe("MAC jurisdiction code (e.g., JM, JH, JK)"),
          payer: z.string().max(50).optional().describe("Filter by payer name"),
          status: z.enum(["active", "retired", "all"]).default("active").describe("Policy status filter"),
          limit: z.number().min(1).max(100).default(20).describe("Results per page"),
          cursor: z.string().optional().describe("Pagination cursor from previous response"),
          include: z.string().optional().describe("Additional data: 'summary', 'criteria', 'codes'"),
        },
      },
      async ({ query, mode, policy_type, jurisdiction, payer, status, limit, cursor, include }) => {
        try {
          const result = await verityRequest<any>("/policies", {
            params: {
              q: query,
              mode,
              policy_type,
              jurisdiction,
              payer,
              status,
              limit,
              cursor,
              include,
            },
          });
    
          if (!result.data || result.data.length === 0) {
            return {
              content: [
                {
                  type: "text",
                  text: `No policies found for "${query || "your search"}". Try:\n- Broader search terms\n- Different policy type\n- Remove jurisdiction filter`,
                },
              ],
            };
          }
    
          const lines: string[] = [`Found ${result.data.length} policies${result.meta?.pagination?.has_more ? " (more available)" : ""}:\n`];
    
          result.data.forEach((policy: any, i: number) => {
            lines.push(`${i + 1}. ${formatPolicy(policy)}`);
            lines.push("");
          });
    
          if (result.meta?.pagination?.cursor) {
            lines.push(`\nMore results available. Use cursor: "${result.meta.pagination.cursor}"`);
          }
    
          return {
            content: [{ type: "text", text: lines.join("\n") }],
          };
        } catch (error) {
          return {
            content: [{ type: "text", text: `Error searching policies: ${error instanceof Error ? error.message : String(error)}` }],
          };
        }
      }
    );
  • Handler function for search_policies tool: destructures input params, calls verityRequest('/policies') with query parameters, handles empty results or errors, formats policy list using formatPolicy, and returns markdown-formatted text content.
    async ({ query, mode, policy_type, jurisdiction, payer, status, limit, cursor, include }) => {
      try {
        const result = await verityRequest<any>("/policies", {
          params: {
            q: query,
            mode,
            policy_type,
            jurisdiction,
            payer,
            status,
            limit,
            cursor,
            include,
          },
        });
    
        if (!result.data || result.data.length === 0) {
          return {
            content: [
              {
                type: "text",
                text: `No policies found for "${query || "your search"}". Try:\n- Broader search terms\n- Different policy type\n- Remove jurisdiction filter`,
              },
            ],
          };
        }
    
        const lines: string[] = [`Found ${result.data.length} policies${result.meta?.pagination?.has_more ? " (more available)" : ""}:\n`];
    
        result.data.forEach((policy: any, i: number) => {
          lines.push(`${i + 1}. ${formatPolicy(policy)}`);
          lines.push("");
        });
    
        if (result.meta?.pagination?.cursor) {
          lines.push(`\nMore results available. Use cursor: "${result.meta.pagination.cursor}"`);
        }
    
        return {
          content: [{ type: "text", text: lines.join("\n") }],
        };
      } catch (error) {
        return {
          content: [{ type: "text", text: `Error searching policies: ${error instanceof Error ? error.message : String(error)}` }],
        };
      }
    }
  • Zod inputSchema for validating parameters of the search_policies tool: query, mode, policy_type, jurisdiction, payer, status, limit, cursor, include.
    inputSchema: {
      query: z.string().max(500).optional().describe("Search query - leave empty to browse"),
      mode: z.enum(["keyword", "semantic"]).default("keyword").describe("Search mode: keyword (exact) or semantic (conceptual)"),
      policy_type: z
        .enum(["LCD", "Article", "NCD", "PayerPolicy", "Medical Policy", "Drug Policy"])
        .optional()
        .describe("Filter by policy type"),
      jurisdiction: z.string().max(10).optional().describe("MAC jurisdiction code (e.g., JM, JH, JK)"),
      payer: z.string().max(50).optional().describe("Filter by payer name"),
      status: z.enum(["active", "retired", "all"]).default("active").describe("Policy status filter"),
      limit: z.number().min(1).max(100).default(20).describe("Results per page"),
      cursor: z.string().optional().describe("Pagination cursor from previous response"),
      include: z.string().optional().describe("Additional data: 'summary', 'criteria', 'codes'"),
    },
  • formatPolicy helper function used by the search_policies handler to format policy data into readable markdown text, supporting detailed mode.
    function formatPolicy(policy: any, detailed = false): string {
      const lines: string[] = [];
      lines.push(`Policy: ${policy.policy_id} - ${policy.title}`);
      lines.push(`Type: ${policy.policy_type} | Status: ${policy.status}`);
      if (policy.jurisdiction) lines.push(`Jurisdiction: ${policy.jurisdiction}`);
      if (policy.effective_date) lines.push(`Effective: ${policy.effective_date}`);
      if (policy.retire_date) lines.push(`Retired: ${policy.retire_date}`);
    
      if (detailed) {
        if (policy.description) lines.push(`\nDescription: ${policy.description}`);
        if (policy.summary) lines.push(`\nSummary: ${policy.summary}`);
    
        if (policy.mac) {
          lines.push(`\nMAC: ${policy.mac.name} (${policy.mac.jurisdiction_name})`);
          if (policy.mac.states) lines.push(`States: ${policy.mac.states.join(", ")}`);
        }
    
        if (policy.sections) {
          if (policy.sections.indications) {
            lines.push(`\n--- Indications ---\n${policy.sections.indications.slice(0, 1000)}${policy.sections.indications.length > 1000 ? "..." : ""}`);
          }
          if (policy.sections.limitations) {
            lines.push(`\n--- Limitations ---\n${policy.sections.limitations.slice(0, 1000)}${policy.sections.limitations.length > 1000 ? "..." : ""}`);
          }
          if (policy.sections.documentation) {
            lines.push(`\n--- Documentation Requirements ---\n${policy.sections.documentation.slice(0, 1000)}${policy.sections.documentation.length > 1000 ? "..." : ""}`);
          }
        }
    
        if (policy.criteria && Object.keys(policy.criteria).length > 0) {
          lines.push("\n--- Coverage Criteria ---");
          Object.entries(policy.criteria).forEach(([section, blocks]: [string, any]) => {
            lines.push(`\n[${section.toUpperCase()}]`);
            blocks.slice(0, 3).forEach((block: any) => {
              lines.push(`  - ${block.text.slice(0, 200)}${block.text.length > 200 ? "..." : ""}`);
              if (block.tags?.length) lines.push(`    Tags: ${block.tags.join(", ")}`);
            });
            if (blocks.length > 3) lines.push(`  ... and ${blocks.length - 3} more criteria`);
          });
        }
    
        if (policy.codes && Object.keys(policy.codes).length > 0) {
          lines.push("\n--- Associated Codes ---");
          Object.entries(policy.codes).forEach(([system, codes]: [string, any]) => {
            lines.push(`\n[${system}] (${codes.length} codes)`);
            codes.slice(0, 10).forEach((c: any) => {
              lines.push(`  - ${c.code}: ${c.display || "No description"} [${c.disposition}]`);
            });
            if (codes.length > 10) lines.push(`  ... and ${codes.length - 10} more codes`);
          });
        }
      }
    
      if (policy.source_url) lines.push(`\nSource: ${policy.source_url}`);
    
      return lines.join("\n");
    }
  • verityRequest helper function used by all tools including search_policies to make authenticated API requests to the Verity API backend.
    async function verityRequest<T>(
      endpoint: string,
      options: {
        method?: "GET" | "POST";
        params?: Record<string, string | number | boolean | undefined>;
        body?: unknown;
      } = {}
    ): Promise<T> {
      const { method = "GET", params, body } = options;
    
      // Build URL with query params
      const url = new URL(`${VERITY_API_BASE}${endpoint}`);
      if (params) {
        Object.entries(params).forEach(([key, value]) => {
          if (value !== undefined && value !== null && value !== "") {
            url.searchParams.append(key, String(value));
          }
        });
      }
    
      const headers: Record<string, string> = {
        Authorization: `Bearer ${VERITY_API_KEY}`,
        "Content-Type": "application/json",
        Accept: "application/json",
      };
    
      const response = await fetch(url.toString(), {
        method,
        headers,
        body: body ? JSON.stringify(body) : undefined,
      });
    
      const data = await response.json();
    
      if (!response.ok) {
        const errorMsg = data.error?.message || `API error: ${response.status}`;
        const hint = data.error?.hint || "";
        throw new Error(hint ? `${errorMsg}. Hint: ${hint}` : errorMsg);
      }
    
      return data as T;
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. While it mentions search modes and gives examples, it doesn't describe important behavioral traits: whether this is a read-only operation, what the response format looks like (e.g., list of policy summaries), pagination behavior beyond the cursor parameter, rate limits, authentication requirements, or error conditions. For a search tool with 9 parameters and no annotations, this is a significant gap.

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

Conciseness5/5

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

The description is well-structured and appropriately sized. It starts with the core purpose, provides usage context, mentions search modes, and gives three helpful examples. Every sentence earns its place, and the examples are directly relevant to demonstrating tool usage without unnecessary elaboration.

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 complexity (9 parameters, no annotations, no output schema), the description is incomplete. While it covers the basic purpose and usage, it lacks crucial information about what the tool returns (no output schema means the description should explain response format), behavioral constraints, and error handling. For a search tool with many filtering options, users need to understand what results look like and how to interpret them.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already documents all 9 parameters thoroughly. The description adds minimal value beyond the schema: it mentions 'keyword and semantic search modes' (covered by the mode parameter) and gives examples that show query usage and policy_type filtering. However, it doesn't provide additional semantic context for parameters like jurisdiction, payer, or include beyond what's in the schema descriptions.

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 states the tool's purpose: 'Search Medicare coverage policies (LCDs, NCDs, Articles).' It specifies the resource (Medicare coverage policies) and the action (search), and distinguishes it from siblings like 'get_policy' (retrieve specific policy) or 'compare_policies' (compare multiple policies). The examples reinforce the search functionality.

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool: 'to find policies related to procedures, conditions, or coverage questions.' It mentions search modes (keyword/semantic) which helps guide usage. However, it doesn't explicitly state when NOT to use it or when to prefer alternatives like 'get_policy' for retrieving a specific known policy or 'search_criteria' for searching within policy criteria.

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/backworkai/verity_mcp'

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