refactor(mcp): Change priority field to string enum

Amolith created

Update the 'priority' field in the MCP schema from a number between -2 and 2 to
a string enum with values like 'lowest', 'low', and 'highest'. This provides a
more descriptive way to specify task priority.

Translate the string input to the corresponding integer value before processing
the task creation.

Change summary

main.go | 36 +++++++++++++++++++++++++-----------
1 file changed, 25 insertions(+), 11 deletions(-)

Detailed changes

main.go 🔗

@@ -239,10 +239,9 @@ func NewMCPServer(config *Config) *server.MCPServer {
 			mcp.Min(0),
 			mcp.Max(1440),
 		),
-		mcp.WithNumber("priority",
-			mcp.Description("Task priority, -2 being lowest, 0 being normal, and 2 being highest"),
-			mcp.Min(-2),
-			mcp.Max(2),
+		mcp.WithString("priority",
+			mcp.Description("Task priority, omit unless priority is mentioned"),
+			mcp.Enum("lowest", "low", "neutral", "high", "highest"),
 		),
 		mcp.WithString("motivation",
 			mcp.Description("Motivation driving task creation"),
@@ -400,14 +399,29 @@ func handleCreateTask(
 		}
 	}
 
-	if priorityVal, exists := arguments["priority"]; exists && priorityVal != nil {
-		if priority, ok := priorityVal.(float64); ok {
-			if priority < -2 || priority > 2 {
-				return reportMCPError("'priority' must be between -2 and 2 (inclusive)")
-			}
-		} else {
-			return reportMCPError("'priority' must be a number")
+	// Priority translation and validation
+	priorityMap := map[string]int{
+		"lowest":  -2,
+		"low":     -1,
+		"neutral": 0,
+		"high":    1,
+		"highest": 2,
+	}
+
+	if priorityArg, exists := arguments["priority"]; exists && priorityArg != nil {
+		priorityStr, ok := priorityArg.(string)
+		if !ok {
+			// This should ideally be caught by MCP schema validation if type is string.
+			return reportMCPError("Invalid type for 'priority' argument: expected string.")
+		}
+		// An empty string for priority is not valid as it's not in the enum.
+		// The map lookup will fail for an empty string, triggering the !isValid block.
+
+		translatedPriority, isValid := priorityMap[strings.ToLower(priorityStr)]
+		if !isValid {
+			return reportMCPError(fmt.Sprintf("Invalid 'priority' value: '%s'. Must be one of 'lowest', 'low', 'neutral', 'high', 'highest'.", priorityStr))
 		}
+		arguments["priority"] = translatedPriority // Update the map with the integer value
 	}
 
 	if motivationVal, exists := arguments["motivation"]; exists && motivationVal != nil {