get-problem
Retrieve LeetCode problem details by providing the URL slug to access coding challenges and solutions.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| titleSlug | Yes | The URL slug of the problem (e.g., 'two-sum') |
Implementation Reference
- src/tools/problem-tools.ts:35-51 (handler)The handler function for the "get-problem" tool. It takes a titleSlug parameter, fetches the problem data from LeetCodeService, and returns the data as a formatted JSON text content block or an error response.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 schema for the "get-problem" tool using Zod, defining the required titleSlug string parameter.{ titleSlug: z.string().describe("The URL slug of the problem (e.g., 'two-sum')") },
- src/tools/problem-tools.ts:30-52 (registration)Registration of the "get-problem" tool on the MCP server, specifying the name, input schema, and handler function.server.tool( "get-problem", { titleSlug: z.string().describe("The URL slug of the problem (e.g., 'two-sum')") }, 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 }; } } );
- Helper method in LeetCodeService that fetches problem details by executing a GraphQL query with the given titleSlug.async fetchProblem(titleSlug: string) { return this.executeQuery(problemDetailsQuery, { titleSlug }); }