Skip to main content
Glama
jinzcdev

LeetCode MCP Server

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;
            });
    }
Behavior3/5

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

No annotations are provided, so the description carries the full burden. It describes the retrieval action and the type of data returned (content, metadata, text, author info, links), which adds useful context beyond basic read operations. However, it lacks details on behavioral traits such as error handling, rate limits, authentication needs, or whether the operation is idempotent, leaving gaps for a tool with no annotation coverage.

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 a single, well-structured sentence that efficiently conveys the tool's purpose and scope without unnecessary words. It front-loads the key action ('retrieves') and details the included elements, making it easy to understand quickly. Every part of the sentence adds value.

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?

Given the tool's complexity (a read operation with one parameter) and the absence of annotations and output schema, the description is moderately complete. It explains what is retrieved but does not cover output format, error cases, or other behavioral aspects. For a tool with no structured output information, more detail on return values would be beneficial, but it meets the minimum viable standard.

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

Parameters4/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 documents the single parameter 'topicId' with its format and source. The description does not add specific parameter semantics beyond what the schema provides, but since there is only one parameter and the schema coverage is high, the baseline is 3. The description's mention of 'specific solution' aligns with the parameter's purpose, slightly enhancing clarity, warranting a score of 4.

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 verb 'retrieves' and specifies the resource as 'complete content and metadata of a specific solution', including details like 'full article text, author information, and related navigation links'. It distinguishes from siblings like 'list_problem_solutions' (which lists solutions) and 'get_problem' (which retrieves problem details rather than solutions).

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

Usage Guidelines4/5

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

The description implies usage for retrieving a specific solution's details, and the input schema's description references the 'list_problem_solutions' tool as a source for the topicId, providing some context. However, it does not explicitly state when to use this tool versus alternatives like 'get_problem' or 'search_problems', nor does it mention exclusions or prerequisites beyond the topicId requirement.

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