Skip to main content
Glama
glaucia86

Star Wars MCP Server

by glaucia86

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
NameRequiredDescriptionDefault
searchYesTítulo do filme para buscar

Implementation Reference

  • 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"); } }
  • 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"); } } );
  • 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;
  • Generic type for SWAPI search responses, used as SearchResponse&lt;Films&gt; in the handler.
    export interface SearchResponse<T> { count: number; next: string | null; previous: string | null; results: T[]; }

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