tools

package
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2025 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package tools provides a framework for implementing and registering Model Context Protocol (MCP) tools, and an extended Forgejo API client.

This package defines the `ToolImpl` interface and `Register` helper function for MCP tool development. Its subpackages contain concrete implementations of these tools.

It also offers `tools.Client`, an extension of the standard Forgejo SDK client, providing additional functionalities for interacting with Forgejo API endpoints not fully covered by the SDK.

Index

Constants

This section is empty.

Variables

View Source
var UserAgent = "Forgejo-MCP/" + types.VERSION

Functions

func BoolPtr

func BoolPtr(b bool) *bool

BoolPtr creates a pointer to a bool value. This is useful for setting optional boolean fields in structs that will be serialized to JSON, such as in MCP tool definitions.

func Float64Ptr

func Float64Ptr(f float64) *float64

Float64Ptr creates a pointer to a float64 value. This is useful for setting optional number fields in structs that will be serialized to JSON, such as in MCP tool definitions.

func IntPtr

func IntPtr(i int) *int

IntPtr creates a pointer to an int value. This is useful for setting optional integer fields in structs that will be serialized to JSON, such as in MCP tool definitions.

func Register

func Register[I, O any](s *mcp.Server, i ToolImpl[I, O])

Register is a helper function that registers a tool implementation with the MCP server. It retrieves the tool's definition and handler through the ToolImpl interface and adds them to the server's tool registry.

Types

type Client

type Client struct {
	*forgejo.Client
	// contains filtered or unexported fields
}

Client wraps the Forgejo SDK client with additional functionality for unsupported API endpoints. It provides methods for JSON requests and multipart file uploads with manual authentication.

func NewClient

func NewClient(base, token, version string, cl *http.Client) (*Client, error)

NewClient creates a new Client instance with extended functionality beyond the standard Forgejo SDK. This client supports custom API endpoints that are not available in the SDK, such as issue dependencies, wiki pages, and Forgejo Actions.

Parameters:

  • base: Forgejo server base URL (e.g., "https://git.example.com")
  • token: API access token for authentication
  • version: Forgejo version string to skip version check, empty to auto-detect
  • cl: HTTP client to use, nil for http.DefaultClient

The client uses manual token authentication for custom endpoints while preserving full SDK functionality for supported operations.

func (*Client) MyAddIssueBlocking added in v0.0.3

func (c *Client) MyAddIssueBlocking(owner, repo string, index int64, blocked types.MyIssueMeta) (*forgejo.Issue, error)

MyAddIssueBlocking blocks the issue given in the body by the issue in path. Creates a relationship where the current issue (index) blocks another issue (blocked). This means the current issue must be closed before the blocked issue can be closed. POST /repos/{owner}/{repo}/issues/{index}/blocks

func (*Client) MyAddIssueDependency

func (c *Client) MyAddIssueDependency(owner, repo string, index int64, dependency types.MyIssueMeta) (*forgejo.Issue, error)

MyAddIssueDependency adds a dependency to an issue. Creates a relationship where the current issue (index) depends on another issue (dependency). This means the dependency issue must be closed before the current issue can be closed. POST /repos/{owner}/{repo}/issues/{index}/dependencies

func (*Client) MyCreateWikiPage

func (c *Client) MyCreateWikiPage(owner, repo string, options types.MyCreateWikiPageOptions) (*types.MyWikiPage, error)

MyCreateWikiPage creates a new wiki page. POST /repos/{owner}/{repo}/wiki/new

func (*Client) MyDeleteIssueAttachment

func (c *Client) MyDeleteIssueAttachment(owner, repo string, index, attachmentID int64) error

MyDeleteIssueAttachment deletes an attachment from an issue. DELETE /repos/{owner}/{repo}/issues/{index}/assets/{attachment_id}

func (*Client) MyDeleteWikiPage

func (c *Client) MyDeleteWikiPage(owner, repo, pageName string) error

MyDeleteWikiPage deletes a wiki page. DELETE /repos/{owner}/{repo}/wiki/page/{pageName}

func (*Client) MyEditIssueAttachment

func (c *Client) MyEditIssueAttachment(owner, repo string, index, attachmentID int64, options MyEditAttachmentOptions) (*forgejo.Attachment, error)

MyEditIssueAttachment edits an attachment of an issue. PATCH /repos/{owner}/{repo}/issues/{index}/assets/{attachment_id}

func (*Client) MyEditWikiPage

func (c *Client) MyEditWikiPage(owner, repo, pageName string, options types.MyCreateWikiPageOptions) (*types.MyWikiPage, error)

MyEditWikiPage edits an existing wiki page. PATCH /repos/{owner}/{repo}/wiki/page/{pageName}

func (*Client) MyGetWikiPage

func (c *Client) MyGetWikiPage(owner, repo, pageName string) (*types.MyWikiPage, error)

MyGetWikiPage gets a single wiki page by name. GET /repos/{owner}/{repo}/wiki/page/{pageName}

func (*Client) MyListActionTasks

func (c *Client) MyListActionTasks(owner, repo string) (*types.MyActionTaskResponse, error)

MyListActionTasks lists all Forgejo Actions tasks in a repository. GET /repos/{owner}/{repo}/actions/tasks

func (*Client) MyListIssueAttachments

func (c *Client) MyListIssueAttachments(owner, repo string, index int64) ([]*forgejo.Attachment, error)

MyListIssueAttachments lists all attachments of an issue. GET /repos/{owner}/{repo}/issues/{index}/assets

func (*Client) MyListIssueBlocking added in v0.0.3

func (c *Client) MyListIssueBlocking(owner, repo string, index int64) ([]*forgejo.Issue, error)

MyListIssueBlocking lists all issues blocked by this issue. Returns issues that cannot be closed until the current issue is closed. GET /repos/{owner}/{repo}/issues/{index}/blocks

func (*Client) MyListIssueDependencies

func (c *Client) MyListIssueDependencies(owner, repo string, index int64) ([]*forgejo.Issue, error)

MyListIssueDependencies lists all dependencies of an issue. Returns issues that must be closed before the current issue can be closed. GET /repos/{owner}/{repo}/issues/{index}/dependencies

func (*Client) MyListWikiPages

func (c *Client) MyListWikiPages(owner, repo string) ([]*types.MyWikiPageMetaData, error)

MyListWikiPages lists all wiki pages in a repository. GET /repos/{owner}/{repo}/wiki/pages

func (*Client) MyRemoveIssueBlocking added in v0.0.3

func (c *Client) MyRemoveIssueBlocking(owner, repo string, index int64, blocked types.MyIssueMeta) (*forgejo.Issue, error)

MyRemoveIssueBlocking unblocks the issue given in the body by the issue in path. Removes the relationship where the current issue blocks another issue. DELETE /repos/{owner}/{repo}/issues/{index}/blocks

func (*Client) MyRemoveIssueDependency

func (c *Client) MyRemoveIssueDependency(owner, repo string, index int64, dependency types.MyIssueMeta) (*forgejo.Issue, error)

MyRemoveIssueDependency removes a dependency from an issue. Removes the relationship where the current issue depends on another issue. DELETE /repos/{owner}/{repo}/issues/{index}/dependencies

type MyEditAttachmentOptions

type MyEditAttachmentOptions struct {
	Name        string `json:"name,omitempty"`
	DownloadURL string `json:"browser_download_url,omitempty"`
}

MyEditAttachmentOptions extends the SDK version with missing fields.

type ToolImpl

type ToolImpl[In, Out any] interface {
	// Definition returns the formal MCP tool definition, including its name,
	// description, and input schema.
	Definition() *mcp.Tool

	// Handler returns the function that contains the core logic of the tool.
	// This function is executed when the tool is called by an MCP client.
	Handler() mcp.ToolHandlerFor[In, Out]
}

ToolImpl defines the interface that every tool implementation must satisfy. This interface standardizes how tools are defined and handled, ensuring they can be registered with the MCP server consistently.

The generic types In and Out represent the tool's input and output data structures.

Directories

Path Synopsis
Package action provides MCP tools related to Forgejo Actions.
Package action provides MCP tools related to Forgejo Actions.
Package issue provides MCP tools for managing Forgejo issues and their comments.
Package issue provides MCP tools for managing Forgejo issues and their comments.
Package label provides MCP tools for managing Forgejo labels.
Package label provides MCP tools for managing Forgejo labels.
Package milestone provides MCP tools for managing Forgejo milestones.
Package milestone provides MCP tools for managing Forgejo milestones.
Package pullreq provides MCP tools for interacting with Forgejo pull requests.
Package pullreq provides MCP tools for interacting with Forgejo pull requests.
Package release provides MCP tools for managing Forgejo releases and their attachments.
Package release provides MCP tools for managing Forgejo releases and their attachments.
Package repo provides MCP tools for interacting with Forgejo repositories.
Package repo provides MCP tools for interacting with Forgejo repositories.
Package wiki provides MCP tools for managing Forgejo wiki pages.
Package wiki provides MCP tools for managing Forgejo wiki pages.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL