Skip to content

Commit 7c08bdf

Browse files
committed
chore(security): replace inline onclick with addEventListener and add demo CSP meta
1 parent 3347174 commit 7c08bdf

File tree

1 file changed

+84
-242
lines changed

1 file changed

+84
-242
lines changed

.github/copilot-instructions.md

Lines changed: 84 additions & 242 deletions
Original file line numberDiff line numberDiff line change
@@ -45,248 +45,90 @@ If you change any MCP tool definitions or schemas:
4545
```bash
4646
# Download dependencies (rarely needed - usually cached)
4747
go mod download
48+
## Quick agent guide — GitHub MCP Server
4849

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
50+
This repository implements a local Model Context Protocol (MCP) server for GitHub. Focus areas for an AI coding agent:
13951

140-
### Toolsnaps (Tool Schema Snapshots)
52+
- Primary server: [cmd/github-mcp-server](cmd/github-mcp-server) — build with `go build ./cmd/github-mcp-server` and run `./github-mcp-server stdio`.
53+
- Tools implementation: `pkg/github/` (tool defs, prompts, and tool registration). Tool schema snapshots live in `pkg/github/__toolsnaps__/`.
54+
- Core runtime: `internal/ghmcp/` — server wiring, middleware (see user-agent middleware in `internal/ghmcp/server.go`).
14155

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
56+
Required quick commands (run before committing):
57+
58+
- `script/lint` — formats and runs `golangci-lint` (always run).
59+
- `script/test` — runs `go test -race ./...` (use `-run TestName` for focused tests).
60+
- If you changed tool schemas: `UPDATE_TOOLSNAPS=true go test ./...` and commit files from `pkg/github/__toolsnaps__/`.
61+
- If you changed tools/docs: `script/generate-docs` to refresh README tool docs.
62+
63+
Important patterns and conventions (project-specific):
64+
65+
- Tool snapshots: every MCP tool has a JSON `.snap` in `pkg/github/__toolsnaps__`. Tests fail on snapshot drift — update intentionally with `UPDATE_TOOLSNAPS=true`.
66+
- Tool registration & prompts: search `pkg/github/*_tools.go`, `prompts.go`, and `workflow_prompts.go` for examples of tool prompts and usage (e.g., `AssignCodingAgentPrompt`).
67+
- Export surface: this repo is consumed as a library by other servers — prefer exporting functions (capitalize) when they might be reused.
68+
- Naming: acronyms use ALL CAPS in identifiers (`ID`, `HTTP`, `API`, `URL`).
69+
- Tests: table-driven tests are common. Mocks used: `go-github-mock` (REST) and `internal/githubv4mock` (GraphQL).
70+
71+
Where to look for quick examples:
72+
73+
- Tool snapshot example: [pkg/github/__toolsnaps__/assign_copilot_to_issue.snap](pkg/github/__toolsnaps__/assign_copilot_to_issue.snap)
74+
- Tool prompts and registration: [pkg/github/issues.go](pkg/github/issues.go) and [pkg/github/prompts.go](pkg/github/prompts.go)
75+
- Main server entry: [cmd/github-mcp-server/main.go](cmd/github-mcp-server/main.go)
76+
- Core wiring and middleware: [internal/ghmcp/server.go](internal/ghmcp/server.go)
77+
78+
CI and workflows:
79+
80+
- CI runs `script/test` and `script/lint`. `docs-check.yml` ensures `script/generate-docs` is run when tools change.
81+
- Don't use `script/tag-release`; releases are managed separately.
82+
83+
Developer tips for agents:
84+
85+
- When adding or modifying a tool: implement in `pkg/github/`, add tests, run `UPDATE_TOOLSNAPS=true go test ./...`, run `script/generate-docs`, then `script/lint` and `script/test`.
86+
- Use focused tests: `go test ./pkg/github -run TestName` or `go test ./pkg/github -run TestGetMe`.
87+
- E2E tests require a GitHub PAT and are in `e2e/` (run with `GITHUB_MCP_SERVER_E2E_TOKEN=<token> go test -v --tags e2e ./e2e`).
88+
89+
If anything in these instructions is unclear or missing, tell me which areas you'd like expanded (examples, common code locations, or sample PR checklist).
90+
Below is an optional appendix with concrete commands, CI notes, a PR checklist, and a short commit/PR template for changes that affect toolsnaps or generated docs.
91+
92+
---
93+
94+
**Appendix — Scripts, CI notes, PR checklist**
95+
96+
- Quick scripts (run before commit or when CI fails):
97+
- `script/lint` — formats and runs `golangci-lint` (auto-fixes formatting).
98+
- `script/test` — full unit test suite (`go test -race ./...`).
99+
- `UPDATE_TOOLSNAPS=true go test ./...` — regenerate tool schema snapshots (`pkg/github/__toolsnaps__`).
100+
- `script/generate-docs` — refreshes README sections derived from tools.
101+
102+
- Common commands:
103+
- Build server: `go build ./cmd/github-mcp-server`
104+
- Run server: `./github-mcp-server stdio`
105+
- Run focused tests: `go test ./pkg/github -run TestName`
106+
- Run e2e (requires PAT): `GITHUB_MCP_SERVER_E2E_TOKEN=<token> go test -v --tags e2e ./e2e`
107+
108+
- CI notes (when a CI job fails):
109+
- docs-check.yml failing → run `script/generate-docs` and commit README changes.
110+
- lint.yml failing → run `script/lint`, fix reported issues, re-run tests.
111+
- license-check.yml failing → run `script/licenses` then commit updated third-party license files.
112+
113+
- PR checklist for changes affecting tools or docs (include in PR description):
114+
1. Run `script/lint` and `script/test` locally.
115+
2. If tool schema changed: run `UPDATE_TOOLSNAPS=true go test ./...` and commit updated `.snap` files from `pkg/github/__toolsnaps__/`.
116+
3. If tools or prompts changed: run `script/generate-docs` and include README diffs.
117+
4. Ensure table-driven tests cover new behavior; add mocks in `internal/githubv4mock` if needed.
118+
5. Verify CI passes `docs-check`, `lint`, and `license-check` before requesting review.
119+
120+
- Minimal PR commit/description template for toolsnaps/docs changes:
121+
122+
Title: `pkg/github: <short description of change>`
123+
124+
Body:
125+
- What: one-sentence summary of the change.
126+
- Why: brief rationale and intended effect on MCP tools.
127+
- Dev steps performed:
128+
- `script/lint`
129+
- `script/test`
130+
- `UPDATE_TOOLSNAPS=true go test ./...` (if applicable) ✅
131+
- `script/generate-docs` (if applicable) ✅
132+
- Files to review: `pkg/github/<file.go>`, `pkg/github/__toolsnaps__/*.snap`, README changes.
133+
134+
If you want, I can also add a small `.github/PULL_REQUEST_TEMPLATE.md` using this template. Say the word and I will create it.

0 commit comments

Comments
 (0)