Skip to main content
Glama

get-problem

Retrieve LeetCode problem details using the problem's URL slug to access content, constraints, and test cases for coding practice or AI integration.

Input Schema

NameRequiredDescriptionDefault
titleSlugYesThe URL slug of the problem (e.g., 'two-sum')

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "titleSlug": { "description": "The URL slug of the problem (e.g., 'two-sum')", "type": "string" } }, "required": [ "titleSlug" ], "type": "object" }

Implementation Reference

  • Handler for the 'get-problem' tool. Fetches problem details from LeetCodeService based on titleSlug and returns formatted content or error.
    async ({ titleSlug }) => { try { const data = await leetcodeService.fetchProblem(titleSlug); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] }; } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [{ type: "text", text: `Error: ${errorMessage}` }], isError: true }; } }
  • Input validation schema using Zod for the titleSlug parameter of get-problem tool.
    { titleSlug: z.string().describe("The URL slug of the problem (e.g., 'two-sum')") },
  • src/index.ts:22-22 (registration)
    Registers the problem tools including 'get-problem' by calling registerProblemTools on the MCP server instance.
    registerProblemTools(server, leetcodeService);
  • Service helper method that executes the GraphQL query to retrieve problem details for the given titleSlug.
    async fetchProblem(titleSlug: string) { return this.executeQuery(problemDetailsQuery, { titleSlug }); }
  • GraphQL query schema defining the data structure fetched for problem details in the get-problem tool.
    export const problemDetailsQuery = ` query questionData($titleSlug: String!) { question(titleSlug: $titleSlug) { questionId questionFrontendId boundTopicId title titleSlug content translatedTitle difficulty likes dislikes isLiked similarQuestions exampleTestcases contributors { username profileUrl avatarUrl } topicTags { name slug } companyTagStats codeSnippets { lang langSlug code } stats hints solution { id canSeeDetail paidOnly hasVideoSolution } status sampleTestCase metaData judgerAvailable judgeType mysqlSchemas enableRunCode enableTestMode enableDebugger envInfo } } `;

Other Tools

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

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