Skip to main content
Glama

search-problems

Search LeetCode problems by difficulty, tags, or other criteria to find coding challenges that match specific requirements.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tagsNoTags to filter by, separated by '+' (e.g., 'array+dynamic-programming')
difficultyNoDifficulty level
limitNoMaximum number of problems to return
skipNoNumber of problems to skip

Implementation Reference

  • 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 }; } } );
  • 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 } }); }
  • 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 } } } `;

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/doggybee/mcp-server-leetcode'

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