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
| Name | Required | Description | Default |
|---|---|---|---|
| titleSlug | Yes | The 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
- src/tools/problem-tools.ts:35-51 (handler)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 }; } }
- src/tools/problem-tools.ts:32-34 (schema)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 }); }
- src/graphql/queries.ts:93-144 (schema)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 } } `;