Skip to main content
Glama
BACH-AI-Tools

Clinical Trials MCP Server

get_similar_studies

Find related clinical trials by matching conditions, interventions, sponsors, or phases to a specific NCT ID study.

Instructions

Find clinical trials similar to a specific study by NCT ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nctIdYesNCT ID of the reference study (e.g., NCT00000419)
similarityTypeNoType of similarity to search forCONDITION
pageSizeNoNumber of results to return (default 10, max 50)

Implementation Reference

  • The handleGetSimilarStudies function is the handler that executes the logic for finding similar clinical trials based on a provided NCT ID. It retrieves the reference study, determines the similarity type (CONDITION, SPONSOR, or PHASE), performs a new search on the ClinicalTrials.gov API using criteria extracted from the reference study, and filters out the reference study from the results.
    private async handleGetSimilarStudies(args: any) {
      if (!args?.nctId || !/^NCT\d{8}$/.test(args.nctId)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          "Valid NCT ID is required (format: NCT########)"
        );
      }
    
      try {
        // First get the reference study to extract similarity criteria
        const referenceResponse: AxiosResponse<StudySearchResponse> =
          await this.axiosInstance.get("/studies", {
            params: {
              format: "json",
              "query.term": args.nctId,
              pageSize: 1,
            },
          });
    
        if (
          !referenceResponse.data.studies ||
          referenceResponse.data.studies.length === 0
        ) {
          return {
            content: [
              {
                type: "text",
                text: `Reference study not found: ${args.nctId}`,
              },
            ],
            isError: true,
          };
        }
    
        const referenceStudy = referenceResponse.data.studies[0];
        const similarityType = args.similarityType || "CONDITION";
        let searchParams: any = {
          format: "json",
          pageSize: args?.pageSize || 10,
        };
    
        // Build search based on similarity type
        switch (similarityType) {
          case "CONDITION":
            const condition =
              referenceStudy.protocolSection.conditionsModule?.conditions?.[0];
            if (condition) {
              searchParams["query.cond"] = condition;
            }
            break;
          case "SPONSOR":
            const sponsor =
              referenceStudy.protocolSection.sponsorCollaboratorsModule
                ?.leadSponsor?.name;
            if (sponsor) {
              searchParams["query.spons"] = sponsor;
            }
            break;
          case "PHASE":
            const phase =
              referenceStudy.protocolSection.designModule?.phases?.[0];
            if (phase) {
              searchParams["filter.phase"] = phase;
            }
            break;
        }
    
        const response: AxiosResponse<StudySearchResponse> =
          await this.axiosInstance.get("/studies", { params: searchParams });
    
        const studies = response.data.studies || [];
        const results = studies
          .filter(
            (study) =>
              study.protocolSection.identificationModule.nctId !== args.nctId
          ) // Exclude reference study
          .map((study) => this.formatStudySummary(study));
    
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(
                {
                  referenceStudy: {
                    nctId: args.nctId,
                    title:
                      referenceStudy.protocolSection.identificationModule
                        .briefTitle,
                  },
                  similarityType,
                  totalCount: response.data.totalCount || 0,
                  resultsShown: results.length,
                  similarStudies: results,
                },
                null,
                2
              ),
            },
          ],
        };
      } catch (error) {
        if (axios.isAxiosError(error)) {
          return {
            content: [
              {
                type: "text",
                text: `Clinical Trials API error: ${
                  error.response?.data?.message || error.message
                }`,
              },
            ],
            isError: true,
          };
        }
        throw error;
      }
    }
  • src/index.ts:531-558 (registration)
    Tool registration definition for "get_similar_studies" in the server's tool list.
      name: "get_similar_studies",
      description:
        "Find clinical trials similar to a specific study by NCT ID",
      inputSchema: {
        type: "object",
        properties: {
          nctId: {
            type: "string",
            description:
              "NCT ID of the reference study (e.g., NCT00000419)",
            pattern: "^NCT\\d{8}$",
          },
          similarityType: {
            type: "string",
            description: "Type of similarity to search for",
            enum: ["CONDITION", "INTERVENTION", "SPONSOR", "PHASE"],
            default: "CONDITION",
          },
          pageSize: {
            type: "number",
            description: "Number of results to return (default 10, max 50)",
            minimum: 1,
            maximum: 50,
          },
        },
        required: ["nctId"],
      },
    },

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.1

TDQS

A3.5/5.0
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. It only states the basic action, with no mention of return format, pagination handling, how similarity is determined, or any operational details. This leaves significant ambiguity about the tool's behavior.

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 a single, concise sentence with no redundant words. It is front-loaded with the core action and resource, making it easy to scan. Every word earns its place.

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

Completeness3/5

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

With 100% schema coverage and no output schema, the description is minimally viable but leaves gaps: it does not explain what 'similar' means, nor does it hint at the response structure. For a simple tool, this may be acceptable, but more context would improve completeness.

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 all three parameters have detailed descriptions in the schema. The description adds minimal value beyond the schema, merely reusing the concept of NCT ID. With full schema coverage, a score of 3 is appropriate.

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 uses a specific verb ('Find') and resource ('clinical trials similar to a specific study') with a clear scope ('by NCT ID'). This clearly distinguishes it from siblings like search_studies and get_study_details, which focus on broader search or detail retrieval.

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

Usage Guidelines3/5

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

The purpose itself implies when to use this tool (when similarity to a known study is needed), but the description does not explicitly state when to use it over alternatives or provide any exclusions. It relies on the reader to infer the use case from the name and description.

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