forgejo-mcp/cmd/lib.go
Ronmi Ren 4a3d21c81c feat: add create_pull_request tool
Add support for creating pull requests through the MCP server. The new tool allows clients to create PRs with full metadata including assignees, labels, milestones, and due dates.

Changes:
- Add CreatePullRequestImpl in tools/pullreq/create.go
- Register create_pull_request tool in cmd/lib.go
- Update pullreq package documentation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-28 15:35:44 +08:00

113 lines
4.3 KiB
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
//
// Copyright © 2025 Ronmi Ren <ronmi.ren@gmail.com>
package cmd
import (
"github.com/raohwork/forgejo-mcp/tools"
"github.com/raohwork/forgejo-mcp/tools/action"
"github.com/raohwork/forgejo-mcp/tools/issue"
"github.com/raohwork/forgejo-mcp/tools/label"
"github.com/raohwork/forgejo-mcp/tools/milestone"
"github.com/raohwork/forgejo-mcp/tools/pullreq"
"github.com/raohwork/forgejo-mcp/tools/release"
"github.com/raohwork/forgejo-mcp/tools/repo"
"github.com/raohwork/forgejo-mcp/tools/wiki"
"github.com/raohwork/forgejo-mcp/types"
"github.com/modelcontextprotocol/go-sdk/mcp"
)
func registerCommands(s *mcp.Server, cl *tools.Client) {
// Issue tools
tools.Register(s, &issue.ListRepoIssuesImpl{Client: cl})
tools.Register(s, &issue.GetIssueImpl{Client: cl})
tools.Register(s, &issue.CreateIssueImpl{Client: cl})
tools.Register(s, &issue.EditIssueImpl{Client: cl})
// Issue label tools
tools.Register(s, &issue.AddIssueLabelsImpl{Client: cl})
tools.Register(s, &issue.RemoveIssueLabelImpl{Client: cl})
tools.Register(s, &issue.ReplaceIssueLabelsImpl{Client: cl})
// Issue comment tools
tools.Register(s, &issue.ListIssueCommentsImpl{Client: cl})
tools.Register(s, &issue.CreateIssueCommentImpl{Client: cl})
tools.Register(s, &issue.EditIssueCommentImpl{Client: cl})
tools.Register(s, &issue.DeleteIssueCommentImpl{Client: cl})
// Issue attachment tools
tools.Register(s, &issue.ListIssueAttachmentsImpl{Client: cl})
tools.Register(s, &issue.DeleteIssueAttachmentImpl{Client: cl})
tools.Register(s, &issue.EditIssueAttachmentImpl{Client: cl})
// Issue dependency tools
tools.Register(s, &issue.ListIssueDependenciesImpl{Client: cl})
tools.Register(s, &issue.AddIssueDependencyImpl{Client: cl})
tools.Register(s, &issue.RemoveIssueDependencyImpl{Client: cl})
// Issue blocking tools
tools.Register(s, &issue.ListIssueBlockingImpl{Client: cl})
tools.Register(s, &issue.AddIssueBlockingImpl{Client: cl})
tools.Register(s, &issue.RemoveIssueBlockingImpl{Client: cl})
// Label tools
tools.Register(s, &label.ListRepoLabelsImpl{Client: cl})
tools.Register(s, &label.CreateLabelImpl{Client: cl})
tools.Register(s, &label.EditLabelImpl{Client: cl})
tools.Register(s, &label.DeleteLabelImpl{Client: cl})
// Milestone tools
tools.Register(s, &milestone.ListRepoMilestonesImpl{Client: cl})
tools.Register(s, &milestone.CreateMilestoneImpl{Client: cl})
tools.Register(s, &milestone.EditMilestoneImpl{Client: cl})
tools.Register(s, &milestone.DeleteMilestoneImpl{Client: cl})
// Release tools
tools.Register(s, &release.ListReleasesImpl{Client: cl})
tools.Register(s, &release.CreateReleaseImpl{Client: cl})
tools.Register(s, &release.EditReleaseImpl{Client: cl})
tools.Register(s, &release.DeleteReleaseImpl{Client: cl})
// Release attachment tools
tools.Register(s, &release.ListReleaseAttachmentsImpl{Client: cl})
tools.Register(s, &release.EditReleaseAttachmentImpl{Client: cl})
tools.Register(s, &release.DeleteReleaseAttachmentImpl{Client: cl})
// Pull request tools
tools.Register(s, &pullreq.ListPullRequestsImpl{Client: cl})
tools.Register(s, &pullreq.GetPullRequestImpl{Client: cl})
tools.Register(s, &pullreq.CreatePullRequestImpl{Client: cl})
// Repository tools
tools.Register(s, &repo.SearchRepositoriesImpl{Client: cl})
tools.Register(s, &repo.ListMyRepositoriesImpl{Client: cl})
tools.Register(s, &repo.ListOrgRepositoriesImpl{Client: cl})
tools.Register(s, &repo.GetRepositoryImpl{Client: cl})
// Wiki tools
tools.Register(s, &wiki.GetWikiPageImpl{Client: cl})
tools.Register(s, &wiki.CreateWikiPageImpl{Client: cl})
tools.Register(s, &wiki.EditWikiPageImpl{Client: cl})
tools.Register(s, &wiki.DeleteWikiPageImpl{Client: cl})
tools.Register(s, &wiki.ListWikiPagesImpl{Client: cl})
// Action tools
tools.Register(s, &action.ListActionTasksImpl{Client: cl})
}
func createServer(cl *tools.Client) *mcp.Server {
server := mcp.NewServer(&mcp.Implementation{
Title: "Forgejo MCP Server",
Version: types.VERSION[1:], // strip leading 'v'
}, &mcp.ServerOptions{
PageSize: 50,
Instructions: "An MCP server to interact with repositories on a Forgejo/Gitea instance.",
})
registerCommands(server, cl)
return server
}