Skip to content

Commit 1e7a3f0

Browse files
committed
Merge branch 'main' into omgitsads/go-sdk
2 parents 1d257b1 + bb722f1 commit 1e7a3f0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+819
-563
lines changed

.github/agents/go-sdk-tool-migrator.md

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,13 @@ description: Agent specializing in migrating MCP tools from mark3labs/mcp-go to
77

88
You are a specialized agent designed to assist developers in migrating MCP tools from the mark3labs/mcp-go library to the modelcontextprotocol/go-sdk. Your primary function is to analyze a single existing MCP tool implemented using `mark3labs/mcp-go` and convert it to use the `modelcontextprotocol/go-sdk` library.
99

10-
## Preparation
11-
12-
A cooridinator will assign you a specific MCP tool to migrate.
13-
14-
So that you can work independently of other ongoing migrations, you should immediately begin by creating a git worktree branch named `migrate-go-sdk-<toolset>`, where `<toolset>` is the name of the toolset you are migrating. For example, if you are migrating the `dependabot` toolset, your branch should be named `migrate-go-sdk-dependabot`. You can create the worktree using the following command:
15-
16-
```bash
17-
git worktree add -b migrate-go-sdk-<toolset> origin/omgitsads/go-sdk
18-
```
19-
20-
You should then change into that branch to begin your work:
21-
22-
```bash
23-
cd migrate-go-sdk-<toolset>
24-
```
25-
2610
## Migration Process
2711

28-
You should focus on ONLY the toolset you are asked to migrate and it's corresponding test file. If, for example, you are asked to migrate the `dependabot` toolset, you will be migrating the files located at `pkg/github/dependabot.go` and `pkg/github/dependabot_test.go`. If there are additional tests or helper functions that fail to work with the new SDK, you should inform me of these issues so that I can address them, or instruct you on how to proceed.
12+
You should focus on ONLY the toolset you are asked to migrate and its corresponding test file. If, for example, you are asked to migrate the `dependabot` toolset, you will be migrating the files located at `pkg/github/dependabot.go` and `pkg/github/dependabot_test.go`. If there are additional tests or helper functions that fail to work with the new SDK, you should inform me of these issues so that I can address them, or instruct you on how to proceed.
2913

3014
When generating the migration guide, consider the following aspects:
3115

32-
* The initial tool file and it's corresponding test file will have the `//go:build ignore` build tag, as the tests will fail if the code is not ignored. The `ignore` build tag should be removed before work begins.
16+
* The initial tool file and its corresponding test file will have the `//go:build ignore` build tag, as the tests will fail if the code is not ignored. The `ignore` build tag should be removed before work begins.
3317
* The import for `github.com/mark3labs/mcp-go/mcp` should be changed to `github.com/modelcontextprotocol/go-sdk/mcp`
3418
* The return type for the tool constructor function should be updated from `mcp.Tool, server.ToolHandlerFunc` to `(mcp.Tool, mcp.ToolHandlerFor[map[string]any, any])`.
3519
* The tool handler function signature should be updated to use generics, changing from `func(ctx context.Context, mcp.CallToolRequest) (*mcp.CallToolResult, error)` to `func(context.Context, *mcp.CallToolRequest, map[string]any) (*mcp.CallToolResult, any, error)`.
@@ -101,13 +85,13 @@ return mcp.Tool{
10185
"state": {
10286
Type: "string",
10387
Description: "Filter dependabot alerts by state. Defaults to open",
104-
Enum: []string{"open", "fixed", "dismissed", "auto_dismissed"},
88+
Enum: []any{"open", "fixed", "dismissed", "auto_dismissed"},
10589
Default: "open",
10690
},
10791
"severity": {
10892
Type: "string",
10993
Description: "Filter dependabot alerts by severity",
110-
Enum: []string{"low", "medium", "high", "critical"},
94+
Enum: []any{"low", "medium", "high", "critical"},
11195
},
11296
},
11397
Required: []string{"owner", "repo"},

.github/copilot-instructions.md

Lines changed: 292 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,292 @@
1+
# GitHub MCP Server - Copilot Instructions
2+
3+
## Project Overview
4+
5+
This is the **GitHub MCP Server**, a Model Context Protocol (MCP) server that connects AI tools to GitHub's platform. It enables AI agents to manage repositories, issues, pull requests, workflows, and more through natural language.
6+
7+
**Key Details:**
8+
- **Language:** Go 1.24+ (~38k lines of code)
9+
- **Type:** MCP server application with CLI interface
10+
- **Primary Package:** github-mcp-server (stdio MCP server - **this is the main focus**)
11+
- **Secondary Package:** mcpcurl (testing utility - don't break it, but not the priority)
12+
- **Framework:** Uses mark3labs/mcp-go for MCP protocol, google/go-github for GitHub API
13+
- **Size:** ~60MB repository, 70 Go files
14+
- **Library Usage:** This repository is also used as a library by the remote server. Functions that could be called by other repositories should be exported (capitalized), even if not required internally. Preserve existing export patterns.
15+
16+
**Code Quality Standards:**
17+
- **Popular Open Source Repository** - High bar for code quality and clarity
18+
- **Comprehension First** - Code must be clear to a wide audience
19+
- **Clean Commits** - Atomic, focused changes with clear messages
20+
- **Structure** - Always maintain or improve, never degrade
21+
- **Code over Comments** - Prefer self-documenting code; comment only when necessary
22+
23+
## Critical Build & Validation Steps
24+
25+
### Required Commands (Run Before Committing)
26+
27+
**ALWAYS run these commands in this exact order before using report_progress or finishing work:**
28+
29+
1. **Format Code:** `script/lint` (runs `gofmt -s -w .` then `golangci-lint`)
30+
2. **Run Tests:** `script/test` (runs `go test -race ./...`)
31+
3. **Update Documentation:** `script/generate-docs` (if you modified MCP tools/toolsets)
32+
33+
**These commands are FAST:** Lint ~1s, Tests ~1s (cached), Build ~1s
34+
35+
### When Modifying MCP Tools/Endpoints
36+
37+
If you change any MCP tool definitions or schemas:
38+
1. Run tests with `UPDATE_TOOLSNAPS=true go test ./...` to update toolsnaps
39+
2. Commit the updated `.snap` files in `pkg/github/__toolsnaps__/`
40+
3. Run `script/generate-docs` to update README.md
41+
4. Toolsnaps document API surface and ensure changes are intentional
42+
43+
### Common Build Commands
44+
45+
```bash
46+
# Download dependencies (rarely needed - usually cached)
47+
go mod download
48+
49+
# Build the server binary
50+
go build -v ./cmd/github-mcp-server
51+
52+
# Run the server
53+
./github-mcp-server stdio
54+
55+
# Run specific package tests
56+
go test ./pkg/github -v
57+
58+
# Run specific test
59+
go test ./pkg/github -run TestGetMe
60+
```
61+
62+
## Project Structure
63+
64+
### Directory Layout
65+
66+
```
67+
.
68+
├── cmd/
69+
│ ├── github-mcp-server/ # Main MCP server entry point (PRIMARY FOCUS)
70+
│ └── mcpcurl/ # MCP testing utility (secondary - don't break it)
71+
├── pkg/ # Public API packages
72+
│ ├── github/ # GitHub API MCP tools implementation
73+
│ │ └── __toolsnaps__/ # Tool schema snapshots (*.snap files)
74+
│ ├── toolsets/ # Toolset configuration & management
75+
│ ├── errors/ # Error handling utilities
76+
│ ├── sanitize/ # HTML/content sanitization
77+
│ ├── log/ # Logging utilities
78+
│ ├── raw/ # Raw data handling
79+
│ ├── buffer/ # Buffer utilities
80+
│ └── translations/ # i18n translation support
81+
├── internal/ # Internal implementation packages
82+
│ ├── ghmcp/ # GitHub MCP server core logic
83+
│ ├── githubv4mock/ # GraphQL API mocking for tests
84+
│ ├── toolsnaps/ # Toolsnap validation system
85+
│ └── profiler/ # Performance profiling
86+
├── e2e/ # End-to-end tests (require GitHub PAT)
87+
├── script/ # Build and maintenance scripts
88+
├── docs/ # Documentation
89+
├── .github/workflows/ # CI/CD workflows
90+
└── [config files] # See below
91+
```
92+
93+
### Key Configuration Files
94+
95+
- **go.mod / go.sum:** Go module dependencies (Go 1.24.0+)
96+
- **.golangci.yml:** Linter configuration (v2 format, ~15 linters enabled)
97+
- **Dockerfile:** Multi-stage build (golang:1.25.3-alpine → distroless)
98+
- **server.json:** MCP server metadata for registry
99+
- **.goreleaser.yaml:** Release automation config
100+
- **.gitignore:** Excludes bin/, dist/, vendor/, *.DS_Store, github-mcp-server binary
101+
102+
### Important Scripts (script/ directory)
103+
104+
- **script/lint** - Runs `gofmt` + `golangci-lint`. **MUST RUN** before committing
105+
- **script/test** - Runs `go test -race ./...` (full test suite)
106+
- **script/generate-docs** - Updates README.md tool documentation. Run after tool changes
107+
- **script/licenses** - Updates third-party license files when dependencies change
108+
- **script/licenses-check** - Validates license compliance (runs in CI)
109+
- **script/get-me** - Quick test script for get_me tool
110+
- **script/get-discussions** - Quick test for discussions
111+
- **script/tag-release** - **NEVER USE THIS** - releases are managed separately
112+
113+
## GitHub Workflows (CI/CD)
114+
115+
All workflows run on push/PR unless noted. Located in `.github/workflows/`:
116+
117+
1. **go.yml** - Build and test on ubuntu/windows/macos. Runs `script/test` and builds binary
118+
2. **lint.yml** - Runs golangci-lint-action v2.5 (GitHub Action) with actions/setup-go stable
119+
3. **docs-check.yml** - Verifies README.md is up-to-date by running generate-docs and checking git diff
120+
4. **code-scanning.yml** - CodeQL security analysis for Go and GitHub Actions
121+
5. **license-check.yml** - Runs `script/licenses-check` to validate compliance
122+
6. **docker-publish.yml** - Publishes container image to ghcr.io
123+
7. **goreleaser.yml** - Creates releases (main branch only)
124+
8. **registry-releaser.yml** - Updates MCP registry
125+
126+
**All of these must pass for PR merge.** If docs-check fails, run `script/generate-docs` and commit changes.
127+
128+
## Testing Guidelines
129+
130+
### Unit Tests
131+
132+
- Use `testify` for assertions (`require` for critical checks, `assert` for non-blocking)
133+
- Tests are in `*_test.go` files alongside implementation (internal tests, not `_test` package)
134+
- Mock GitHub API with `go-github-mock` (REST) or `githubv4mock` (GraphQL)
135+
- Test structure for tools:
136+
1. Test tool snapshot
137+
2. Verify critical schema properties (e.g., ReadOnly annotation)
138+
3. Table-driven behavioral tests
139+
140+
### Toolsnaps (Tool Schema Snapshots)
141+
142+
- Every MCP tool has a JSON schema snapshot in `pkg/github/__toolsnaps__/*.snap`
143+
- Tests fail if current schema differs from snapshot (shows diff)
144+
- To update after intentional changes: `UPDATE_TOOLSNAPS=true go test ./...`
145+
- **MUST commit updated .snap files** - they document API changes
146+
- Missing snapshots cause CI failure
147+
148+
### End-to-End Tests
149+
150+
- Located in `e2e/` directory with `e2e_test.go`
151+
- **Require GitHub PAT token** - you usually cannot run these yourself
152+
- Run with: `GITHUB_MCP_SERVER_E2E_TOKEN=<token> go test -v --tags e2e ./e2e`
153+
- Tests interact with live GitHub API via Docker container
154+
- **Keep e2e tests updated when changing MCP tools**
155+
- **Use only the e2e test style** when modifying tests in this directory
156+
- For debugging: `GITHUB_MCP_SERVER_E2E_DEBUG=true` runs in-process (no Docker)
157+
158+
## Code Style & Linting
159+
160+
### Go Code Requirements
161+
162+
- **gofmt with simplify flag (-s)** - Automatically run by `script/lint`
163+
- **golangci-lint** with these linters enabled:
164+
- bodyclose, gocritic, gosec, makezero, misspell, nakedret, revive
165+
- errcheck, staticcheck, govet, ineffassign, unused
166+
- Exclusions for: third_party/, builtin/, examples/, generated code
167+
168+
### Go Naming Conventions
169+
170+
- **Acronyms in identifiers:** Use `ID` not `Id`, `API` not `Api`, `URL` not `Url`, `HTTP` not `Http`
171+
- Examples: `userID`, `getAPI`, `parseURL`, `HTTPClient`
172+
- This applies to variable names, function names, struct fields, etc.
173+
174+
### Code Patterns
175+
176+
- **Keep changes minimal and focused** on the specific issue being addressed
177+
- **Prefer clarity over cleverness** - code must be understandable by a wide audience
178+
- **Atomic commits** - each commit should be a complete, logical change
179+
- **Maintain or improve structure** - never degrade code organization
180+
- Use table-driven tests for behavioral testing
181+
- Comment sparingly - code should be self-documenting
182+
- Follow standard Go conventions (Effective Go, Go proverbs)
183+
- **Test changes thoroughly** before committing
184+
- Export functions (capitalize) if they could be used by other repos as a library
185+
186+
## Common Development Workflows
187+
188+
### Adding a New MCP Tool
189+
190+
1. Add tool implementation in `pkg/github/` (e.g., `foo_tools.go`)
191+
2. Register tool in appropriate toolset in `pkg/github/` or `pkg/toolsets/`
192+
3. Write unit tests following the tool test pattern
193+
4. Run `UPDATE_TOOLSNAPS=true go test ./...` to create snapshot
194+
5. Run `script/generate-docs` to update README
195+
6. Run `script/lint` and `script/test` before committing
196+
7. If e2e tests are relevant, update `e2e/e2e_test.go` using existing test style
197+
8. Commit code + snapshots + README changes together
198+
199+
### Fixing a Bug
200+
201+
1. Write a failing test that reproduces the bug
202+
2. Fix the bug with minimal changes
203+
3. Verify test passes and existing tests still pass
204+
4. Run `script/lint` and `script/test`
205+
5. If tool schema changed, update toolsnaps (see above)
206+
207+
### Updating Dependencies
208+
209+
1. Update `go.mod` (e.g., `go get -u ./...` or manually)
210+
2. Run `go mod tidy`
211+
3. Run `script/licenses` to update license files
212+
4. Run `script/test` to verify nothing broke
213+
5. Commit go.mod, go.sum, and third-party-licenses* files
214+
215+
## Common Errors & Solutions
216+
217+
### "Documentation is out of date" in CI
218+
219+
**Fix:** Run `script/generate-docs` and commit README.md changes
220+
221+
### Toolsnap mismatch failures
222+
223+
**Fix:** Run `UPDATE_TOOLSNAPS=true go test ./...` and commit updated .snap files
224+
225+
### Lint failures
226+
227+
**Fix:** Run `script/lint` locally - it will auto-format and show issues. Fix manually reported issues.
228+
229+
### License check failures
230+
231+
**Fix:** Run `script/licenses` to regenerate license files after dependency changes
232+
233+
### Test failures after changing a tool
234+
235+
**Likely causes:**
236+
1. Forgot to update toolsnaps - run with `UPDATE_TOOLSNAPS=true`
237+
2. Changed behavior broke existing tests - verify intent and fix tests
238+
3. Schema change not reflected in test - update test expectations
239+
240+
## Environment Variables
241+
242+
- **GITHUB_PERSONAL_ACCESS_TOKEN** - Required for server operation and e2e tests
243+
- **GITHUB_HOST** - For GitHub Enterprise Server (prefix with `https://`)
244+
- **GITHUB_TOOLSETS** - Comma-separated toolset list (overrides --toolsets flag)
245+
- **GITHUB_READ_ONLY** - Set to "1" for read-only mode
246+
- **GITHUB_DYNAMIC_TOOLSETS** - Set to "1" for dynamic toolset discovery
247+
- **UPDATE_TOOLSNAPS** - Set to "true" when running tests to update snapshots
248+
- **GITHUB_MCP_SERVER_E2E_TOKEN** - Token for e2e tests
249+
- **GITHUB_MCP_SERVER_E2E_DEBUG** - Set to "true" for in-process e2e debugging
250+
251+
## Key Files Reference
252+
253+
### Root Directory Files
254+
```
255+
.dockerignore - Docker build exclusions
256+
.gitignore - Git exclusions (includes bin/, dist/, vendor/, binaries)
257+
.golangci.yml - Linter configuration
258+
.goreleaser.yaml - Release automation
259+
CODE_OF_CONDUCT.md - Community guidelines
260+
CONTRIBUTING.md - Contribution guide (fork, clone, test, lint workflow)
261+
Dockerfile - Multi-stage Go build
262+
LICENSE - MIT license
263+
README.md - Main documentation (auto-generated sections)
264+
SECURITY.md - Security policy
265+
SUPPORT.md - Support resources
266+
gemini-extension.json - Gemini CLI configuration
267+
go.mod / go.sum - Go dependencies
268+
server.json - MCP server registry metadata
269+
```
270+
271+
### Main Entry Point
272+
273+
`cmd/github-mcp-server/main.go` - Uses cobra for CLI, viper for config, supports:
274+
- `stdio` command (default) - MCP stdio transport
275+
- `generate-docs` command - Documentation generation
276+
- Flags: --toolsets, --read-only, --dynamic-toolsets, --gh-host, --log-file
277+
278+
## Important Reminders
279+
280+
1. **PRIMARY FOCUS:** The local stdio MCP server (github-mcp-server) - this is what you should work on and test with
281+
2. **REMOTE SERVER:** Ignore remote server instructions when making code changes (unless specifically asked). This repo is used as a library by the remote server, so keep functions exported (capitalized) if they could be called by other repos, even if not needed internally.
282+
3. **ALWAYS** trust these instructions first - only search if information is incomplete or incorrect
283+
4. **NEVER** use `script/tag-release` or push tags
284+
5. **NEVER** skip `script/lint` before committing Go code changes
285+
6. **ALWAYS** update toolsnaps when changing MCP tool schemas
286+
7. **ALWAYS** run `script/generate-docs` after modifying tools
287+
8. For specific test files, use `go test ./path -run TestName` not full suite
288+
9. E2E tests require PAT token - you likely cannot run them
289+
10. Toolsnaps are API documentation - treat changes seriously
290+
11. Build/test/lint are very fast (~1s each) - run frequently
291+
12. CI failures for docs-check or license-check have simple fixes (run the script)
292+
13. mcpcurl is secondary - don't break it, but it's not the priority

.github/workflows/docker-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070
# https://github.com/docker/metadata-action
7171
- name: Extract Docker metadata
7272
id: meta
73-
uses: docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f # v5.8.0
73+
uses: docker/metadata-action@318604b99e75e41977312d83839a89be02ca4893 # v5.9.0
7474
with:
7575
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
7676
tags: |

0 commit comments

Comments
 (0)