-
Notifications
You must be signed in to change notification settings - Fork 307
Expand file tree
/
Copy pathproblemTools.ts
More file actions
181 lines (167 loc) · 5.43 KB
/
problemTools.ts
File metadata and controls
181 lines (167 loc) · 5.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { z } from 'zod';
import {
addProblemToFavorite,
getDailyProblem,
getDailyProblemLegacy,
getDailyProblemRaw,
getOfficialSolution,
getProblemNote,
getProblemSet,
getProblemStatus,
getSelectProblem,
getSelectProblemRaw,
getSubmissionDetails,
removeProblemFromFavorite,
updateProblemNote,
} from '../leetCodeService';
import { runTool } from '../serverUtils';
import { ToolModule } from '../types';
export class ProblemToolsModule implements ToolModule {
// Registers problem-related tools with the MCP server.
register(server: McpServer): void {
server.registerTool(
'leetcode_problem_daily',
{
title: 'Daily Problem',
description: 'Retrieves the formatted daily challenge',
},
async () => runTool(() => getDailyProblem()),
);
server.registerTool(
'leetcode_problem_daily_raw',
{
title: 'Daily Problem Raw',
description: 'Retrieves the raw daily challenge payload',
},
async () => runTool(() => getDailyProblemRaw()),
);
server.registerTool(
'leetcode_problem_select',
{
title: 'Selected Problem',
description: 'Fetches formatted data for a problem by slug',
inputSchema: {
titleSlug: z.string(),
},
},
async ({ titleSlug }) => runTool(() => getSelectProblem(titleSlug)),
);
server.registerTool(
'leetcode_problem_select_raw',
{
title: 'Selected Problem Raw',
description: 'Fetches raw data for a problem by slug',
inputSchema: {
titleSlug: z.string(),
},
},
async ({ titleSlug }) => runTool(() => getSelectProblemRaw(titleSlug)),
);
server.registerTool(
'leetcode_problem_list',
{
title: 'Problem List',
description: 'Retrieves a filtered set of problems',
inputSchema: {
limit: z.number().int().positive().max(100).optional(),
skip: z.number().int().min(0).optional(),
tags: z.string().optional(),
difficulty: z.enum(['EASY', 'MEDIUM', 'HARD']).optional(),
},
},
async ({ limit, skip, tags, difficulty }) => runTool(() => getProblemSet({ limit, skip, tags, difficulty })),
);
server.registerTool(
'leetcode_problem_official_solution',
{
title: 'Official Solution',
description: 'Retrieves the official LeetCode solution for a problem',
inputSchema: {
titleSlug: z.string(),
},
},
async ({ titleSlug }) => runTool(() => getOfficialSolution(titleSlug)),
);
server.registerTool(
'leetcode_problem_daily_legacy',
{
title: 'Daily Problem Legacy',
description: 'Retrieves the legacy daily challenge payload',
},
async () => runTool(() => getDailyProblemLegacy()),
);
// ── Auth-required tools ───────────────────────────────────────────
server.registerTool(
'leetcode_submission_details',
{
title: 'Submission Details',
description: '[Auth Required] Full submission: source code, runtime, memory, percentiles, errors',
inputSchema: {
submissionId: z.number().int().positive(),
},
},
async ({ submissionId }) => runTool(() => getSubmissionDetails({ submissionId })),
);
server.registerTool(
'leetcode_problem_note',
{
title: 'Problem Note',
description: "[Auth Required] User's personal note on a problem",
inputSchema: {
titleSlug: z.string(),
},
},
async ({ titleSlug }) => runTool(() => getProblemNote(titleSlug)),
);
server.registerTool(
'leetcode_problem_note_update',
{
title: 'Update Problem Note',
description: '[Auth Required] Create/update personal note on a problem',
inputSchema: {
titleSlug: z.string(),
note: z.string(),
},
},
async ({ titleSlug, note }) => runTool(() => updateProblemNote({ titleSlug, note })),
);
server.registerTool(
'leetcode_problem_favorite_add',
{
title: 'Add to Favorites',
description: '[Auth Required] Add problem to a favorites list',
inputSchema: {
favoriteIdHash: z.string(),
questionId: z.string(),
},
},
async ({ favoriteIdHash, questionId }) =>
runTool(() => addProblemToFavorite({ favoriteIdHash, questionId })),
);
server.registerTool(
'leetcode_problem_favorite_remove',
{
title: 'Remove from Favorites',
description: '[Auth Required] Remove problem from a favorites list',
inputSchema: {
favoriteIdHash: z.string(),
questionId: z.string(),
},
},
async ({ favoriteIdHash, questionId }) =>
runTool(() => removeProblemFromFavorite({ favoriteIdHash, questionId })),
);
server.registerTool(
'leetcode_problem_status',
{
title: 'Problem Status',
description: '[Auth Required] Solve status for a specific problem (ac/notac/null) — lighter than full select',
inputSchema: {
titleSlug: z.string(),
},
},
async ({ titleSlug }) => runTool(() => getProblemStatus(titleSlug)),
);
}
}