search_films
Search for Star Wars films by title to find specific movies from the saga and access their details through the SWAPI database.
Instructions
Busca filmes do Star Wars por título
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| search | Yes | Título do filme para buscar |
Implementation Reference
- src/index.ts:152-194 (handler)Executes the search_films tool: queries SWAPI /films endpoint with search param, formats and returns results as text or error message.async ({ search }) => { try { const response = await this.axiosInstance.get<SearchResponse<Films>>( "/films/", { params: { search }, } ); if (response.data.results.length === 0) { return { content: [ { type: "text" as const, text: `Nenhum filme encontrado com o título "${search}".`, }, ], }; } const filmsInfo = response.data.results .map((film) => { return `Título: ${film.title} Episódio: ${film.episode_id} Diretor: ${film.director} Produtor: ${film.producer} Data de Lançamento: ${film.release_date} Abertura: ${film.opening_crawl}`; }) .join("\n---\n\n"); return { content: [ { type: "text" as const, text: `Encontrados ${response.data.results.length} filme(s):\n\n${filmsInfo}`, }, ], }; } catch (error) { return this.handleError(error, "buscar filmes"); } }
- src/index.ts:145-151 (schema)Input schema and metadata (title, description) for the search_films tool, using Zod for validation.{ title: "Buscar Filmes", description: "Busca filmes do Star Wars por título", inputSchema: { search: z.string().describe("Título do filme para buscar"), }, },
- src/index.ts:143-195 (registration)Registers the search_films tool on the MCP server with name, schema, and handler function.this.server.registerTool( "search_films", { title: "Buscar Filmes", description: "Busca filmes do Star Wars por título", inputSchema: { search: z.string().describe("Título do filme para buscar"), }, }, async ({ search }) => { try { const response = await this.axiosInstance.get<SearchResponse<Films>>( "/films/", { params: { search }, } ); if (response.data.results.length === 0) { return { content: [ { type: "text" as const, text: `Nenhum filme encontrado com o título "${search}".`, }, ], }; } const filmsInfo = response.data.results .map((film) => { return `Título: ${film.title} Episódio: ${film.episode_id} Diretor: ${film.director} Produtor: ${film.producer} Data de Lançamento: ${film.release_date} Abertura: ${film.opening_crawl}`; }) .join("\n---\n\n"); return { content: [ { type: "text" as const, text: `Encontrados ${response.data.results.length} filme(s):\n\n${filmsInfo}`, }, ], }; } catch (error) { return this.handleError(error, "buscar filmes"); } } );
- src/types.ts:37-51 (helper)TypeScript interface for Film objects returned from SWAPI, used to type the API response in the handler.export interface Films { title: string; episode_id: number; opening_crawl: string; director: string; producer: string; release_date: string; species: string[]; starships: string[]; vehicles: string[]; characters: string[]; planets: string[]; url: string; created: string; edited: string;
- src/types.ts:54-59 (helper)Generic type for SWAPI search responses, used as SearchResponse<Films> in the handler.export interface SearchResponse<T> { count: number; next: string | null; previous: string | null; results: T[]; }