11/**
22 * MCP Tool validation schemas
3- *
3+ *
44 * This module defines Zod schemas for validating MCP tool arguments.
55 * It reuses business logic schemas from @codervisor/devlog-core and adds
66 * MCP-specific validation layers.
@@ -12,7 +12,6 @@ import {
1212 UpdateDevlogEntrySchema ,
1313 DevlogIdSchema ,
1414 DevlogFilterSchema ,
15-
1615 CreateProjectRequestSchema ,
1716 UpdateProjectRequestSchema ,
1817 ProjectIdSchema ,
@@ -21,25 +20,29 @@ import {
2120/**
2221 * Devlog tool argument schemas
2322 */
24- export const CreateDevlogArgsSchema = z . object ( {
25- title : z . string ( ) . min ( 1 , 'Title is required' ) . max ( 200 , 'Title too long' ) ,
26- type : z . enum ( [ 'feature' , 'bugfix' , 'task' , 'refactor' , 'docs' ] ) ,
27- description : z . string ( ) . min ( 1 , 'Description is required' ) . max ( 2000 , 'Description too long' ) ,
28- priority : z . enum ( [ 'low' , 'medium' , 'high' , 'critical' ] ) . optional ( ) ,
29- businessContext : z . string ( ) . max ( 1000 ) . optional ( ) ,
30- technicalContext : z . string ( ) . max ( 1000 ) . optional ( ) ,
31- acceptanceCriteria : z . array ( z . string ( ) ) . optional ( ) ,
32- } ) . transform ( data => ( {
33- ...data ,
34- priority : data . priority ?? 'medium' as const ,
35- } ) ) ;
23+ export const CreateDevlogArgsSchema = z
24+ . object ( {
25+ title : z . string ( ) . min ( 1 , 'Title is required' ) . max ( 200 , 'Title too long' ) ,
26+ type : z . enum ( [ 'feature' , 'bugfix' , 'task' , 'refactor' , 'docs' ] ) ,
27+ description : z . string ( ) . min ( 1 , 'Description is required' ) ,
28+ priority : z . enum ( [ 'low' , 'medium' , 'high' , 'critical' ] ) . optional ( ) ,
29+ businessContext : z . string ( ) . optional ( ) ,
30+ technicalContext : z . string ( ) . optional ( ) ,
31+ acceptanceCriteria : z . array ( z . string ( ) ) . optional ( ) ,
32+ } )
33+ . transform ( ( data ) => ( {
34+ ...data ,
35+ priority : data . priority ?? ( 'medium' as const ) ,
36+ } ) ) ;
3637
3738export const UpdateDevlogArgsSchema = z . object ( {
3839 id : DevlogIdSchema ,
39- status : z . enum ( [ 'new' , 'in-progress' , 'blocked' , 'in-review' , 'testing' , 'done' , 'cancelled' ] ) . optional ( ) ,
40+ status : z
41+ . enum ( [ 'new' , 'in-progress' , 'blocked' , 'in-review' , 'testing' , 'done' , 'cancelled' ] )
42+ . optional ( ) ,
4043 priority : z . enum ( [ 'low' , 'medium' , 'high' , 'critical' ] ) . optional ( ) ,
41- businessContext : z . string ( ) . max ( 1000 ) . optional ( ) ,
42- technicalContext : z . string ( ) . max ( 1000 ) . optional ( ) ,
44+ businessContext : z . string ( ) . optional ( ) ,
45+ technicalContext : z . string ( ) . optional ( ) ,
4346 acceptanceCriteria : z . array ( z . string ( ) ) . optional ( ) ,
4447} ) ;
4548
@@ -48,7 +51,9 @@ export const GetDevlogArgsSchema = z.object({
4851} ) ;
4952
5053export const ListDevlogsArgsSchema = z . object ( {
51- status : z . enum ( [ 'new' , 'in-progress' , 'blocked' , 'in-review' , 'testing' , 'done' , 'cancelled' ] ) . optional ( ) ,
54+ status : z
55+ . enum ( [ 'new' , 'in-progress' , 'blocked' , 'in-review' , 'testing' , 'done' , 'cancelled' ] )
56+ . optional ( ) ,
5257 type : z . enum ( [ 'feature' , 'bugfix' , 'task' , 'refactor' , 'docs' ] ) . optional ( ) ,
5358 priority : z . enum ( [ 'low' , 'medium' , 'high' , 'critical' ] ) . optional ( ) ,
5459 archived : z . boolean ( ) . optional ( ) ,
@@ -60,35 +65,43 @@ export const ListDevlogsArgsSchema = z.object({
6065
6166export const SearchDevlogsArgsSchema = z . object ( {
6267 query : z . string ( ) . min ( 1 , 'Search query is required' ) ,
63- status : z . enum ( [ 'new' , 'in-progress' , 'blocked' , 'in-review' , 'testing' , 'done' , 'cancelled' ] ) . optional ( ) ,
68+ status : z
69+ . enum ( [ 'new' , 'in-progress' , 'blocked' , 'in-review' , 'testing' , 'done' , 'cancelled' ] )
70+ . optional ( ) ,
6471 type : z . enum ( [ 'feature' , 'bugfix' , 'task' , 'refactor' , 'docs' ] ) . optional ( ) ,
6572 priority : z . enum ( [ 'low' , 'medium' , 'high' , 'critical' ] ) . optional ( ) ,
6673 archived : z . boolean ( ) . optional ( ) ,
6774} ) ;
6875
69- export const AddDevlogNoteArgsSchema = z . object ( {
70- id : DevlogIdSchema ,
71- note : z . string ( ) . min ( 1 , 'Note content is required' ) ,
72- category : z . enum ( [ 'progress' , 'issue' , 'solution' , 'idea' , 'reminder' , 'feedback' ] ) . optional ( ) ,
73- files : z . array ( z . string ( ) ) . optional ( ) ,
74- codeChanges : z . string ( ) . optional ( ) ,
75- } ) . transform ( data => ( {
76- ...data ,
77- category : data . category ?? 'progress' as const ,
78- } ) ) ;
79-
80- export const UpdateDevlogWithNoteArgsSchema = z . object ( {
81- id : DevlogIdSchema ,
82- status : z . enum ( [ 'new' , 'in-progress' , 'blocked' , 'in-review' , 'testing' , 'done' , 'cancelled' ] ) . optional ( ) ,
83- priority : z . enum ( [ 'low' , 'medium' , 'high' , 'critical' ] ) . optional ( ) ,
84- note : z . string ( ) . min ( 1 , 'Note content is required' ) ,
85- category : z . enum ( [ 'progress' , 'issue' , 'solution' , 'idea' , 'reminder' , 'feedback' ] ) . optional ( ) ,
86- files : z . array ( z . string ( ) ) . optional ( ) ,
87- codeChanges : z . string ( ) . optional ( ) ,
88- } ) . transform ( data => ( {
89- ...data ,
90- category : data . category ?? 'progress' as const ,
91- } ) ) ;
76+ export const AddDevlogNoteArgsSchema = z
77+ . object ( {
78+ id : DevlogIdSchema ,
79+ note : z . string ( ) . min ( 1 , 'Note content is required' ) ,
80+ category : z . enum ( [ 'progress' , 'issue' , 'solution' , 'idea' , 'reminder' , 'feedback' ] ) . optional ( ) ,
81+ files : z . array ( z . string ( ) ) . optional ( ) ,
82+ codeChanges : z . string ( ) . optional ( ) ,
83+ } )
84+ . transform ( ( data ) => ( {
85+ ...data ,
86+ category : data . category ?? ( 'progress' as const ) ,
87+ } ) ) ;
88+
89+ export const UpdateDevlogWithNoteArgsSchema = z
90+ . object ( {
91+ id : DevlogIdSchema ,
92+ status : z
93+ . enum ( [ 'new' , 'in-progress' , 'blocked' , 'in-review' , 'testing' , 'done' , 'cancelled' ] )
94+ . optional ( ) ,
95+ priority : z . enum ( [ 'low' , 'medium' , 'high' , 'critical' ] ) . optional ( ) ,
96+ note : z . string ( ) . min ( 1 , 'Note content is required' ) ,
97+ category : z . enum ( [ 'progress' , 'issue' , 'solution' , 'idea' , 'reminder' , 'feedback' ] ) . optional ( ) ,
98+ files : z . array ( z . string ( ) ) . optional ( ) ,
99+ codeChanges : z . string ( ) . optional ( ) ,
100+ } )
101+ . transform ( ( data ) => ( {
102+ ...data ,
103+ category : data . category ?? ( 'progress' as const ) ,
104+ } ) ) ;
92105
93106export const CompleteDevlogArgsSchema = z . object ( {
94107 id : DevlogIdSchema ,
@@ -153,17 +166,17 @@ export class McpToolValidator {
153166 */
154167 static validate < T > (
155168 schema : z . ZodSchema < T > ,
156- data : unknown
169+ data : unknown ,
157170 ) : { success : true ; data : T } | { success : false ; errors : string [ ] } {
158171 const result = schema . safeParse ( data ) ;
159-
172+
160173 if ( result . success ) {
161174 return { success : true , data : result . data } ;
162175 }
163176
164177 return {
165178 success : false ,
166- errors : result . error . errors . map ( err => `${ err . path . join ( '.' ) } : ${ err . message } ` ) ,
179+ errors : result . error . errors . map ( ( err ) => `${ err . path . join ( '.' ) } : ${ err . message } ` ) ,
167180 } ;
168181 }
169182
0 commit comments