Documentation
¶
Index ¶
- Constants
- func CleanPath(path string) string
- func CreateFileNotFoundError(owner, repo, path, ref string) error
- func ExtractIssueNumber(url string) (int, error)
- func ExtractPullRequestNumber(url string) (int, error)
- func ExtractWorkflowRunID(url string) (int64, error)
- func GetEnvInt(envVar string, defaultValue int) int
- func GetEnvRateLimit(envVar string, defaultValue int) int
- func NewGitHubClient(ctx context.Context, config *AuthConfig) (*github.Client, error)
- func ValidateRepository(repository string) (owner, repo string, err error)
- type AuthConfig
- type Branch
- type CloneResult
- type Comment
- type DirectoryItem
- type DirectoryListing
- type FileContent
- type FileResult
- type FilteredFileContent
- type FilteredIssue
- type FilteredIssueDetails
- type FilteredPullRequest
- type FilteredPullRequestDetails
- type FilteredRepository
- type GitHubClient
- func (gc *GitHubClient) CloneRepository(ctx context.Context, owner, repo, localPath string) (*CloneResult, error)
- func (gc *GitHubClient) GetFileContents(ctx context.Context, owner, repo string, paths []string, ref string, ...) ([]FileResult, error)
- func (gc *GitHubClient) GetIssue(ctx context.Context, owner, repo string, number int, includeComments bool) (*FilteredIssueDetails, []Comment, error)
- func (gc *GitHubClient) GetPullRequest(ctx context.Context, owner, repo string, number int, includeComments bool) (*FilteredPullRequestDetails, []Comment, error)
- func (gc *GitHubClient) GetWorkflowRun(ctx context.Context, owner, repo string, runID int64, includeLogs bool) (*WorkflowRun, string, error)
- func (gc *GitHubClient) ListDirectory(ctx context.Context, owner, repo, path, ref string) (*DirectoryListing, error)
- func (gc *GitHubClient) SearchIssues(ctx context.Context, owner, repo, query string, limit int, includeClosed bool) (*SearchResult, error)
- func (gc *GitHubClient) SearchPullRequests(ctx context.Context, owner, repo, query string, limit int, includeClosed bool) (*SearchResult, error)
- func (gc *GitHubClient) SearchRepositories(ctx context.Context, query string, limit int) (*SearchResult, error)
- type GitHubRequest
- type GitHubTool
- type Issue
- type Label
- type PullRequest
- type Repository
- type SearchResult
- type User
- type WorkflowRun
Constants ¶
const ( // GitHub API rate limits based on GitHub best practices DefaultCoreAPIRateLimit = 80 // requests per minute (4800/hour, under 5000/hour limit) DefaultSearchAPIRateLimit = 25 // requests per minute (under 30/minute limit) DefaultMaxLines = 3000 // maximum lines to return from get_file_contents before truncating GitHubCoreAPIRateLimitEnvVar = "GITHUB_CORE_API_RATE_LIMIT" GitHubSearchAPIRateLimitEnvVar = "GITHUB_SEARCH_API_RATE_LIMIT" GitHubMaxLinesEnvVar = "GITHUB_MAX_LINES" )
Variables ¶
This section is empty.
Functions ¶
func CreateFileNotFoundError ¶ added in v0.23.1
CreateFileNotFoundError creates a helpful error message for file not found
func ExtractIssueNumber ¶
ExtractIssueNumber extracts issue number from GitHub issue URL
func ExtractPullRequestNumber ¶
ExtractPullRequestNumber extracts PR number from GitHub PR URL
func ExtractWorkflowRunID ¶
ExtractWorkflowRunID extracts workflow run ID from GitHub Actions URL
func GetEnvInt ¶ added in v0.42.0
GetEnvInt gets an integer value from environment variable with fallback to default
func GetEnvRateLimit ¶ added in v0.21.2
GetEnvRateLimit gets rate limit from environment variable with fallback to default
func NewGitHubClient ¶
NewGitHubClient creates a new GitHub client with appropriate authentication
func ValidateRepository ¶
ValidateRepository parses and validates repository identifier Supports formats: - owner/repo - https://github.com/owner/repo - https://github.com/owner/repo.git - https://github.com/owner/repo/issues/123 - https://github.com/owner/repo/pull/456
Types ¶
type AuthConfig ¶
type AuthConfig struct {
Method string `json:"method"` // "token", "ssh", or "none"
Token string `json:"token,omitempty"`
SSHKeyPath string `json:"ssh_key_path,omitempty"`
}
AuthConfig represents authentication configuration
func GetAuthConfig ¶
func GetAuthConfig() (*AuthConfig, error)
GetAuthConfig determines the authentication method and configuration
type Branch ¶
type Branch struct {
Label string `json:"label"`
Ref string `json:"ref"`
SHA string `json:"sha"`
User User `json:"user"`
}
Branch represents a GitHub branch
type CloneResult ¶
type CloneResult struct {
Repository string `json:"repository"`
LocalPath string `json:"local_path"`
CloneURL string `json:"clone_url"`
Success bool `json:"success"`
Message string `json:"message,omitempty"`
}
CloneResult represents the result of a clone operation
type Comment ¶
type Comment struct {
ID int64 `json:"id"`
Body string `json:"body"`
User User `json:"user"`
HTMLURL string `json:"html_url"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
Comment represents a GitHub comment
type DirectoryItem ¶ added in v0.23.1
type DirectoryItem struct {
Name string `json:"name"`
Path string `json:"path"`
Type string `json:"type"` // "file", "dir", "symlink", etc.
Size int `json:"size,omitempty"`
SHA string `json:"sha,omitempty"`
}
DirectoryItem represents an item in a directory listing
type DirectoryListing ¶ added in v0.23.1
type DirectoryListing struct {
Path string `json:"path"`
Items []DirectoryItem `json:"items"`
}
DirectoryListing represents the contents of a directory
type FileContent ¶
type FileContent struct {
Name string `json:"name"`
Path string `json:"path"`
SHA string `json:"sha"`
Size int `json:"size"`
URL string `json:"url"`
HTMLURL string `json:"html_url"`
GitURL string `json:"git_url"`
DownloadURL string `json:"download_url"`
Type string `json:"type"`
Content string `json:"content,omitempty"`
Encoding string `json:"encoding,omitempty"`
}
FileContent represents the content of a file in a repository
type FileResult ¶ added in v0.23.1
type FileResult struct {
Path string `json:"path"`
Size int `json:"size,omitempty"`
Content string `json:"content,omitempty"`
Success bool `json:"success"`
Error string `json:"error,omitempty"`
TotalLines int `json:"total_lines,omitempty"`
LinesReturned string `json:"lines_returned,omitempty"`
Truncated bool `json:"truncated,omitempty"`
Message string `json:"message,omitempty"`
}
FileResult represents the result of attempting to fetch a file (success or failure)
type FilteredFileContent ¶
type FilteredFileContent struct {
Path string `json:"path"`
Size int `json:"size"`
Content string `json:"content,omitempty"`
}
FilteredFileContent represents minimal file content
type FilteredIssue ¶
type FilteredIssue struct {
ID int64 `json:"id"`
Number int `json:"number"`
Title string `json:"title"`
Body string `json:"body,omitempty"`
State string `json:"state"`
Login string `json:"login"` // user.login
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
FilteredIssue represents minimal issue for search results
type FilteredIssueDetails ¶
type FilteredIssueDetails struct {
ID int64 `json:"id"`
Body string `json:"body,omitempty"`
Login string `json:"login"` // user.login
Repository string `json:"repository"`
}
FilteredIssueDetails represents minimal issue details for get_issue
type FilteredPullRequest ¶
type FilteredPullRequest struct {
ID int64 `json:"id"`
Number int `json:"number"`
Title string `json:"title"`
Body string `json:"body,omitempty"`
State string `json:"state"`
Login string `json:"login"` // user.login
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
FilteredPullRequest represents minimal PR for search results
type FilteredPullRequestDetails ¶
type FilteredPullRequestDetails struct {
ID int64 `json:"id"`
Number int `json:"number"`
Title string `json:"title"`
Body string `json:"body,omitempty"`
State string `json:"state"`
Login string `json:"login"` // user.login
HeadLabel string `json:"head_label"` // head.label (e.g., "user:branch")
HeadRepo string `json:"head_repo"` // head repository full name (e.g., "user/repo")
HeadRef string `json:"head_ref"` // head branch/ref name (e.g., "branch")
BaseLabel string `json:"base_label"` // base.label (e.g., "owner:main")
BaseRepo string `json:"base_repo"` // base repository full name (e.g., "owner/repo")
BaseRef string `json:"base_ref"` // base branch/ref name (e.g., "main")
Comments int `json:"comments"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
FilteredPullRequestDetails represents minimal PR details for get_pull_request
type FilteredRepository ¶
type FilteredRepository struct {
ID int64 `json:"id"`
FullName string `json:"full_name"`
Description string `json:"description,omitempty"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
FilteredRepository represents a minimal repository for search results
type GitHubClient ¶
type GitHubClient struct {
// contains filtered or unexported fields
}
GitHubClient wraps the GitHub API client with additional functionality
func NewGitHubClientWrapper ¶
NewGitHubClientWrapper creates a new GitHub client wrapper
func (*GitHubClient) CloneRepository ¶
func (gc *GitHubClient) CloneRepository(ctx context.Context, owner, repo, localPath string) (*CloneResult, error)
CloneRepository clones a repository to a local directory
func (*GitHubClient) GetFileContents ¶
func (gc *GitHubClient) GetFileContents(ctx context.Context, owner, repo string, paths []string, ref string, lineStart int) ([]FileResult, error)
GetFileContents gets the contents of one or more files from a repository with graceful error handling lineStart is optional (0 or 1 means start from beginning) lineStart is 1-based (first line is 1, not 0) Files exceeding max lines are automatically truncated with guidance
func (*GitHubClient) GetIssue ¶
func (gc *GitHubClient) GetIssue(ctx context.Context, owner, repo string, number int, includeComments bool) (*FilteredIssueDetails, []Comment, error)
GetIssue gets a specific issue with optional comments
func (*GitHubClient) GetPullRequest ¶
func (gc *GitHubClient) GetPullRequest(ctx context.Context, owner, repo string, number int, includeComments bool) (*FilteredPullRequestDetails, []Comment, error)
GetPullRequest gets a specific pull request with optional comments
func (*GitHubClient) GetWorkflowRun ¶
func (gc *GitHubClient) GetWorkflowRun(ctx context.Context, owner, repo string, runID int64, includeLogs bool) (*WorkflowRun, string, error)
GetWorkflowRun gets GitHub Actions workflow run status and optionally logs
func (*GitHubClient) ListDirectory ¶ added in v0.23.1
func (gc *GitHubClient) ListDirectory(ctx context.Context, owner, repo, path, ref string) (*DirectoryListing, error)
ListDirectory lists the contents of a directory in a repository
func (*GitHubClient) SearchIssues ¶
func (gc *GitHubClient) SearchIssues(ctx context.Context, owner, repo, query string, limit int, includeClosed bool) (*SearchResult, error)
SearchIssues searches for issues in a repository
func (*GitHubClient) SearchPullRequests ¶
func (gc *GitHubClient) SearchPullRequests(ctx context.Context, owner, repo, query string, limit int, includeClosed bool) (*SearchResult, error)
SearchPullRequests searches for pull requests in a repository
func (*GitHubClient) SearchRepositories ¶
func (gc *GitHubClient) SearchRepositories(ctx context.Context, query string, limit int) (*SearchResult, error)
SearchRepositories searches for repositories
type GitHubRequest ¶
type GitHubRequest struct {
Function string `json:"function"`
Repository string `json:"repository"`
Options map[string]any `json:"options,omitempty"`
}
GitHubRequest represents the unified request structure for all GitHub operations
type GitHubTool ¶
type GitHubTool struct{}
GitHubTool implements GitHub functionality for MCP
func (*GitHubTool) Definition ¶
func (t *GitHubTool) Definition() mcp.Tool
Definition returns the tool's definition for MCP registration
func (*GitHubTool) Execute ¶
func (t *GitHubTool) Execute(ctx context.Context, logger *logrus.Logger, cache *sync.Map, args map[string]any) (*mcp.CallToolResult, error)
Execute executes the GitHub tool
func (*GitHubTool) ProvideExtendedInfo ¶ added in v0.22.0
func (t *GitHubTool) ProvideExtendedInfo() *tools.ExtendedHelp
ProvideExtendedInfo provides detailed usage information for the github tool
type Issue ¶
type Issue struct {
ID int64 `json:"id"`
Number int `json:"number"`
Title string `json:"title"`
Body string `json:"body,omitempty"`
State string `json:"state"`
User User `json:"user"`
Assignee *User `json:"assignee,omitempty"`
Labels []Label `json:"labels"`
Comments int `json:"comments"`
HTMLURL string `json:"html_url"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
ClosedAt string `json:"closed_at,omitempty"`
}
Issue represents a GitHub issue
type Label ¶
type Label struct {
ID int64 `json:"id"`
Name string `json:"name"`
Color string `json:"color"`
Description string `json:"description,omitempty"`
}
Label represents a GitHub label
type PullRequest ¶
type PullRequest struct {
ID int64 `json:"id"`
Number int `json:"number"`
Title string `json:"title"`
Body string `json:"body,omitempty"`
State string `json:"state"`
User User `json:"user"`
Assignee *User `json:"assignee,omitempty"`
Labels []Label `json:"labels"`
Head Branch `json:"head"`
Base Branch `json:"base"`
Merged bool `json:"merged"`
Mergeable *bool `json:"mergeable,omitempty"`
Comments int `json:"comments"`
Commits int `json:"commits"`
Additions int `json:"additions"`
Deletions int `json:"deletions"`
HTMLURL string `json:"html_url"`
DiffURL string `json:"diff_url"`
PatchURL string `json:"patch_url"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
ClosedAt string `json:"closed_at,omitempty"`
MergedAt string `json:"merged_at,omitempty"`
}
PullRequest represents a GitHub pull request
type Repository ¶
type Repository struct {
ID int64 `json:"id"`
Name string `json:"name"`
FullName string `json:"full_name"`
Description string `json:"description,omitempty"`
Private bool `json:"private"`
HTMLURL string `json:"html_url"`
CloneURL string `json:"clone_url"`
SSHURL string `json:"ssh_url"`
Language string `json:"language,omitempty"`
Stars int `json:"stargazers_count"`
Forks int `json:"forks_count"`
OpenIssues int `json:"open_issues_count"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
Repository represents a GitHub repository
type SearchResult ¶
type SearchResult struct {
TotalCount int `json:"total_count"`
IncompleteResults bool `json:"incomplete_results"`
Items any `json:"items"`
}
SearchResult represents a generic search result wrapper
type User ¶
type User struct {
ID int64 `json:"id"`
Login string `json:"login"`
Name string `json:"name,omitempty"`
Email string `json:"email,omitempty"`
AvatarURL string `json:"avatar_url"`
HTMLURL string `json:"html_url"`
Type string `json:"type"`
}
User represents a GitHub user
type WorkflowRun ¶
type WorkflowRun struct {
ID int64 `json:"id"`
Name string `json:"name"`
Status string `json:"status"`
Conclusion string `json:"conclusion,omitempty"`
URL string `json:"url"`
HTMLURL string `json:"html_url"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
RunStartedAt string `json:"run_started_at,omitempty"`
}
WorkflowRun represents a GitHub Actions workflow run