Skip to main content
Glama

random-pokemon-by-type

Find a random Pokémon based on a specific type (e.g., fire, water, grass) using this tool. Ideal for discovering Pokémon by type for games, research, or entertainment.

Instructions

Get a random Pokémon of a specific type

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
typeYesThe Pokémon type (e.g., fire, water, grass, etc.)

Implementation Reference

  • Core handler function that fetches type-specific Pokémon list from PokeAPI, selects a random one, retrieves details, and formats the response with type, stats, abilities, and description.
    async function getRandomPokemonByType(type: string): Promise<PokemonResponse> { const normalizedType = type.toLowerCase(); // Get all Pokémon of this type const typeData = await fetchFromPokeAPI<TypeData>(`/type/${normalizedType}`); if (!typeData || !typeData.pokemon || typeData.pokemon.length === 0) { return { content: [ { type: "text", text: `Unknown type: ${type} or no Pokémon found of this type.`, }, ], }; } // Select a random Pokémon const randomPokemon = getRandomItem(typeData.pokemon); // Get detailed information about this Pokémon const details = await getPokemonDetails(randomPokemon.pokemon.name); if (!details) { return { content: [ { type: "text", text: `Failed to retrieve details for the selected ${normalizedType} Pokémon.`, }, ], }; } // Add type 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( normalizedType )} 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:340-351 (registration)
    Registers the 'random-pokemon-by-type' tool with MCP server, defining input schema and linking to the handler function.
    server.tool( "random-pokemon-by-type", "Get a random Pokémon of a specific type", { type: z .string() .describe("The Pokémon type (e.g., fire, water, grass, etc.)"), }, async ({ type }, _extra) => { return await getRandomPokemonByType(type); } );
  • Zod input schema for the tool, validating the 'type' parameter as a string.
    { type: z .string() .describe("The Pokémon type (e.g., fire, water, grass, etc.)"), },
  • TypeScript interface defining the structure of PokeAPI type data response used in the handler.
    export interface TypeData { pokemon: { pokemon: { name: string; url: string; }; }[]; }
  • Helper function to fetch detailed Pokémon data including species information, used by the handler.
    async function getPokemonDetails(pokemonNameOrId: string) { const pokemon = await fetchFromPokeAPI<Pokemon>( `/pokemon/${pokemonNameOrId.toLowerCase()}` ); if (!pokemon) return null; const species = await fetchFromPokeAPI<PokemonSpeciesDetails>( `/pokemon-species/${pokemon.id}` ); if (!species) return null; return { pokemon, species }; }

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