search_problems
Find LeetCode problems by filtering with categories, tags, difficulty levels, or keywords. Supports pagination for efficient navigation through search results.
Instructions
Searches for LeetCode problems based on multiple filter criteria including categories, tags, difficulty levels, and keywords, with pagination support
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| category | No | Problem category filter (e.g., 'algorithms', 'database', 'shell') to narrow down the problem domain | all-code-essentials |
| difficulty | No | Problem difficulty level filter to show only problems of a specific difficulty | |
| limit | No | Maximum number of problems to return in a single request (for pagination) | |
| offset | No | Number of problems to skip (for pagination) | |
| searchKeywords | No | Keywords to search in problem titles and descriptions | |
| tags | No | List of topic tags to filter problems by (e.g., ['array', 'dynamic-programming', 'tree']) |
Implementation Reference
- src/mcp/tools/problem-tools.ts:105-133 (handler)MCP tool handler for 'search_problems': delegates to LeetCode service and formats response as text content.async ({ category, tags, difficulty, limit, offset, searchKeywords }) => { const data = await this.leetcodeService.searchProblems( category, tags, difficulty, limit, offset, searchKeywords ); return { content: [ { type: "text", text: JSON.stringify({ filters: { tags, difficulty, searchKeywords }, pagination: { limit, offset }, problems: data }) } ] }; }
- Zod input schema for the search_problems tool parameters.{ category: z .enum(PROBLEM_CATEGORIES as [string]) .default("all-code-essentials") .describe( "Problem category filter (e.g., 'algorithms', 'database', 'shell') to narrow down the problem domain" ), tags: z .array(z.enum(PROBLEM_TAGS as [string])) .optional() .describe( "List of topic tags to filter problems by (e.g., ['array', 'dynamic-programming', 'tree'])" ), difficulty: z .enum(["EASY", "MEDIUM", "HARD"]) .optional() .describe( "Problem difficulty level filter to show only problems of a specific difficulty" ), searchKeywords: z .string() .optional() .describe( "Keywords to search in problem titles and descriptions" ), limit: z .number() .optional() .default(10) .describe( "Maximum number of problems to return in a single request (for pagination)" ), offset: z .number() .optional() .describe("Number of problems to skip (for pagination)") },
- src/index.ts:93-93 (registration)Top-level registration of problem tools (including search_problems) in the main server initialization.registerProblemTools(server, leetcodeService);
- LeetCode CN service implementation of searchProblems using GraphQL query.async searchProblems( category?: string, tags?: string[], difficulty?: string, limit: number = 10, offset: number = 0, searchKeywords?: string ): Promise<any> { const filters: any = {}; if (difficulty) { filters.difficulty = difficulty.toUpperCase(); } if (tags && tags.length > 0) { filters.tags = tags; } if (searchKeywords) { filters.searchKeywords = searchKeywords; } const { data } = await this.leetCodeApi.graphql({ query: SEARCH_PROBLEMS_QUERY, variables: { categorySlug: category, limit, skip: offset, filters } }); const questionList = data?.problemsetQuestionList; if (!questionList) { return { hasMore: false, total: 0, questions: [] }; } return { hasMore: questionList.hasMore, total: questionList.total, questions: questionList.questions.map((q: any) => ({ title: q.title, titleCn: q.titleCn, titleSlug: q.titleSlug, difficulty: q.difficulty, acRate: q.acRate, topicTags: q.topicTags.map((tag: any) => tag.slug) })) }; }
- LeetCode Global service implementation of searchProblems using GraphQL query.async searchProblems( category?: string, tags?: string[], difficulty?: string, limit: number = 10, offset: number = 0, searchKeywords?: string ): Promise<any> { const filters: any = {}; if (difficulty) { filters.difficulty = difficulty.toUpperCase(); } if (tags && tags.length > 0) { filters.tags = tags; } if (searchKeywords) { filters.searchKeywords = searchKeywords; } const response = await this.leetCodeApi.graphql({ query: SEARCH_PROBLEMS_QUERY, variables: { categorySlug: category, limit, skip: offset, filters } }); const questionList = response.data?.problemsetQuestionList; if (!questionList) { return { total: 0, questions: [] }; } return { total: questionList.total, questions: questionList.questions.map((question: any) => ({ title: question.title, titleSlug: question.titleSlug, difficulty: question.difficulty, acRate: question.acRate, topicTags: question.topicTags.map((tag: any) => tag.slug) })) }; }