Skip to content

Commit ef37c96

Browse files
authored
Merge branch 'main' into feat/git-blame-tool
2 parents 8e494d9 + 90a1255 commit ef37c96

File tree

5 files changed

+41
-13
lines changed

5 files changed

+41
-13
lines changed

pkg/github/__toolsnaps__/get_me.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
},
66
"description": "Get details of the authenticated GitHub user. Use this when a request is about the user's own profile for GitHub. Or when information is missing to build other tool calls.",
77
"inputSchema": {
8-
"type": "object"
8+
"type": "object",
9+
"properties": {}
910
},
1011
"name": "get_me"
1112
}

pkg/github/context_tools.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package github
22

33
import (
44
"context"
5+
"encoding/json"
56
"time"
67

78
ghErrors "github.com/github/github-mcp-server/pkg/errors"
@@ -43,9 +44,9 @@ func GetMe(getClient GetClientFn, t translations.TranslationHelperFunc) (mcp.Too
4344
Title: t("TOOL_GET_ME_USER_TITLE", "Get my user profile"),
4445
ReadOnlyHint: true,
4546
},
46-
InputSchema: &jsonschema.Schema{
47-
Type: "object",
48-
},
47+
// Use json.RawMessage to ensure "properties" is included even when empty.
48+
// OpenAI strict mode requires the properties field to be present.
49+
InputSchema: json.RawMessage(`{"type":"object","properties":{}}`),
4950
},
5051
mcp.ToolHandlerFor[map[string]any, any](func(ctx context.Context, _ *mcp.CallToolRequest, _ map[string]any) (*mcp.CallToolResult, any, error) {
5152
client, err := getClient(ctx)

pkg/github/issues.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,11 +1381,14 @@ func ListIssues(getGQLClient GetGQLClientFn, t translations.TranslationHelperFun
13811381
return utils.NewToolResultError(err.Error()), nil, nil
13821382
}
13831383

1384-
// If the state has a value, cast into an array of strings
1384+
// Normalize and filter by state
1385+
state = strings.ToUpper(state)
13851386
var states []githubv4.IssueState
1386-
if state != "" {
1387-
states = append(states, githubv4.IssueState(state))
1388-
} else {
1387+
1388+
switch state {
1389+
case "OPEN", "CLOSED":
1390+
states = []githubv4.IssueState{githubv4.IssueState(state)}
1391+
default:
13891392
states = []githubv4.IssueState{githubv4.IssueStateOpen, githubv4.IssueStateClosed}
13901393
}
13911394

@@ -1405,13 +1408,21 @@ func ListIssues(getGQLClient GetGQLClientFn, t translations.TranslationHelperFun
14051408
return utils.NewToolResultError(err.Error()), nil, nil
14061409
}
14071410

1408-
// These variables are required for the GraphQL query to be set by default
1409-
// If orderBy is empty, default to CREATED_AT
1410-
if orderBy == "" {
1411+
// Normalize and validate orderBy
1412+
orderBy = strings.ToUpper(orderBy)
1413+
switch orderBy {
1414+
case "CREATED_AT", "UPDATED_AT", "COMMENTS":
1415+
// Valid, keep as is
1416+
default:
14111417
orderBy = "CREATED_AT"
14121418
}
1413-
// If direction is empty, default to DESC
1414-
if direction == "" {
1419+
1420+
// Normalize and validate direction
1421+
direction = strings.ToUpper(direction)
1422+
switch direction {
1423+
case "ASC", "DESC":
1424+
// Valid, keep as is
1425+
default:
14151426
direction = "DESC"
14161427
}
14171428

pkg/github/issues_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,16 @@ func Test_ListIssues(t *testing.T) {
11831183
expectError: false,
11841184
expectedCount: 2,
11851185
},
1186+
{
1187+
name: "filter by open state - lc",
1188+
reqParams: map[string]interface{}{
1189+
"owner": "owner",
1190+
"repo": "repo",
1191+
"state": "open",
1192+
},
1193+
expectError: false,
1194+
expectedCount: 2,
1195+
},
11861196
{
11871197
name: "filter by closed state",
11881198
reqParams: map[string]interface{}{
@@ -1229,6 +1239,9 @@ func Test_ListIssues(t *testing.T) {
12291239
case "filter by open state":
12301240
matcher := githubv4mock.NewQueryMatcher(qBasicNoLabels, varsOpenOnly, mockResponseOpenOnly)
12311241
httpClient = githubv4mock.NewMockedHTTPClient(matcher)
1242+
case "filter by open state - lc":
1243+
matcher := githubv4mock.NewQueryMatcher(qBasicNoLabels, varsOpenOnly, mockResponseOpenOnly)
1244+
httpClient = githubv4mock.NewMockedHTTPClient(matcher)
12321245
case "filter by closed state":
12331246
matcher := githubv4mock.NewQueryMatcher(qBasicNoLabels, varsClosedOnly, mockResponseClosedOnly)
12341247
httpClient = githubv4mock.NewMockedHTTPClient(matcher)

pkg/github/repositories.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,8 @@ func CreateOrUpdateFile(getClient GetClientFn, t translations.TranslationHelperF
403403
if err != nil {
404404
return nil, nil, fmt.Errorf("failed to get GitHub client: %w", err)
405405
}
406+
407+
path = strings.TrimPrefix(path, "/")
406408
fileContent, resp, err := client.Repositories.CreateFile(ctx, owner, repo, path, opts)
407409
if err != nil {
408410
return ghErrors.NewGitHubAPIErrorResponse(ctx,

0 commit comments

Comments
 (0)