Skip to main content
Glama
glaucia86

Star Wars MCP Server

by glaucia86

get_character_by_id

Retrieve detailed character information from the Star Wars universe using a character ID to access comprehensive data about specific Star Wars characters.

Instructions

Obtém informações detalhadas de um personagem pelo ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesID do personagem

Implementation Reference

  • Executes the tool logic: fetches character details from SWAPI /people/{id} endpoint using axios, formats the response into a text string with key fields, and returns it as content. Catches errors and calls handleError.
    async ({ id }) => {
      try {
        const response = await this.axiosInstance.get<People>(
          `/people/${id}/`
        );
    
        const char = response.data;
        const characterInfo = `Nome: ${char.name}
          Altura: ${char.height}cm
          Massa: ${char.mass}kg
          Cor do Cabelo: ${char.hair_color}
          Cor dos Olhos: ${char.eye_color}
          Ano de Nascimento: ${char.birth_year}
          Gênero: ${char.gender}
          URL do Mundo Natal: ${char.homeworld}
          Número de Filmes: ${char.films.length}`;
    
        return {
          content: [
            {
              type: "text" as const,
              text: characterInfo,
            },
          ],
        };
      } catch (error) {
        return this.handleError(error, `obter personagem com ID ${id}`);
      }
    }
  • Input schema using Zod validation: requires a numeric 'id' parameter for the character ID.
    inputSchema: {
      id: z.number().describe("ID do personagem"),
    },
  • src/index.ts:197-235 (registration)
    Registers the 'get_character_by_id' tool with the MCP server, providing title, description, input schema, and the handler function.
    this.server.registerTool(
      "get_character_by_id",
      {
        title: "Obter Personagem por ID",
        description: "Obtém informações detalhadas de um personagem pelo ID",
        inputSchema: {
          id: z.number().describe("ID do personagem"),
        },
      },
      async ({ id }) => {
        try {
          const response = await this.axiosInstance.get<People>(
            `/people/${id}/`
          );
    
          const char = response.data;
          const characterInfo = `Nome: ${char.name}
            Altura: ${char.height}cm
            Massa: ${char.mass}kg
            Cor do Cabelo: ${char.hair_color}
            Cor dos Olhos: ${char.eye_color}
            Ano de Nascimento: ${char.birth_year}
            Gênero: ${char.gender}
            URL do Mundo Natal: ${char.homeworld}
            Número de Filmes: ${char.films.length}`;
    
          return {
            content: [
              {
                type: "text" as const,
                text: characterInfo,
              },
            ],
          };
        } catch (error) {
          return this.handleError(error, `obter personagem com ID ${id}`);
        }
      }
    );
  • TypeScript interface definition for 'People' used to type the SWAPI response in the get_character_by_id handler.
    export interface People {
      name: string;
      height: string;
      mass: string;
      hair_color: string;
      skin_color: string;
      eye_color: string;
      birth_year: string;
      gender: string;
      homeworld: string;
      films: string[];
      species: string[];
      vehicles: string[];
      starships: string[];
      created: string;
      edited: string;
      url: string;
    }

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/glaucia86/swapi-mcp-server-app'

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