Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit76766b7

Browse files
feat: read-only flag
1 parentdd46f8a commit76766b7

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

‎cmd/github-mcp-server/main.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ var (
3232
Long:`Start a server that communicates via standard input/output streams using JSON-RPC messages.`,
3333
Run:func(cmd*cobra.Command,args []string) {
3434
logFile:=viper.GetString("log-file")
35+
readOnly:=viper.GetBool("read-only")
36+
exportTranslations:=viper.GetBool("export-translations")
3537
logger,err:=initLogger(logFile)
3638
iferr!=nil {
3739
stdlog.Fatal("Failed to initialize logger:",err)
3840
}
3941
logCommands:=viper.GetBool("enable-command-logging")
40-
iferr:=runStdioServer(logger,logCommands,viper.GetBool("export-translations"));err!=nil {
42+
iferr:=runStdioServer(readOnly,logger,logCommands,exportTranslations);err!=nil {
4143
stdlog.Fatal("failed to run stdio server:",err)
4244
}
4345
},
@@ -48,11 +50,13 @@ func init() {
4850
cobra.OnInitialize(initConfig)
4951

5052
// Add global flags that will be shared by all commands
53+
rootCmd.PersistentFlags().Bool("read-only",false,"Restrict the server to read-only operations")
5154
rootCmd.PersistentFlags().String("log-file","","Path to log file")
5255
rootCmd.PersistentFlags().Bool("enable-command-logging",false,"When enabled, the server will log all command requests and responses to the log file")
5356
rootCmd.PersistentFlags().Bool("export-translations",false,"Save translations to a JSON file")
5457

5558
// Bind flag to viper
59+
viper.BindPFlag("read-only",rootCmd.PersistentFlags().Lookup("read-only"))
5660
viper.BindPFlag("log-file",rootCmd.PersistentFlags().Lookup("log-file"))
5761
viper.BindPFlag("enable-command-logging",rootCmd.PersistentFlags().Lookup("enable-command-logging"))
5862
viper.BindPFlag("export-translations",rootCmd.PersistentFlags().Lookup("export-translations"))
@@ -84,7 +88,7 @@ func initLogger(outPath string) (*log.Logger, error) {
8488
returnlogger,nil
8589
}
8690

87-
funcrunStdioServer(logger*log.Logger,logCommandsbool,exportTranslationsbool)error {
91+
funcrunStdioServer(readOnlybool,logger*log.Logger,logCommandsbool,exportTranslationsbool)error {
8892
// Create app context
8993
ctx,stop:=signal.NotifyContext(context.Background(),os.Interrupt,syscall.SIGTERM)
9094
deferstop()
@@ -98,8 +102,8 @@ func runStdioServer(logger *log.Logger, logCommands bool, exportTranslations boo
98102

99103
t,dumpTranslations:=translations.TranslationHelper()
100104

101-
// Create server
102-
ghServer:=github.NewServer(ghClient,t)
105+
// Create
106+
ghServer:=github.NewServer(ghClient,readOnly,t)
103107
stdioServer:=server.NewStdioServer(ghServer)
104108

105109
stdLogger:=stdlog.New(logger.Writer(),"stdioserver",0)

‎pkg/github/server.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
)
1717

1818
// NewServer creates a new GitHub MCP server with the specified GH client and logger.
19-
funcNewServer(client*github.Client,t translations.TranslationHelperFunc)*server.MCPServer {
19+
funcNewServer(client*github.Client,readOnlybool,t translations.TranslationHelperFunc)*server.MCPServer {
2020
// Create a new MCP server
2121
s:=server.NewMCPServer(
2222
"github-mcp-server",
@@ -35,29 +35,36 @@ func NewServer(client *github.Client, t translations.TranslationHelperFunc) *ser
3535

3636
// Add GitHub tools - Issues
3737
s.AddTool(getIssue(client,t))
38-
s.AddTool(addIssueComment(client,t))
39-
s.AddTool(createIssue(client,t))
4038
s.AddTool(searchIssues(client,t))
4139
s.AddTool(listIssues(client,t))
40+
if!readOnly {
41+
s.AddTool(createIssue(client,t))
42+
s.AddTool(addIssueComment(client,t))
43+
s.AddTool(createIssue(client,t))
44+
}
4245

4346
// Add GitHub tools - Pull Requests
4447
s.AddTool(getPullRequest(client,t))
4548
s.AddTool(listPullRequests(client,t))
46-
s.AddTool(mergePullRequest(client,t))
4749
s.AddTool(getPullRequestFiles(client,t))
4850
s.AddTool(getPullRequestStatus(client,t))
49-
s.AddTool(updatePullRequestBranch(client,t))
5051
s.AddTool(getPullRequestComments(client,t))
5152
s.AddTool(getPullRequestReviews(client,t))
53+
if!readOnly {
54+
s.AddTool(mergePullRequest(client,t))
55+
s.AddTool(updatePullRequestBranch(client,t))
56+
}
5257

5358
// Add GitHub tools - Repositories
54-
s.AddTool(createOrUpdateFile(client,t))
5559
s.AddTool(searchRepositories(client,t))
56-
s.AddTool(createRepository(client,t))
5760
s.AddTool(getFileContents(client,t))
58-
s.AddTool(forkRepository(client,t))
59-
s.AddTool(createBranch(client,t))
6061
s.AddTool(listCommits(client,t))
62+
if!readOnly {
63+
s.AddTool(createOrUpdateFile(client,t))
64+
s.AddTool(createRepository(client,t))
65+
s.AddTool(forkRepository(client,t))
66+
s.AddTool(createBranch(client,t))
67+
}
6168

6269
// Add GitHub tools - Search
6370
s.AddTool(searchCode(client,t))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp