Skip to content

fix: handle empty string values in datetime parameters #443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added github-mcp-server
Binary file not shown.
7 changes: 5 additions & 2 deletions pkg/github/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,9 @@ func ListIssues(getClient GetClientFn, t translations.TranslationHelperFunc) (to
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
if since != "" {
timestamp, err := parseISOTimestamp(since)
// Enhanced validation: handle empty strings, whitespace, and null values
if since != "" && strings.TrimSpace(since) != "" {
timestamp, err := parseISOTimestamp(strings.TrimSpace(since))
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("failed to list issues: %s", err.Error())), nil
}
Expand Down Expand Up @@ -912,6 +913,8 @@ type ReplaceActorsForAssignableInput struct {
// Returns the parsed time or an error if parsing fails.
// Example formats supported: "2023-01-15T14:30:00Z", "2023-01-15"
func parseISOTimestamp(timestamp string) (time.Time, error) {
// Trim whitespace and check for empty string
timestamp = strings.TrimSpace(timestamp)
if timestamp == "" {
return time.Time{}, fmt.Errorf("empty timestamp")
}
Expand Down
13 changes: 7 additions & 6 deletions pkg/github/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"net/http"
"strconv"
"strings"
"time"

"github.com/github/github-mcp-server/pkg/translations"
Expand Down Expand Up @@ -93,16 +94,16 @@ func ListNotifications(getClient GetClientFn, t translations.TranslationHelperFu
}

// Parse time parameters if provided
if since != "" {
sinceTime, err := time.Parse(time.RFC3339, since)
if since != "" && strings.TrimSpace(since) != "" {
sinceTime, err := time.Parse(time.RFC3339, strings.TrimSpace(since))
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("invalid since time format, should be RFC3339/ISO8601: %v", err)), nil
}
opts.Since = sinceTime
}

if before != "" {
beforeTime, err := time.Parse(time.RFC3339, before)
if before != "" && strings.TrimSpace(before) != "" {
beforeTime, err := time.Parse(time.RFC3339, strings.TrimSpace(before))
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("invalid before time format, should be RFC3339/ISO8601: %v", err)), nil
}
Expand Down Expand Up @@ -242,8 +243,8 @@ func MarkAllNotificationsRead(getClient GetClientFn, t translations.TranslationH
}

var lastReadTime time.Time
if lastReadAt != "" {
lastReadTime, err = time.Parse(time.RFC3339, lastReadAt)
if lastReadAt != "" && strings.TrimSpace(lastReadAt) != "" {
lastReadTime, err = time.Parse(time.RFC3339, strings.TrimSpace(lastReadAt))
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("invalid lastReadAt time format, should be RFC3339/ISO8601: %v", err)), nil
}
Expand Down