@@ -3,6 +3,7 @@ package github
3
3
import (
4
4
"context"
5
5
"encoding/base64"
6
+ "errors"
6
7
"mime"
7
8
"path/filepath"
8
9
"strings"
@@ -60,30 +61,41 @@ func getRepositoryResourcePrContent(client *github.Client, t translations.Transl
60
61
61
62
func repositoryResourceContentsHandler (client * github.Client ) func (ctx context.Context , request mcp.ReadResourceRequest ) ([]mcp.ResourceContents , error ) {
62
63
return func (ctx context.Context , request mcp.ReadResourceRequest ) ([]mcp.ResourceContents , error ) {
64
+ // the matcher will give []string with one elemenent
65
+ // https://github.com/mark3labs/mcp-go/pull/54
66
+ o , ok := request .Params .Arguments ["owner" ].([]string )
67
+ if ! ok || len (o ) == 0 {
68
+ return nil , errors .New ("owner is required" )
69
+ }
70
+ owner := o [0 ]
71
+
72
+ r , ok := request .Params .Arguments ["repo" ].([]string )
73
+ if ! ok || len (r ) == 0 {
74
+ return nil , errors .New ("repo is required" )
75
+ }
76
+ repo := r [0 ]
63
77
64
- owner := request .Params .Arguments ["owner" ].([]string )[0 ]
65
- repo := request .Params .Arguments ["repo" ].([]string )[0 ]
66
78
// path should be a joined list of the path parts
67
79
path := strings .Join (request .Params .Arguments ["path" ].([]string ), "/" )
68
80
69
81
opts := & github.RepositoryContentGetOptions {}
70
82
71
83
sha , ok := request .Params .Arguments ["sha" ].([]string )
72
- if ok {
84
+ if ok && len ( sha ) > 0 {
73
85
opts .Ref = sha [0 ]
74
86
}
75
87
76
88
branch , ok := request .Params .Arguments ["branch" ].([]string )
77
- if ok {
89
+ if ok && len ( branch ) > 0 {
78
90
opts .Ref = "refs/heads/" + branch [0 ]
79
91
}
80
92
81
93
tag , ok := request .Params .Arguments ["tag" ].([]string )
82
- if ok {
94
+ if ok && len ( tag ) > 0 {
83
95
opts .Ref = "refs/tags/" + tag [0 ]
84
96
}
85
97
prNumber , ok := request .Params .Arguments ["pr_number" ].([]string )
86
- if ok {
98
+ if ok && len ( prNumber ) > 0 {
87
99
opts .Ref = "refs/pull/" + prNumber [0 ] + "/head"
88
100
}
89
101
0 commit comments