Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 6 additions & 6 deletions .github/agents/go-sdk-tool-migrator.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ When generating the migration guide, consider the following aspects:

* 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.
* The import for `github.com/mark3labs/mcp-go/mcp` should be changed to `github.com/modelcontextprotocol/go-sdk/mcp`
* 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])`.
* The return type for the tool constructor function should be updated from `mcp.Tool, server.ToolHandlerFunc` to `inventory.ServerTool`.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🛠️ Return a registrable tool: The old tuple does not match the current constructor contract. The migration still supports the existing generic handler shape, but its constructor must return inventory.ServerTool.

* 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)`.
* The `RequiredParam`, `RequiredInt`, `RequiredBigInt`, `OptionalParamOK`, `OptionalParam`, `OptionalIntParam`, `OptionalIntParamWithDefault`, `OptionalBoolParamWithDefault`, `OptionalStringArrayParam`, `OptionalBigIntArrayParam` and `OptionalCursorPaginationParams` functions should be changed to use the tool arguments that are now passed as a map in the tool handler function, rather than extracting them from the `mcp.CallToolRequest`.
* `mcp.NewToolResultText`, `mcp.NewToolResultError`, `mcp.NewToolResultErrorFromErr` and `mcp.NewToolResultResource` no longer available in `modelcontextprotocol/go-sdk`. There are a few helper functions available in `pkg/utils/result.go` that can be used to replace these, in the `utils` package.
Expand Down Expand Up @@ -60,11 +60,11 @@ return mcp.NewTool(
...
```

The corresponding input schema in modelcontextprotocol/go-sdk would look like this:
The corresponding `mcp.Tool` component inside the `inventory.ServerTool` constructor would look like this:

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🛠️ Distinguish schema from constructor: The old illustration could be read as a complete constructor return. The current constructor embeds mcp.Tool inside the server-tool wrapper, so the example now identifies only that component.


```go
...
return mcp.Tool{
mcp.Tool{

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🛠️ Avoid the wrong return value: Returning this bare value conflicts with the server-tool constructor. Removing return keeps this a component illustration rather than a contradictory constructor body.

Name: "list_dependabot_alerts",
Description: t("TOOL_LIST_DEPENDABOT_ALERTS_DESCRIPTION", "List dependabot alerts in a GitHub repository."),
Annotations: &mcp.ToolAnnotations{
Expand All @@ -86,7 +86,7 @@ return mcp.Tool{
Type: "string",
Description: "Filter dependabot alerts by state. Defaults to open",
Enum: []any{"open", "fixed", "dismissed", "auto_dismissed"},
Default: "open",
Default: json.RawMessage(`"open"`),

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🛠️ Use a copyable default: The string default does not match the JSON-encoded default used by the tool. The allowed values and default meaning remain unchanged.

},
"severity": {
Type: "string",
Expand All @@ -103,10 +103,10 @@ return mcp.Tool{

After migrating the tool code and test file, ensure that all tests pass successfully. If any tests fail, review the error messages and adjust the migrated code as necessary to resolve any issues. If you encounter any challenges or need further assistance during the migration process, please let me know.

At the end of your changes, you will continue to have an issue with the `toolsnaps` tests, these validate that the schema has not changed unexpectedly. You can update the snapshots by setting `UPDATE_TOOLSNAPS=true` before running the tests, e.g.:
You can update the snapshots by setting `UPDATE_TOOLSNAPS=true` before running the tests, e.g.:

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🛠️ Do not assume snapshot failure: The snapshot comparison succeeds when schemas are equivalent. Intentional changes may still require an update; the update command and intentional-change safeguard remain.


```bash
UPDATE_TOOLSNAPS=true go test ./...
```

You should however, only update the toolsnaps after confirming that the schema changes are intentional and correct. Some schema changes are unavoidable, such as argument ordering, however the schemas themselves should remain logically equivalent.
You should however, only update the toolsnaps after confirming that the schema changes are intentional and correct. The schemas themselves should remain logically equivalent.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🛠️ Do not require ordering churn: The old example treats argument ordering as an unavoidable snapshot change, but arrays are compared without order sensitivity. The independent requirement to preserve logical equivalence remains.

48 changes: 16 additions & 32 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ This is the **GitHub MCP Server**, a Model Context Protocol (MCP) server that co
- **Primary Package:** github-mcp-server (stdio MCP server - **this is the main focus**)
- **Secondary Package:** mcpcurl (testing utility - don't break it, but not the priority)
- **Framework:** Uses modelcontextprotocol/go-sdk for MCP protocol, google/go-github for GitHub API
- **Size:** ~60MB repository, 70 Go files

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🧹 Avoid a misleading size shortcut: The fixed file total understates the tracked Go inventory and could narrow an investigation prematurely. It is removed rather than replaced with another snapshot; the Go setup requirement remains.

- **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.

**Code Quality Standards:**
Expand Down Expand Up @@ -56,7 +55,7 @@ go build -v ./cmd/github-mcp-server
go test ./pkg/github -v

# Run specific test
go test ./pkg/github -run TestGetMe
go test ./pkg/github -run Test_GetMe

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🛠️ Run the intended test: The old selector does not name the package's Test_GetMe test, so it can return success without exercising it. The example now selects that test.

```

## Project Structure
Expand All @@ -71,7 +70,6 @@ go test ./pkg/github -run TestGetMe
├── pkg/ # Public API packages
│ ├── github/ # GitHub API MCP tools implementation
│ │ └── __toolsnaps__/ # Tool schema snapshots (*.snap files)
│ ├── toolsets/ # Toolset configuration & management

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🧹 Use the existing registration owner: The directory entry points to a missing package. Tool registration remains in the retained pkg/github location through its server-tool registry; no replacement tree entry is needed.

│ ├── errors/ # Error handling utilities
│ ├── sanitize/ # HTML/content sanitization
│ ├── log/ # Logging utilities
Expand Down Expand Up @@ -101,9 +99,9 @@ go test ./pkg/github -run TestGetMe

### Important Scripts (script/ directory)

- **script/lint** - Runs `gofmt` + `golangci-lint`. **MUST RUN** before committing
- **script/lint** - Runs `gofmt` + `golangci-lint`.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🛠️ Pre-commit lint stays required: The required validation sequence already requires this exact script before finishing or committing. Only the repeated mandate is removed.

- **script/test** - Runs `go test -race ./...` (full test suite)
- **script/generate-docs** - Updates README.md tool documentation. Run after tool changes
- **script/generate-docs** - Updates README.md tool documentation.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🛠️ Tool documentation stays required: The required-command rule already covers both tools and toolsets. Removing this narrower repeat does not change when documentation must be regenerated.

- **script/licenses** - Updates third-party license files when dependencies change
- **script/licenses-check** - Validates license compliance (runs in CI)
- **script/get-me** - Quick test script for get_me tool
Expand All @@ -112,15 +110,15 @@ go test ./pkg/github -run TestGetMe

## GitHub Workflows (CI/CD)

All workflows run on push/PR unless noted. Located in `.github/workflows/`:
Located in `.github/workflows/`:

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🛠️ Do not expect every workflow on a PR: The blanket push/PR claim is contradicted by the release workflow's tag-only trigger. This removes the event claim, not the separate merge-policy sentence.


1. **go.yml** - Build and test on ubuntu/windows/macos. Runs `script/test` and builds binary
2. **lint.yml** - Runs golangci-lint-action v2.5 (GitHub Action) with actions/setup-go stable
2. **lint.yml** - Runs golangci-lint-action v9 (GitHub Action) with actions/setup-go using go.mod

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🛠️ Follow the configured lint runtime: The old action version and stable-Go description disagree with the owning workflow, which uses action v9 and reads Go from go.mod.

3. **docs-check.yml** - Verifies README.md is up-to-date by running generate-docs and checking git diff
4. **code-scanning.yml** - CodeQL security analysis for Go and GitHub Actions
5. **license-check.yml** - Runs `script/licenses-check` to validate compliance
6. **docker-publish.yml** - Publishes container image to ghcr.io
7. **goreleaser.yml** - Creates releases (main branch only)
7. **goreleaser.yml** - Creates releases (version-tag pushes)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🛠️ Distinguish tags from branches: The release trigger selects version-tag pushes, not main-branch pushes. The prohibition on creating releases remains elsewhere.

8. **registry-releaser.yml** - Updates MCP registry

**All of these must pass for PR merge.** If docs-check fails, run `script/generate-docs` and commit changes.
Expand All @@ -130,8 +128,8 @@ All workflows run on push/PR unless noted. Located in `.github/workflows/`:
### Unit Tests

- Use `testify` for assertions (`require` for critical checks, `assert` for non-blocking)
- Tests are in `*_test.go` files alongside implementation (internal tests, not `_test` package)
- Mock GitHub API with `go-github-mock` (REST) or `githubv4mock` (GraphQL)
- Tests are in `*_test.go` files alongside implementation

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🛠️ Keep supported test-package choices: The categorical internal-package aside could prompt rewriting valid tests such as the external dependencies test package. Filename and alongside-implementation guidance remain.

- Mock GitHub API with `MockHTTPClientWithHandlers` (REST) or `githubv4mock` (GraphQL)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🛠️ Use the repository REST helper: The old library was replaced by the local HTTP mock helpers. The GraphQL helper remains unchanged.

- Test structure for tools:
1. Test tool snapshot
2. Verify critical schema properties (e.g., ReadOnly annotation)
Expand Down Expand Up @@ -174,21 +172,15 @@ All workflows run on push/PR unless noted. Located in `.github/workflows/`:
### Code Patterns

- **Keep changes minimal and focused** on the specific issue being addressed
- **Prefer clarity over cleverness** - code must be understandable by a wide audience

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🧹 Clarity stays required: The comprehension rule retains the same wide-audience clarity duty. Removing this repeated mandate does not loosen it.

- **Atomic commits** - each commit should be a complete, logical change

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🧹 Atomic commits stay required: The clean-commit rule still requires atomic, focused changes with clear messages.

- **Maintain or improve structure** - never degrade code organization

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🧹 Structure protection stays covered: The structure rule retains the same maintain-or-improve requirement and prohibition on degrading organization.

- Use table-driven tests for behavioral testing
- Comment sparingly - code should be self-documenting

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🧹 Necessary-comment guidance stays covered: The self-documenting-code rule already limits comments to necessary cases; deleting this duplicate does not permit unnecessary comments.

- Follow standard Go conventions (Effective Go, Go proverbs)
- **Test changes thoroughly** before committing

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🧹 Pre-commit testing stays required: The required test sequence still requires the full race suite before finishing or committing. This removes only its generic repeated testing mandate.

- Export functions (capitalize) if they could be used by other repos as a library

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🧹 Library exports stay required: The library-usage rule retains exports for potential external callers even when unused internally, and preserves existing export patterns.


## Common Development Workflows

### Adding a New MCP Tool

1. Add tool implementation in `pkg/github/` (e.g., `foo_tools.go`)
2. Register tool in appropriate toolset in `pkg/github/` or `pkg/toolsets/`
2. Register tool in appropriate toolset in `pkg/github/`

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🛠️ Register at an existing owner: The removed package alternative is missing. The constructor registry supports the retained pkg/github route; registration is still required.

3. Write unit tests following the tool test pattern
4. Run `UPDATE_TOOLSNAPS=true go test ./...` to create snapshot
5. Run `script/generate-docs` to update README
Expand Down Expand Up @@ -239,7 +231,6 @@ All workflows run on push/PR unless noted. Located in `.github/workflows/`:

## Environment Variables

- **GITHUB_PERSONAL_ACCESS_TOKEN** - Required for server operation and e2e tests

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🧹 Do not require the wrong token: The server also supports App and OAuth authentication, so the universal personal-token prerequisite is false. The separate e2e token requirement and invocation remain documented.

- **GITHUB_HOST** - For GitHub Enterprise Server (prefix with `https://`)
- **GITHUB_TOOLSETS** - Comma-separated toolset list (overrides --toolsets flag)
- **GITHUB_READ_ONLY** - Set to "1" for read-only mode
Expand Down Expand Up @@ -270,22 +261,15 @@ server.json - MCP server registry metadata
### Main Entry Point

`cmd/github-mcp-server/main.go` - Uses cobra for CLI, viper for config, supports:
- `stdio` command (default) - MCP stdio transport
- `stdio` command - MCP stdio transport

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🛠️ Invoke stdio explicitly: The root command and stdio subcommand are distinct; the root has no default server handler. Only the default qualifier is removed.

- `generate-docs` command - Documentation generation
- Flags: --toolsets, --read-only, --gh-host, --log-file

## Important Reminders

1. **PRIMARY FOCUS:** The local stdio MCP server (github-mcp-server) - this is what you should work on and test with

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🧹 Local-server priority stays explicit: The primary-package rule retains the same local stdio focus; this removes only its repeated reminder.

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.
3. **ALWAYS** trust these instructions first - only search if information is incomplete or incorrect
4. **NEVER** use `script/tag-release` or push tags
5. **NEVER** skip `script/lint` before committing Go code changes

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🧹 Pre-commit lint stays required: The required-command sequence already names this exact script and covers Go commits.

6. **ALWAYS** update toolsnaps when changing MCP tool schemas

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🧹 Schema snapshots stay required: The tool-change recipe retains generation and commit duties for intentional schema changes.

7. **ALWAYS** run `script/generate-docs` after modifying tools

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🧹 Generated documentation stays required: The required-command rule already covers both tool and toolset changes.

8. For specific test files, use `go test ./path -run TestName` not full suite
9. E2E tests require PAT token - you likely cannot run them

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🧹 Live-test prerequisites stay explicit: The e2e prerequisite and invocation retain the token warning and dedicated variable name.

10. Toolsnaps are API documentation - treat changes seriously
11. Build/test/lint are very fast (~1s each) - run frequently
12. CI failures for docs-check or license-check have simple fixes (run the script)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🧹 Concrete recovery steps stay available: The documentation recovery and license recovery retain both failure triggers and their exact scripts.

13. mcpcurl is secondary - don't break it, but it's not the priority

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🧹 The testing utility stays protected: The secondary-package rule still says not to break mcpcurl and retains its lower priority.

1. **REMOTE SERVER:** Ignore remote server instructions when making code changes (unless specifically asked).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🛠️ Keep the remote exception and export duty: The explicit-request exception remains here. The removed export sentence is already covered by the library-usage rule, including exports unused internally.

2. **ALWAYS** trust these instructions first - only search if information is incomplete or incorrect
3. **NEVER** use `script/tag-release` or push tags
4. For specific test files, use `go test ./path -run TestName` not full suite
5. Toolsnaps are API documentation - treat changes seriously
6. Build/test/lint are very fast (~1s each) - run frequently
Loading