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
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | ID do personagem |
Implementation Reference
- src/index.ts:206-234 (handler)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}`); } }
- src/index.ts:202-204 (schema)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}`); } } );
- src/types.ts:1-18 (schema)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; }