Skip to content

Commit 3e948c9

Browse files
committed
Add demo prompt support
1 parent c135157 commit 3e948c9

File tree

4 files changed

+57
-1
lines changed

4 files changed

+57
-1
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.23.7
44

55
require (
66
github.com/google/go-github/v69 v69.2.0
7-
github.com/mark3labs/mcp-go v0.11.2
7+
github.com/mark3labs/mcp-go v0.13.0
88
github.com/sirupsen/logrus v1.9.3
99
github.com/spf13/cobra v1.9.1
1010
github.com/spf13/viper v1.19.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0V
2828
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
2929
github.com/mark3labs/mcp-go v0.11.2 h1:mCxWFUTrcXOtJIn9t7F8bxAL8rpE/ZZTTnx3PU/VNdA=
3030
github.com/mark3labs/mcp-go v0.11.2/go.mod h1:cjMlBU0cv/cj9kjlgmRhoJ5JREdS7YX83xeIG9Ko/jE=
31+
github.com/mark3labs/mcp-go v0.13.0 h1:HP+cJaE9KjWufUF9FxN/XgcXE6LVSebFZLiZYPmFbGU=
32+
github.com/mark3labs/mcp-go v0.13.0/go.mod h1:cjMlBU0cv/cj9kjlgmRhoJ5JREdS7YX83xeIG9Ko/jE=
3133
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
3234
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
3335
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=

pkg/github/prompts.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package github
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"fmt"
7+
8+
"github.com/google/go-github/v69/github"
9+
"github.com/mark3labs/mcp-go/mcp"
10+
"github.com/mark3labs/mcp-go/server"
11+
)
12+
13+
func NewMePrompt(client *github.Client) (mcp.Prompt, server.PromptHandlerFunc) {
14+
prompt := mcp.NewPrompt("github_me", mcp.WithPromptDescription("GitHub Prompt"))
15+
prompt.Arguments = []mcp.PromptArgument{}
16+
17+
return prompt, func(ctx context.Context, request mcp.GetPromptRequest) (*mcp.GetPromptResult, error) {
18+
user, resp, err := client.Users.Get(ctx, "")
19+
if err != nil {
20+
return nil, fmt.Errorf("failed to get user: %w", err)
21+
}
22+
defer func() { _ = resp.Body.Close() }()
23+
24+
if resp.StatusCode != 200 {
25+
return nil, fmt.Errorf("failed to read response body: %w", err)
26+
}
27+
28+
r, err := json.Marshal(user)
29+
if err != nil {
30+
return nil, fmt.Errorf("failed to marshal user: %w", err)
31+
}
32+
33+
return &mcp.GetPromptResult{
34+
Description: "Your GitHub Identity",
35+
Messages: []mcp.PromptMessage{
36+
{
37+
Role: mcp.RoleUser,
38+
Content: mcp.TextContent{
39+
Type: "text",
40+
Text: string(r),
41+
},
42+
},
43+
},
44+
}, nil
45+
46+
}
47+
48+
}

pkg/github/server.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ func NewServer(client *github.Client) *server.MCPServer {
1818
"github-mcp-server",
1919
"0.0.1",
2020
server.WithResourceCapabilities(true, true),
21+
server.WithPromptCapabilities(true),
22+
server.WithToolCapabilities(true),
2123
server.WithLogging())
2224

2325
// Add GitHub tools - Issues
@@ -51,6 +53,10 @@ func NewServer(client *github.Client) *server.MCPServer {
5153
// Add GitHub tools - Users
5254
s.AddTool(getMe(client))
5355

56+
// Add github_me prompt handler
57+
prompt, handler := NewMePrompt(client)
58+
s.AddPrompt(prompt, handler)
59+
5460
return s
5561
}
5662

0 commit comments

Comments
 (0)