Skip to main content
Glama

get-problem

Retrieve LeetCode problem details by providing the URL slug to access coding challenges and solutions.

Input Schema

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

Implementation Reference

  • 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 }; } }
  • 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')") },
  • 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 }); }

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