From d774a297aeddb28b88134b7111fed2648bb0c5b8 Mon Sep 17 00:00:00 2001 From: Amolith Date: Mon, 12 May 2025 22:59:50 -0600 Subject: [PATCH] refactor(mcp): Change priority field to string enum 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. --- main.go | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/main.go b/main.go index 2bdf8944caef60c661c8560fc18e5fc60dbda9d5..cb2f2610e6b7edd974d80d0039d057b923fb4f08 100644 --- a/main.go +++ b/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 {