Skip to content

Support debugging e2e tests #380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 7, 2025
Merged

Support debugging e2e tests #380

merged 2 commits into from
May 7, 2025

Conversation

williammartin
Copy link
Collaborator

@williammartin williammartin commented May 7, 2025

Description

While working on other issues, I often found myself experiencing failures that were not easy to debug given the black box nature of the e2e tests. Now we can use GITHUB_MCP_SERVER_E2E_DEBUG=true to run an inprocess server version of the server, allowing for breakpointing. Open to renaming the env var to indicate exactly what it does, rather than debug. See image:

image
➜  github-mcp-server git:(wm/debug-e2e-tests) GOMAXPROCS=1 GITHUB_MCP_SERVER_E2E_TOKEN=$(gh auth token) go test -v -count=1 --tags e2e ./e2e

=== RUN   TestGetMe
=== PAUSE TestGetMe
=== RUN   TestToolsets
=== PAUSE TestToolsets
=== RUN   TestTags
=== PAUSE TestTags
=== CONT  TestGetMe
    e2e_test.go:49: Building Docker image for e2e tests...
    e2e_test.go:122: Starting Stdio MCP client...
--- PASS: TestGetMe (3.07s)
=== CONT  TestTags
    e2e_test.go:122: Starting Stdio MCP client...
    e2e_test.go:245: Getting current user...
    e2e_test.go:274: Creating repository williammartin/github-mcp-server-e2e-TestTags-1746619480361...
    e2e_test.go:291: Creating tag williammartin/github-mcp-server-e2e-TestTags-1746619480361:v0.0.1...
    e2e_test.go:321: Listing tags for williammartin/github-mcp-server-e2e-TestTags-1746619480361...
    e2e_test.go:354: Getting tag williammartin/github-mcp-server-e2e-TestTags-1746619480361:v0.0.1...
    e2e_test.go:283: Deleting repository williammartin/github-mcp-server-e2e-TestTags-1746619480361...
--- PASS: TestTags (3.51s)
=== CONT  TestToolsets
    e2e_test.go:122: Starting Stdio MCP client...
--- PASS: TestToolsets (0.19s)
PASS
ok      github.com/github/github-mcp-server/e2e 7.048s

➜  github-mcp-server git:(wm/debug-e2e-tests) GOMAXPROCS=1 GITHUB_MCP_SERVER_E2E_DEBUG=true GITHUB_MCP_SERVER_E2E_TOKEN=$(gh auth token) go test -v -count=1 --tags e2e ./e2e

=== RUN   TestGetMe
=== PAUSE TestGetMe
=== RUN   TestToolsets
=== PAUSE TestToolsets
=== RUN   TestTags
=== PAUSE TestTags
=== CONT  TestGetMe
    e2e_test.go:142: Starting In Process MCP client...
--- PASS: TestGetMe (0.46s)
=== CONT  TestTags
    e2e_test.go:142: Starting In Process MCP client...
    e2e_test.go:245: Getting current user...
    e2e_test.go:274: Creating repository williammartin/github-mcp-server-e2e-TestTags-1746619493471...
    e2e_test.go:291: Creating tag williammartin/github-mcp-server-e2e-TestTags-1746619493471:v0.0.1...
    e2e_test.go:321: Listing tags for williammartin/github-mcp-server-e2e-TestTags-1746619493471...
    e2e_test.go:354: Getting tag williammartin/github-mcp-server-e2e-TestTags-1746619493471:v0.0.1...
    e2e_test.go:283: Deleting repository williammartin/github-mcp-server-e2e-TestTags-1746619493471...
--- PASS: TestTags (3.04s)
=== CONT  TestToolsets
    e2e_test.go:142: Starting In Process MCP client...
--- PASS: TestToolsets (0.00s)
PASS
ok      github.com/github/github-mcp-server/e2e 3.738s
➜  github-mcp-server git:(wm/debug-e2e-tests)

Doing this also drove out some nice cleanups, separating config parsing, mcp server construction and stdio server execution. I have not written unit tests for these extracted functions as they were not previously tested and currently get most of their coverage from the e2e tests. I believe that later we may want to look into further testing of these to support further refactors, but that is out of scope for this PR.

@Copilot Copilot AI review requested due to automatic review settings May 7, 2025 12:04
@williammartin williammartin requested a review from a team as a code owner May 7, 2025 12:04
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors server startup logic into a shared internal package and adds an in-process debug mode for end-to-end tests.

  • Extract NewMCPServer and RunStdioServer into internal/ghmcp and wire them into the CLI
  • Update e2e tests to optionally run the MCP server in‐process via GITHUB_MCP_SERVER_E2E_DEBUG
  • Document the new debug mode in e2e/README.md

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
internal/ghmcp/server.go New shared server construction & stdio runner
e2e/e2e_test.go Refactor test client setup to support Docker vs. in-process debug
e2e/README.md Add instructions for the GITHUB_MCP_SERVER_E2E_DEBUG flag
cmd/github-mcp-server/main.go Switch CLI commands to use internal/ghmcp and RunE for errors
Comments suppressed due to low confidence (2)

internal/ghmcp/server.go:101

  • [nitpick] The variable name context shadows the imported context package. Consider renaming to ctxToolset or similar to avoid confusion.
context := github.InitContextToolset(getClient, cfg.Translator)

internal/ghmcp/server.go:47

  • Newly extracted functions like NewMCPServer and RunStdioServer lack direct unit tests. Consider adding unit tests to cover config parsing, hook registration, and shutdown behavior.
func NewMCPServer(cfg MCPServerConfig) (*server.MCPServer, error) {

enabledToolsets = github.DefaultTools
}

ghServer, err := ghmcp.NewMCPServer(ghmcp.MCPServerConfig{
Copy link
Preview

Copilot AI May 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MCPServerConfig only sets Token, EnabledToolsets, and Translator, leaving Version, Host, DynamicToolsets, and ReadOnly at zero values. This can change client behavior—please populate all required fields.

Copilot uses AI. Check for mistakes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeh they aren't required, that's why.

This commit cleanly separates config parsing, stdio server execution and
mcp server construction. Aside from significant clarity improvements, it
allows for direct construction of the mcp server in e2e tests to allow
for breakpoint debugging.
juruen
juruen previously approved these changes May 7, 2025
Copy link
Collaborator

@juruen juruen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Just a small comment. 🚀

e2e/e2e_test.go Outdated
args = append(args, "github/e2e-github-mcp-server")

// Construct the env vars for the MCP Client to execute docker with
dockerEnvVars := make([]string, 0, len(opts.enabledToolsets)+1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm not mistaken, as you are joining opts.enabledToolsets below, you might not want to set this slice size, and it could be just 2?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this was part of the previous implementation where we supported WithEnvVars, so it could have been n. Good spot, thanks, will adjust before merge.

@williammartin
Copy link
Collaborator Author

Bypassing review requirement as the only thing I changed after @juruen approved was to fix https://github.com/github/github-mcp-server/pull/380/files#r2077653340

@williammartin williammartin merged commit 0ca07aa into main May 7, 2025
16 checks passed
@williammartin williammartin deleted the wm/debug-e2e-tests branch May 7, 2025 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants