Skip to main content
Glama

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
NameRequiredDescriptionDefault
topicIdYesThe 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

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

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