@@ -66,7 +66,18 @@ apiClient.interceptors.request.use(
66
66
}
67
67
)
68
68
69
- function handleError ( error : unknown ) {
69
+ function handleResult ( data : unknown ) : CallToolResult {
70
+ return {
71
+ content : [
72
+ {
73
+ type : 'text' ,
74
+ text : JSON . stringify ( data , null , 2 ) ,
75
+ } ,
76
+ ] ,
77
+ }
78
+ }
79
+
80
+ function handleError ( error : unknown ) : CallToolResult {
70
81
console . error ( error )
71
82
logger . error ( 'Error occurred:' , JSON . stringify ( error ) )
72
83
@@ -85,19 +96,224 @@ function handleError(error: unknown) {
85
96
}
86
97
87
98
// Tools
88
- mcpServer . tool ( 'get-journal' , `Get habit journal for a specific date` , { } , async ( args ) => {
99
+ mcpServer . tool (
100
+ 'get-journal' ,
101
+ `Get habit journal for a specific date` ,
102
+ {
103
+ target_date : z
104
+ . string ( )
105
+ . regex ( / ^ \d { 4 } - \d { 2 } - \d { 2 } $ / )
106
+ . optional ( ) ,
107
+ order_by : z . any ( ) . optional ( ) ,
108
+ status : z . any ( ) . optional ( ) ,
109
+ area_id : z . string ( ) . optional ( ) ,
110
+ time_of_day : z . any ( ) . optional ( ) ,
111
+ } ,
112
+ async ( args ) => {
113
+ try {
114
+ const response = await apiClient . get ( '/journal' , {
115
+ params : args ,
116
+ } )
117
+ return handleResult ( response . data )
118
+ } catch ( error ) {
119
+ return handleError ( error )
120
+ }
121
+ }
122
+ )
123
+
124
+ mcpServer . tool (
125
+ 'post-logs-by-id' ,
126
+ `Add a habit log` ,
127
+ {
128
+ habit_id : z . string ( ) . min ( 1 ) ,
129
+ } ,
130
+ async ( args ) => {
131
+ try {
132
+ // Extract path parameters and request data
133
+ const { habit_id, ...requestData } = args
134
+ const url = `/logs/${ habit_id } `
135
+
136
+ const response = await apiClient . post ( url , requestData )
137
+ return handleResult ( response . data )
138
+ } catch ( error ) {
139
+ return handleError ( error )
140
+ }
141
+ }
142
+ )
143
+
144
+ mcpServer . tool (
145
+ 'delete-logs-by-id' ,
146
+ `Delete habit logs in date range` ,
147
+ {
148
+ habit_id : z . string ( ) . min ( 1 ) ,
149
+ start_date : z . string ( ) . regex ( / ^ \d { 4 } - \d { 2 } - \d { 2 } $ / ) ,
150
+ end_date : z . string ( ) . regex ( / ^ \d { 4 } - \d { 2 } - \d { 2 } $ / ) ,
151
+ } ,
152
+ async ( args ) => {
153
+ try {
154
+ // Extract path parameters and query parameters
155
+ const { habit_id, ...queryParams } = args
156
+ const url = `/logs/${ habit_id } `
157
+
158
+ const response = await apiClient . delete ( url , {
159
+ params : queryParams ,
160
+ } )
161
+ return handleResult ( response . data )
162
+ } catch ( error ) {
163
+ return handleError ( error )
164
+ }
165
+ }
166
+ )
167
+
168
+ mcpServer . tool (
169
+ 'delete-logs-by-id-by-id' ,
170
+ `Delete a specific habit log` ,
171
+ {
172
+ habit_id : z . string ( ) . min ( 1 ) ,
173
+ log_id : z . string ( ) . min ( 1 ) ,
174
+ } ,
175
+ async ( args ) => {
176
+ try {
177
+ // Extract path parameters and query parameters
178
+ const { habit_id, log_id, ...queryParams } = args
179
+ const url = `/logs/${ habit_id } /${ log_id } `
180
+
181
+ const response = await apiClient . delete ( url , {
182
+ params : queryParams ,
183
+ } )
184
+ return handleResult ( response . data )
185
+ } catch ( error ) {
186
+ return handleError ( error )
187
+ }
188
+ }
189
+ )
190
+
191
+ mcpServer . tool (
192
+ 'get-habits' ,
193
+ `Get all habits` ,
194
+ {
195
+ status : z . any ( ) . optional ( ) ,
196
+ area_id : z . string ( ) . optional ( ) ,
197
+ } ,
198
+ async ( args ) => {
199
+ try {
200
+ const response = await apiClient . get ( '/habits' , {
201
+ params : args ,
202
+ } )
203
+ return handleResult ( response . data )
204
+ } catch ( error ) {
205
+ return handleError ( error )
206
+ }
207
+ }
208
+ )
209
+
210
+ mcpServer . tool (
211
+ 'get-habits-by-id' ,
212
+ `Get habit details` ,
213
+ {
214
+ habit_id : z . string ( ) . min ( 1 ) ,
215
+ } ,
216
+ async ( args ) => {
217
+ try {
218
+ // Extract path parameters and query parameters
219
+ const { habit_id, ...queryParams } = args
220
+ const url = `/habits/${ habit_id } `
221
+
222
+ const response = await apiClient . get ( url , {
223
+ params : queryParams ,
224
+ } )
225
+ return handleResult ( response . data )
226
+ } catch ( error ) {
227
+ return handleError ( error )
228
+ }
229
+ }
230
+ )
231
+
232
+ mcpServer . tool ( 'get-areas' , `Get all areas` , { } , async ( args ) => {
89
233
try {
90
- const response = await apiClient . get ( '/journal ' , {
234
+ const response = await apiClient . get ( '/areas ' , {
91
235
params : args ,
92
236
} )
93
- return {
94
- content : [
95
- {
96
- type : 'text' ,
97
- text : JSON . stringify ( response . data , null , 2 ) ,
98
- } ,
99
- ] ,
237
+ return handleResult ( response . data )
238
+ } catch ( error ) {
239
+ return handleError ( error )
240
+ }
241
+ } )
242
+
243
+ mcpServer . tool (
244
+ 'get-moods' ,
245
+ `Get mood entries` ,
246
+ {
247
+ start_date : z
248
+ . string ( )
249
+ . regex ( / ^ \d { 4 } - \d { 2 } - \d { 2 } $ / )
250
+ . optional ( ) ,
251
+ end_date : z
252
+ . string ( )
253
+ . regex ( / ^ \d { 4 } - \d { 2 } - \d { 2 } $ / )
254
+ . optional ( ) ,
255
+ } ,
256
+ async ( args ) => {
257
+ try {
258
+ const response = await apiClient . get ( '/moods' , {
259
+ params : args ,
260
+ } )
261
+ return handleResult ( response . data )
262
+ } catch ( error ) {
263
+ return handleError ( error )
264
+ }
265
+ }
266
+ )
267
+
268
+ mcpServer . tool ( 'post-moods' , `Add mood entry` , { } , async ( args ) => {
269
+ try {
270
+ const response = await apiClient . post ( '/moods' , args )
271
+ return handleResult ( response . data )
272
+ } catch ( error ) {
273
+ return handleError ( error )
274
+ }
275
+ } )
276
+
277
+ mcpServer . tool (
278
+ 'get-notes' ,
279
+ `Get notes` ,
280
+ {
281
+ start_date : z
282
+ . string ( )
283
+ . regex ( / ^ \d { 4 } - \d { 2 } - \d { 2 } $ / )
284
+ . optional ( ) ,
285
+ end_date : z
286
+ . string ( )
287
+ . regex ( / ^ \d { 4 } - \d { 2 } - \d { 2 } $ / )
288
+ . optional ( ) ,
289
+ } ,
290
+ async ( args ) => {
291
+ try {
292
+ const response = await apiClient . get ( '/notes' , {
293
+ params : args ,
294
+ } )
295
+ return handleResult ( response . data )
296
+ } catch ( error ) {
297
+ return handleError ( error )
100
298
}
299
+ }
300
+ )
301
+
302
+ mcpServer . tool ( 'post-notes' , `Add note` , { } , async ( args ) => {
303
+ try {
304
+ const response = await apiClient . post ( '/notes' , args )
305
+ return handleResult ( response . data )
306
+ } catch ( error ) {
307
+ return handleError ( error )
308
+ }
309
+ } )
310
+
311
+ mcpServer . tool ( 'get-actions' , `Get available actions` , { } , async ( args ) => {
312
+ try {
313
+ const response = await apiClient . get ( '/actions' , {
314
+ params : args ,
315
+ } )
316
+ return handleResult ( response . data )
101
317
} catch ( error ) {
102
318
return handleError ( error )
103
319
}
0 commit comments