Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
edbdf4b
docs: Add Google Gemini CLI installation guide and integration
ipapapa Jul 26, 2025
89ec9f5
Fix Gemini CLI command syntax and add remote server method
ipapapa Aug 2, 2025
526a6c1
Merge branch 'main' into add-gemini-cli-docs
ipapapa Aug 3, 2025
0127628
Emphasize official Gemini CLI documentation link
ipapapa Aug 5, 2025
a6e2426
Fix Gemini CLI configuration file name: config.json -> settings.json
ipapapa Aug 8, 2025
bc96391
Remove Gemini CLI installation and authentication sections
ipapapa Aug 8, 2025
79e0782
Add Podman as Docker alternative in prerequisites
ipapapa Aug 8, 2025
6bfae0d
Remove references to deprecated npm package
ipapapa Aug 8, 2025
c52a1de
Add comprehensive ~/.gemini/.env file example
ipapapa Aug 8, 2025
e5e7bfd
Fix authorization header to use literal token placeholder
ipapapa Aug 8, 2025
d6696f6
Merge branch 'main' into add-gemini-cli-docs
ipapapa Aug 14, 2025
7e73679
Add issue types (#869)
JoannaaKL Aug 14, 2025
8f794ab
Enable Dependabot (#654)
zkoppert Aug 14, 2025
660967c
Bump SDK version to 0.36.0 (#863)
almaleksia Aug 14, 2025
83c67d1
Use server.ServerResourceTemplate and server.ServerPrompt wrappers (#…
almaleksia Aug 14, 2025
0d4dca9
Update "Close inactive issues" workflow to close issues after 180 day…
tommaso-moro Aug 18, 2025
34434aa
Update Claude MCP install guide after testing (#706)
D1M1TR10S Aug 18, 2025
fc381f8
Add actions job log buffer and profiler (#866)
mattdholloway Aug 19, 2025
615cc60
Add get_release_by_tag tool (#938)
tommaso-moro Aug 21, 2025
72a7214
docs(readme): Update readme to point to correct installation guides i…
beccccaboo Aug 21, 2025
cd4454e
Add Global Security Advisories Toolset (#919)
jurre Aug 21, 2025
ad3bf32
Repository security advisories (#925)
jurre Aug 21, 2025
6d4e070
Update Cursor installation link (#940)
tommaso-moro Aug 21, 2025
b33df25
Change role from "system" to "user" in prompt messages for `AssignCod…
tommaso-moro Aug 21, 2025
7acaad0
Resolve merge conflict with latest upstream main
ipapapa Aug 28, 2025
60fa301
Merge branch 'main' into add-gemini-cli-docs
LuluBeatson Aug 29, 2025
39db9e7
Local MCP is supported
LuluBeatson Aug 29, 2025
ff86293
Refactor Gemini CLI install guide
LuluBeatson Aug 29, 2025
f2e5ad7
Remove Bearer from Authorization header
ipapapa Aug 29, 2025
26d9139
Add reference to main README for latest config
ipapapa Aug 31, 2025
f86124e
Bearer needed for headers, add references
LuluBeatson Sep 2, 2025
12040db
Add minimal response to CRUD tools, `repositories` and `search` tools…
mattdholloway Sep 1, 2025
f898f17
initial org repo create support (#1023)
mattdholloway Sep 2, 2025
f6718c7
Merge branch 'main' into add-gemini-cli-docs
LuluBeatson Sep 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add actions job log buffer and profiler (#866)
* add sliding window for actions logs

* refactor: fix sliding

* remove trim content

* only use up to 1mb of memory for logs

* update to tail lines in second pass

* add better memory usage calculation

* increase window size to 5MB

* update test

* update vers

* undo vers change

* add incremental memory tracking

* use ring buffer

* remove unused ctx param

* remove manual GC clear

* fix cca feedback

* extract ring buffer logic to new package

* handle log content processing errors and use correct param for maxjobloglines

* fix tailing

* account for if tailLines exceeds window size

* add profiling thats reusable

* remove profiler testing

* refactor profiler: introduce safeMemoryDelta for accurate memory delta calculations

* linter fixes

* Update pkg/buffer/buffer.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* use flag for maxJobLogLines

* add param passing for context window size

* refactor: rename contextWindowSize to contentWindowSize for consistency

* fix: use tailLines if bigger but only if <= 5000

* fix: limit tailLines to a maximum of 500 for log content download

* Update cmd/github-mcp-server/main.go

Co-authored-by: Adam Holt <omgitsads@github.com>

* Update cmd/github-mcp-server/main.go

Co-authored-by: Adam Holt <omgitsads@github.com>

* move profiler to internal/

* update actions test with new profiler location

* fix: adjust buffer size limits

* make line buffer 1028kb

* fix mod path

* change test to use same buffer size as normal use

* improve test for non-sliding window implementation to not count empty lines

* make test memory measurement more accurate

* remove impossible conditional

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Adam Holt <omgitsads@github.com>
  • Loading branch information
3 people authored and ipapapa committed Aug 28, 2025
commit fc381f899fb85d0015d472df302cb94c6f468ab7
4 changes: 2 additions & 2 deletions cmd/github-mcp-server/generate_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func generateReadmeDocs(readmePath string) error {
t, _ := translations.TranslationHelper()

// Create toolset group with mock clients
tsg := github.DefaultToolsetGroup(false, mockGetClient, mockGetGQLClient, mockGetRawClient, t)
tsg := github.DefaultToolsetGroup(false, mockGetClient, mockGetGQLClient, mockGetRawClient, t, 5000)

// Generate toolsets documentation
toolsetsDoc := generateToolsetsDoc(tsg)
Expand Down Expand Up @@ -302,7 +302,7 @@ func generateRemoteToolsetsDoc() string {
t, _ := translations.TranslationHelper()

// Create toolset group with mock clients
tsg := github.DefaultToolsetGroup(false, mockGetClient, mockGetGQLClient, mockGetRawClient, t)
tsg := github.DefaultToolsetGroup(false, mockGetClient, mockGetGQLClient, mockGetRawClient, t, 5000)

// Generate table header
buf.WriteString("| Name | Description | API URL | 1-Click Install (VS Code) | Read-only Link | 1-Click Read-only Install (VS Code) |\n")
Expand Down
3 changes: 3 additions & 0 deletions cmd/github-mcp-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ var (
ExportTranslations: viper.GetBool("export-translations"),
EnableCommandLogging: viper.GetBool("enable-command-logging"),
LogFilePath: viper.GetString("log-file"),
ContentWindowSize: viper.GetInt("content-window-size"),
}
return ghmcp.RunStdioServer(stdioServerConfig)
},
Expand All @@ -75,6 +76,7 @@ func init() {
rootCmd.PersistentFlags().Bool("enable-command-logging", false, "When enabled, the server will log all command requests and responses to the log file")
rootCmd.PersistentFlags().Bool("export-translations", false, "Save translations to a JSON file")
rootCmd.PersistentFlags().String("gh-host", "", "Specify the GitHub hostname (for GitHub Enterprise etc.)")
rootCmd.PersistentFlags().Int("content-window-size", 5000, "Specify the content window size")

// Bind flag to viper
_ = viper.BindPFlag("toolsets", rootCmd.PersistentFlags().Lookup("toolsets"))
Expand All @@ -84,6 +86,7 @@ func init() {
_ = viper.BindPFlag("enable-command-logging", rootCmd.PersistentFlags().Lookup("enable-command-logging"))
_ = viper.BindPFlag("export-translations", rootCmd.PersistentFlags().Lookup("export-translations"))
_ = viper.BindPFlag("host", rootCmd.PersistentFlags().Lookup("gh-host"))
_ = viper.BindPFlag("content-window-size", rootCmd.PersistentFlags().Lookup("content-window-size"))

// Add subcommands
rootCmd.AddCommand(stdioCmd)
Expand Down
23 changes: 15 additions & 8 deletions internal/ghmcp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ type MCPServerConfig struct {

// Translator provides translated text for the server tooling
Translator translations.TranslationHelperFunc

// Content window size
ContentWindowSize int
}

const stdioServerLogPrefix = "stdioserver"
Expand Down Expand Up @@ -132,7 +135,7 @@ func NewMCPServer(cfg MCPServerConfig) (*server.MCPServer, error) {
}

// Create default toolsets
tsg := github.DefaultToolsetGroup(cfg.ReadOnly, getClient, getGQLClient, getRawClient, cfg.Translator)
tsg := github.DefaultToolsetGroup(cfg.ReadOnly, getClient, getGQLClient, getRawClient, cfg.Translator, cfg.ContentWindowSize)
err = tsg.EnableToolsets(enabledToolsets)

if err != nil {
Expand Down Expand Up @@ -180,6 +183,9 @@ type StdioServerConfig struct {

// Path to the log file if not stderr
LogFilePath string

// Content window size
ContentWindowSize int
}

// RunStdioServer is not concurrent safe.
Expand All @@ -191,13 +197,14 @@ func RunStdioServer(cfg StdioServerConfig) error {
t, dumpTranslations := translations.TranslationHelper()

ghServer, err := NewMCPServer(MCPServerConfig{
Version: cfg.Version,
Host: cfg.Host,
Token: cfg.Token,
EnabledToolsets: cfg.EnabledToolsets,
DynamicToolsets: cfg.DynamicToolsets,
ReadOnly: cfg.ReadOnly,
Translator: t,
Version: cfg.Version,
Host: cfg.Host,
Token: cfg.Token,
EnabledToolsets: cfg.EnabledToolsets,
DynamicToolsets: cfg.DynamicToolsets,
ReadOnly: cfg.ReadOnly,
Translator: t,
ContentWindowSize: cfg.ContentWindowSize,
})
if err != nil {
return fmt.Errorf("failed to create MCP server: %w", err)
Expand Down
215 changes: 215 additions & 0 deletions internal/profiler/profiler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
package profiler

import (
"context"
"fmt"
"os"
"runtime"
"strconv"
"time"

"log/slog"
"math"
)

// Profile represents performance metrics for an operation
type Profile struct {
Operation string `json:"operation"`
Duration time.Duration `json:"duration_ns"`
MemoryBefore uint64 `json:"memory_before_bytes"`
MemoryAfter uint64 `json:"memory_after_bytes"`
MemoryDelta int64 `json:"memory_delta_bytes"`
LinesCount int `json:"lines_count,omitempty"`
BytesCount int64 `json:"bytes_count,omitempty"`
Timestamp time.Time `json:"timestamp"`
}

// String returns a human-readable representation of the profile
func (p *Profile) String() string {
return fmt.Sprintf("[%s] %s: duration=%v, memory_delta=%+dB, lines=%d, bytes=%d",
p.Timestamp.Format("15:04:05.000"),
p.Operation,
p.Duration,
p.MemoryDelta,
p.LinesCount,
p.BytesCount,
)
}

func safeMemoryDelta(after, before uint64) int64 {
if after > math.MaxInt64 || before > math.MaxInt64 {
if after >= before {
diff := after - before
if diff > math.MaxInt64 {
return math.MaxInt64
}
return int64(diff)
}
diff := before - after
if diff > math.MaxInt64 {
return -math.MaxInt64
}
return -int64(diff)
}

return int64(after) - int64(before)
}

// Profiler provides minimal performance profiling capabilities
type Profiler struct {
logger *slog.Logger
enabled bool
}

// New creates a new Profiler instance
func New(logger *slog.Logger, enabled bool) *Profiler {
return &Profiler{
logger: logger,
enabled: enabled,
}
}

// ProfileFunc profiles a function execution
func (p *Profiler) ProfileFunc(ctx context.Context, operation string, fn func() error) (*Profile, error) {
if !p.enabled {
return nil, fn()
}

profile := &Profile{
Operation: operation,
Timestamp: time.Now(),
}

var memBefore runtime.MemStats
runtime.ReadMemStats(&memBefore)
profile.MemoryBefore = memBefore.Alloc

start := time.Now()
err := fn()
profile.Duration = time.Since(start)

var memAfter runtime.MemStats
runtime.ReadMemStats(&memAfter)
profile.MemoryAfter = memAfter.Alloc
profile.MemoryDelta = safeMemoryDelta(memAfter.Alloc, memBefore.Alloc)

if p.logger != nil {
p.logger.InfoContext(ctx, "Performance profile", "profile", profile.String())
}

return profile, err
}

// ProfileFuncWithMetrics profiles a function execution and captures additional metrics
func (p *Profiler) ProfileFuncWithMetrics(ctx context.Context, operation string, fn func() (int, int64, error)) (*Profile, error) {
if !p.enabled {
_, _, err := fn()
return nil, err
}

profile := &Profile{
Operation: operation,
Timestamp: time.Now(),
}

var memBefore runtime.MemStats
runtime.ReadMemStats(&memBefore)
profile.MemoryBefore = memBefore.Alloc

start := time.Now()
lines, bytes, err := fn()
profile.Duration = time.Since(start)
profile.LinesCount = lines
profile.BytesCount = bytes

var memAfter runtime.MemStats
runtime.ReadMemStats(&memAfter)
profile.MemoryAfter = memAfter.Alloc
profile.MemoryDelta = safeMemoryDelta(memAfter.Alloc, memBefore.Alloc)

if p.logger != nil {
p.logger.InfoContext(ctx, "Performance profile", "profile", profile.String())
}

return profile, err
}

// Start begins timing an operation and returns a function to complete the profiling
func (p *Profiler) Start(ctx context.Context, operation string) func(lines int, bytes int64) *Profile {
if !p.enabled {
return func(int, int64) *Profile { return nil }
}

profile := &Profile{
Operation: operation,
Timestamp: time.Now(),
}

var memBefore runtime.MemStats
runtime.ReadMemStats(&memBefore)
profile.MemoryBefore = memBefore.Alloc

start := time.Now()

return func(lines int, bytes int64) *Profile {
profile.Duration = time.Since(start)
profile.LinesCount = lines
profile.BytesCount = bytes

var memAfter runtime.MemStats
runtime.ReadMemStats(&memAfter)
profile.MemoryAfter = memAfter.Alloc
profile.MemoryDelta = safeMemoryDelta(memAfter.Alloc, memBefore.Alloc)

if p.logger != nil {
p.logger.InfoContext(ctx, "Performance profile", "profile", profile.String())
}

return profile
}
}

var globalProfiler *Profiler

// IsProfilingEnabled checks if profiling is enabled via environment variables
func IsProfilingEnabled() bool {
if enabled, err := strconv.ParseBool(os.Getenv("GITHUB_MCP_PROFILING_ENABLED")); err == nil {
return enabled
}
return false
}

// Init initializes the global profiler
func Init(logger *slog.Logger, enabled bool) {
globalProfiler = New(logger, enabled)
}

// InitFromEnv initializes the global profiler using environment variables
func InitFromEnv(logger *slog.Logger) {
globalProfiler = New(logger, IsProfilingEnabled())
}

// ProfileFunc profiles a function using the global profiler
func ProfileFunc(ctx context.Context, operation string, fn func() error) (*Profile, error) {
if globalProfiler == nil {
return nil, fn()
}
return globalProfiler.ProfileFunc(ctx, operation, fn)
}

// ProfileFuncWithMetrics profiles a function with metrics using the global profiler
func ProfileFuncWithMetrics(ctx context.Context, operation string, fn func() (int, int64, error)) (*Profile, error) {
if globalProfiler == nil {
_, _, err := fn()
return nil, err
}
return globalProfiler.ProfileFuncWithMetrics(ctx, operation, fn)
}

// Start begins timing using the global profiler
func Start(ctx context.Context, operation string) func(int, int64) *Profile {
if globalProfiler == nil {
return func(int, int64) *Profile { return nil }
}
return globalProfiler.Start(ctx, operation)
}
69 changes: 69 additions & 0 deletions pkg/buffer/buffer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package buffer

import (
"bufio"
"fmt"
"net/http"
"strings"
)

// ProcessResponseAsRingBufferToEnd reads the body of an HTTP response line by line,
// storing only the last maxJobLogLines lines using a ring buffer (sliding window).
// This efficiently retains the most recent lines, overwriting older ones as needed.
//
// Parameters:
//
// httpResp: The HTTP response whose body will be read.
// maxJobLogLines: The maximum number of log lines to retain.
//
// Returns:
//
// string: The concatenated log lines (up to maxJobLogLines), separated by newlines.
// int: The total number of lines read from the response.
// *http.Response: The original HTTP response.
// error: Any error encountered during reading.
//
// The function uses a ring buffer to efficiently store only the last maxJobLogLines lines.
// If the response contains more lines than maxJobLogLines, only the most recent lines are kept.
func ProcessResponseAsRingBufferToEnd(httpResp *http.Response, maxJobLogLines int) (string, int, *http.Response, error) {
lines := make([]string, maxJobLogLines)
validLines := make([]bool, maxJobLogLines)
totalLines := 0
writeIndex := 0

scanner := bufio.NewScanner(httpResp.Body)
scanner.Buffer(make([]byte, 0, 64*1024), 1024*1024)

for scanner.Scan() {
line := scanner.Text()
totalLines++

lines[writeIndex] = line
validLines[writeIndex] = true
writeIndex = (writeIndex + 1) % maxJobLogLines
}

if err := scanner.Err(); err != nil {
return "", 0, httpResp, fmt.Errorf("failed to read log content: %w", err)
}

var result []string
linesInBuffer := totalLines
if linesInBuffer > maxJobLogLines {
linesInBuffer = maxJobLogLines
}

startIndex := 0
if totalLines > maxJobLogLines {
startIndex = writeIndex
}

for i := 0; i < linesInBuffer; i++ {
idx := (startIndex + i) % maxJobLogLines
if validLines[idx] {
result = append(result, lines[idx])
}
}

return strings.Join(result, "\n"), totalLines, httpResp, nil
}
Loading