Skip to content

Commit 35921e5

Browse files
committed
removed unnecessary file
1 parent 0f92ee9 commit 35921e5

File tree

2 files changed

+65
-2
lines changed

2 files changed

+65
-2
lines changed

Sources/SwiftMCPMacros/MCPDiagnostics.swift

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

Sources/SwiftMCPMacros/MCPToolMacro.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,37 @@ public struct MCPToolMacro: PeerMacro {
155155
context.diagnose(diagnostic)
156156
}
157157

158+
// Check for optional parameters without default values
159+
let isOptional = param.type.is(OptionalTypeSyntax.self) ||
160+
param.type.is(ImplicitlyUnwrappedOptionalTypeSyntax.self) ||
161+
paramType.hasSuffix("?") ||
162+
paramType.hasSuffix("!")
163+
164+
if isOptional && param.defaultValue == nil {
165+
let diagnostic = Diagnostic(
166+
node: param.type,
167+
message: MCPToolDiagnostic.optionalParameterNeedsDefault(
168+
paramName: paramName,
169+
typeName: paramType
170+
),
171+
fixIts: [
172+
FixIt(
173+
message: MCPToolFixItMessage.addDefaultValue(paramName: paramName),
174+
changes: [
175+
.replace(
176+
oldNode: Syntax(param),
177+
newNode: Syntax(param.with(\.defaultValue, InitializerClauseSyntax(
178+
equal: TokenSyntax.equalToken(leadingTrivia: .spaces(1), trailingTrivia: .spaces(1)),
179+
value: ExprSyntax(NilLiteralExprSyntax())
180+
)))
181+
)
182+
]
183+
)
184+
]
185+
)
186+
context.diagnose(diagnostic)
187+
}
188+
158189
// Store parameter info for wrapper function generation
159190

160191
// Special case for the longDescription function's text parameter in tests

0 commit comments

Comments
 (0)