Skip to content
Merged
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
6 changes: 5 additions & 1 deletion cmd/github-mcp-server/generate_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,12 @@ func generateToolDoc(tool mcp.Tool) string {
lines = append(lines, fmt.Sprintf("- **%s** - %s", tool.Name, tool.Annotations.Title))

// Parameters
if tool.InputSchema == nil {
lines = append(lines, " - No parameters required")
return strings.Join(lines, "\n")
}
schema, ok := tool.InputSchema.(*jsonschema.Schema)
if !ok {
if !ok || schema == nil {
lines = append(lines, " - No parameters required")
return strings.Join(lines, "\n")
}
Expand Down
33 changes: 33 additions & 0 deletions pkg/github/__toolsnaps__/create_gist.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"annotations": {
"title": "Create Gist"
},
"description": "Create a new gist",
"inputSchema": {
"type": "object",
"required": [
"filename",
"content"
],
"properties": {
"content": {
"type": "string",
"description": "Content for simple single-file gist creation"
},
"description": {
"type": "string",
"description": "Description of the gist"
},
"filename": {
"type": "string",
"description": "Filename for simple single-file gist creation"
},
"public": {
"type": "boolean",
"description": "Whether the gist is public",
"default": false
}
}
},
"name": "create_gist"
}
20 changes: 20 additions & 0 deletions pkg/github/__toolsnaps__/get_gist.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"annotations": {
"readOnlyHint": true,
"title": "Get Gist Content"
},
"description": "Get gist content of a particular gist, by gist ID",
"inputSchema": {
"type": "object",
"required": [
"gist_id"
],
"properties": {
"gist_id": {
"type": "string",
"description": "The ID of the gist"
}
}
},
"name": "get_gist"
}
32 changes: 32 additions & 0 deletions pkg/github/__toolsnaps__/list_gists.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"annotations": {
"readOnlyHint": true,
"title": "List Gists"
},
"description": "List gists for a user",
"inputSchema": {
"type": "object",
"properties": {
"page": {
"type": "number",
"description": "Page number for pagination (min 1)",
"minimum": 1
},
"perPage": {
"type": "number",
"description": "Results per page for pagination (min 1, max 100)",
"minimum": 1,
"maximum": 100
},
"since": {
"type": "string",
"description": "Only gists updated after this time (ISO 8601 timestamp)"
},
"username": {
"type": "string",
"description": "GitHub username (omit for authenticated user's gists)"
}
}
},
"name": "list_gists"
}
33 changes: 33 additions & 0 deletions pkg/github/__toolsnaps__/update_gist.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"annotations": {
"title": "Update Gist"
},
"description": "Update an existing gist",
"inputSchema": {
"type": "object",
"required": [
"gist_id",
"filename",
"content"
],
"properties": {
"content": {
"type": "string",
"description": "Content for the file"
},
"description": {
"type": "string",
"description": "Updated description of the gist"
},
"filename": {
"type": "string",
"description": "Filename to update or create"
},
"gist_id": {
"type": "string",
"description": "ID of the gist to update"
}
}
},
"name": "update_gist"
}
99 changes: 48 additions & 51 deletions pkg/github/context_tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,61 +36,58 @@ type UserDetails struct {

// GetMe creates a tool to get details of the authenticated user.
func GetMe(getClient GetClientFn, t translations.TranslationHelperFunc) (mcp.Tool, mcp.ToolHandlerFor[map[string]any, any]) {
tool := mcp.Tool{
Name: "get_me",
Description: t("TOOL_GET_ME_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."),
Annotations: &mcp.ToolAnnotations{
Title: t("TOOL_GET_ME_USER_TITLE", "Get my user profile"),
ReadOnlyHint: true,
return mcp.Tool{
Name: "get_me",
Description: t("TOOL_GET_ME_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."),
Annotations: &mcp.ToolAnnotations{
Title: t("TOOL_GET_ME_USER_TITLE", "Get my user profile"),
ReadOnlyHint: true,
},
},
}

handler := mcp.ToolHandlerFor[map[string]any, any](func(ctx context.Context, _ *mcp.CallToolRequest, _ map[string]any) (*mcp.CallToolResult, any, error) {
client, err := getClient(ctx)
if err != nil {
return utils.NewToolResultErrorFromErr("failed to get GitHub client", err), nil, err
}

user, res, err := client.Users.Get(ctx, "")
if err != nil {
return ghErrors.NewGitHubAPIErrorResponse(ctx,
"failed to get user",
res,
err,
), nil, err
}
mcp.ToolHandlerFor[map[string]any, any](func(ctx context.Context, _ *mcp.CallToolRequest, _ map[string]any) (*mcp.CallToolResult, any, error) {
client, err := getClient(ctx)
if err != nil {
return utils.NewToolResultErrorFromErr("failed to get GitHub client", err), nil, err
}

// Create minimal user representation instead of returning full user object
minimalUser := MinimalUser{
Login: user.GetLogin(),
ID: user.GetID(),
ProfileURL: user.GetHTMLURL(),
AvatarURL: user.GetAvatarURL(),
Details: &UserDetails{
Name: user.GetName(),
Company: user.GetCompany(),
Blog: user.GetBlog(),
Location: user.GetLocation(),
Email: user.GetEmail(),
Hireable: user.GetHireable(),
Bio: user.GetBio(),
TwitterUsername: user.GetTwitterUsername(),
PublicRepos: user.GetPublicRepos(),
PublicGists: user.GetPublicGists(),
Followers: user.GetFollowers(),
Following: user.GetFollowing(),
CreatedAt: user.GetCreatedAt().Time,
UpdatedAt: user.GetUpdatedAt().Time,
PrivateGists: user.GetPrivateGists(),
TotalPrivateRepos: user.GetTotalPrivateRepos(),
OwnedPrivateRepos: user.GetOwnedPrivateRepos(),
},
}
user, res, err := client.Users.Get(ctx, "")
if err != nil {
return ghErrors.NewGitHubAPIErrorResponse(ctx,
"failed to get user",
res,
err,
), nil, err
}

return MarshalledTextResult(minimalUser), nil, nil
})
// Create minimal user representation instead of returning full user object
minimalUser := MinimalUser{
Login: user.GetLogin(),
ID: user.GetID(),
ProfileURL: user.GetHTMLURL(),
AvatarURL: user.GetAvatarURL(),
Details: &UserDetails{
Name: user.GetName(),
Company: user.GetCompany(),
Blog: user.GetBlog(),
Location: user.GetLocation(),
Email: user.GetEmail(),
Hireable: user.GetHireable(),
Bio: user.GetBio(),
TwitterUsername: user.GetTwitterUsername(),
PublicRepos: user.GetPublicRepos(),
PublicGists: user.GetPublicGists(),
Followers: user.GetFollowers(),
Following: user.GetFollowing(),
CreatedAt: user.GetCreatedAt().Time,
UpdatedAt: user.GetUpdatedAt().Time,
PrivateGists: user.GetPrivateGists(),
TotalPrivateRepos: user.GetTotalPrivateRepos(),
OwnedPrivateRepos: user.GetOwnedPrivateRepos(),
},
}

return tool, handler
return MarshalledTextResult(minimalUser), nil, nil
})
}

type TeamInfo struct {
Expand Down
Loading
Loading