Skip to content

Commit b2f07e5

Browse files
committed
Get tests fully working
1 parent afc455d commit b2f07e5

File tree

7 files changed

+53
-47
lines changed

7 files changed

+53
-47
lines changed

cmd/github-mcp-server/generate_docs.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import (
1414
"github.com/github/github-mcp-server/pkg/toolsets"
1515
"github.com/github/github-mcp-server/pkg/translations"
1616
gogithub "github.com/google/go-github/v77/github"
17-
"github.com/mark3labs/mcp-go/mcp"
17+
"github.com/google/jsonschema-go/jsonschema"
18+
"github.com/modelcontextprotocol/go-sdk/mcp"
1819
"github.com/shurcooL/githubv4"
1920
"github.com/spf13/cobra"
2021
)
@@ -224,7 +225,12 @@ func generateToolDoc(tool mcp.Tool) string {
224225
lines = append(lines, fmt.Sprintf("- **%s** - %s", tool.Name, tool.Annotations.Title))
225226

226227
// Parameters
227-
schema := tool.InputSchema
228+
schema, ok := tool.InputSchema.(*jsonschema.Schema)
229+
if !ok {
230+
lines = append(lines, " - No parameters required")
231+
return strings.Join(lines, "\n")
232+
}
233+
228234
if len(schema.Properties) > 0 {
229235
// Get parameter names and sort them for deterministic order
230236
var paramNames []string
@@ -245,26 +251,19 @@ func generateToolDoc(tool mcp.Tool) string {
245251
typeStr := "unknown"
246252
description := ""
247253

248-
if propMap, ok := prop.(map[string]interface{}); ok {
249-
if typeVal, ok := propMap["type"].(string); ok {
250-
if typeVal == "array" {
251-
if items, ok := propMap["items"].(map[string]interface{}); ok {
252-
if itemType, ok := items["type"].(string); ok {
253-
typeStr = itemType + "[]"
254-
}
255-
} else {
256-
typeStr = "array"
257-
}
258-
} else {
259-
typeStr = typeVal
260-
}
261-
}
262-
263-
if desc, ok := propMap["description"].(string); ok {
264-
description = desc
254+
switch prop.Type {
255+
case "array":
256+
if prop.Items != nil {
257+
typeStr = prop.Items.Type + "[]"
258+
} else {
259+
typeStr = "array"
265260
}
261+
default:
262+
typeStr = prop.Type
266263
}
267264

265+
description = prop.Description
266+
268267
paramLine := fmt.Sprintf(" - `%s`: %s (%s, %s)", propName, description, typeStr, requiredStr)
269268
lines = append(lines, paramLine)
270269
}
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
{
22
"annotations": {
3-
"title": "Get my user profile",
4-
"readOnlyHint": true
3+
"readOnlyHint": true,
4+
"title": "Get my user profile"
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.",
7-
"inputSchema": {
8-
"properties": {},
9-
"type": "object"
10-
},
7+
"inputSchema": null,
118
"name": "get_me"
129
}
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
{
22
"annotations": {
3-
"title": "Get team members",
4-
"readOnlyHint": true
3+
"readOnlyHint": true,
4+
"title": "Get team members"
55
},
66
"description": "Get member usernames of a specific team in an organization. Limited to organizations accessible with current credentials",
77
"inputSchema": {
8+
"type": "object",
9+
"required": [
10+
"org",
11+
"team_slug"
12+
],
813
"properties": {
914
"org": {
10-
"description": "Organization login (owner) that contains the team.",
11-
"type": "string"
15+
"type": "string",
16+
"description": "Organization login (owner) that contains the team."
1217
},
1318
"team_slug": {
14-
"description": "Team slug",
15-
"type": "string"
19+
"type": "string",
20+
"description": "Team slug"
1621
}
17-
},
18-
"required": [
19-
"org",
20-
"team_slug"
21-
],
22-
"type": "object"
22+
}
2323
},
2424
"name": "get_team_members"
2525
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
22
"annotations": {
3-
"title": "Get teams",
4-
"readOnlyHint": true
3+
"readOnlyHint": true,
4+
"title": "Get teams"
55
},
66
"description": "Get details of the teams the user is a member of. Limited to organizations accessible with current credentials",
77
"inputSchema": {
8+
"type": "object",
89
"properties": {
910
"user": {
10-
"description": "Username to get teams for. If not provided, uses the authenticated user.",
11-
"type": "string"
11+
"type": "string",
12+
"description": "Username to get teams for. If not provided, uses the authenticated user."
1213
}
13-
},
14-
"type": "object"
14+
}
1515
},
1616
"name": "get_teams"
1717
}

pkg/github/context_tools.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,15 @@ func GetTeams(getClient GetClientFn, getGQLClient GetGQLClientFn, t translations
112112
Title: t("TOOL_GET_TEAMS_TITLE", "Get teams"),
113113
ReadOnlyHint: true,
114114
},
115+
InputSchema: &jsonschema.Schema{
116+
Type: "object",
117+
Properties: map[string]*jsonschema.Schema{
118+
"user": {
119+
Type: "string",
120+
Description: t("TOOL_GET_TEAMS_USER_DESCRIPTION", "Username to get teams for. If not provided, uses the authenticated user."),
121+
},
122+
},
123+
},
115124
},
116125
func(ctx context.Context, request *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) {
117126
user, err := OptionalParam[string](args, "user")

pkg/github/context_tools_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ func Test_GetMe(t *testing.T) {
112112

113113
request := createMCPRequest(tc.requestArgs)
114114
result, _, err := handler(context.Background(), &request, tc.requestArgs)
115-
require.NoError(t, err)
116115
textContent := getTextResult(t, result)
117116

118117
if tc.expectToolError {
118+
assert.Error(t, err)
119119
assert.True(t, result.IsError, "expected tool call result to be an error")
120120
assert.Contains(t, textContent.Text, tc.expectedToolErrMsg)
121121
return

pkg/github/helper_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ func getTextResult(t *testing.T, result *mcp.CallToolResult) *mcp.TextContent {
133133
t.Helper()
134134
assert.NotNil(t, result)
135135
require.Len(t, result.Content, 1)
136-
require.IsType(t, mcp.TextContent{}, result.Content[0])
137-
textContent := result.Content[0].(*mcp.TextContent)
136+
textContent, ok := result.Content[0].(*mcp.TextContent)
137+
require.True(t, ok, "expected content to be of type TextContent")
138138
return textContent
139139
}
140140

@@ -151,7 +151,8 @@ func getTextResourceResult(t *testing.T, result *mcp.CallToolResult) *mcp.Resour
151151
require.Len(t, result.Content, 2)
152152
content := result.Content[1]
153153
require.IsType(t, mcp.EmbeddedResource{}, content)
154-
resource := content.(*mcp.EmbeddedResource)
154+
resource, ok := content.(*mcp.EmbeddedResource)
155+
require.True(t, ok, "expected content to be of type EmbeddedResource")
155156

156157
require.IsType(t, mcp.ResourceContents{}, resource.Resource)
157158
require.NotEmpty(t, resource.Resource.Text)

0 commit comments

Comments
 (0)