Skip to main content
Glama
BACH-AI-Tools

Clinical Trials MCP Server

search_by_location

Find clinical trials by geographic location using country, state, city, or facility name to identify nearby research studies for patient participation or medical research.

Instructions

Find clinical trials by geographic location

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
countryNoCountry name
stateNoState or province
cityNoCity name
facilityNameNoName of medical facility or institution
distanceNoSearch radius in miles (when using city)
pageSizeNoNumber of results to return (default 10, max 100)

Implementation Reference

  • Implementation of the handleSearchByLocation tool handler.
    private async handleSearchByLocation(args: any) {
      const params: any = {
        format: "json",
        pageSize: args?.pageSize || 10,
      };
    
      // Build location query
      let locationQuery = "";
      if (args?.country) locationQuery += args.country;
      if (args?.state) locationQuery += (locationQuery ? ", " : "") + args.state;
      if (args?.city) locationQuery += (locationQuery ? ", " : "") + args.city;
      if (args?.facilityName)
        locationQuery += (locationQuery ? ", " : "") + args.facilityName;
    
      if (locationQuery) {
        params["query.locn"] = locationQuery;
      }
    
      if (args?.distance && args?.city) {
        params["filter.distance"] = args.distance;
      }
    
      try {
        const response: AxiosResponse<StudySearchResponse> =
          await this.axiosInstance.get("/studies", { params });
    
        const studies = response.data.studies || [];
        const results = studies.map((study) => ({
          ...this.formatStudySummary(study),
          locations:
            study.protocolSection.contactsLocationsModule?.locations?.slice(
              0,
              3
            ) || [],
        }));
    
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(
                {
                  searchCriteria: { locationQuery, distance: args?.distance },
                  totalCount: response.data.totalCount || 0,
                  resultsShown: results.length,
                  studies: 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:202-238 (registration)
    Definition/registration of the search_by_location tool.
      name: "search_by_location",
      description: "Find clinical trials by geographic location",
      inputSchema: {
        type: "object",
        properties: {
          country: {
            type: "string",
            description: "Country name",
          },
          state: {
            type: "string",
            description: "State or province",
          },
          city: {
            type: "string",
            description: "City name",
          },
          facilityName: {
            type: "string",
            description: "Name of medical facility or institution",
          },
          distance: {
            type: "number",
            description: "Search radius in miles (when using city)",
            minimum: 1,
            maximum: 500,
          },
          pageSize: {
            type: "number",
            description:
              "Number of results to return (default 10, max 100)",
            minimum: 1,
            maximum: 100,
          },
        },
      },
    },

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/BACH-AI-Tools/ClinicalTrials-MCP-Server'

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