3
3
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js" ;
4
4
import { Server } from "@modelcontextprotocol/sdk/server/index.js" ;
5
5
import { TaskManager } from "./src/server/TaskManager.js" ;
6
- import { ALL_TOOLS } from "./src/server/tools.js" ;
6
+ import { ALL_TOOLS , executeToolWithErrorHandling } from "./src/server/tools.js" ;
7
7
import { ListToolsRequestSchema , CallToolRequestSchema } from "@modelcontextprotocol/sdk/types.js" ;
8
8
9
9
// Create server with capabilities BEFORE setting up handlers
10
10
const server = new Server (
11
11
{
12
12
name : "task-manager-server" ,
13
- version : "1.0.9 "
13
+ version : "1.1.0 "
14
14
} ,
15
15
{
16
16
capabilities : {
@@ -28,7 +28,7 @@ console.error('Server starting with env:', {
28
28
NODE_ENV : process . env . NODE_ENV
29
29
} ) ;
30
30
31
- // Initialize task manager
31
+ // Create task manager instance
32
32
const taskManager = new TaskManager ( ) ;
33
33
34
34
// Set up request handlers AFTER capabilities are configured
@@ -39,210 +39,11 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
39
39
} ) ;
40
40
41
41
server . setRequestHandler ( CallToolRequestSchema , async ( request ) => {
42
- try {
43
- const { name } = request . params ;
44
- const args = request . params . arguments || { } ;
45
-
46
- // For validation, ensure args is an object when expected
47
- if ( name !== "list_projects" && name !== "list_tasks" && Object . keys ( args ) . length === 0 ) {
48
- throw new Error ( "Invalid arguments: expected object with parameters" ) ;
49
- }
50
-
51
- switch ( name ) {
52
- // Project tools
53
- case "list_projects" : {
54
- const result = await taskManager . listProjects ( ) ;
55
- return {
56
- content : [ { type : "text" , text : JSON . stringify ( result , null , 2 ) } ] ,
57
- } ;
58
- }
59
-
60
- case "read_project" : {
61
- const projectId = String ( args . projectId ) ;
62
- if ( ! projectId ) {
63
- throw new Error ( "Missing required parameter: projectId" ) ;
64
- }
65
- const result = await taskManager . getNextTask ( projectId ) ;
66
- return {
67
- content : [ { type : "text" , text : JSON . stringify ( result , null , 2 ) } ] ,
68
- } ;
69
- }
70
-
71
- case "create_project" : {
72
- const initialPrompt = String ( args . initialPrompt || "" ) ;
73
- if ( ! initialPrompt || ! args . tasks || ! Array . isArray ( args . tasks ) ) {
74
- throw new Error ( "Missing required parameters: initialPrompt and/or tasks" ) ;
75
- }
76
- const projectPlan = args . projectPlan ? String ( args . projectPlan ) : undefined ;
77
-
78
- const result = await taskManager . createProject (
79
- initialPrompt ,
80
- args . tasks ,
81
- projectPlan
82
- ) ;
83
- return {
84
- content : [ { type : "text" , text : JSON . stringify ( result , null , 2 ) } ] ,
85
- } ;
86
- }
87
-
88
- case "delete_project" : {
89
- const projectId = String ( args . projectId ) ;
90
- if ( ! projectId ) {
91
- throw new Error ( "Missing required parameter: projectId" ) ;
92
- }
93
- // Use the private data and saveTasks via indexing since there's no explicit delete method
94
- const projectIndex = taskManager [ "data" ] . projects . findIndex ( ( p ) => p . projectId === projectId ) ;
95
- if ( projectIndex === - 1 ) {
96
- return {
97
- content : [ { type : "text" , text : JSON . stringify ( { status : "error" , message : "Project not found" } , null , 2 ) } ] ,
98
- } ;
99
- }
100
-
101
- taskManager [ "data" ] . projects . splice ( projectIndex , 1 ) ;
102
- await taskManager [ "saveTasks" ] ( ) ;
103
- return {
104
- content : [ { type : "text" , text : JSON . stringify ( {
105
- status : "project_deleted" ,
106
- message : `Project ${ projectId } has been deleted.`
107
- } , null , 2 ) } ] ,
108
- } ;
109
- }
110
-
111
- case "add_tasks_to_project" : {
112
- const projectId = String ( args . projectId ) ;
113
- if ( ! projectId || ! args . tasks || ! Array . isArray ( args . tasks ) ) {
114
- throw new Error ( "Missing required parameters: projectId and/or tasks" ) ;
115
- }
116
- const result = await taskManager . addTasksToProject ( projectId , args . tasks ) ;
117
- return {
118
- content : [ { type : "text" , text : JSON . stringify ( result , null , 2 ) } ] ,
119
- } ;
120
- }
121
-
122
- case "finalize_project" : {
123
- const projectId = String ( args . projectId ) ;
124
- if ( ! projectId ) {
125
- throw new Error ( "Missing required parameter: projectId" ) ;
126
- }
127
- const result = await taskManager . approveProjectCompletion ( projectId ) ;
128
- return {
129
- content : [ { type : "text" , text : JSON . stringify ( result , null , 2 ) } ] ,
130
- } ;
131
- }
132
-
133
- // Task tools
134
- case "list_tasks" : {
135
- // No explicit list tasks method, so return a message
136
- return {
137
- content : [ { type : "text" , text : JSON . stringify ( {
138
- status : "error" ,
139
- message : "list_tasks functionality to be implemented in future version"
140
- } , null , 2 ) } ] ,
141
- } ;
142
- }
143
-
144
- case "read_task" : {
145
- const taskId = String ( args . taskId ) ;
146
- if ( ! taskId ) {
147
- throw new Error ( "Missing required parameter: taskId" ) ;
148
- }
149
- const result = await taskManager . openTaskDetails ( taskId ) ;
150
- return {
151
- content : [ { type : "text" , text : JSON . stringify ( result , null , 2 ) } ] ,
152
- } ;
153
- }
154
-
155
- case "create_task" : {
156
- const projectId = String ( args . projectId ) ;
157
- const title = String ( args . title || "" ) ;
158
- const description = String ( args . description || "" ) ;
159
-
160
- if ( ! projectId || ! title || ! description ) {
161
- throw new Error ( "Missing required parameters: projectId, title, and/or description" ) ;
162
- }
163
-
164
- const result = await taskManager . addTasksToProject ( projectId , [ {
165
- title,
166
- description
167
- } ] ) ;
168
- return {
169
- content : [ { type : "text" , text : JSON . stringify ( result , null , 2 ) } ] ,
170
- } ;
171
- }
172
-
173
- case "update_task" : {
174
- const projectId = String ( args . projectId ) ;
175
- const taskId = String ( args . taskId ) ;
176
-
177
- if ( ! projectId || ! taskId ) {
178
- throw new Error ( "Missing required parameters: projectId and/or taskId" ) ;
179
- }
180
-
181
- const updates = Object . fromEntries (
182
- Object . entries ( {
183
- title : args . title !== undefined ? String ( args . title ) : undefined ,
184
- description : args . description !== undefined ? String ( args . description ) : undefined ,
185
- status : args . status !== undefined ? String ( args . status ) as "not started" | "in progress" | "done" : undefined ,
186
- completedDetails : args . completedDetails !== undefined ? String ( args . completedDetails ) : undefined ,
187
- toolRecommendations : args . toolRecommendations !== undefined ? String ( args . toolRecommendations ) : undefined ,
188
- ruleRecommendations : args . ruleRecommendations !== undefined ? String ( args . ruleRecommendations ) : undefined
189
- } ) . filter ( ( [ _ , value ] ) => value !== undefined )
190
- ) ;
191
-
192
- const result = await taskManager . updateTask ( projectId , taskId , updates ) ;
193
-
194
- return {
195
- content : [ { type : "text" , text : JSON . stringify ( result , null , 2 ) } ] ,
196
- } ;
197
- }
198
-
199
- case "delete_task" : {
200
- const projectId = String ( args . projectId ) ;
201
- const taskId = String ( args . taskId ) ;
202
-
203
- if ( ! projectId || ! taskId ) {
204
- throw new Error ( "Missing required parameters: projectId and/or taskId" ) ;
205
- }
206
- const result = await taskManager . deleteTask ( projectId , taskId ) ;
207
- return {
208
- content : [ { type : "text" , text : JSON . stringify ( result , null , 2 ) } ] ,
209
- } ;
210
- }
211
-
212
- case "approve_task" : {
213
- const projectId = String ( args . projectId ) ;
214
- const taskId = String ( args . taskId ) ;
215
-
216
- if ( ! projectId || ! taskId ) {
217
- throw new Error ( "Missing required parameters: projectId and/or taskId" ) ;
218
- }
219
- const result = await taskManager . approveTaskCompletion ( projectId , taskId ) ;
220
- return {
221
- content : [ { type : "text" , text : JSON . stringify ( result , null , 2 ) } ] ,
222
- } ;
223
- }
224
-
225
- case "get_next_task" : {
226
- const projectId = String ( args . projectId ) ;
227
- if ( ! projectId ) {
228
- throw new Error ( "Missing required parameter: projectId" ) ;
229
- }
230
- const result = await taskManager . getNextTask ( projectId ) ;
231
- return {
232
- content : [ { type : "text" , text : JSON . stringify ( result , null , 2 ) } ] ,
233
- } ;
234
- }
235
-
236
- default :
237
- throw new Error ( `Unknown tool: ${ name } ` ) ;
238
- }
239
- } catch ( error ) {
240
- const errorMessage = error instanceof Error ? error . message : String ( error ) ;
241
- return {
242
- content : [ { type : "text" , text : `Error: ${ errorMessage } ` } ] ,
243
- isError : true ,
244
- } ;
245
- }
42
+ return executeToolWithErrorHandling (
43
+ request . params . name ,
44
+ request . params . arguments || { } ,
45
+ taskManager
46
+ ) ;
246
47
} ) ;
247
48
248
49
// Start the server
0 commit comments