@@ -29,6 +29,9 @@ enum MCPToolDiagnostic: DiagnosticMessage {
2929
3030 /// Error when a parameter has an unsupported closure type
3131 case closureTypeNotSupported( paramName: String , typeName: String )
32+
33+ /// Error when an optional parameter is missing a default value
34+ case optionalParameterNeedsDefault( paramName: String , typeName: String )
3235
3336 var message : String {
3437 switch self {
@@ -40,18 +43,20 @@ enum MCPToolDiagnostic: DiagnosticMessage {
4043 return " Parameter ' \( paramName) ' has an unsupported default value type ' \( typeName) '. Only numbers, booleans, and strings are supported. "
4144 case . closureTypeNotSupported( let paramName, let typeName) :
4245 return " Parameter ' \( paramName) ' has an unsupported closure type ' \( typeName) '. Closures are not supported in MCP tools. "
46+ case . optionalParameterNeedsDefault( let paramName, let typeName) :
47+ return " Optional parameter ' \( paramName) ' of type ' \( typeName) ' requires a default value (e.g. = nil). "
4348 }
4449 }
4550
4651 var severity : DiagnosticSeverity {
4752 switch self {
48- case . onlyFunctions, . invalidDefaultValueType, . closureTypeNotSupported:
53+ case . onlyFunctions, . invalidDefaultValueType, . closureTypeNotSupported, . optionalParameterNeedsDefault :
4954 return . error
5055 case . missingDescription:
5156 return . warning
5257 }
5358 }
54-
59+
5560 var diagnosticID : MessageID {
5661 switch self {
5762 case . onlyFunctions:
@@ -62,6 +67,33 @@ enum MCPToolDiagnostic: DiagnosticMessage {
6267 return MessageID ( domain: " SwiftMCP " , id: " invalidDefaultValueType " )
6368 case . closureTypeNotSupported:
6469 return MessageID ( domain: " SwiftMCP " , id: " closureTypeNotSupported " )
70+ case . optionalParameterNeedsDefault:
71+ return MessageID ( domain: " SwiftMCP " , id: " optionalParameterNeedsDefault " )
72+ }
73+ }
74+ }
75+
76+ enum MCPToolFixItMessage : FixItMessage {
77+ case addDefaultValue( paramName: String )
78+
79+ var message : String {
80+ switch self {
81+ case . addDefaultValue( let paramName) :
82+ return " Add default value '= nil' for parameter ' \( paramName) ' "
83+ }
84+ }
85+
86+ var diagnosticID : MessageID {
87+ switch self {
88+ case . addDefaultValue:
89+ return MessageID ( domain: " SwiftMCP " , id: " addDefaultValue " )
90+ }
91+ }
92+
93+ var fixItID : MessageID {
94+ switch self {
95+ case . addDefaultValue:
96+ return MessageID ( domain: " SwiftMCP " , id: " addDefaultValue " )
6597 }
6698 }
6799}
0 commit comments