@@ -104,15 +104,31 @@ func main() {
// loadLocation loads a timezone location string, returning a *time.Location or error
func loadLocation(timezone string) (*time.Location, error) {
if timezone == "" {
- return nil, fmt.Errorf("Timezone is not configured; please set the 'timezone' value in your config file (e.g. 'UTC' or 'America/New_York')")
+ return nil, fmt.Errorf("timezone is not configured; please set the 'timezone' value in your config file (e.g. 'UTC' or 'America/New_York')")
}
loc, err := time.LoadLocation(timezone)
if err != nil {
- return nil, fmt.Errorf("Could not load timezone '%s': %v", timezone, err)
+ return nil, fmt.Errorf("could not load timezone '%s': %v", timezone, err)
}
return loc, nil
}
+// closeResponseBody properly closes an HTTP response body, handling any errors
+func closeResponseBody(resp *http.Response) {
+ err := resp.Body.Close()
+ if err != nil {
+ log.Printf("Error closing response body: %v", err)
+ }
+}
+
+// closeFile properly closes a file, handling any errors
+func closeFile(f *os.File) {
+ err := f.Close()
+ if err != nil {
+ log.Printf("Error closing file: %v", err)
+ }
+}
+
func NewMCPServer(config *Config) *server.MCPServer {
hooks := &server.Hooks{}
@@ -360,7 +376,7 @@ func handleCreateTask(
if err != nil {
return reportMCPError(fmt.Sprintf("Failed to send HTTP request: %v", err))
}
- defer resp.Body.Close()
+ defer closeResponseBody(resp)
if resp.StatusCode == http.StatusNoContent {
return &mcp.CallToolResult{
@@ -425,7 +441,7 @@ func createDefaultConfigFile(configPath string) {
if err != nil {
log.Fatalf("Failed to create default config at %s: %v", configPath, err)
}
- defer file.Close()
+ defer closeFile(file)
if err := toml.NewEncoder(file).Encode(defaultConfig); err != nil {
log.Fatalf("Failed to encode default config to %s: %v", configPath, err)
}