get_problem_solution
Retrieve the complete solution content for a LeetCode problem, including full article text, author details, and navigation links.
Instructions
Retrieves the complete content and metadata of a specific solution, including the full article text, author information, and related navigation links
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| topicId | Yes | The unique topic ID of the solution to retrieve. This ID can be obtained from the 'topicId' field in the response of the 'list_problem_solutions' tool. Format is typically a string of numbers and letters that uniquely identifies the solution in LeetCode's database. |
Implementation Reference
- src/mcp/tools/solution-tools.ts:107-149 (registration)MCP tool registration for 'get_problem_solution' in global context: defines schema (topicId), description, and handler that calls LeetCode service to fetch solution details.this.server.tool( "get_problem_solution", "Retrieves the complete content and metadata of a specific solution, including the full article text, author information, and related navigation links", { topicId: z .string() .describe( "The unique topic ID of the solution to retrieve. This ID can be obtained from the 'topicId' field in the response of the 'list_problem_solutions' tool. Format is typically a string of numbers and letters that uniquely identifies the solution in LeetCode's database." ) }, async ({ topicId }) => { try { const data = await this.leetcodeService.fetchSolutionArticleDetail( topicId ); return { content: [ { type: "text", text: JSON.stringify({ topicId, solution: data }) } ] }; } catch (error: any) { return { content: [ { type: "text", text: JSON.stringify({ error: "Failed to fetch solution detail", message: error.message }) } ] }; } } );
- src/mcp/tools/solution-tools.ts:255-297 (registration)MCP tool registration for 'get_problem_solution' in China (CN) context: defines schema (slug), description, and handler that calls LeetCode service to fetch solution details.this.server.tool( "get_problem_solution", "Retrieves the complete content and metadata of a specific solution, including the full article text, author information, and related navigation links", { slug: z .string() .describe( "The unique slug/identifier of the solution to retrieve. This slug can be obtained from the 'node.slug' field in the response of the 'list_problem_solutions' tool. A URL-friendly slug string to identify solutions." ) }, async ({ slug }) => { try { const data = await this.leetcodeService.fetchSolutionArticleDetail( slug ); return { content: [ { type: "text", text: JSON.stringify({ slug, solution: data }) } ] }; } catch (error: any) { return { content: [ { type: "text", text: JSON.stringify({ error: "Failed to fetch solution detail", message: error.message }) } ] }; } } );
- Core handler logic for fetching solution article details in LeetCode Global service using GraphQL query with topicId.async fetchSolutionArticleDetail(topicId: string): Promise<any> { return await this.leetCodeApi .graphql({ query: SOLUTION_ARTICLE_DETAIL_QUERY, variables: { topicId } }) .then((response) => { return response.data?.ugcArticleSolutionArticle; }); }
- Core handler logic for fetching solution article details in LeetCode CN service using GraphQL query with slug.async fetchSolutionArticleDetail(slug: string): Promise<any> { return await this.leetCodeApi .graphql({ query: SOLUTION_ARTICLE_DETAIL_QUERY, variables: { slug } }) .then((res) => { return res.data?.solutionArticle; }); }