Skip to main content
Glama

search-movies

Find movies by title or keywords using The Movie Database API. Enter a search query to retrieve relevant film results with pagination support.

Instructions

Search for movies by title or keywords

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query
pageNoPage number for results

Implementation Reference

  • The handler function for the 'search-movies' tool that invokes the searchMovies helper from tmdb-api.ts.
    "search-movies": async ({ query, page = 1, }: { query: string; page?: number; }) => { try { // Return the raw results directly return await searchMovies(query, page); } catch (error: unknown) { if (error instanceof Error) { throw new Error(`Failed to search movies: ${error.message}`); } throw new Error("Failed to search movies: Unknown error"); } },
  • The input schema and metadata definition for the 'search-movies' tool.
    "search-movies": { name: "search-movies", description: "Search for movies by title or keywords", inputSchema: { type: "object", properties: { query: { type: "string", description: "Search query", }, page: { type: "number", description: "Page number for results", }, }, required: ["query"], }, },
  • The core implementation of movie search using TMDB API, called by the tool handler.
    export async function searchMovies(query: string, page: number = 1): Promise<SearchMoviesResponse> { try { const response = await axiosWithRetry<SearchMoviesResponse>({ url: '/search/movie', params: { query: query, page: page } }); return response.data; } catch (error) { const err = error as Error; console.error('Error searching movies:', err.message); throw new Error(`Failed to search movies: ${err.message}`); } }
  • src/handlers.ts:62-98 (registration)
    Generic registration of tool handlers, dispatching calls to toolHandlers[name] including 'search-movies'.
    server.setRequestHandler(CallToolRequestSchema, async (request) => { try { const { name, arguments: args } = request.params; // Using type assertion to tell TypeScript this is a valid key const handler = toolHandlers[name as keyof typeof toolHandlers]; if (!handler) throw new Error(`Tool not found: ${name}`); // Execute the handler but wrap the response in the expected format const result = await handler(args as any); // Return in the format expected by the SDK return { tools: [{ name, inputSchema: { type: "object", properties: {} // This would ideally be populated with actual schema }, description: `Tool: ${name}`, result }] }; } catch (error) { // Properly handle errors if (error instanceof Error) { return { tools: [], error: error.message }; } return { tools: [], error: "An unknown error occurred" }; } });

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/ShubhanshuSondhiya/MCP-TMDB'

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