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
| Name | Required | Description | Default |
|---|---|---|---|
| questionSlug | Yes | 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 | No | 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 | No | 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 | No | 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). | HOT |
| userInput | No | Search term to filter solutions by title, content, or author name. Case insensitive. Useful for finding specific approaches or algorithms mentioned in solutions. | |
| tagSlugs | No | 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. |
Implementation Reference
- src/mcp/tools/solution-tools.ts:56-103 (handler)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 }) } ] }; } }
- src/mcp/tools/solution-tools.ts:204-251 (handler)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." )
- src/mcp/tools/solution-tools.ts:307-313 (registration)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);