server

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const GitCommandTimeout = 30 * time.Second

GitCommandTimeout is the timeout for git command execution

Variables

This section is empty.

Functions

func BranchExists

func BranchExists(directory, branch string) (bool, error)

BranchExists checks if a branch exists locally

func FormatCommentCreateSuccess added in v0.2.0

func FormatCommentCreateSuccess(comment *remote.Comment) string

FormatCommentCreateSuccess creates success message for comment creation

func FormatCommentDetails added in v0.2.0

func FormatCommentDetails(comment *remote.Comment) string

FormatCommentDetails creates detailed comment information

func FormatCommentEditSuccess added in v0.2.0

func FormatCommentEditSuccess(comment *remote.Comment) string

FormatCommentEditSuccess creates success message for comment editing

func FormatCommentList added in v0.2.0

func FormatCommentList(comments []remote.Comment) string

FormatCommentList creates a human-readable summary of comments

func FormatIssueCreateSuccess added in v0.2.0

func FormatIssueCreateSuccess(issue *remote.Issue) string

FormatIssueCreateSuccess creates success message for issue creation

func FormatIssueDetails added in v0.2.0

func FormatIssueDetails(issue *remote.Issue) string

FormatIssueDetails creates detailed issue information

func FormatIssueEditSuccess added in v0.2.0

func FormatIssueEditSuccess(issue *remote.Issue) string

FormatIssueEditSuccess creates success message for issue editing

func FormatIssueList added in v0.2.0

func FormatIssueList(issues []remote.Issue) string

FormatIssueList creates a human-readable summary of issues

func FormatPullRequestCreateSuccess added in v0.2.0

func FormatPullRequestCreateSuccess(pr *remote.PullRequest) string

FormatPullRequestCreateSuccess creates success message for PR creation

func FormatPullRequestDetails added in v0.2.0

func FormatPullRequestDetails(pr *remote.PullRequestDetails) string

FormatPullRequestDetails creates detailed PR information

func FormatPullRequestEditSuccess added in v0.2.0

func FormatPullRequestEditSuccess(pr *remote.PullRequest) string

FormatPullRequestEditSuccess creates success message for PR editing

func FormatPullRequestList added in v0.2.0

func FormatPullRequestList(pullRequests []remote.PullRequest) string

FormatPullRequestList creates a human-readable summary of pull requests

func GetCommitCount

func GetCommitCount(directory, base, head string) (int, error)

GetCommitCount returns number of commits between base and head

func GetCurrentBranch

func GetCurrentBranch(directory string) (string, error)

GetCurrentBranch returns the current git branch name

func HasConflicts

func HasConflicts(directory, base, head string) (bool, []string, error)

HasConflicts detects if merging base into head would cause conflicts

func IsBranchBehind

func IsBranchBehind(directory, base, head string) (bool, error)

IsBranchBehind checks if head branch is behind base branch

func LoadPRTemplate

func LoadPRTemplate(ctx context.Context, client remote.FileContentFetcher, owner, repo, branch string) (string, error)

LoadPRTemplate attempts to load PR template from repository

func MergeTemplateContent

func MergeTemplateContent(template, userContent string) string

MergeTemplateContent merges template with user-provided content

func NewDirectoryNotFoundError

func NewDirectoryNotFoundError(path string) error

func NewInvalidRemoteURLError

func NewInvalidRemoteURLError(url string) error

func NewNoRemotesConfiguredError

func NewNoRemotesConfiguredError(path string) error

func NewNotGitRepositoryError

func NewNotGitRepositoryError(path, reason string) error

func TextError

func TextError(msg string) *mcp.CallToolResult

func TextErrorf

func TextErrorf(format string, args ...any) *mcp.CallToolResult

func TextResult

func TextResult(msg string) *mcp.CallToolResult

func TextResultf

func TextResultf(format string, args ...any) *mcp.CallToolResult

func ValidateAttachment

func ValidateAttachment(data []byte, filename string, maxSize int64, allowedTypes []string) error

ValidateAttachment validates file data, filename, and size

Types

type CommentEditResult

type CommentEditResult struct {
	Comment *remote.Comment `json:"comment,omitempty"`
}

CommentEditResult represents the result data for the issue_comment_edit tool.

type CommentListResult

type CommentListResult struct {
	Comments []remote.Comment `json:"comments,omitempty"`
	Total    int              `json:"total,omitempty"`
	Limit    int              `json:"limit,omitzero"`
	Offset   int              `json:"offset,omitzero"`
}

CommentListResult represents the result data for the list_issue_comments tool.

type CommentResult

type CommentResult struct {
	Comment remote.Comment `json:"comment,omitempty"`
}

CommentResult represents the result data for the create_issue_comment tool.

type ConflictDetail

type ConflictDetail struct {
	File     string   `json:"file"`     // Path to the conflicting file
	Type     string   `json:"type"`     // Type of conflict: "content", "add_add", "delete_modify"
	Lines    []int    `json:"lines"`    // Line numbers where conflicts occur (if available)
	Markers  []string `json:"markers"`  // Conflict markers found
	Severity string   `json:"severity"` // "low", "medium", "high" based on conflict complexity
}

ConflictDetail represents detailed information about a conflict

type ConflictReport

type ConflictReport struct {
	HasConflicts     bool             `json:"has_conflicts"`
	ConflictFiles    []string         `json:"conflict_files"`    // Simple list of conflicting files
	ConflictDetails  []ConflictDetail `json:"conflict_details"`  // Detailed conflict information
	TotalConflicts   int              `json:"total_conflicts"`   // Total number of conflict regions
	SuggestedActions []string         `json:"suggested_actions"` // Suggested resolution steps
}

ConflictReport represents a comprehensive conflict analysis

func GetConflictReport

func GetConflictReport(directory, base, head string) (*ConflictReport, error)

GetConflictReport provides detailed conflict analysis

type DirectoryNotFoundError

type DirectoryNotFoundError struct {
	RepositoryError
}

DirectoryNotFoundError indicates that a directory does not exist

func (*DirectoryNotFoundError) Is

func (e *DirectoryNotFoundError) Is(target error) bool

type ForkInfo

type ForkInfo struct {
	IsFork        bool   `json:"is_fork"`
	ForkOwner     string `json:"fork_owner,omitempty"`
	OriginalOwner string `json:"original_owner,omitempty"`
	ForkRemote    string `json:"fork_remote,omitempty"`
}

ForkInfo contains information about fork relationships

type HelloArgs added in v0.1.2

type HelloArgs struct {
}

HelloArgs represents the arguments for the hello tool

type HelloResult added in v0.1.2

type HelloResult struct {
	Message string `json:"message,omitempty"`
}

HelloResult represents the result data for the hello tool

type InvalidRemoteURLError

type InvalidRemoteURLError struct {
	RepositoryError
	URL string
}

InvalidRemoteURLError indicates that a remote URL cannot be parsed

func (*InvalidRemoteURLError) Error

func (e *InvalidRemoteURLError) Error() string

func (*InvalidRemoteURLError) Is

func (e *InvalidRemoteURLError) Is(target error) bool

type IssueCommentArgs

type IssueCommentArgs struct {
	Repository  string `json:"repository,omitzero"` // Repository path in "owner/repo" format
	Directory   string `json:"directory,omitzero"`  // Local directory path containing a git repository for automatic resolution
	IssueNumber int    `json:"issue_number"`
	Comment     string `json:"comment"`
}

type IssueCommentEditArgs

type IssueCommentEditArgs struct {
	Repository  string `json:"repository,omitzero"` // Repository path in "owner/repo" format
	Directory   string `json:"directory,omitzero"`  // Local directory path containing a git repository for automatic resolution
	IssueNumber int    `json:"issue_number"`
	CommentID   int    `json:"comment_id"`
	NewContent  string `json:"new_content"`
}

type IssueCommentListArgs

type IssueCommentListArgs struct {
	Repository  string `json:"repository,omitzero"` // Repository path in "owner/repo" format
	Directory   string `json:"directory,omitzero"`  // Local directory path containing a git repository for automatic resolution
	IssueNumber int    `json:"issue_number"`
	Limit       int    `json:"limit,omitzero"`
	Offset      int    `json:"offset,omitzero"`
}

type IssueCreateArgs

type IssueCreateArgs struct {
	Repository  string        `json:"repository,omitzero"`
	Directory   string        `json:"directory,omitzero"`
	Title       string        `json:"title"`
	Body        string        `json:"body,omitzero"`
	Attachments []interface{} `json:"attachments,omitzero"` // MCP Content objects
}

type IssueCreateResult

type IssueCreateResult struct {
	Issue *remote.Issue `json:"issue,omitempty"`
}

type IssueEditArgs

type IssueEditArgs struct {
	Repository  string `json:"repository,omitzero"` // Repository path in "owner/repo" format
	Directory   string `json:"directory,omitzero"`  // Local directory path containing a git repository for automatic resolution
	IssueNumber int    `json:"issue_number" validate:"required,min=1"`
	Title       string `json:"title,omitzero"` // New title for the issue
	Body        string `json:"body,omitzero"`  // New description/body for the issue
	State       string `json:"state,omitzero"` // New state ("open" or "closed")
}

IssueEditArgs represents the arguments for editing an issue with validation tags

type IssueEditResult

type IssueEditResult struct {
	Issue *remote.Issue `json:"issue,omitempty"`
}

IssueEditResult represents the result data for the issue_edit tool

type IssueList

type IssueList struct {
	Issues []remote.Issue `json:"issues,omitempty"`
}

IssueList represents a collection of repository issues. This struct is used as the result data for the list_issues tool.

type IssueListArgs

type IssueListArgs struct {
	Repository string `json:"repository,omitzero"` // Repository path in "owner/repo" format
	Directory  string `json:"directory,omitzero"`  // Local directory path containing a git repository for automatic resolution
	Limit      int    `json:"limit,omitzero"`
	Offset     int    `json:"offset,omitzero"`
}

type NoRemotesConfiguredError

type NoRemotesConfiguredError struct {
	RepositoryError
}

NoRemotesConfiguredError indicates that no git remotes are configured

func (*NoRemotesConfiguredError) Is

func (e *NoRemotesConfiguredError) Is(target error) bool

type NotGitRepositoryError

type NotGitRepositoryError struct {
	RepositoryError
	Reason string
}

NotGitRepositoryError indicates that a directory is not a git repository

func (*NotGitRepositoryError) Error

func (e *NotGitRepositoryError) Error() string

func (*NotGitRepositoryError) Is

func (e *NotGitRepositoryError) Is(target error) bool

type NotificationList added in v0.2.1

type NotificationList struct {
	Notifications []remote.Notification `json:"notifications"`
	Total         int                   `json:"total"`
	Limit         int                   `json:"limit"`
	Offset        int                   `json:"offset"`
}

NotificationList represents a collection of notifications. This struct is used as the result data for the notification_list tool.

type NotificationListArgs added in v0.2.1

type NotificationListArgs struct {
	Repository string `json:"repository,omitzero"` // Repository path in "owner/repo" format
	Directory  string `json:"directory,omitzero"`  // Local directory path containing a git repository for automatic resolution
	Status     string `json:"status,omitzero"`     // Filter by status: "read", "unread", or "all"
	Limit      int    `json:"limit,omitzero"`      // Pagination limit (1-100, default 15)
	Offset     int    `json:"offset,omitzero"`     // Pagination offset (default 0)
}

NotificationListArgs represents the arguments for listing notifications

type PullRequestCommentCreateArgs

type PullRequestCommentCreateArgs struct {
	Repository        string `json:"repository,omitzero"` // Repository path in "owner/repo" format
	Directory         string `json:"directory,omitzero"`  // Local directory path containing a git repository for automatic resolution
	PullRequestNumber int    `json:"pull_request_number" validate:"required,min=1"`
	Comment           string `json:"comment" validate:"required,min=1"`
}

PullRequestCommentCreateArgs represents the arguments for creating a pull request comment with validation tags

type PullRequestCommentCreateResult

type PullRequestCommentCreateResult struct {
	Comment *remote.Comment `json:"comment,omitempty"`
}

PullRequestCommentCreateResult represents the result data for the pr_comment_create tool

type PullRequestCommentEditArgs

type PullRequestCommentEditArgs struct {
	Repository        string `json:"repository,omitzero"` // Repository path in "owner/repo" format
	Directory         string `json:"directory,omitzero"`  // Local directory path containing a git repository for automatic resolution
	PullRequestNumber int    `json:"pull_request_number" validate:"required,min=1"`
	CommentID         int    `json:"comment_id" validate:"required,min=1"`
	NewContent        string `json:"new_content" validate:"required,min=1"`
}

PullRequestCommentEditArgs represents the arguments for editing a pull request comment with validation tags

type PullRequestCommentEditResult

type PullRequestCommentEditResult struct {
	Comment *remote.Comment `json:"comment,omitempty"`
}

PullRequestCommentEditResult represents the result data for the pr_comment_edit tool

type PullRequestCommentList

type PullRequestCommentList struct {
	PullRequestComments []remote.Comment `json:"pull_request_comments,omitempty"`
}

PullRequestCommentList represents a collection of pull request comments. This struct is used as the result data for the pr_comment_list tool.

type PullRequestCommentListArgs

type PullRequestCommentListArgs struct {
	Repository        string `json:"repository,omitzero"` // Repository path in "owner/repo" format
	Directory         string `json:"directory,omitzero"`  // Local directory path containing a git repository for automatic resolution
	PullRequestNumber int    `json:"pull_request_number" validate:"required,min=1"`
	Limit             int    `json:"limit,omitzero" validate:"min=1,max=100"`
	Offset            int    `json:"offset,omitzero" validate:"min=0"`
}

PullRequestCommentListArgs represents the arguments for listing pull request comments with validation tags

type PullRequestCreateArgs

type PullRequestCreateArgs struct {
	Repository string `json:"repository,omitzero"`       // Repository path in "owner/repo" format
	Directory  string `json:"directory,omitzero"`        // Local directory path containing a git repository for automatic resolution
	Head       string `json:"head,omitzero"`             // Source branch (auto-detected if not provided)
	Base       string `json:"base,omitzero"`             // Target branch (default if not provided)
	Title      string `json:"title" validate:"required"` // PR title
	Body       string `json:"body,omitzero"`             // PR description
	Draft      bool   `json:"draft,omitzero"`            // Create as draft PR
	Assignee   string `json:"assignee,omitzero"`         // Single reviewer
}

PullRequestCreateArgs represents the arguments for creating a pull request with validation tags

type PullRequestCreateResult

type PullRequestCreateResult struct {
	PullRequest *remote.PullRequest `json:"pull_request,omitempty"`
}

PullRequestCreateResult represents the result data for the pr_create tool

type PullRequestEditArgs

type PullRequestEditArgs struct {
	Repository        string `json:"repository,omitzero"` // Repository path in "owner/repo" format
	Directory         string `json:"directory,omitzero"`  // Local directory path containing a git repository for automatic resolution
	PullRequestNumber int    `json:"pull_request_number" validate:"required,min=1"`
	Title             string `json:"title,omitzero"`       // New title for the pull request
	Body              string `json:"body,omitzero"`        // New description/body for the pull request
	State             string `json:"state,omitzero"`       // New state ("open" or "closed")
	BaseBranch        string `json:"base_branch,omitzero"` // New base branch for the pull request
}

PullRequestEditArgs represents the arguments for editing a pull request with validation tags

type PullRequestEditResult

type PullRequestEditResult struct {
	PullRequest *remote.PullRequest `json:"pull_request,omitempty"`
}

PullRequestEditResult represents the result data for the pr_edit tool

type PullRequestFetchArgs added in v0.1.1

type PullRequestFetchArgs struct {
	Repository        string `json:"repository,omitzero"` // Repository path in "owner/repo" format
	Directory         string `json:"directory,omitzero"`  // Local directory path for automatic resolution
	PullRequestNumber int    `json:"pull_request_number" validate:"required,min=1"`
}

PullRequestFetchArgs represents the arguments for fetching a pull request

type PullRequestFetchResult added in v0.1.1

type PullRequestFetchResult struct {
	PullRequest *remote.PullRequestDetails `json:"pull_request,omitempty"`
}

PullRequestFetchResult represents the result data for the pr_fetch tool

type PullRequestList

type PullRequestList struct {
	PullRequests []remote.PullRequest `json:"pull_requests,omitempty"`
}

PullRequestList represents a collection of repository pull requests. This struct is used as the result data for the pr_list tool.

type PullRequestListArgs

type PullRequestListArgs struct {
	Repository string `json:"repository,omitzero"` // Repository path in "owner/repo" format
	Directory  string `json:"directory,omitzero"`  // Local directory path containing a git repository for automatic resolution
	Limit      int    `json:"limit,omitzero"`
	Offset     int    `json:"offset,omitzero"`
	State      string `json:"state"`
}

PullRequestListArgs represents the arguments for listing pull requests with validation tags

type RepositoryError

type RepositoryError struct {
	Op   string // Operation that failed
	Path string // Path involved in the error
	Err  error  // Underlying error
}

RepositoryError represents a base error type for repository resolution operations

func (*RepositoryError) Error

func (e *RepositoryError) Error() string

func (*RepositoryError) Unwrap

func (e *RepositoryError) Unwrap() error

type RepositoryResolution

type RepositoryResolution struct {
	Directory  string `json:"directory,omitzero"`  // The original directory path
	Repository string `json:"repository,omitzero"` // The resolved repository in "owner/repo" format
	RemoteURL  string `json:"remote_url"`          // The full remote URL
	RemoteName string `json:"remote_name"`         // The name of the remote (e.g., "origin", "upstream")
}

RepositoryResolution represents the result of resolving a directory to repository information

type RepositoryResolver

type RepositoryResolver struct {
}

RepositoryResolver handles directory-to-repository resolution

func NewRepositoryResolver

func NewRepositoryResolver() *RepositoryResolver

NewRepositoryResolver creates a new RepositoryResolver instance

func (*RepositoryResolver) DetectForkRelationship

func (r *RepositoryResolver) DetectForkRelationship(remotes map[string]string, targetRepo string) (*ForkInfo, error)

DetectForkRelationship analyzes remotes to detect fork relationships

func (*RepositoryResolver) ExtractAllRemotes

func (r *RepositoryResolver) ExtractAllRemotes(directory string) (map[string]string, error)

ExtractAllRemotes extracts all remote configurations from git config

func (*RepositoryResolver) ExtractRemoteInfo

func (r *RepositoryResolver) ExtractRemoteInfo(directory string) (string, error)

ExtractRemoteInfo extracts repository information from git remote configuration

func (*RepositoryResolver) ResolveRepository

func (r *RepositoryResolver) ResolveRepository(directory string) (*RepositoryResolution, error)

ResolveRepository performs the complete directory to repository resolution

func (*RepositoryResolver) ResolveWithForkInfo

func (r *RepositoryResolver) ResolveWithForkInfo(directory string) (*RepositoryResolution, *ForkInfo, error)

ResolveWithForkInfo performs repository resolution with fork detection

func (*RepositoryResolver) ValidateDirectory

func (r *RepositoryResolver) ValidateDirectory(directory string) error

ValidateDirectory validates that the directory exists and is a git repository

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server represents the MCP server instance using the official MCP SDK. This server provides tools for interacting with Forgejo/Gitea repositories through the Model Context Protocol.

Migration Note: Updated from mark3labs/mcp-go to github.com/modelcontextprotocol/go-sdk/mcp v0.4.0 for official protocol compliance and long-term stability.

func New

func New() (*Server, error)

New creates a new MCP server instance with default configuration. It initializes the server with the official MCP SDK and registers all available tools.

Migration Note: Constructor updated to use the official MCP SDK's server initialization pattern instead of the third-party library's approach.

func NewFromConfig

func NewFromConfig(cfg *config.Config) (*Server, error)

NewFromConfig creates a new MCP server instance with the provided configuration. This allows for custom server setup while maintaining the official SDK integration.

Migration Note: Tool registration updated to use mcp.AddTool() instead of the previous SDK's tool registration methods.

func NewFromConfigWithDebug

func NewFromConfigWithDebug(cfg *config.Config, debug bool) (*Server, error)

NewFromConfigWithDebug creates a new MCP server instance with the provided configuration and debug mode. When debug is true, the hello tool will be registered for debugging purposes.

func NewFromConfigWithDebugAndCompat added in v0.2.0

func NewFromConfigWithDebugAndCompat(cfg *config.Config, debug, compat bool) (*Server, error)

NewFromConfigWithDebugAndCompat creates a new MCP server instance with the provided configuration, debug mode, and compatibility mode. When debug is true, the hello tool will be registered for debugging purposes. When compat is true, tools return detailed text responses alongside structured data.

func NewFromService

func NewFromService(service remote.ClientInterface, cfg *config.Config) (*Server, error)

NewFromService creates a new MCP server instance with the provided service. This allows for dependency injection, particularly useful for testing with mock services.

func NewFromServiceWithDebug

func NewFromServiceWithDebug(service remote.ClientInterface, cfg *config.Config, debug bool) (*Server, error)

NewFromServiceWithDebug creates a new MCP server instance with the provided service and debug mode. When debug is true, the hello tool will be registered for debugging purposes.

func NewFromServiceWithDebugAndCompat added in v0.2.0

func NewFromServiceWithDebugAndCompat(service remote.ClientInterface, cfg *config.Config, debug, compat bool) (*Server, error)

NewFromServiceWithDebugAndCompat creates a new MCP server instance with the provided service, debug mode, and compatibility mode. When debug is true, the hello tool will be registered for debugging purposes. When compat is true, tools return detailed text responses alongside structured data.

func NewWithDebug

func NewWithDebug(debug bool) (*Server, error)

NewWithDebug creates a new MCP server instance with debug mode support. When debug is true, the hello tool will be registered for debugging purposes.

func NewWithDebugAndCompat added in v0.2.0

func NewWithDebugAndCompat(debug, compat bool) (*Server, error)

NewWithDebugAndCompat creates a new MCP server instance with debug mode and compatibility mode support. When debug is true, the hello tool will be registered for debugging purposes. When compat is true, tools return detailed text responses alongside structured data.

func (*Server) Config

func (s *Server) Config() *config.Config

Config returns the server configuration. This provides access to the configuration used by the server.

func (*Server) MCPServer

func (s *Server) MCPServer() *mcp.Server

MCPServer returns the underlying MCP server instance. This provides access to the official SDK server for advanced use cases.

Migration Note: Returns the official SDK's *mcp.Server instead of the previous third-party library's server type.

func (*Server) Start

func (s *Server) Start() error

Start starts the MCP server using stdio transport. The server will listen for MCP protocol messages on stdin/stdout.

Migration Note: Updated to use the official SDK's Run method with StdioTransport instead of the previous SDK's server start pattern.

func (*Server) Stop

func (s *Server) Stop() error

Stop stops the MCP server gracefully. Note: For stdio transport, the server runs until the process ends, so this method primarily handles cleanup of resources.

Migration Note: The official SDK handles server lifecycle differently; stdio servers run until process termination rather than explicit stopping.

Jump to

Keyboard shortcuts

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