search-problems
Search LeetCode problems by difficulty, tags, or other criteria to find coding challenges that match specific requirements.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "search-problems"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tags | No | Tags to filter by, separated by '+' (e.g., 'array+dynamic-programming') | |
| difficulty | No | Difficulty level | |
| limit | No | Maximum number of problems to return | |
| skip | No | Number of problems to skip |
Implementation Reference
- src/tools/problem-tools.ts:54-80 (registration)Registers the 'search-problems' MCP tool, including input schema and execution handler.
// Search problems server.tool( "search-problems", { tags: z.string().optional().describe("Tags to filter by, separated by '+' (e.g., 'array+dynamic-programming')"), difficulty: z.enum(["EASY", "MEDIUM", "HARD"]).optional().describe("Difficulty level"), limit: z.number().min(1).max(100).optional().default(20).describe("Maximum number of problems to return"), skip: z.number().optional().default(0).describe("Number of problems to skip") }, async ({ tags, difficulty, limit, skip }) => { try { const data = await leetcodeService.searchProblems(tags, difficulty, limit, skip); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] }; } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [{ type: "text", text: `Error: ${errorMessage}` }], isError: true }; } } ); - src/tools/problem-tools.ts:63-79 (handler)Handler function for the 'search-problems' tool that calls LeetCodeService and formats response.
async ({ tags, difficulty, limit, skip }) => { try { const data = await leetcodeService.searchProblems(tags, difficulty, limit, skip); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] }; } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [{ type: "text", text: `Error: ${errorMessage}` }], isError: true }; } } - LeetCodeService.searchProblems method that executes the GraphQL search query with filters.
/** * Search for problems matching criteria */ async searchProblems(tags?: string, difficulty?: string, limit: number = 20, skip: number = 0) { return this.executeQuery(searchProblemsQuery, { categorySlug: "", limit, skip, filters: { tags: tags ? tags.split("+") : [], difficulty: difficulty || null } }); } - src/graphql/queries.ts:146-175 (schema)GraphQL query definition for searching LeetCode problems used by the tool.
export const searchProblemsQuery = ` query problemsetQuestionList($categorySlug: String, $limit: Int, $skip: Int, $filters: QuestionListFilterInput) { problemsetQuestionList: questionList( categorySlug: $categorySlug limit: $limit skip: $skip filters: $filters ) { total: totalNum questions: data { acRate difficulty freqBar frontendQuestionId: questionFrontendId isFavor paidOnly: isPaidOnly status title titleSlug topicTags { name id slug } hasSolution hasVideoSolution } } } `;