search-movies
Find movies by title or keywords using the TMDB MCP Server API. Submit a search query to retrieve results and navigate pages for detailed listings.
Instructions
Search for movies by title or keywords
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page | No | Page number for results | |
| query | Yes | Search query |
Implementation Reference
- src/tools.ts:73-89 (handler)The handler function for the "search-movies" tool. It receives the input parameters and calls the underlying searchMovies function from tmdb-api.ts, with error handling."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"); } },
- src/tools.ts:9-26 (schema)The schema definition for the "search-movies" tool, used for listing tools and input validation."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"], }, },
- src/tmdb-api.ts:98-113 (helper)Core implementation of movie search using TMDB API via axios, with retry logic via axiosWithRetry.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:56-98 (registration)Registers the ListTools and CallTool request handlers on the MCP server, using the tools schemas and toolHandlers to handle tool listing and execution for all tools including "search-movies".// Tool handlers server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: Object.values(tools), })); // This is the key fix - we need to format the response properly 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" }; } });