Skip to main content
Glama
jinzcdev

LeetCode MCP Server

list_problem_solutions

Retrieve metadata for community solutions to a specific LeetCode problem, including topic IDs for accessing full solution content.

Instructions

Retrieves a list of community solutions for a specific LeetCode problem, including only metadata like topicId. To view the full content of a solution, use the 'get_problem_solution' tool with the topicId returned by this tool.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
questionSlugYesThe URL slug/identifier of the problem to retrieve solutions for (e.g., 'two-sum', 'add-two-numbers'). This is the same string that appears in the LeetCode problem URL after '/problems/'
limitNoMaximum number of solutions to return per request. Used for pagination and controlling response size. Default is 20 if not specified. Must be a positive integer.
skipNoNumber of solutions to skip before starting to collect results. Used in conjunction with 'limit' for implementing pagination. Default is 0 if not specified. Must be a non-negative integer.
orderByNoSorting criteria for the returned solutions. 'DEFAULT' sorts by LeetCode's default algorithm (typically a combination of recency and popularity), 'MOST_VOTES' sorts by the number of upvotes (highest first), and 'MOST_RECENT' sorts by publication date (newest first).HOT
userInputNoSearch term to filter solutions by title, content, or author name. Case insensitive. Useful for finding specific approaches or algorithms mentioned in solutions.
tagSlugsNoArray of tag identifiers to filter solutions by programming languages (e.g., 'python', 'java') or problem algorithm/data-structure tags (e.g., 'dynamic-programming', 'recursion'). Only solutions tagged with at least one of the specified tags will be returned.

Implementation Reference

  • Global variant of the 'list_problem_solutions' tool handler: an inline async function that constructs options from input params, calls leetcodeService.fetchQuestionSolutionArticles(questionSlug, options), and returns structured JSON content with solutionArticles list or error details.
    async ({
        questionSlug,
        limit,
        skip,
        orderBy,
        userInput,
        tagSlugs
    }) => {
        try {
            const options = {
                limit,
                skip,
                orderBy,
                userInput,
                tagSlugs
            };
    
            const data =
                await this.leetcodeService.fetchQuestionSolutionArticles(
                    questionSlug,
                    options
                );
    
            return {
                content: [
                    {
                        type: "text",
                        text: JSON.stringify({
                            questionSlug,
                            solutionArticles: data
                        })
                    }
                ]
            };
        } catch (error: any) {
            return {
                content: [
                    {
                        type: "text",
                        text: JSON.stringify({
                            error: "Failed to fetch solutions",
                            message: error.message
                        })
                    }
                ]
            };
        }
    }
  • China variant of the 'list_problem_solutions' tool handler: an inline async function identical in logic to the global version, calling leetcodeService.fetchQuestionSolutionArticles with the same options structure.
    async ({
        questionSlug,
        limit,
        skip,
        orderBy,
        userInput,
        tagSlugs
    }) => {
        try {
            const options = {
                limit,
                skip,
                orderBy,
                userInput,
                tagSlugs
            };
    
            const data =
                await this.leetcodeService.fetchQuestionSolutionArticles(
                    questionSlug,
                    options
                );
    
            return {
                content: [
                    {
                        type: "text",
                        text: JSON.stringify({
                            questionSlug,
                            solutionArticles: data
                        })
                    }
                ]
            };
        } catch (error: any) {
            return {
                content: [
                    {
                        type: "text",
                        text: JSON.stringify({
                            error: "Failed to fetch solutions",
                            message: error.message
                        })
                    }
                ]
            };
        }
    }
  • Zod schema definition for the 'list_problem_solutions' tool inputs in global mode, including questionSlug (required), limit/skip (optional pagination), orderBy (HOT/MOST_RECENT/MOST_VOTES), userInput (search), tagSlugs (filter).
    {
        questionSlug: z
            .string()
            .describe(
                "The URL slug/identifier of the problem to retrieve solutions for (e.g., 'two-sum', 'add-two-numbers'). This is the same string that appears in the LeetCode problem URL after '/problems/'"
            ),
        limit: z
            .number()
            .optional()
            .default(10)
            .describe(
                "Maximum number of solutions to return per request. Used for pagination and controlling response size. Default is 20 if not specified. Must be a positive integer."
            ),
        skip: z
            .number()
            .optional()
            .describe(
                "Number of solutions to skip before starting to collect results. Used in conjunction with 'limit' for implementing pagination. Default is 0 if not specified. Must be a non-negative integer."
            ),
        orderBy: z
            .enum(["HOT", " MOST_RECENT", "MOST_VOTES"])
            .default("HOT")
            .optional()
            .describe(
                "Sorting criteria for the returned solutions. 'DEFAULT' sorts by LeetCode's default algorithm (typically a combination of recency and popularity), 'MOST_VOTES' sorts by the number of upvotes (highest first), and 'MOST_RECENT' sorts by publication date (newest first)."
            ),
        userInput: z
            .string()
            .optional()
            .describe(
                "Search term to filter solutions by title, content, or author name. Case insensitive. Useful for finding specific approaches or algorithms mentioned in solutions."
            ),
        tagSlugs: z
            .array(z.string())
            .optional()
            .default([])
            .describe(
                "Array of tag identifiers to filter solutions by programming languages (e.g., 'python', 'java') or problem algorithm/data-structure tags (e.g., 'dynamic-programming', 'recursion'). Only solutions tagged with at least one of the specified tags will be returned."
            )
    },
  • Zod schema definition for the 'list_problem_solutions' tool inputs in China mode, similar to global but with expanded orderBy enum (DEFAULT/MOST_UPVOTE/HOT/NEWEST_TO_OLDEST/OLDEST_TO_NEWEST).
    {
        questionSlug: z
            .string()
            .describe(
                "The URL slug/identifier of the problem to retrieve solutions for (e.g., 'two-sum', 'add-two-numbers'). This is the same string that appears in the LeetCode problem URL after '/problems/'"
            ),
        limit: z
            .number()
            .min(1)
            .optional()
            .default(10)
            .describe(
                "Maximum number of solutions to return per request. Used for pagination and controlling response size. Default is 20 if not specified. Must be a positive integer. If not provided or set to a very large number, the system may still apply internal limits."
            ),
        skip: z
            .number()
            .optional()
            .describe(
                "Number of solutions to skip before starting to collect results. Used in conjunction with 'limit' for implementing pagination. Default is 0 if not specified. Must be a non-negative integer."
            ),
        orderBy: z
            .enum([
                "DEFAULT",
                "MOST_UPVOTE",
                "HOT",
                "NEWEST_TO_OLDEST",
                "OLDEST_TO_NEWEST"
            ])
            .default("DEFAULT")
            .optional()
            .describe(
                "Sorting criteria for the returned solutions. 'DEFAULT' uses the default algorithm, 'MOST_UPVOTE' sorts by the number of upvotes (highest first), 'HOT' prioritizes trending solutions with recent engagement, 'NEWEST_TO_OLDEST' sorts by publication date (newest first), and 'OLDEST_TO_NEWEST' sorts by publication date (oldest first)."
            ),
        userInput: z
            .string()
            .optional()
            .describe(
                "Search term to filter solutions by title, content, or author name. Case insensitive. Useful for finding specific approaches or algorithms mentioned in solutions."
            ),
        tagSlugs: z
            .array(z.string())
            .optional()
            .default([])
            .describe(
                "Array of tag identifiers to filter solutions by programming languages (e.g., 'python', 'java') or problem algorithm/data-structure approaches (e.g., 'dynamic-programming', 'recursion'). Only solutions tagged with at least one of the specified tags will be returned."
            )
  • Top-level function registerSolutionTools that instantiates SolutionToolRegistry with server and leetcodeService, and calls registry.registerTools() to register both global and CN variants of the tool.
    export function registerSolutionTools(
        server: McpServer,
        leetcodeService: LeetCodeBaseService
    ): void {
        const registry = new SolutionToolRegistry(server, leetcodeService);
        registry.registerTools();
    }
  • src/index.ts:96-96 (registration)
    Invocation of registerSolutionTools(server, leetcodeService) in the main entrypoint, which triggers the registration of the list_problem_solutions tool.
    registerSolutionTools(server, leetcodeService);
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions the tool 'retrieves' (implying read-only) and describes the output as 'metadata like topicId', but doesn't specify authentication requirements, rate limits, error conditions, or pagination behavior beyond what's implied by parameters. The description adds some context but leaves significant behavioral aspects undocumented.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is perfectly concise with two sentences that each earn their place. The first sentence states the core purpose and output, while the second provides crucial usage guidance. No wasted words, front-loaded with essential information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 6-parameter tool with no annotations and no output schema, the description provides adequate purpose and usage guidance but lacks details about return format, error handling, authentication, or rate limiting. The context signals show high schema coverage which helps, but the description should do more to compensate for the missing annotations and output schema.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already fully documents all 6 parameters. The description doesn't add any parameter-specific information beyond what's in the schema descriptions. It mentions 'topicId' as output but doesn't explain parameter relationships or usage patterns. Baseline 3 is appropriate when schema does all the parameter documentation work.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Retrieves a list of community solutions') and resource ('for a specific LeetCode problem'), including what metadata is included ('only metadata like topicId'). It distinguishes from sibling 'get_problem_solution' by specifying this tool returns only metadata while that tool provides full content.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly states when to use this tool vs an alternative: 'To view the full content of a solution, use the 'get_problem_solution' tool with the topicId returned by this tool.' This provides clear guidance on the relationship between these two tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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

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