Skip to main content
Glama

random-pokemon-from-region

Generate a random Pokémon from a specified region like Kanto, Johto, or Hoenn using a dedicated tool that fetches data from the PokeAPI for easy discovery.

Instructions

Get a random Pokémon from a specific region

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
regionYesThe Pokémon region (e.g., kanto, johto, hoenn, etc.)

Implementation Reference

  • Main handler function that implements the logic to retrieve and format a random Pokémon from the specified region using PokeAPI data.
    async function getRandomPokemonFromRegion(
      region: string
    ): Promise<PokemonResponse> {
      const normalizedRegion = region.toLowerCase();
      const generation = REGION_TO_GENERATION[normalizedRegion];
    
      if (!generation) {
        return {
          content: [
            {
              type: "text",
              text: `Unknown region: ${region}. Available regions are: ${Object.keys(
                REGION_TO_GENERATION
              ).join(", ")}`,
            },
          ],
        };
      }
    
      // Get all Pokémon from this generation
      const generationData = await fetchFromPokeAPI<GenerationData>(
        `/generation/${generation}`
      );
    
      if (
        !generationData ||
        !generationData.pokemon_species ||
        generationData.pokemon_species.length === 0
      ) {
        return {
          content: [
            {
              type: "text",
              text: `Failed to retrieve Pokémon from the ${normalizedRegion} region.`,
            },
          ],
        };
      }
    
      // Select a random Pokémon
      const randomPokemon = getRandomItem(generationData.pokemon_species);
    
      // Get detailed information about this Pokémon
      const details = await getPokemonDetails(randomPokemon.name);
    
      if (!details) {
        return {
          content: [
            {
              type: "text",
              text: `Failed to retrieve details for the selected Pokémon from ${normalizedRegion}.`,
            },
          ],
        };
      }
    
      // Add region information to the response
      const types = formatPokemonTypes(details.pokemon.types);
      const abilities = formatPokemonAbilities(details.pokemon.abilities);
      const flavorText = getEnglishFlavorText(details.species);
    
      return {
        content: [
          {
            type: "text",
            text: `
    # Random ${capitalizeFirstLetter(
              normalizedRegion
            )} Pokémon: ${capitalizeFirstLetter(details.pokemon.name)} (#${
              details.pokemon.id
            })
    
    **Types:** ${types}
    **Height:** ${details.pokemon.height / 10}m
    **Weight:** ${details.pokemon.weight / 10}kg
    **Abilities:** ${abilities}
    
    **Description:** ${flavorText}
            `.trim(),
          },
        ],
      };
    }
  • src/index.ts:327-338 (registration)
    Registration of the 'random-pokemon-from-region' tool with the MCP server, including input schema and handler reference.
    server.tool(
      "random-pokemon-from-region",
      "Get a random Pokémon from a specific region",
      {
        region: z
          .string()
          .describe("The Pokémon region (e.g., kanto, johto, hoenn, etc.)"),
      },
      async ({ region }, _extra) => {
        return await getRandomPokemonFromRegion(region);
      }
    );
  • Zod input schema defining the 'region' parameter for the tool.
    {
      region: z
        .string()
        .describe("The Pokémon region (e.g., kanto, johto, hoenn, etc.)"),
    },
  • Mapping of region names to Pokémon generations used by the handler.
    const REGION_TO_GENERATION: Record<string, number> = {
      kanto: 1,
      johto: 2,
      hoenn: 3,
      sinnoh: 4,
      unova: 5,
      kalos: 6,
      alola: 7,
      galar: 8,
      paldea: 9,
    };
Install Server

Other Tools

Related 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/NaveenBandarage/poke-mcp'

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