diff --git a/.github/agents/go-sdk-tool-migrator.md b/.github/agents/go-sdk-tool-migrator.md new file mode 100644 index 000000000..f8003fd25 --- /dev/null +++ b/.github/agents/go-sdk-tool-migrator.md @@ -0,0 +1,112 @@ +--- +name: go-sdk-tool-migrator +description: Agent specializing in migrating MCP tools from mark3labs/mcp-go to modelcontextprotocol/go-sdk +--- + +# Go SDK Tool Migrator Agent + +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. + +## Migration Process + +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. + +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 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. + +### Schema Changes + +The biggest change when migrating MCP tools from mark3labs/mcp-go to modelcontextprotocol/go-sdk is the way input and output schemas are defined and handled. In `mark3labs/mcp-go`, input and output schemas were often defined using a DSL provided by the library. In `modelcontextprotocol/go-sdk`, schemas are defined using `jsonschema.Schema` structures using `github.com/google/jsonschema-go`, which are more verbose. + +When migrating a tool, you will need to convert the existing schema definitions to JSON Schema format. This involves defining the properties, types, and any validation rules using the JSON Schema specification. + +#### Example Schema Guide + +If we take an example of a tool that has the following input schema in mark3labs/mcp-go: + +```go +... +return mcp.NewTool( + "list_dependabot_alerts", + mcp.WithDescription(t("TOOL_LIST_DEPENDABOT_ALERTS_DESCRIPTION", "List dependabot alerts in a GitHub repository.")), + mcp.WithToolAnnotation(mcp.ToolAnnotation{ + Title: t("TOOL_LIST_DEPENDABOT_ALERTS_USER_TITLE", "List dependabot alerts"), + ReadOnlyHint: ToBoolPtr(true), + }), + mcp.WithString("owner", + mcp.Required(), + mcp.Description("The owner of the repository."), + ), + mcp.WithString("repo", + mcp.Required(), + mcp.Description("The name of the repository."), + ), + mcp.WithString("state", + mcp.Description("Filter dependabot alerts by state. Defaults to open"), + mcp.DefaultString("open"), + mcp.Enum("open", "fixed", "dismissed", "auto_dismissed"), + ), + mcp.WithString("severity", + mcp.Description("Filter dependabot alerts by severity"), + mcp.Enum("low", "medium", "high", "critical"), + ), + ), +... +``` + +The corresponding input schema in modelcontextprotocol/go-sdk would look like this: + +```go +... +return mcp.Tool{ + Name: "list_dependabot_alerts", + Description: t("TOOL_LIST_DEPENDABOT_ALERTS_DESCRIPTION", "List dependabot alerts in a GitHub repository."), + Annotations: &mcp.ToolAnnotations{ + Title: t("TOOL_LIST_DEPENDABOT_ALERTS_USER_TITLE", "List dependabot alerts"), + ReadOnlyHint: true, + }, + InputSchema: &jsonschema.Schema{ + Type: "object", + Properties: map[string]*jsonschema.Schema{ + "owner": { + Type: "string", + Description: "The owner of the repository.", + }, + "repo": { + Type: "string", + Description: "The name of the repository.", + }, + "state": { + Type: "string", + Description: "Filter dependabot alerts by state. Defaults to open", + Enum: []any{"open", "fixed", "dismissed", "auto_dismissed"}, + Default: "open", + }, + "severity": { + Type: "string", + Description: "Filter dependabot alerts by severity", + Enum: []any{"low", "medium", "high", "critical"}, + }, + }, + Required: []string{"owner", "repo"}, + }, +} +``` + +### Tests + +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.: + +```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. diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md new file mode 100644 index 000000000..bc7a647a6 --- /dev/null +++ b/.github/copilot-instructions.md @@ -0,0 +1,292 @@ +# GitHub MCP Server - Copilot Instructions + +## Project Overview + +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. + +**Key Details:** +- **Language:** Go 1.24+ (~38k lines of code) +- **Type:** MCP server application with CLI interface +- **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 mark3labs/mcp-go for MCP protocol, google/go-github for GitHub API +- **Size:** ~60MB repository, 70 Go files +- **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:** +- **Popular Open Source Repository** - High bar for code quality and clarity +- **Comprehension First** - Code must be clear to a wide audience +- **Clean Commits** - Atomic, focused changes with clear messages +- **Structure** - Always maintain or improve, never degrade +- **Code over Comments** - Prefer self-documenting code; comment only when necessary + +## Critical Build & Validation Steps + +### Required Commands (Run Before Committing) + +**ALWAYS run these commands in this exact order before using report_progress or finishing work:** + +1. **Format Code:** `script/lint` (runs `gofmt -s -w .` then `golangci-lint`) +2. **Run Tests:** `script/test` (runs `go test -race ./...`) +3. **Update Documentation:** `script/generate-docs` (if you modified MCP tools/toolsets) + +**These commands are FAST:** Lint ~1s, Tests ~1s (cached), Build ~1s + +### When Modifying MCP Tools/Endpoints + +If you change any MCP tool definitions or schemas: +1. Run tests with `UPDATE_TOOLSNAPS=true go test ./...` to update toolsnaps +2. Commit the updated `.snap` files in `pkg/github/__toolsnaps__/` +3. Run `script/generate-docs` to update README.md +4. Toolsnaps document API surface and ensure changes are intentional + +### Common Build Commands + +```bash +# Download dependencies (rarely needed - usually cached) +go mod download + +# Build the server binary +go build -v ./cmd/github-mcp-server + +# Run the server +./github-mcp-server stdio + +# Run specific package tests +go test ./pkg/github -v + +# Run specific test +go test ./pkg/github -run TestGetMe +``` + +## Project Structure + +### Directory Layout + +``` +. +├── cmd/ +│ ├── github-mcp-server/ # Main MCP server entry point (PRIMARY FOCUS) +│ └── mcpcurl/ # MCP testing utility (secondary - don't break it) +├── pkg/ # Public API packages +│ ├── github/ # GitHub API MCP tools implementation +│ │ └── __toolsnaps__/ # Tool schema snapshots (*.snap files) +│ ├── toolsets/ # Toolset configuration & management +│ ├── errors/ # Error handling utilities +│ ├── sanitize/ # HTML/content sanitization +│ ├── log/ # Logging utilities +│ ├── raw/ # Raw data handling +│ ├── buffer/ # Buffer utilities +│ └── translations/ # i18n translation support +├── internal/ # Internal implementation packages +│ ├── ghmcp/ # GitHub MCP server core logic +│ ├── githubv4mock/ # GraphQL API mocking for tests +│ ├── toolsnaps/ # Toolsnap validation system +│ └── profiler/ # Performance profiling +├── e2e/ # End-to-end tests (require GitHub PAT) +├── script/ # Build and maintenance scripts +├── docs/ # Documentation +├── .github/workflows/ # CI/CD workflows +└── [config files] # See below +``` + +### Key Configuration Files + +- **go.mod / go.sum:** Go module dependencies (Go 1.24.0+) +- **.golangci.yml:** Linter configuration (v2 format, ~15 linters enabled) +- **Dockerfile:** Multi-stage build (golang:1.25.3-alpine → distroless) +- **server.json:** MCP server metadata for registry +- **.goreleaser.yaml:** Release automation config +- **.gitignore:** Excludes bin/, dist/, vendor/, *.DS_Store, github-mcp-server binary + +### Important Scripts (script/ directory) + +- **script/lint** - Runs `gofmt` + `golangci-lint`. **MUST RUN** before committing +- **script/test** - Runs `go test -race ./...` (full test suite) +- **script/generate-docs** - Updates README.md tool documentation. Run after tool changes +- **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 +- **script/get-discussions** - Quick test for discussions +- **script/tag-release** - **NEVER USE THIS** - releases are managed separately + +## GitHub Workflows (CI/CD) + +All workflows run on push/PR unless noted. Located in `.github/workflows/`: + +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 +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) +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. + +## Testing Guidelines + +### 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) +- Test structure for tools: + 1. Test tool snapshot + 2. Verify critical schema properties (e.g., ReadOnly annotation) + 3. Table-driven behavioral tests + +### Toolsnaps (Tool Schema Snapshots) + +- Every MCP tool has a JSON schema snapshot in `pkg/github/__toolsnaps__/*.snap` +- Tests fail if current schema differs from snapshot (shows diff) +- To update after intentional changes: `UPDATE_TOOLSNAPS=true go test ./...` +- **MUST commit updated .snap files** - they document API changes +- Missing snapshots cause CI failure + +### End-to-End Tests + +- Located in `e2e/` directory with `e2e_test.go` +- **Require GitHub PAT token** - you usually cannot run these yourself +- Run with: `GITHUB_MCP_SERVER_E2E_TOKEN= go test -v --tags e2e ./e2e` +- Tests interact with live GitHub API via Docker container +- **Keep e2e tests updated when changing MCP tools** +- **Use only the e2e test style** when modifying tests in this directory +- For debugging: `GITHUB_MCP_SERVER_E2E_DEBUG=true` runs in-process (no Docker) + +## Code Style & Linting + +### Go Code Requirements + +- **gofmt with simplify flag (-s)** - Automatically run by `script/lint` +- **golangci-lint** with these linters enabled: + - bodyclose, gocritic, gosec, makezero, misspell, nakedret, revive + - errcheck, staticcheck, govet, ineffassign, unused +- Exclusions for: third_party/, builtin/, examples/, generated code + +### Go Naming Conventions + +- **Acronyms in identifiers:** Use `ID` not `Id`, `API` not `Api`, `URL` not `Url`, `HTTP` not `Http` +- Examples: `userID`, `getAPI`, `parseURL`, `HTTPClient` +- This applies to variable names, function names, struct fields, etc. + +### 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 +- **Atomic commits** - each commit should be a complete, logical change +- **Maintain or improve structure** - never degrade code organization +- Use table-driven tests for behavioral testing +- Comment sparingly - code should be self-documenting +- Follow standard Go conventions (Effective Go, Go proverbs) +- **Test changes thoroughly** before committing +- Export functions (capitalize) if they could be used by other repos as a library + +## 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/` +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 +6. Run `script/lint` and `script/test` before committing +7. If e2e tests are relevant, update `e2e/e2e_test.go` using existing test style +8. Commit code + snapshots + README changes together + +### Fixing a Bug + +1. Write a failing test that reproduces the bug +2. Fix the bug with minimal changes +3. Verify test passes and existing tests still pass +4. Run `script/lint` and `script/test` +5. If tool schema changed, update toolsnaps (see above) + +### Updating Dependencies + +1. Update `go.mod` (e.g., `go get -u ./...` or manually) +2. Run `go mod tidy` +3. Run `script/licenses` to update license files +4. Run `script/test` to verify nothing broke +5. Commit go.mod, go.sum, and third-party-licenses* files + +## Common Errors & Solutions + +### "Documentation is out of date" in CI + +**Fix:** Run `script/generate-docs` and commit README.md changes + +### Toolsnap mismatch failures + +**Fix:** Run `UPDATE_TOOLSNAPS=true go test ./...` and commit updated .snap files + +### Lint failures + +**Fix:** Run `script/lint` locally - it will auto-format and show issues. Fix manually reported issues. + +### License check failures + +**Fix:** Run `script/licenses` to regenerate license files after dependency changes + +### Test failures after changing a tool + +**Likely causes:** +1. Forgot to update toolsnaps - run with `UPDATE_TOOLSNAPS=true` +2. Changed behavior broke existing tests - verify intent and fix tests +3. Schema change not reflected in test - update test expectations + +## Environment Variables + +- **GITHUB_PERSONAL_ACCESS_TOKEN** - Required for server operation and e2e tests +- **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 +- **GITHUB_DYNAMIC_TOOLSETS** - Set to "1" for dynamic toolset discovery +- **UPDATE_TOOLSNAPS** - Set to "true" when running tests to update snapshots +- **GITHUB_MCP_SERVER_E2E_TOKEN** - Token for e2e tests +- **GITHUB_MCP_SERVER_E2E_DEBUG** - Set to "true" for in-process e2e debugging + +## Key Files Reference + +### Root Directory Files +``` +.dockerignore - Docker build exclusions +.gitignore - Git exclusions (includes bin/, dist/, vendor/, binaries) +.golangci.yml - Linter configuration +.goreleaser.yaml - Release automation +CODE_OF_CONDUCT.md - Community guidelines +CONTRIBUTING.md - Contribution guide (fork, clone, test, lint workflow) +Dockerfile - Multi-stage Go build +LICENSE - MIT license +README.md - Main documentation (auto-generated sections) +SECURITY.md - Security policy +SUPPORT.md - Support resources +gemini-extension.json - Gemini CLI configuration +go.mod / go.sum - Go dependencies +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 +- `generate-docs` command - Documentation generation +- Flags: --toolsets, --read-only, --dynamic-toolsets, --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 +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 +6. **ALWAYS** update toolsnaps when changing MCP tool schemas +7. **ALWAYS** run `script/generate-docs` after modifying tools +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 +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) +13. mcpcurl is secondary - don't break it, but it's not the priority \ No newline at end of file diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 28c7f00a0..baaf6c2f0 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -70,7 +70,7 @@ jobs: # https://github.com/docker/metadata-action - name: Extract Docker metadata id: meta - uses: docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f # v5.8.0 + uses: docker/metadata-action@318604b99e75e41977312d83839a89be02ca4893 # v5.9.0 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | diff --git a/README.md b/README.md index 70491f6fd..7c4884074 100644 --- a/README.md +++ b/README.md @@ -414,7 +414,7 @@ The following sets of tools are available: | `users` | GitHub User related tools | -### Additional Toolsets in Remote Github MCP Server +### Additional Toolsets in Remote GitHub MCP Server | Toolset | Description | | ----------------------- | ------------------------------------------------------------- | @@ -844,24 +844,30 @@ Options are: - `project_number`: The project's number. (number, required) - **list_project_fields** - List project fields + - `after`: Forward pagination cursor from previous pageInfo.nextCursor. (string, optional) + - `before`: Backward pagination cursor from previous pageInfo.prevCursor (rare). (string, optional) - `owner`: If owner_type == user it is the handle for the GitHub user account. If owner_type == org it is the name of the organization. The name is not case sensitive. (string, required) - `owner_type`: Owner type (string, required) - - `per_page`: Number of results per page (max 100, default: 30) (number, optional) + - `per_page`: Results per page (max 50) (number, optional) - `project_number`: The project's number. (number, required) - **list_project_items** - List project items - - `fields`: Specific list of field IDs to include in the response (e.g. ["102589", "985201", "169875"]). If not provided, only the title field is included. (string[], optional) + - `after`: Forward pagination cursor from previous pageInfo.nextCursor. (string, optional) + - `before`: Backward pagination cursor from previous pageInfo.prevCursor (rare). (string, optional) + - `fields`: Field IDs to include (e.g. ["102589", "985201"]). CRITICAL: Always provide to get field values. Without this, only titles returned. (string[], optional) - `owner`: If owner_type == user it is the handle for the GitHub user account. If owner_type == org it is the name of the organization. The name is not case sensitive. (string, required) - `owner_type`: Owner type (string, required) - - `per_page`: Number of results per page (max 100, default: 30) (number, optional) + - `per_page`: Results per page (max 50) (number, optional) - `project_number`: The project's number. (number, required) - - `query`: Search query to filter items (string, optional) + - `query`: Query string for advanced filtering of project items using GitHub's project filtering syntax. (string, optional) - **list_projects** - List projects + - `after`: Forward pagination cursor from previous pageInfo.nextCursor. (string, optional) + - `before`: Backward pagination cursor from previous pageInfo.prevCursor (rare). (string, optional) - `owner`: If owner_type == user it is the handle for the GitHub user account. If owner_type == org it is the name of the organization. The name is not case sensitive. (string, required) - `owner_type`: Owner type (string, required) - - `per_page`: Number of results per page (max 100, default: 30) (number, optional) - - `query`: Filter projects by a search query (matches title and description) (string, optional) + - `per_page`: Results per page (max 50) (number, optional) + - `query`: Filter projects by title text and open/closed state; permitted qualifiers: is:open, is:closed; examples: "roadmap is:open", "is:open feature planning". (string, optional) - **update_project_item** - Update project item - `item_id`: The unique identifier of the project item. This is not the issue or pull request ID. (number, required) @@ -1182,7 +1188,7 @@ Possible options: -### Additional Tools in Remote Github MCP Server +### Additional Tools in Remote GitHub MCP Server
@@ -1218,7 +1224,7 @@ Possible options: ## Dynamic Tool Discovery -**Note**: This feature is currently in beta and may not be available in all environments. Please test it out and let us know if you encounter any issues. +**Note**: This feature is currently in beta and is not available in the Remote GitHub MCP Server. Please test it out and let us know if you encounter any issues. Instead of starting with all tools enabled, you can turn on dynamic toolset discovery. Dynamic toolsets allow the MCP host to list and enable toolsets in response to a user prompt. This should help to avoid situations where the model gets confused by the sheer number of tools available. diff --git a/cmd/github-mcp-server/generate_docs.go b/cmd/github-mcp-server/generate_docs.go index 478b35bd4..546bd716b 100644 --- a/cmd/github-mcp-server/generate_docs.go +++ b/cmd/github-mcp-server/generate_docs.go @@ -13,8 +13,9 @@ import ( "github.com/github/github-mcp-server/pkg/raw" "github.com/github/github-mcp-server/pkg/toolsets" "github.com/github/github-mcp-server/pkg/translations" - gogithub "github.com/google/go-github/v77/github" - "github.com/mark3labs/mcp-go/mcp" + gogithub "github.com/google/go-github/v79/github" + "github.com/google/jsonschema-go/jsonschema" + "github.com/modelcontextprotocol/go-sdk/mcp" "github.com/shurcooL/githubv4" "github.com/spf13/cobra" ) @@ -224,7 +225,12 @@ func generateToolDoc(tool mcp.Tool) string { lines = append(lines, fmt.Sprintf("- **%s** - %s", tool.Name, tool.Annotations.Title)) // Parameters - schema := tool.InputSchema + schema, ok := tool.InputSchema.(*jsonschema.Schema) + if !ok { + lines = append(lines, " - No parameters required") + return strings.Join(lines, "\n") + } + if len(schema.Properties) > 0 { // Get parameter names and sort them for deterministic order var paramNames []string @@ -241,30 +247,22 @@ func generateToolDoc(tool mcp.Tool) string { requiredStr = "required" } - // Get the type and description - typeStr := "unknown" - description := "" - - if propMap, ok := prop.(map[string]interface{}); ok { - if typeVal, ok := propMap["type"].(string); ok { - if typeVal == "array" { - if items, ok := propMap["items"].(map[string]interface{}); ok { - if itemType, ok := items["type"].(string); ok { - typeStr = itemType + "[]" - } - } else { - typeStr = "array" - } - } else { - typeStr = typeVal - } - } + var typeStr, description string - if desc, ok := propMap["description"].(string); ok { - description = desc + // Get the type and description + switch prop.Type { + case "array": + if prop.Items != nil { + typeStr = prop.Items.Type + "[]" + } else { + typeStr = "array" } + default: + typeStr = prop.Type } + description = prop.Description + paramLine := fmt.Sprintf(" - `%s`: %s (%s, %s)", propName, description, typeStr, requiredStr) lines = append(lines, paramLine) } diff --git a/docs/remote-server.md b/docs/remote-server.md index ce506893e..b263d70aa 100644 --- a/docs/remote-server.md +++ b/docs/remote-server.md @@ -57,7 +57,7 @@ The Remote GitHub MCP server has optional headers equivalent to the Local server - `X-MCP-Toolsets`: Comma-separated list of toolsets to enable. E.g. "repos,issues". - Equivalent to `GITHUB_TOOLSETS` env var for Local server. - - If the list is empty, default toolsets will be used. If a bad toolset is provided, the server will fail to start and emit a 400 bad request status. Whitespace is ignored. + - If the list is empty, default toolsets will be used. Invalid or unknown toolsets are silently ignored without error and will not prevent the server from starting. Whitespace is ignored. - `X-MCP-Readonly`: Enables only "read" tools. - Equivalent to `GITHUB_READ_ONLY` env var for Local server. - If this header is empty, "false", "f", "no", "n", "0", or "off" (ignoring whitespace and case), it will be interpreted as false. All other values are interpreted as true. diff --git a/e2e/e2e_test.go b/e2e/e2e_test.go index 8c713649a..49dc3e6ee 100644 --- a/e2e/e2e_test.go +++ b/e2e/e2e_test.go @@ -18,7 +18,7 @@ import ( "github.com/github/github-mcp-server/internal/ghmcp" "github.com/github/github-mcp-server/pkg/github" "github.com/github/github-mcp-server/pkg/translations" - gogithub "github.com/google/go-github/v77/github" + gogithub "github.com/google/go-github/v79/github" mcpClient "github.com/mark3labs/mcp-go/client" "github.com/mark3labs/mcp-go/mcp" "github.com/stretchr/testify/require" diff --git a/go.mod b/go.mod index eea55c143..cb0d0e89c 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,8 @@ module github.com/github/github-mcp-server go 1.24.0 require ( - github.com/google/go-github/v77 v77.0.0 + github.com/google/go-github/v79 v79.0.0 + github.com/google/jsonschema-go v0.3.0 github.com/josephburnett/jd v1.9.2 github.com/mark3labs/mcp-go v0.36.0 github.com/microcosm-cc/bluemonday v1.0.27 @@ -40,6 +41,7 @@ require ( github.com/google/go-querystring v1.1.0 github.com/google/uuid v1.6.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/modelcontextprotocol/go-sdk v1.1.0 github.com/pelletier/go-toml/v2 v2.2.4 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/rogpeppe/go-internal v1.13.1 // indirect @@ -52,7 +54,7 @@ require ( github.com/spf13/pflag v1.0.10 github.com/subosito/gotenv v1.6.0 // indirect github.com/yosida95/uritemplate/v3 v3.0.2 // indirect - golang.org/x/oauth2 v0.29.0 // indirect + golang.org/x/oauth2 v0.30.0 // indirect golang.org/x/sys v0.31.0 // indirect golang.org/x/text v0.28.0 // indirect golang.org/x/time v0.5.0 // indirect diff --git a/go.sum b/go.sum index 72ef812df..56a066492 100644 --- a/go.sum +++ b/go.sum @@ -26,10 +26,12 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/go-github/v71 v71.0.0 h1:Zi16OymGKZZMm8ZliffVVJ/Q9YZreDKONCr+WUd0Z30= github.com/google/go-github/v71 v71.0.0/go.mod h1:URZXObp2BLlMjwu0O8g4y6VBneUj2bCHgnI8FfgZ51M= -github.com/google/go-github/v77 v77.0.0 h1:9DsKKbZqil5y/4Z9mNpZDQnpli6PJbqipSuuNdcbjwI= -github.com/google/go-github/v77 v77.0.0/go.mod h1:c8VmGXRUmaZUqbctUcGEDWYnMrtzZfJhDSylEf1wfmA= +github.com/google/go-github/v79 v79.0.0 h1:MdodQojuFPBhmtwHiBcIGLw/e/wei2PvFX9ndxK0X4Y= +github.com/google/go-github/v79 v79.0.0/go.mod h1:OAFbNhq7fQwohojb06iIIQAB9CBGYLq999myfUFnrS4= github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= +github.com/google/jsonschema-go v0.3.0 h1:6AH2TxVNtk3IlvkkhjrtbUc4S8AvO0Xii0DxIygDg+Q= +github.com/google/jsonschema-go v0.3.0/go.mod h1:r5quNTdLOYEz95Ru18zA0ydNbBuYoo9tgaYcxEYhJVE= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8= @@ -63,6 +65,8 @@ github.com/microcosm-cc/bluemonday v1.0.27 h1:MpEUotklkwCSLeH+Qdx1VJgNqLlpY2KXwX github.com/microcosm-cc/bluemonday v1.0.27/go.mod h1:jFi9vgW+H7c3V0lb6nR74Ib/DIB5OBs92Dimizgw2cA= github.com/migueleliasweb/go-github-mock v1.3.0 h1:2sVP9JEMB2ubQw1IKto3/fzF51oFC6eVWOOFDgQoq88= github.com/migueleliasweb/go-github-mock v1.3.0/go.mod h1:ipQhV8fTcj/G6m7BKzin08GaJ/3B5/SonRAkgrk0zCY= +github.com/modelcontextprotocol/go-sdk v1.1.0 h1:Qjayg53dnKC4UZ+792W21e4BpwEZBzwgRW6LrjLWSwA= +github.com/modelcontextprotocol/go-sdk v1.1.0/go.mod h1:6fM3LCm3yV7pAs8isnKLn07oKtB0MP9LHd3DfAcKw10= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4= github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= @@ -112,6 +116,8 @@ golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8= golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8= golang.org/x/oauth2 v0.29.0 h1:WdYw2tdTK1S8olAzWHdgeqfy+Mtm9XNhv/xJsY65d98= golang.org/x/oauth2 v0.29.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8= +golang.org/x/oauth2 v0.30.0 h1:dnDm7JmhM45NNpd8FDDeLhK6FwqbOf4MLCM9zb1BOHI= +golang.org/x/oauth2 v0.30.0/go.mod h1:B++QgG3ZKulg6sRPGD/mqlHQs5rB3Ml9erfeDY7xKlU= golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik= golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng= diff --git a/internal/ghmcp/server.go b/internal/ghmcp/server.go index 0e338cfd9..39a6726ce 100644 --- a/internal/ghmcp/server.go +++ b/internal/ghmcp/server.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "io" - "log" "log/slog" "net/http" "net/url" @@ -19,9 +18,8 @@ import ( mcplog "github.com/github/github-mcp-server/pkg/log" "github.com/github/github-mcp-server/pkg/raw" "github.com/github/github-mcp-server/pkg/translations" - gogithub "github.com/google/go-github/v77/github" - "github.com/mark3labs/mcp-go/mcp" - "github.com/mark3labs/mcp-go/server" + gogithub "github.com/google/go-github/v79/github" + "github.com/modelcontextprotocol/go-sdk/mcp" "github.com/shurcooL/githubv4" ) @@ -54,11 +52,14 @@ type MCPServerConfig struct { // LockdownMode indicates if we should enable lockdown mode LockdownMode bool + + // Logger is used for logging within the server + Logger *slog.Logger } const stdioServerLogPrefix = "stdioserver" -func NewMCPServer(cfg MCPServerConfig) (*server.MCPServer, error) { +func NewMCPServer(cfg MCPServerConfig) (*mcp.Server, error) { apiHost, err := parseAPIHost(cfg.Host) if err != nil { return nil, fmt.Errorf("failed to parse API host: %w", err) @@ -81,34 +82,6 @@ func NewMCPServer(cfg MCPServerConfig) (*server.MCPServer, error) { } // We're going to wrap the Transport later in beforeInit gqlClient := githubv4.NewEnterpriseClient(apiHost.graphqlURL.String(), gqlHTTPClient) - // When a client send an initialize request, update the user agent to include the client info. - beforeInit := func(_ context.Context, _ any, message *mcp.InitializeRequest) { - userAgent := fmt.Sprintf( - "github-mcp-server/%s (%s/%s)", - cfg.Version, - message.Params.ClientInfo.Name, - message.Params.ClientInfo.Version, - ) - - restClient.UserAgent = userAgent - - gqlHTTPClient.Transport = &userAgentTransport{ - transport: gqlHTTPClient.Transport, - agent: userAgent, - } - } - - hooks := &server.Hooks{ - OnBeforeInitialize: []server.OnBeforeInitializeFunc{beforeInit}, - OnBeforeAny: []server.BeforeAnyHookFunc{ - func(ctx context.Context, _ any, _ mcp.MCPMethod, _ any) { - // Ensure the context is cleared of any previous errors - // as context isn't propagated through middleware - errors.ContextWithGitHubErrors(ctx) - }, - }, - } - enabledToolsets := cfg.EnabledToolsets // If dynamic toolsets are enabled, remove "all" from the enabled toolsets @@ -135,10 +108,14 @@ func NewMCPServer(cfg MCPServerConfig) (*server.MCPServer, error) { // Generate instructions based on enabled toolsets instructions := github.GenerateInstructions(enabledToolsets) - ghServer := github.NewServer(cfg.Version, - server.WithInstructions(instructions), - server.WithHooks(hooks), - ) + ghServer := github.NewServer(cfg.Version, &mcp.ServerOptions{ + Instructions: instructions, + Logger: cfg.Logger, + }) + + // Add middlewares + ghServer.AddReceivingMiddleware(addGitHubAPIErrorToContext) + ghServer.AddReceivingMiddleware(addUserAgentsMiddleware(cfg, restClient, gqlHTTPClient)) getClient := func(_ context.Context) (*gogithub.Client, error) { return restClient, nil // closing over client @@ -229,23 +206,6 @@ 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, - ContentWindowSize: cfg.ContentWindowSize, - LockdownMode: cfg.LockdownMode, - }) - if err != nil { - return fmt.Errorf("failed to create MCP server: %w", err) - } - - stdioServer := server.NewStdioServer(ghServer) - var slogHandler slog.Handler var logOutput io.Writer if cfg.LogFilePath != "" { @@ -261,8 +221,22 @@ func RunStdioServer(cfg StdioServerConfig) error { } logger := slog.New(slogHandler) logger.Info("starting server", "version", cfg.Version, "host", cfg.Host, "dynamicToolsets", cfg.DynamicToolsets, "readOnly", cfg.ReadOnly, "lockdownEnabled", cfg.LockdownMode) - stdLogger := log.New(logOutput, stdioServerLogPrefix, 0) - stdioServer.SetErrorLogger(stdLogger) + + ghServer, err := NewMCPServer(MCPServerConfig{ + Version: cfg.Version, + Host: cfg.Host, + Token: cfg.Token, + EnabledToolsets: cfg.EnabledToolsets, + DynamicToolsets: cfg.DynamicToolsets, + ReadOnly: cfg.ReadOnly, + Translator: t, + ContentWindowSize: cfg.ContentWindowSize, + LockdownMode: cfg.LockdownMode, + Logger: logger, + }) + if err != nil { + return fmt.Errorf("failed to create MCP server: %w", err) + } if cfg.ExportTranslations { // Once server is initialized, all translations are loaded @@ -272,15 +246,20 @@ func RunStdioServer(cfg StdioServerConfig) error { // Start listening for messages errC := make(chan error, 1) go func() { - in, out := io.Reader(os.Stdin), io.Writer(os.Stdout) + var in io.ReadCloser + var out io.WriteCloser + + in = os.Stdin + out = os.Stdout if cfg.EnableCommandLogging { loggedIO := mcplog.NewIOLogger(in, out, logger) in, out = loggedIO, loggedIO } + // enable GitHub errors in the context ctx := errors.ContextWithGitHubErrors(ctx) - errC <- stdioServer.Listen(ctx, in, out) + errC <- ghServer.Run(ctx, &mcp.IOTransport{Reader: in, Writer: out}) }() // Output github-mcp-server string @@ -497,3 +476,44 @@ func (t *bearerAuthTransport) RoundTrip(req *http.Request) (*http.Response, erro req.Header.Set("Authorization", "Bearer "+t.token) return t.transport.RoundTrip(req) } + +func addGitHubAPIErrorToContext(next mcp.MethodHandler) mcp.MethodHandler { + return func(ctx context.Context, method string, req mcp.Request) (result mcp.Result, err error) { + // Ensure the context is cleared of any previous errors + // as context isn't propagated through middleware + ctx = errors.ContextWithGitHubErrors(ctx) + return next(ctx, method, req) + } +} + +func addUserAgentsMiddleware(cfg MCPServerConfig, restClient *gogithub.Client, gqlHTTPClient *http.Client) func(next mcp.MethodHandler) mcp.MethodHandler { + return func(next mcp.MethodHandler) mcp.MethodHandler { + return func(ctx context.Context, method string, request mcp.Request) (result mcp.Result, err error) { + if method != "initialize" { + return next(ctx, method, request) + } + + initializeRequest, ok := request.(*mcp.InitializeRequest) + if !ok { + return next(ctx, method, request) + } + + message := initializeRequest + userAgent := fmt.Sprintf( + "github-mcp-server/%s (%s/%s)", + cfg.Version, + message.Params.ClientInfo.Name, + message.Params.ClientInfo.Version, + ) + + restClient.UserAgent = userAgent + + gqlHTTPClient.Transport = &userAgentTransport{ + transport: gqlHTTPClient.Transport, + agent: userAgent, + } + + return next(ctx, method, request) + } + } +} diff --git a/pkg/errors/error.go b/pkg/errors/error.go index 72bbeed53..be2cf58f9 100644 --- a/pkg/errors/error.go +++ b/pkg/errors/error.go @@ -4,8 +4,9 @@ import ( "context" "fmt" - "github.com/google/go-github/v77/github" - "github.com/mark3labs/mcp-go/mcp" + "github.com/github/github-mcp-server/pkg/utils" + "github.com/google/go-github/v79/github" + "github.com/modelcontextprotocol/go-sdk/mcp" ) type GitHubAPIError struct { @@ -112,7 +113,7 @@ func NewGitHubAPIErrorResponse(ctx context.Context, message string, resp *github if ctx != nil { _, _ = addGitHubAPIErrorToContext(ctx, apiErr) // Explicitly ignore error for graceful handling } - return mcp.NewToolResultErrorFromErr(message, err) + return utils.NewToolResultErrorFromErr(message, err) } // NewGitHubGraphQLErrorResponse returns an mcp.NewToolResultError and retains the error in the context for access via middleware @@ -121,5 +122,5 @@ func NewGitHubGraphQLErrorResponse(ctx context.Context, message string, err erro if ctx != nil { _, _ = addGitHubGraphQLErrorToContext(ctx, graphQLErr) // Explicitly ignore error for graceful handling } - return mcp.NewToolResultErrorFromErr(message, err) + return utils.NewToolResultErrorFromErr(message, err) } diff --git a/pkg/errors/error_test.go b/pkg/errors/error_test.go index 654be569b..0d7aa6afa 100644 --- a/pkg/errors/error_test.go +++ b/pkg/errors/error_test.go @@ -6,7 +6,7 @@ import ( "net/http" "testing" - "github.com/google/go-github/v77/github" + "github.com/google/go-github/v79/github" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/github/__toolsnaps__/get_me.snap b/pkg/github/__toolsnaps__/get_me.snap index 13b061741..2ccdeda5b 100644 --- a/pkg/github/__toolsnaps__/get_me.snap +++ b/pkg/github/__toolsnaps__/get_me.snap @@ -1,12 +1,9 @@ { "annotations": { - "title": "Get my user profile", - "readOnlyHint": true + "readOnlyHint": true, + "title": "Get my user profile" }, "description": "Get details of the authenticated GitHub user. Use this when a request is about the user's own profile for GitHub. Or when information is missing to build other tool calls.", - "inputSchema": { - "properties": {}, - "type": "object" - }, + "inputSchema": null, "name": "get_me" } \ No newline at end of file diff --git a/pkg/github/__toolsnaps__/get_team_members.snap b/pkg/github/__toolsnaps__/get_team_members.snap index 2d91bb5ea..5b7f090fe 100644 --- a/pkg/github/__toolsnaps__/get_team_members.snap +++ b/pkg/github/__toolsnaps__/get_team_members.snap @@ -1,25 +1,25 @@ { "annotations": { - "title": "Get team members", - "readOnlyHint": true + "readOnlyHint": true, + "title": "Get team members" }, "description": "Get member usernames of a specific team in an organization. Limited to organizations accessible with current credentials", "inputSchema": { + "type": "object", + "required": [ + "org", + "team_slug" + ], "properties": { "org": { - "description": "Organization login (owner) that contains the team.", - "type": "string" + "type": "string", + "description": "Organization login (owner) that contains the team." }, "team_slug": { - "description": "Team slug", - "type": "string" + "type": "string", + "description": "Team slug" } - }, - "required": [ - "org", - "team_slug" - ], - "type": "object" + } }, "name": "get_team_members" } \ No newline at end of file diff --git a/pkg/github/__toolsnaps__/get_teams.snap b/pkg/github/__toolsnaps__/get_teams.snap index 39ed4db35..595dd262d 100644 --- a/pkg/github/__toolsnaps__/get_teams.snap +++ b/pkg/github/__toolsnaps__/get_teams.snap @@ -1,17 +1,17 @@ { "annotations": { - "title": "Get teams", - "readOnlyHint": true + "readOnlyHint": true, + "title": "Get teams" }, "description": "Get details of the teams the user is a member of. Limited to organizations accessible with current credentials", "inputSchema": { + "type": "object", "properties": { "user": { - "description": "Username to get teams for. If not provided, uses the authenticated user.", - "type": "string" + "type": "string", + "description": "Username to get teams for. If not provided, uses the authenticated user." } - }, - "type": "object" + } }, "name": "get_teams" } \ No newline at end of file diff --git a/pkg/github/__toolsnaps__/list_project_fields.snap b/pkg/github/__toolsnaps__/list_project_fields.snap index 0a2180e2b..c543e69d7 100644 --- a/pkg/github/__toolsnaps__/list_project_fields.snap +++ b/pkg/github/__toolsnaps__/list_project_fields.snap @@ -6,6 +6,14 @@ "description": "List Project fields for a user or org", "inputSchema": { "properties": { + "after": { + "description": "Forward pagination cursor from previous pageInfo.nextCursor.", + "type": "string" + }, + "before": { + "description": "Backward pagination cursor from previous pageInfo.prevCursor (rare).", + "type": "string" + }, "owner": { "description": "If owner_type == user it is the handle for the GitHub user account. If owner_type == org it is the name of the organization. The name is not case sensitive.", "type": "string" @@ -19,7 +27,7 @@ "type": "string" }, "per_page": { - "description": "Number of results per page (max 100, default: 30)", + "description": "Results per page (max 50)", "type": "number" }, "project_number": { diff --git a/pkg/github/__toolsnaps__/list_project_items.snap b/pkg/github/__toolsnaps__/list_project_items.snap index ebc7d17df..38d3cb509 100644 --- a/pkg/github/__toolsnaps__/list_project_items.snap +++ b/pkg/github/__toolsnaps__/list_project_items.snap @@ -3,11 +3,19 @@ "title": "List project items", "readOnlyHint": true }, - "description": "List Project items for a user or org", + "description": "Search project items with advanced filtering", "inputSchema": { "properties": { + "after": { + "description": "Forward pagination cursor from previous pageInfo.nextCursor.", + "type": "string" + }, + "before": { + "description": "Backward pagination cursor from previous pageInfo.prevCursor (rare).", + "type": "string" + }, "fields": { - "description": "Specific list of field IDs to include in the response (e.g. [\"102589\", \"985201\", \"169875\"]). If not provided, only the title field is included.", + "description": "Field IDs to include (e.g. [\"102589\", \"985201\"]). CRITICAL: Always provide to get field values. Without this, only titles returned.", "items": { "type": "string" }, @@ -26,7 +34,7 @@ "type": "string" }, "per_page": { - "description": "Number of results per page (max 100, default: 30)", + "description": "Results per page (max 50)", "type": "number" }, "project_number": { @@ -34,7 +42,7 @@ "type": "number" }, "query": { - "description": "Search query to filter items", + "description": "Query string for advanced filtering of project items using GitHub's project filtering syntax.", "type": "string" } }, diff --git a/pkg/github/__toolsnaps__/list_projects.snap b/pkg/github/__toolsnaps__/list_projects.snap index 8de28989a..8a035271c 100644 --- a/pkg/github/__toolsnaps__/list_projects.snap +++ b/pkg/github/__toolsnaps__/list_projects.snap @@ -3,9 +3,17 @@ "title": "List projects", "readOnlyHint": true }, - "description": "List Projects for a user or org", + "description": "List Projects for a user or organization", "inputSchema": { "properties": { + "after": { + "description": "Forward pagination cursor from previous pageInfo.nextCursor.", + "type": "string" + }, + "before": { + "description": "Backward pagination cursor from previous pageInfo.prevCursor (rare).", + "type": "string" + }, "owner": { "description": "If owner_type == user it is the handle for the GitHub user account. If owner_type == org it is the name of the organization. The name is not case sensitive.", "type": "string" @@ -19,11 +27,11 @@ "type": "string" }, "per_page": { - "description": "Number of results per page (max 100, default: 30)", + "description": "Results per page (max 50)", "type": "number" }, "query": { - "description": "Filter projects by a search query (matches title and description)", + "description": "Filter projects by title text and open/closed state; permitted qualifiers: is:open, is:closed; examples: \"roadmap is:open\", \"is:open feature planning\".", "type": "string" } }, diff --git a/pkg/github/actions.go b/pkg/github/actions.go index ecf538323..8dee61deb 100644 --- a/pkg/github/actions.go +++ b/pkg/github/actions.go @@ -1,3 +1,5 @@ +//go:build ignore + package github import ( @@ -12,7 +14,7 @@ import ( buffer "github.com/github/github-mcp-server/pkg/buffer" ghErrors "github.com/github/github-mcp-server/pkg/errors" "github.com/github/github-mcp-server/pkg/translations" - "github.com/google/go-github/v77/github" + "github.com/google/go-github/v79/github" "github.com/mark3labs/mcp-go/mcp" "github.com/mark3labs/mcp-go/server" ) diff --git a/pkg/github/actions_test.go b/pkg/github/actions_test.go index 1738bc8e5..f09f8082b 100644 --- a/pkg/github/actions_test.go +++ b/pkg/github/actions_test.go @@ -1,3 +1,5 @@ +//go:build ignore + package github import ( @@ -15,7 +17,7 @@ import ( "github.com/github/github-mcp-server/internal/profiler" buffer "github.com/github/github-mcp-server/pkg/buffer" "github.com/github/github-mcp-server/pkg/translations" - "github.com/google/go-github/v77/github" + "github.com/google/go-github/v79/github" "github.com/migueleliasweb/go-github-mock/src/mock" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/pkg/github/code_scanning.go b/pkg/github/code_scanning.go index aa39cfc35..a087bf0bf 100644 --- a/pkg/github/code_scanning.go +++ b/pkg/github/code_scanning.go @@ -1,3 +1,5 @@ +//go:build ignore + package github import ( @@ -9,7 +11,7 @@ import ( ghErrors "github.com/github/github-mcp-server/pkg/errors" "github.com/github/github-mcp-server/pkg/translations" - "github.com/google/go-github/v77/github" + "github.com/google/go-github/v79/github" "github.com/mark3labs/mcp-go/mcp" "github.com/mark3labs/mcp-go/server" ) diff --git a/pkg/github/code_scanning_test.go b/pkg/github/code_scanning_test.go index 874d1eeda..dc2d66446 100644 --- a/pkg/github/code_scanning_test.go +++ b/pkg/github/code_scanning_test.go @@ -1,3 +1,5 @@ +//go:build ignore + package github import ( @@ -8,7 +10,7 @@ import ( "github.com/github/github-mcp-server/internal/toolsnaps" "github.com/github/github-mcp-server/pkg/translations" - "github.com/google/go-github/v77/github" + "github.com/google/go-github/v79/github" "github.com/migueleliasweb/go-github-mock/src/mock" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/pkg/github/context_tools.go b/pkg/github/context_tools.go index 06642aa15..5f248934b 100644 --- a/pkg/github/context_tools.go +++ b/pkg/github/context_tools.go @@ -6,8 +6,9 @@ import ( ghErrors "github.com/github/github-mcp-server/pkg/errors" "github.com/github/github-mcp-server/pkg/translations" - "github.com/mark3labs/mcp-go/mcp" - "github.com/mark3labs/mcp-go/server" + "github.com/github/github-mcp-server/pkg/utils" + "github.com/google/jsonschema-go/jsonschema" + "github.com/modelcontextprotocol/go-sdk/mcp" "github.com/shurcooL/githubv4" ) @@ -34,20 +35,20 @@ type UserDetails struct { } // GetMe creates a tool to get details of the authenticated user. -func GetMe(getClient GetClientFn, t translations.TranslationHelperFunc) (mcp.Tool, server.ToolHandlerFunc) { - tool := mcp.NewTool("get_me", - mcp.WithDescription(t("TOOL_GET_ME_DESCRIPTION", "Get details of the authenticated GitHub user. Use this when a request is about the user's own profile for GitHub. Or when information is missing to build other tool calls.")), - mcp.WithToolAnnotation(mcp.ToolAnnotation{ +func GetMe(getClient GetClientFn, t translations.TranslationHelperFunc) (mcp.Tool, mcp.ToolHandlerFor[map[string]any, any]) { + tool := mcp.Tool{ + Name: "get_me", + Description: t("TOOL_GET_ME_DESCRIPTION", "Get details of the authenticated GitHub user. Use this when a request is about the user's own profile for GitHub. Or when information is missing to build other tool calls."), + Annotations: &mcp.ToolAnnotations{ Title: t("TOOL_GET_ME_USER_TITLE", "Get my user profile"), - ReadOnlyHint: ToBoolPtr(true), - }), - ) + ReadOnlyHint: true, + }, + } - type args struct{} - handler := mcp.NewTypedToolHandler(func(ctx context.Context, _ mcp.CallToolRequest, _ args) (*mcp.CallToolResult, error) { + handler := mcp.ToolHandlerFor[map[string]any, any](func(ctx context.Context, _ *mcp.CallToolRequest, _ map[string]any) (*mcp.CallToolResult, any, error) { client, err := getClient(ctx) if err != nil { - return mcp.NewToolResultErrorFromErr("failed to get GitHub client", err), nil + return utils.NewToolResultErrorFromErr("failed to get GitHub client", err), nil, err } user, res, err := client.Users.Get(ctx, "") @@ -56,7 +57,7 @@ func GetMe(getClient GetClientFn, t translations.TranslationHelperFunc) (mcp.Too "failed to get user", res, err, - ), nil + ), nil, err } // Create minimal user representation instead of returning full user object @@ -86,7 +87,7 @@ func GetMe(getClient GetClientFn, t translations.TranslationHelperFunc) (mcp.Too }, } - return MarshalledTextResult(minimalUser), nil + return MarshalledTextResult(minimalUser), nil, nil }) return tool, handler @@ -103,21 +104,28 @@ type OrganizationTeams struct { Teams []TeamInfo `json:"teams"` } -func GetTeams(getClient GetClientFn, getGQLClient GetGQLClientFn, t translations.TranslationHelperFunc) (mcp.Tool, server.ToolHandlerFunc) { - return mcp.NewTool("get_teams", - mcp.WithDescription(t("TOOL_GET_TEAMS_DESCRIPTION", "Get details of the teams the user is a member of. Limited to organizations accessible with current credentials")), - mcp.WithString("user", - mcp.Description(t("TOOL_GET_TEAMS_USER_DESCRIPTION", "Username to get teams for. If not provided, uses the authenticated user.")), - ), - mcp.WithToolAnnotation(mcp.ToolAnnotation{ +func GetTeams(getClient GetClientFn, getGQLClient GetGQLClientFn, t translations.TranslationHelperFunc) (mcp.Tool, mcp.ToolHandlerFor[map[string]any, any]) { + return mcp.Tool{ + Name: "get_teams", + Description: t("TOOL_GET_TEAMS_DESCRIPTION", "Get details of the teams the user is a member of. Limited to organizations accessible with current credentials"), + Annotations: &mcp.ToolAnnotations{ Title: t("TOOL_GET_TEAMS_TITLE", "Get teams"), - ReadOnlyHint: ToBoolPtr(true), - }), - ), - func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { - user, err := OptionalParam[string](request, "user") + ReadOnlyHint: true, + }, + InputSchema: &jsonschema.Schema{ + Type: "object", + Properties: map[string]*jsonschema.Schema{ + "user": { + Type: "string", + Description: t("TOOL_GET_TEAMS_USER_DESCRIPTION", "Username to get teams for. If not provided, uses the authenticated user."), + }, + }, + }, + }, + func(ctx context.Context, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) { + user, err := OptionalParam[string](args, "user") if err != nil { - return mcp.NewToolResultError(err.Error()), nil + return utils.NewToolResultError(err.Error()), nil, nil } var username string @@ -126,7 +134,7 @@ func GetTeams(getClient GetClientFn, getGQLClient GetGQLClientFn, t translations } else { client, err := getClient(ctx) if err != nil { - return mcp.NewToolResultErrorFromErr("failed to get GitHub client", err), nil + return utils.NewToolResultErrorFromErr("failed to get GitHub client", err), nil, nil } userResp, res, err := client.Users.Get(ctx, "") @@ -135,14 +143,14 @@ func GetTeams(getClient GetClientFn, getGQLClient GetGQLClientFn, t translations "failed to get user", res, err, - ), nil + ), nil, nil } username = userResp.GetLogin() } gqlClient, err := getGQLClient(ctx) if err != nil { - return mcp.NewToolResultErrorFromErr("failed to get GitHub GQL client", err), nil + return utils.NewToolResultErrorFromErr("failed to get GitHub GQL client", err), nil, nil } var q struct { @@ -165,7 +173,7 @@ func GetTeams(getClient GetClientFn, getGQLClient GetGQLClientFn, t translations "login": githubv4.String(username), } if err := gqlClient.Query(ctx, &q, vars); err != nil { - return ghErrors.NewGitHubGraphQLErrorResponse(ctx, "Failed to find teams", err), nil + return ghErrors.NewGitHubGraphQLErrorResponse(ctx, "Failed to find teams", err), nil, nil } var organizations []OrganizationTeams @@ -186,40 +194,47 @@ func GetTeams(getClient GetClientFn, getGQLClient GetGQLClientFn, t translations organizations = append(organizations, orgTeams) } - return MarshalledTextResult(organizations), nil + return MarshalledTextResult(organizations), nil, nil } } -func GetTeamMembers(getGQLClient GetGQLClientFn, t translations.TranslationHelperFunc) (mcp.Tool, server.ToolHandlerFunc) { - return mcp.NewTool("get_team_members", - mcp.WithDescription(t("TOOL_GET_TEAM_MEMBERS_DESCRIPTION", "Get member usernames of a specific team in an organization. Limited to organizations accessible with current credentials")), - mcp.WithString("org", - mcp.Description(t("TOOL_GET_TEAM_MEMBERS_ORG_DESCRIPTION", "Organization login (owner) that contains the team.")), - mcp.Required(), - ), - mcp.WithString("team_slug", - mcp.Description(t("TOOL_GET_TEAM_MEMBERS_TEAM_SLUG_DESCRIPTION", "Team slug")), - mcp.Required(), - ), - mcp.WithToolAnnotation(mcp.ToolAnnotation{ +func GetTeamMembers(getGQLClient GetGQLClientFn, t translations.TranslationHelperFunc) (mcp.Tool, mcp.ToolHandlerFor[map[string]any, any]) { + return mcp.Tool{ + Name: "get_team_members", + Description: t("TOOL_GET_TEAM_MEMBERS_DESCRIPTION", "Get member usernames of a specific team in an organization. Limited to organizations accessible with current credentials"), + Annotations: &mcp.ToolAnnotations{ Title: t("TOOL_GET_TEAM_MEMBERS_TITLE", "Get team members"), - ReadOnlyHint: ToBoolPtr(true), - }), - ), - func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { - org, err := RequiredParam[string](request, "org") + ReadOnlyHint: true, + }, + InputSchema: &jsonschema.Schema{ + Type: "object", + Properties: map[string]*jsonschema.Schema{ + "org": { + Type: "string", + Description: t("TOOL_GET_TEAM_MEMBERS_ORG_DESCRIPTION", "Organization login (owner) that contains the team."), + }, + "team_slug": { + Type: "string", + Description: t("TOOL_GET_TEAM_MEMBERS_TEAM_SLUG_DESCRIPTION", "Team slug"), + }, + }, + Required: []string{"org", "team_slug"}, + }, + }, + func(ctx context.Context, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) { + org, err := RequiredParam[string](args, "org") if err != nil { - return mcp.NewToolResultError(err.Error()), nil + return utils.NewToolResultError(err.Error()), nil, nil } - teamSlug, err := RequiredParam[string](request, "team_slug") + teamSlug, err := RequiredParam[string](args, "team_slug") if err != nil { - return mcp.NewToolResultError(err.Error()), nil + return utils.NewToolResultError(err.Error()), nil, nil } gqlClient, err := getGQLClient(ctx) if err != nil { - return mcp.NewToolResultErrorFromErr("failed to get GitHub GQL client", err), nil + return utils.NewToolResultErrorFromErr("failed to get GitHub GQL client", err), nil, nil } var q struct { @@ -238,7 +253,7 @@ func GetTeamMembers(getGQLClient GetGQLClientFn, t translations.TranslationHelpe "teamSlug": githubv4.String(teamSlug), } if err := gqlClient.Query(ctx, &q, vars); err != nil { - return ghErrors.NewGitHubGraphQLErrorResponse(ctx, "Failed to get team members", err), nil + return ghErrors.NewGitHubGraphQLErrorResponse(ctx, "Failed to get team members", err), nil, nil } var members []string @@ -246,6 +261,6 @@ func GetTeamMembers(getGQLClient GetGQLClientFn, t translations.TranslationHelpe members = append(members, string(member.Login)) } - return MarshalledTextResult(members), nil + return MarshalledTextResult(members), nil, nil } } diff --git a/pkg/github/context_tools_test.go b/pkg/github/context_tools_test.go index 880d9d98c..13992fb91 100644 --- a/pkg/github/context_tools_test.go +++ b/pkg/github/context_tools_test.go @@ -10,7 +10,7 @@ import ( "github.com/github/github-mcp-server/internal/githubv4mock" "github.com/github/github-mcp-server/internal/toolsnaps" "github.com/github/github-mcp-server/pkg/translations" - "github.com/google/go-github/v77/github" + "github.com/google/go-github/v79/github" "github.com/migueleliasweb/go-github-mock/src/mock" "github.com/shurcooL/githubv4" "github.com/stretchr/testify/assert" @@ -25,7 +25,7 @@ func Test_GetMe(t *testing.T) { // Verify some basic very important properties assert.Equal(t, "get_me", tool.Name) - assert.True(t, *tool.Annotations.ReadOnlyHint, "get_me tool should be read-only") + assert.True(t, tool.Annotations.ReadOnlyHint, "get_me tool should be read-only") // Setup mock user response mockUser := &github.User{ @@ -111,11 +111,11 @@ func Test_GetMe(t *testing.T) { _, handler := GetMe(tc.stubbedGetClientFn, translations.NullTranslationHelper) request := createMCPRequest(tc.requestArgs) - result, err := handler(context.Background(), request) - require.NoError(t, err) + result, _, err := handler(context.Background(), &request, tc.requestArgs) textContent := getTextResult(t, result) if tc.expectToolError { + assert.Error(t, err) assert.True(t, result.IsError, "expected tool call result to be an error") assert.Contains(t, textContent.Text, tc.expectedToolErrMsg) return @@ -150,7 +150,7 @@ func Test_GetTeams(t *testing.T) { require.NoError(t, toolsnaps.Test(tool.Name, tool)) assert.Equal(t, "get_teams", tool.Name) - assert.True(t, *tool.Annotations.ReadOnlyHint, "get_teams tool should be read-only") + assert.True(t, tool.Annotations.ReadOnlyHint, "get_teams tool should be read-only") mockUser := &github.User{ Login: github.Ptr("testuser"), @@ -335,7 +335,7 @@ func Test_GetTeams(t *testing.T) { _, handler := GetTeams(tc.stubbedGetClientFn, tc.stubbedGetGQLClientFn, translations.NullTranslationHelper) request := createMCPRequest(tc.requestArgs) - result, err := handler(context.Background(), request) + result, _, err := handler(context.Background(), &request, tc.requestArgs) require.NoError(t, err) textContent := getTextResult(t, result) @@ -377,7 +377,7 @@ func Test_GetTeamMembers(t *testing.T) { require.NoError(t, toolsnaps.Test(tool.Name, tool)) assert.Equal(t, "get_team_members", tool.Name) - assert.True(t, *tool.Annotations.ReadOnlyHint, "get_team_members tool should be read-only") + assert.True(t, tool.Annotations.ReadOnlyHint, "get_team_members tool should be read-only") mockTeamMembersResponse := githubv4mock.DataResponse(map[string]any{ "organization": map[string]any{ @@ -471,7 +471,7 @@ func Test_GetTeamMembers(t *testing.T) { _, handler := GetTeamMembers(tc.stubbedGetGQLClientFn, translations.NullTranslationHelper) request := createMCPRequest(tc.requestArgs) - result, err := handler(context.Background(), request) + result, _, err := handler(context.Background(), &request, tc.requestArgs) require.NoError(t, err) textContent := getTextResult(t, result) diff --git a/pkg/github/dependabot.go b/pkg/github/dependabot.go index e21562c02..2823daf3e 100644 --- a/pkg/github/dependabot.go +++ b/pkg/github/dependabot.go @@ -1,3 +1,5 @@ +//go:build ignore + package github import ( @@ -9,7 +11,7 @@ import ( ghErrors "github.com/github/github-mcp-server/pkg/errors" "github.com/github/github-mcp-server/pkg/translations" - "github.com/google/go-github/v77/github" + "github.com/google/go-github/v79/github" "github.com/mark3labs/mcp-go/mcp" "github.com/mark3labs/mcp-go/server" ) diff --git a/pkg/github/dependabot_test.go b/pkg/github/dependabot_test.go index 302692a3a..2aa02981e 100644 --- a/pkg/github/dependabot_test.go +++ b/pkg/github/dependabot_test.go @@ -1,3 +1,5 @@ +//go:build ignore + package github import ( @@ -8,7 +10,7 @@ import ( "github.com/github/github-mcp-server/internal/toolsnaps" "github.com/github/github-mcp-server/pkg/translations" - "github.com/google/go-github/v77/github" + "github.com/google/go-github/v79/github" "github.com/migueleliasweb/go-github-mock/src/mock" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/pkg/github/discussions.go b/pkg/github/discussions.go index 3aa92f05c..ac4077952 100644 --- a/pkg/github/discussions.go +++ b/pkg/github/discussions.go @@ -1,3 +1,5 @@ +//go:build ignore + package github import ( @@ -7,7 +9,7 @@ import ( "github.com/github/github-mcp-server/pkg/translations" "github.com/go-viper/mapstructure/v2" - "github.com/google/go-github/v77/github" + "github.com/google/go-github/v79/github" "github.com/mark3labs/mcp-go/mcp" "github.com/mark3labs/mcp-go/server" "github.com/shurcooL/githubv4" @@ -44,11 +46,14 @@ type DiscussionFragment struct { } type NodeFragment struct { - Number githubv4.Int - Title githubv4.String - CreatedAt githubv4.DateTime - UpdatedAt githubv4.DateTime - Author struct { + Number githubv4.Int + Title githubv4.String + CreatedAt githubv4.DateTime + UpdatedAt githubv4.DateTime + Closed githubv4.Boolean + IsAnswered githubv4.Boolean + AnswerChosenAt *githubv4.DateTime + Author struct { Login githubv4.String } Category struct { @@ -294,12 +299,15 @@ func GetDiscussion(getGQLClient GetGQLClientFn, t translations.TranslationHelper var q struct { Repository struct { Discussion struct { - Number githubv4.Int - Title githubv4.String - Body githubv4.String - CreatedAt githubv4.DateTime - URL githubv4.String `graphql:"url"` - Category struct { + Number githubv4.Int + Title githubv4.String + Body githubv4.String + CreatedAt githubv4.DateTime + Closed githubv4.Boolean + IsAnswered githubv4.Boolean + AnswerChosenAt *githubv4.DateTime + URL githubv4.String `graphql:"url"` + Category struct { Name githubv4.String } `graphql:"category"` } `graphql:"discussion(number: $discussionNumber)"` @@ -314,17 +322,30 @@ func GetDiscussion(getGQLClient GetGQLClientFn, t translations.TranslationHelper return mcp.NewToolResultError(err.Error()), nil } d := q.Repository.Discussion - discussion := &github.Discussion{ - Number: github.Ptr(int(d.Number)), - Title: github.Ptr(string(d.Title)), - Body: github.Ptr(string(d.Body)), - HTMLURL: github.Ptr(string(d.URL)), - CreatedAt: &github.Timestamp{Time: d.CreatedAt.Time}, - DiscussionCategory: &github.DiscussionCategory{ - Name: github.Ptr(string(d.Category.Name)), + + // Build response as map to include fields not present in go-github's Discussion struct. + // The go-github library's Discussion type lacks isAnswered and answerChosenAt fields, + // so we use map[string]interface{} for the response (consistent with other functions + // like ListDiscussions and GetDiscussionComments). + response := map[string]interface{}{ + "number": int(d.Number), + "title": string(d.Title), + "body": string(d.Body), + "url": string(d.URL), + "closed": bool(d.Closed), + "isAnswered": bool(d.IsAnswered), + "createdAt": d.CreatedAt.Time, + "category": map[string]interface{}{ + "name": string(d.Category.Name), }, } - out, err := json.Marshal(discussion) + + // Add optional timestamp fields if present + if d.AnswerChosenAt != nil { + response["answerChosenAt"] = d.AnswerChosenAt.Time + } + + out, err := json.Marshal(response) if err != nil { return nil, fmt.Errorf("failed to marshal discussion: %w", err) } diff --git a/pkg/github/discussions_test.go b/pkg/github/discussions_test.go index 0930b1421..03dd4ae1d 100644 --- a/pkg/github/discussions_test.go +++ b/pkg/github/discussions_test.go @@ -1,3 +1,5 @@ +//go:build ignore + package github import ( @@ -5,11 +7,10 @@ import ( "encoding/json" "net/http" "testing" - "time" "github.com/github/github-mcp-server/internal/githubv4mock" "github.com/github/github-mcp-server/pkg/translations" - "github.com/google/go-github/v77/github" + "github.com/google/go-github/v79/github" "github.com/shurcooL/githubv4" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -17,75 +18,89 @@ import ( var ( discussionsGeneral = []map[string]any{ - {"number": 1, "title": "Discussion 1 title", "createdAt": "2023-01-01T00:00:00Z", "updatedAt": "2023-01-01T00:00:00Z", "author": map[string]any{"login": "user1"}, "url": "https://github.com/owner/repo/discussions/1", "category": map[string]any{"name": "General"}}, - {"number": 3, "title": "Discussion 3 title", "createdAt": "2023-03-01T00:00:00Z", "updatedAt": "2023-02-01T00:00:00Z", "author": map[string]any{"login": "user1"}, "url": "https://github.com/owner/repo/discussions/3", "category": map[string]any{"name": "General"}}, + {"number": 1, "title": "Discussion 1 title", "createdAt": "2023-01-01T00:00:00Z", "updatedAt": "2023-01-01T00:00:00Z", "closed": false, "isAnswered": false, "author": map[string]any{"login": "user1"}, "url": "https://github.com/owner/repo/discussions/1", "category": map[string]any{"name": "General"}}, + {"number": 3, "title": "Discussion 3 title", "createdAt": "2023-03-01T00:00:00Z", "updatedAt": "2023-02-01T00:00:00Z", "closed": false, "isAnswered": false, "author": map[string]any{"login": "user1"}, "url": "https://github.com/owner/repo/discussions/3", "category": map[string]any{"name": "General"}}, } discussionsAll = []map[string]any{ { - "number": 1, - "title": "Discussion 1 title", - "createdAt": "2023-01-01T00:00:00Z", - "updatedAt": "2023-01-01T00:00:00Z", - "author": map[string]any{"login": "user1"}, - "url": "https://github.com/owner/repo/discussions/1", - "category": map[string]any{"name": "General"}, + "number": 1, + "title": "Discussion 1 title", + "createdAt": "2023-01-01T00:00:00Z", + "updatedAt": "2023-01-01T00:00:00Z", + "closed": false, + "isAnswered": false, + "author": map[string]any{"login": "user1"}, + "url": "https://github.com/owner/repo/discussions/1", + "category": map[string]any{"name": "General"}, }, { - "number": 2, - "title": "Discussion 2 title", - "createdAt": "2023-02-01T00:00:00Z", - "updatedAt": "2023-02-01T00:00:00Z", - "author": map[string]any{"login": "user2"}, - "url": "https://github.com/owner/repo/discussions/2", - "category": map[string]any{"name": "Questions"}, + "number": 2, + "title": "Discussion 2 title", + "createdAt": "2023-02-01T00:00:00Z", + "updatedAt": "2023-02-01T00:00:00Z", + "closed": false, + "isAnswered": false, + "author": map[string]any{"login": "user2"}, + "url": "https://github.com/owner/repo/discussions/2", + "category": map[string]any{"name": "Questions"}, }, { - "number": 3, - "title": "Discussion 3 title", - "createdAt": "2023-03-01T00:00:00Z", - "updatedAt": "2023-03-01T00:00:00Z", - "author": map[string]any{"login": "user3"}, - "url": "https://github.com/owner/repo/discussions/3", - "category": map[string]any{"name": "General"}, + "number": 3, + "title": "Discussion 3 title", + "createdAt": "2023-03-01T00:00:00Z", + "updatedAt": "2023-03-01T00:00:00Z", + "closed": false, + "isAnswered": false, + "author": map[string]any{"login": "user3"}, + "url": "https://github.com/owner/repo/discussions/3", + "category": map[string]any{"name": "General"}, }, } discussionsOrgLevel = []map[string]any{ { - "number": 1, - "title": "Org Discussion 1 - Community Guidelines", - "createdAt": "2023-01-15T00:00:00Z", - "updatedAt": "2023-01-15T00:00:00Z", - "author": map[string]any{"login": "org-admin"}, - "url": "https://github.com/owner/.github/discussions/1", - "category": map[string]any{"name": "Announcements"}, + "number": 1, + "title": "Org Discussion 1 - Community Guidelines", + "createdAt": "2023-01-15T00:00:00Z", + "updatedAt": "2023-01-15T00:00:00Z", + "closed": false, + "isAnswered": false, + "author": map[string]any{"login": "org-admin"}, + "url": "https://github.com/owner/.github/discussions/1", + "category": map[string]any{"name": "Announcements"}, }, { - "number": 2, - "title": "Org Discussion 2 - Roadmap 2023", - "createdAt": "2023-02-20T00:00:00Z", - "updatedAt": "2023-02-20T00:00:00Z", - "author": map[string]any{"login": "org-admin"}, - "url": "https://github.com/owner/.github/discussions/2", - "category": map[string]any{"name": "General"}, + "number": 2, + "title": "Org Discussion 2 - Roadmap 2023", + "createdAt": "2023-02-20T00:00:00Z", + "updatedAt": "2023-02-20T00:00:00Z", + "closed": false, + "isAnswered": false, + "author": map[string]any{"login": "org-admin"}, + "url": "https://github.com/owner/.github/discussions/2", + "category": map[string]any{"name": "General"}, }, { - "number": 3, - "title": "Org Discussion 3 - Roadmap 2024", - "createdAt": "2023-02-20T00:00:00Z", - "updatedAt": "2023-02-20T00:00:00Z", - "author": map[string]any{"login": "org-admin"}, - "url": "https://github.com/owner/.github/discussions/3", - "category": map[string]any{"name": "General"}, + "number": 3, + "title": "Org Discussion 3 - Roadmap 2024", + "createdAt": "2023-02-20T00:00:00Z", + "updatedAt": "2023-02-20T00:00:00Z", + "closed": false, + "isAnswered": false, + "author": map[string]any{"login": "org-admin"}, + "url": "https://github.com/owner/.github/discussions/3", + "category": map[string]any{"name": "General"}, }, { - "number": 4, - "title": "Org Discussion 4 - Roadmap 2025", - "createdAt": "2023-02-20T00:00:00Z", - "updatedAt": "2023-02-20T00:00:00Z", - "author": map[string]any{"login": "org-admin"}, - "url": "https://github.com/owner/.github/discussions/4", - "category": map[string]any{"name": "General"}, + "number": 4, + "title": "Org Discussion 4 - Roadmap 2025", + "createdAt": "2023-02-20T00:00:00Z", + "updatedAt": "2023-02-20T00:00:00Z", + "closed": false, + "isAnswered": false, + "author": map[string]any{"login": "org-admin"}, + "url": "https://github.com/owner/.github/discussions/4", + "category": map[string]any{"name": "General"}, }, } @@ -388,10 +403,10 @@ func Test_ListDiscussions(t *testing.T) { } // Define the actual query strings that match the implementation - qBasicNoOrder := "query($after:String$first:Int!$owner:String!$repo:String!){repository(owner: $owner, name: $repo){discussions(first: $first, after: $after){nodes{number,title,createdAt,updatedAt,author{login},category{name},url},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}" - qWithCategoryNoOrder := "query($after:String$categoryId:ID!$first:Int!$owner:String!$repo:String!){repository(owner: $owner, name: $repo){discussions(first: $first, after: $after, categoryId: $categoryId){nodes{number,title,createdAt,updatedAt,author{login},category{name},url},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}" - qBasicWithOrder := "query($after:String$first:Int!$orderByDirection:OrderDirection!$orderByField:DiscussionOrderField!$owner:String!$repo:String!){repository(owner: $owner, name: $repo){discussions(first: $first, after: $after, orderBy: { field: $orderByField, direction: $orderByDirection }){nodes{number,title,createdAt,updatedAt,author{login},category{name},url},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}" - qWithCategoryAndOrder := "query($after:String$categoryId:ID!$first:Int!$orderByDirection:OrderDirection!$orderByField:DiscussionOrderField!$owner:String!$repo:String!){repository(owner: $owner, name: $repo){discussions(first: $first, after: $after, categoryId: $categoryId, orderBy: { field: $orderByField, direction: $orderByDirection }){nodes{number,title,createdAt,updatedAt,author{login},category{name},url},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}" + qBasicNoOrder := "query($after:String$first:Int!$owner:String!$repo:String!){repository(owner: $owner, name: $repo){discussions(first: $first, after: $after){nodes{number,title,createdAt,updatedAt,closed,isAnswered,answerChosenAt,author{login},category{name},url},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}" + qWithCategoryNoOrder := "query($after:String$categoryId:ID!$first:Int!$owner:String!$repo:String!){repository(owner: $owner, name: $repo){discussions(first: $first, after: $after, categoryId: $categoryId){nodes{number,title,createdAt,updatedAt,closed,isAnswered,answerChosenAt,author{login},category{name},url},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}" + qBasicWithOrder := "query($after:String$first:Int!$orderByDirection:OrderDirection!$orderByField:DiscussionOrderField!$owner:String!$repo:String!){repository(owner: $owner, name: $repo){discussions(first: $first, after: $after, orderBy: { field: $orderByField, direction: $orderByDirection }){nodes{number,title,createdAt,updatedAt,closed,isAnswered,answerChosenAt,author{login},category{name},url},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}" + qWithCategoryAndOrder := "query($after:String$categoryId:ID!$first:Int!$orderByDirection:OrderDirection!$orderByField:DiscussionOrderField!$owner:String!$repo:String!){repository(owner: $owner, name: $repo){discussions(first: $first, after: $after, categoryId: $categoryId, orderBy: { field: $orderByField, direction: $orderByDirection }){nodes{number,title,createdAt,updatedAt,closed,isAnswered,answerChosenAt,author{login},category{name},url},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}" for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { @@ -484,7 +499,7 @@ func Test_GetDiscussion(t *testing.T) { assert.ElementsMatch(t, toolDef.InputSchema.Required, []string{"owner", "repo", "discussionNumber"}) // Use exact string query that matches implementation output - qGetDiscussion := "query($discussionNumber:Int!$owner:String!$repo:String!){repository(owner: $owner, name: $repo){discussion(number: $discussionNumber){number,title,body,createdAt,url,category{name}}}}" + qGetDiscussion := "query($discussionNumber:Int!$owner:String!$repo:String!){repository(owner: $owner, name: $repo){discussion(number: $discussionNumber){number,title,body,createdAt,closed,isAnswered,answerChosenAt,url,category{name}}}}" vars := map[string]interface{}{ "owner": "owner", @@ -495,31 +510,31 @@ func Test_GetDiscussion(t *testing.T) { name string response githubv4mock.GQLResponse expectError bool - expected *github.Discussion + expected map[string]interface{} errContains string }{ { name: "successful retrieval", response: githubv4mock.DataResponse(map[string]any{ "repository": map[string]any{"discussion": map[string]any{ - "number": 1, - "title": "Test Discussion Title", - "body": "This is a test discussion", - "url": "https://github.com/owner/repo/discussions/1", - "createdAt": "2025-04-25T12:00:00Z", - "category": map[string]any{"name": "General"}, + "number": 1, + "title": "Test Discussion Title", + "body": "This is a test discussion", + "url": "https://github.com/owner/repo/discussions/1", + "createdAt": "2025-04-25T12:00:00Z", + "closed": false, + "isAnswered": false, + "category": map[string]any{"name": "General"}, }}, }), expectError: false, - expected: &github.Discussion{ - HTMLURL: github.Ptr("https://github.com/owner/repo/discussions/1"), - Number: github.Ptr(1), - Title: github.Ptr("Test Discussion Title"), - Body: github.Ptr("This is a test discussion"), - CreatedAt: &github.Timestamp{Time: time.Date(2025, 4, 25, 12, 0, 0, 0, time.UTC)}, - DiscussionCategory: &github.DiscussionCategory{ - Name: github.Ptr("General"), - }, + expected: map[string]interface{}{ + "number": float64(1), + "title": "Test Discussion Title", + "body": "This is a test discussion", + "url": "https://github.com/owner/repo/discussions/1", + "closed": false, + "isAnswered": false, }, }, { @@ -547,14 +562,18 @@ func Test_GetDiscussion(t *testing.T) { } require.NoError(t, err) - var out github.Discussion + var out map[string]interface{} require.NoError(t, json.Unmarshal([]byte(text), &out)) - assert.Equal(t, *tc.expected.HTMLURL, *out.HTMLURL) - assert.Equal(t, *tc.expected.Number, *out.Number) - assert.Equal(t, *tc.expected.Title, *out.Title) - assert.Equal(t, *tc.expected.Body, *out.Body) - // Check category label - assert.Equal(t, *tc.expected.DiscussionCategory.Name, *out.DiscussionCategory.Name) + assert.Equal(t, tc.expected["number"], out["number"]) + assert.Equal(t, tc.expected["title"], out["title"]) + assert.Equal(t, tc.expected["body"], out["body"]) + assert.Equal(t, tc.expected["url"], out["url"]) + assert.Equal(t, tc.expected["closed"], out["closed"]) + assert.Equal(t, tc.expected["isAnswered"], out["isAnswered"]) + // Check category is present + category, ok := out["category"].(map[string]interface{}) + require.True(t, ok) + assert.Equal(t, "General", category["name"]) }) } } diff --git a/pkg/github/dynamic_tools.go b/pkg/github/dynamic_tools.go index e703a885e..45a481576 100644 --- a/pkg/github/dynamic_tools.go +++ b/pkg/github/dynamic_tools.go @@ -1,3 +1,5 @@ +//go:build ignore + package github import ( diff --git a/pkg/github/gists.go b/pkg/github/gists.go index 7168f8c0e..ccda72486 100644 --- a/pkg/github/gists.go +++ b/pkg/github/gists.go @@ -1,3 +1,5 @@ +//go:build ignore + package github import ( @@ -8,7 +10,7 @@ import ( "net/http" "github.com/github/github-mcp-server/pkg/translations" - "github.com/google/go-github/v77/github" + "github.com/google/go-github/v79/github" "github.com/mark3labs/mcp-go/mcp" "github.com/mark3labs/mcp-go/server" ) diff --git a/pkg/github/gists_test.go b/pkg/github/gists_test.go index e8eb6d7f4..fa40ba1af 100644 --- a/pkg/github/gists_test.go +++ b/pkg/github/gists_test.go @@ -1,3 +1,5 @@ +//go:build ignore + package github import ( @@ -8,7 +10,7 @@ import ( "time" "github.com/github/github-mcp-server/pkg/translations" - "github.com/google/go-github/v77/github" + "github.com/google/go-github/v79/github" "github.com/migueleliasweb/go-github-mock/src/mock" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/pkg/github/git.go b/pkg/github/git.go index 5dfc8e0e8..cbbc8e3d7 100644 --- a/pkg/github/git.go +++ b/pkg/github/git.go @@ -1,3 +1,5 @@ +//go:build ignore + package github import ( @@ -8,7 +10,7 @@ import ( ghErrors "github.com/github/github-mcp-server/pkg/errors" "github.com/github/github-mcp-server/pkg/translations" - "github.com/google/go-github/v77/github" + "github.com/google/go-github/v79/github" "github.com/mark3labs/mcp-go/mcp" "github.com/mark3labs/mcp-go/server" ) diff --git a/pkg/github/helper_test.go b/pkg/github/helper_test.go index bc1ae412f..1e4627544 100644 --- a/pkg/github/helper_test.go +++ b/pkg/github/helper_test.go @@ -5,7 +5,7 @@ import ( "net/http" "testing" - "github.com/mark3labs/mcp-go/mcp" + "github.com/modelcontextprotocol/go-sdk/mcp" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -110,56 +110,67 @@ func mockResponse(t *testing.T, code int, body interface{}) http.HandlerFunc { // createMCPRequest is a helper function to create a MCP request with the given arguments. func createMCPRequest(args any) mcp.CallToolRequest { + // convert args to map[string]interface{} and serialize to JSON + argsMap, ok := args.(map[string]interface{}) + if !ok { + argsMap = make(map[string]interface{}) + } + + argsJSON, err := json.Marshal(argsMap) + require.NoError(nil, err) + + jsonRawMessage := json.RawMessage(argsJSON) + return mcp.CallToolRequest{ - Params: struct { - Name string `json:"name"` - Arguments any `json:"arguments,omitempty"` - Meta *mcp.Meta `json:"_meta,omitempty"` - }{ - Arguments: args, + Params: &mcp.CallToolParamsRaw{ + Arguments: jsonRawMessage, }, } } // getTextResult is a helper function that returns a text result from a tool call. -func getTextResult(t *testing.T, result *mcp.CallToolResult) mcp.TextContent { +func getTextResult(t *testing.T, result *mcp.CallToolResult) *mcp.TextContent { t.Helper() assert.NotNil(t, result) require.Len(t, result.Content, 1) - require.IsType(t, mcp.TextContent{}, result.Content[0]) - textContent := result.Content[0].(mcp.TextContent) - assert.Equal(t, "text", textContent.Type) + textContent, ok := result.Content[0].(*mcp.TextContent) + require.True(t, ok, "expected content to be of type TextContent") return textContent } -func getErrorResult(t *testing.T, result *mcp.CallToolResult) mcp.TextContent { +func getErrorResult(t *testing.T, result *mcp.CallToolResult) *mcp.TextContent { res := getTextResult(t, result) require.True(t, result.IsError, "expected tool call result to be an error") return res } // getTextResourceResult is a helper function that returns a text result from a tool call. -func getTextResourceResult(t *testing.T, result *mcp.CallToolResult) mcp.TextResourceContents { +func getTextResourceResult(t *testing.T, result *mcp.CallToolResult) *mcp.ResourceContents { t.Helper() assert.NotNil(t, result) require.Len(t, result.Content, 2) content := result.Content[1] require.IsType(t, mcp.EmbeddedResource{}, content) - resource := content.(mcp.EmbeddedResource) - require.IsType(t, mcp.TextResourceContents{}, resource.Resource) - return resource.Resource.(mcp.TextResourceContents) + resource, ok := content.(*mcp.EmbeddedResource) + require.True(t, ok, "expected content to be of type EmbeddedResource") + + require.IsType(t, mcp.ResourceContents{}, resource.Resource) + require.NotEmpty(t, resource.Resource.Text) + return resource.Resource } // getBlobResourceResult is a helper function that returns a blob result from a tool call. -func getBlobResourceResult(t *testing.T, result *mcp.CallToolResult) mcp.BlobResourceContents { +func getBlobResourceResult(t *testing.T, result *mcp.CallToolResult) *mcp.ResourceContents { t.Helper() assert.NotNil(t, result) require.Len(t, result.Content, 2) content := result.Content[1] require.IsType(t, mcp.EmbeddedResource{}, content) - resource := content.(mcp.EmbeddedResource) - require.IsType(t, mcp.BlobResourceContents{}, resource.Resource) - return resource.Resource.(mcp.BlobResourceContents) + + resource := content.(*mcp.EmbeddedResource) + require.IsType(t, mcp.ResourceContents{}, resource.Resource) + require.NotEmpty(t, resource.Resource.Blob) + return resource.Resource } func TestOptionalParamOK(t *testing.T) { @@ -226,11 +237,9 @@ func TestOptionalParamOK(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - request := createMCPRequest(tc.args) - // Test with string type assertion if _, isString := tc.expectedVal.(string); isString || tc.errorMsg == "parameter myParam is not of type string, is bool" { - val, ok, err := OptionalParamOK[string](request, tc.paramName) + val, ok, err := OptionalParamOK[string, map[string]any](tc.args, tc.paramName) if tc.expectError { require.Error(t, err) assert.Contains(t, err.Error(), tc.errorMsg) @@ -245,7 +254,7 @@ func TestOptionalParamOK(t *testing.T) { // Test with bool type assertion if _, isBool := tc.expectedVal.(bool); isBool || tc.errorMsg == "parameter myParam is not of type bool, is string" { - val, ok, err := OptionalParamOK[bool](request, tc.paramName) + val, ok, err := OptionalParamOK[bool, map[string]any](tc.args, tc.paramName) if tc.expectError { require.Error(t, err) assert.Contains(t, err.Error(), tc.errorMsg) @@ -260,7 +269,7 @@ func TestOptionalParamOK(t *testing.T) { // Test with float64 type assertion (for number case) if _, isFloat := tc.expectedVal.(float64); isFloat { - val, ok, err := OptionalParamOK[float64](request, tc.paramName) + val, ok, err := OptionalParamOK[float64, map[string]any](tc.args, tc.paramName) if tc.expectError { // This case shouldn't happen for float64 in the defined tests require.Fail(t, "Unexpected error case for float64") diff --git a/pkg/github/instructions.go b/pkg/github/instructions.go index e783c6c08..338b8b987 100644 --- a/pkg/github/instructions.go +++ b/pkg/github/instructions.go @@ -62,6 +62,75 @@ Check 'list_issue_types' first for organizations to use proper issue types. Use return `## Discussions Use 'list_discussion_categories' to understand available categories before creating discussions. Filter by category for better organization.` + case "projects": + return `## Projects + +Workflow: 1) list_project_fields (get field IDs), 2) list_project_items (with pagination), 3) optional updates. + +Field usage: + - Call list_project_fields first to understand available fields and get IDs/types before filtering. + - Use EXACT returned field names (case-insensitive match). Don't invent names or IDs. + - Iteration synonyms (sprint/cycle) only if that field exists; map to the actual name (e.g. sprint:@current). + - Only include filters for fields that exist and are relevant. + +Pagination (mandatory): + - Loop while pageInfo.hasNextPage=true using after=pageInfo.nextCursor. + - Keep query, fields, per_page IDENTICAL on every page. + - Use before=pageInfo.prevCursor only when explicitly navigating to a previous page. + +Counting rules: + - Count items array length after full pagination. + - Never count field objects, content, or nested arrays as separate items. + +Summary vs list: + - Summaries ONLY if user uses verbs: analyze | summarize | summary | report | overview | insights. + - Listing verbs (list/show/get/fetch/display/enumerate) → enumerate + total. + +Self-check before returning: + - Paginated fully + - Correct IDs used + - Field names valid + - Summary only if requested. + +Return COMPLETE data or state what's missing (e.g. pages skipped). + +list_project_items query rules: +Query string - For advanced filtering of project items using GitHub's project filtering syntax: + +MUST reflect user intent; strongly prefer explicit content type if narrowed: + - "open issues" → state:open is:issue + - "merged PRs" → state:merged is:pr + - "items updated this week" → updated:>@today-7d (omit type only if mixed desired) + - "list all P1 priority items" → priority:p1 (omit state if user wants all, omit type if user specifies "items") + - "list all open P2 issues" → is:issue state:open priority:p2 (include state if user wants open or closed, include type if user specifies "issues" or "PRs") + - "all open issues I'm working on" → is:issue state:open assignee:@me + +Query Construction Heuristics: + a. Extract type nouns: issues → is:issue | PRs, Pulls, or Pull Requests → is:pr | tasks/tickets → is:issue (ask if ambiguity) + b. Map temporal phrases: "this week" → updated:>@today-7d + c. Map negations: "excluding wontfix" → -label:wontfix + d. Map priority adjectives: "high/sev1/p1" → priority:high OR priority:p1 (choose based on field presence) + e. When filtering by label, always use wildcard matching to account for cross-repository differences or emojis: (e.g. "bug 🐛" → label:*bug*) + f. When filtering by milestone, always use wildcard matching to account for cross-repository differences: (e.g. "v1.0" → milestone:*v1.0*) + +Syntax Essentials (items): + AND: space-separated. (label:bug priority:high). + OR: comma inside one qualifier (label:bug,critical). + NOT: leading '-' (-label:wontfix). + Hyphenate multi-word field names. (team-name:"Backend Team", story-points:>5). + Quote multi-word values. (status:"In Review" team-name:"Backend Team"). + Ranges: points:1..3, updated:<@today-30d. + Wildcards: title:*crash*, label:bug*. + Assigned to User: assignee:@me | assignee:username | no:assignee + +Common Qualifier Glossary (items): + is:issue | is:pr | state:open|closed|merged | assignee:@me|username | label:NAME | status:VALUE | + priority:p1|high | sprint-name:@current | team-name:"Backend Team" | parent-issue:"org/repo#123" | + updated:>@today-7d | title:*text* | -label:wontfix | label:bug,critical | no:assignee | has:label + +Never: + - Infer field IDs; fetch via list_project_fields. + - Drop 'fields' param on subsequent pages if field values are needed.` default: return "" } diff --git a/pkg/github/issues.go b/pkg/github/issues.go index 1032d4d04..a37583a18 100644 --- a/pkg/github/issues.go +++ b/pkg/github/issues.go @@ -1,3 +1,5 @@ +//go:build ignore + package github import ( @@ -14,7 +16,7 @@ import ( "github.com/github/github-mcp-server/pkg/sanitize" "github.com/github/github-mcp-server/pkg/translations" "github.com/go-viper/mapstructure/v2" - "github.com/google/go-github/v77/github" + "github.com/google/go-github/v79/github" "github.com/mark3labs/mcp-go/mcp" "github.com/mark3labs/mcp-go/server" "github.com/shurcooL/githubv4" @@ -237,8 +239,8 @@ func IssueRead(getClient GetClientFn, getGQLClient GetGQLClientFn, t translation }), mcp.WithString("method", mcp.Required(), - mcp.Description(`The read operation to perform on a single issue. -Options are: + mcp.Description(`The read operation to perform on a single issue. +Options are: 1. get - Get details of a specific issue. 2. get_comments - Get issue comments. 3. get_sub_issues - Get sub-issues of the issue. @@ -862,8 +864,8 @@ func IssueWrite(getClient GetClientFn, getGQLClient GetGQLClientFn, t translatio mcp.WithString("method", mcp.Required(), mcp.Description(`Write operation to perform on a single issue. -Options are: -- 'create' - creates a new issue. +Options are: +- 'create' - creates a new issue. - 'update' - updates an existing issue. `), mcp.Enum("create", "update"), diff --git a/pkg/github/issues_test.go b/pkg/github/issues_test.go index d13b93e4b..60e6f57de 100644 --- a/pkg/github/issues_test.go +++ b/pkg/github/issues_test.go @@ -1,3 +1,5 @@ +//go:build ignore + package github import ( @@ -12,7 +14,7 @@ import ( "github.com/github/github-mcp-server/internal/githubv4mock" "github.com/github/github-mcp-server/internal/toolsnaps" "github.com/github/github-mcp-server/pkg/translations" - "github.com/google/go-github/v77/github" + "github.com/google/go-github/v79/github" "github.com/migueleliasweb/go-github-mock/src/mock" "github.com/shurcooL/githubv4" "github.com/stretchr/testify/assert" diff --git a/pkg/github/labels.go b/pkg/github/labels.go index c9be7be75..42b53fc6d 100644 --- a/pkg/github/labels.go +++ b/pkg/github/labels.go @@ -1,3 +1,5 @@ +//go:build ignore + package github import ( diff --git a/pkg/github/labels_test.go b/pkg/github/labels_test.go index 6bb91da26..5055364f0 100644 --- a/pkg/github/labels_test.go +++ b/pkg/github/labels_test.go @@ -1,3 +1,5 @@ +//go:build ignore + package github import ( diff --git a/pkg/github/minimal_types.go b/pkg/github/minimal_types.go index dd3b25af3..b06b333bc 100644 --- a/pkg/github/minimal_types.go +++ b/pkg/github/minimal_types.go @@ -1,6 +1,6 @@ package github -import "github.com/google/go-github/v77/github" +import "github.com/google/go-github/v79/github" // MinimalUser is the output type for user and organization search results. type MinimalUser struct { diff --git a/pkg/github/notifications.go b/pkg/github/notifications.go index 6dca53cca..ac2dcec6b 100644 --- a/pkg/github/notifications.go +++ b/pkg/github/notifications.go @@ -1,3 +1,5 @@ +//go:build ignore + package github import ( @@ -11,7 +13,7 @@ import ( ghErrors "github.com/github/github-mcp-server/pkg/errors" "github.com/github/github-mcp-server/pkg/translations" - "github.com/google/go-github/v77/github" + "github.com/google/go-github/v79/github" "github.com/mark3labs/mcp-go/mcp" "github.com/mark3labs/mcp-go/server" ) diff --git a/pkg/github/notifications_test.go b/pkg/github/notifications_test.go index 034d8d4e2..4920589e1 100644 --- a/pkg/github/notifications_test.go +++ b/pkg/github/notifications_test.go @@ -1,3 +1,5 @@ +//go:build ignore + package github import ( @@ -8,7 +10,7 @@ import ( "github.com/github/github-mcp-server/internal/toolsnaps" "github.com/github/github-mcp-server/pkg/translations" - "github.com/google/go-github/v77/github" + "github.com/google/go-github/v79/github" "github.com/migueleliasweb/go-github-mock/src/mock" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/pkg/github/projects.go b/pkg/github/projects.go index 21d4c1103..6710a4f6f 100644 --- a/pkg/github/projects.go +++ b/pkg/github/projects.go @@ -1,3 +1,5 @@ +//go:build ignore + package github import ( @@ -6,14 +8,11 @@ import ( "fmt" "io" "net/http" - "net/url" - "reflect" "strings" ghErrors "github.com/github/github-mcp-server/pkg/errors" "github.com/github/github-mcp-server/pkg/translations" - "github.com/google/go-github/v77/github" - "github.com/google/go-querystring/query" + "github.com/google/go-github/v79/github" "github.com/mark3labs/mcp-go/mcp" "github.com/mark3labs/mcp-go/server" ) @@ -23,11 +22,12 @@ const ( ProjectAddFailedError = "failed to add a project item" ProjectDeleteFailedError = "failed to delete a project item" ProjectListFailedError = "failed to list project items" + MaxProjectsPerPage = 50 ) func ListProjects(getClient GetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { return mcp.NewTool("list_projects", - mcp.WithDescription(t("TOOL_LIST_PROJECTS_DESCRIPTION", "List Projects for a user or org")), + mcp.WithDescription(t("TOOL_LIST_PROJECTS_DESCRIPTION", `List Projects for a user or organization`)), mcp.WithToolAnnotation(mcp.ToolAnnotation{ Title: t("TOOL_LIST_PROJECTS_USER_TITLE", "List projects"), ReadOnlyHint: ToBoolPtr(true), @@ -40,28 +40,38 @@ func ListProjects(getClient GetClientFn, t translations.TranslationHelperFunc) ( mcp.Description("If owner_type == user it is the handle for the GitHub user account. If owner_type == org it is the name of the organization. The name is not case sensitive."), ), mcp.WithString("query", - mcp.Description("Filter projects by a search query (matches title and description)"), + mcp.Description(`Filter projects by title text and open/closed state; permitted qualifiers: is:open, is:closed; examples: "roadmap is:open", "is:open feature planning".`), ), mcp.WithNumber("per_page", - mcp.Description("Number of results per page (max 100, default: 30)"), + mcp.Description(fmt.Sprintf("Results per page (max %d)", MaxProjectsPerPage)), + ), + mcp.WithString("after", + mcp.Description("Forward pagination cursor from previous pageInfo.nextCursor."), + ), + mcp.WithString("before", + mcp.Description("Backward pagination cursor from previous pageInfo.prevCursor (rare)."), ), ), func(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) { owner, err := RequiredParam[string](req, "owner") if err != nil { return mcp.NewToolResultError(err.Error()), nil } + ownerType, err := RequiredParam[string](req, "owner_type") if err != nil { return mcp.NewToolResultError(err.Error()), nil } + queryStr, err := OptionalParam[string](req, "query") if err != nil { return mcp.NewToolResultError(err.Error()), nil } - perPage, err := OptionalIntParamWithDefault(req, "per_page", 30) + + pagination, err := extractPaginationOptions(req) if err != nil { return mcp.NewToolResultError(err.Error()), nil } + client, err := getClient(ctx) if err != nil { return mcp.NewToolResultError(err.Error()), nil @@ -77,7 +87,7 @@ func ListProjects(getClient GetClientFn, t translations.TranslationHelperFunc) ( minimalProjects := []MinimalProject{} opts := &github.ListProjectsOptions{ - ListProjectsPaginationOptions: github.ListProjectsPaginationOptions{PerPage: &perPage}, + ListProjectsPaginationOptions: pagination, Query: queryPtr, } @@ -100,14 +110,12 @@ func ListProjects(getClient GetClientFn, t translations.TranslationHelperFunc) ( minimalProjects = append(minimalProjects, *convertToMinimalProject(project)) } - if resp.StatusCode != http.StatusOK { - body, err := io.ReadAll(resp.Body) - if err != nil { - return nil, fmt.Errorf("failed to read response body: %w", err) - } - return mcp.NewToolResultError(fmt.Sprintf("failed to list projects: %s", string(body))), nil + response := map[string]any{ + "projects": minimalProjects, + "pageInfo": buildPageInfo(resp), } - r, err := json.Marshal(minimalProjects) + + r, err := json.Marshal(response) if err != nil { return nil, fmt.Errorf("failed to marshal response: %w", err) } @@ -213,25 +221,35 @@ func ListProjectFields(getClient GetClientFn, t translations.TranslationHelperFu mcp.Description("The project's number."), ), mcp.WithNumber("per_page", - mcp.Description("Number of results per page (max 100, default: 30)"), + mcp.Description(fmt.Sprintf("Results per page (max %d)", MaxProjectsPerPage)), + ), + mcp.WithString("after", + mcp.Description("Forward pagination cursor from previous pageInfo.nextCursor."), + ), + mcp.WithString("before", + mcp.Description("Backward pagination cursor from previous pageInfo.prevCursor (rare)."), ), ), func(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) { owner, err := RequiredParam[string](req, "owner") if err != nil { return mcp.NewToolResultError(err.Error()), nil } + ownerType, err := RequiredParam[string](req, "owner_type") if err != nil { return mcp.NewToolResultError(err.Error()), nil } + projectNumber, err := RequiredInt(req, "project_number") if err != nil { return mcp.NewToolResultError(err.Error()), nil } - perPage, err := OptionalIntParamWithDefault(req, "per_page", 30) + + pagination, err := extractPaginationOptions(req) if err != nil { return mcp.NewToolResultError(err.Error()), nil } + client, err := getClient(ctx) if err != nil { return mcp.NewToolResultError(err.Error()), nil @@ -241,7 +259,7 @@ func ListProjectFields(getClient GetClientFn, t translations.TranslationHelperFu var projectFields []*github.ProjectV2Field opts := &github.ListProjectsOptions{ - ListProjectsPaginationOptions: github.ListProjectsPaginationOptions{PerPage: &perPage}, + ListProjectsPaginationOptions: pagination, } if ownerType == "org" { @@ -259,14 +277,12 @@ func ListProjectFields(getClient GetClientFn, t translations.TranslationHelperFu } defer func() { _ = resp.Body.Close() }() - if resp.StatusCode != http.StatusOK { - body, err := io.ReadAll(resp.Body) - if err != nil { - return nil, fmt.Errorf("failed to read response body: %w", err) - } - return mcp.NewToolResultError(fmt.Sprintf("failed to list project fields: %s", string(body))), nil + response := map[string]any{ + "fields": projectFields, + "pageInfo": buildPageInfo(resp), } - r, err := json.Marshal(projectFields) + + r, err := json.Marshal(response) if err != nil { return nil, fmt.Errorf("failed to marshal response: %w", err) } @@ -354,7 +370,7 @@ func GetProjectField(getClient GetClientFn, t translations.TranslationHelperFunc func ListProjectItems(getClient GetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { return mcp.NewTool("list_project_items", - mcp.WithDescription(t("TOOL_LIST_PROJECT_ITEMS_DESCRIPTION", "List Project items for a user or org")), + mcp.WithDescription(t("TOOL_LIST_PROJECT_ITEMS_DESCRIPTION", `Search project items with advanced filtering`)), mcp.WithToolAnnotation(mcp.ToolAnnotation{ Title: t("TOOL_LIST_PROJECT_ITEMS_USER_TITLE", "List project items"), ReadOnlyHint: ToBoolPtr(true), @@ -372,13 +388,19 @@ func ListProjectItems(getClient GetClientFn, t translations.TranslationHelperFun mcp.Description("The project's number."), ), mcp.WithString("query", - mcp.Description("Search query to filter items"), + mcp.Description(`Query string for advanced filtering of project items using GitHub's project filtering syntax.`), ), mcp.WithNumber("per_page", - mcp.Description("Number of results per page (max 100, default: 30)"), + mcp.Description(fmt.Sprintf("Results per page (max %d)", MaxProjectsPerPage)), + ), + mcp.WithString("after", + mcp.Description("Forward pagination cursor from previous pageInfo.nextCursor."), + ), + mcp.WithString("before", + mcp.Description("Backward pagination cursor from previous pageInfo.prevCursor (rare)."), ), mcp.WithArray("fields", - mcp.Description("Specific list of field IDs to include in the response (e.g. [\"102589\", \"985201\", \"169875\"]). If not provided, only the title field is included."), + mcp.Description("Field IDs to include (e.g. [\"102589\", \"985201\"]). CRITICAL: Always provide to get field values. Without this, only titles returned."), mcp.WithStringItems(), ), ), func(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) { @@ -386,26 +408,32 @@ func ListProjectItems(getClient GetClientFn, t translations.TranslationHelperFun if err != nil { return mcp.NewToolResultError(err.Error()), nil } + ownerType, err := RequiredParam[string](req, "owner_type") if err != nil { return mcp.NewToolResultError(err.Error()), nil } + projectNumber, err := RequiredInt(req, "project_number") if err != nil { return mcp.NewToolResultError(err.Error()), nil } - perPage, err := OptionalIntParamWithDefault(req, "per_page", 30) + + queryStr, err := OptionalParam[string](req, "query") if err != nil { return mcp.NewToolResultError(err.Error()), nil } - queryStr, err := OptionalParam[string](req, "query") + + fields, err := OptionalBigIntArrayParam(req, "fields") if err != nil { return mcp.NewToolResultError(err.Error()), nil } - fields, err := OptionalBigIntArrayParam(req, "fields") + + pagination, err := extractPaginationOptions(req) if err != nil { return mcp.NewToolResultError(err.Error()), nil } + client, err := getClient(ctx) if err != nil { return mcp.NewToolResultError(err.Error()), nil @@ -422,7 +450,7 @@ func ListProjectItems(getClient GetClientFn, t translations.TranslationHelperFun opts := &github.ListProjectItemsOptions{ Fields: fields, ListProjectsOptions: github.ListProjectsOptions{ - ListProjectsPaginationOptions: github.ListProjectsPaginationOptions{PerPage: &perPage}, + ListProjectsPaginationOptions: pagination, Query: queryPtr, }, } @@ -442,15 +470,12 @@ func ListProjectItems(getClient GetClientFn, t translations.TranslationHelperFun } defer func() { _ = resp.Body.Close() }() - if resp.StatusCode != http.StatusOK { - body, err := io.ReadAll(resp.Body) - if err != nil { - return nil, fmt.Errorf("failed to read response body: %w", err) - } - return mcp.NewToolResultError(fmt.Sprintf("%s: %s", ProjectListFailedError, string(body))), nil + response := map[string]any{ + "items": projectItems, + "pageInfo": buildPageInfo(resp), } - r, err := json.Marshal(projectItems) + r, err := json.Marshal(response) if err != nil { return nil, fmt.Errorf("failed to marshal response: %w", err) } @@ -492,10 +517,12 @@ func GetProjectItem(getClient GetClientFn, t translations.TranslationHelperFunc) if err != nil { return mcp.NewToolResultError(err.Error()), nil } + ownerType, err := RequiredParam[string](req, "owner_type") if err != nil { return mcp.NewToolResultError(err.Error()), nil } + projectNumber, err := RequiredInt(req, "project_number") if err != nil { return mcp.NewToolResultError(err.Error()), nil @@ -514,32 +541,22 @@ func GetProjectItem(getClient GetClientFn, t translations.TranslationHelperFunc) return mcp.NewToolResultError(err.Error()), nil } - var url string - if ownerType == "org" { - url = fmt.Sprintf("orgs/%s/projectsV2/%d/items/%d", owner, projectNumber, itemID) - } else { - url = fmt.Sprintf("users/%s/projectsV2/%d/items/%d", owner, projectNumber, itemID) - } - - opts := fieldSelectionOptions{} + var resp *github.Response + var projectItem *github.ProjectV2Item + var opts *github.GetProjectItemOptions if len(fields) > 0 { - opts.Fields = fields - } - - url, err = addOptions(url, opts) - if err != nil { - return mcp.NewToolResultError(err.Error()), nil + opts = &github.GetProjectItemOptions{ + Fields: fields, + } } - projectItem := projectV2Item{} - - httpRequest, err := client.NewRequest("GET", url, nil) - if err != nil { - return nil, fmt.Errorf("failed to create request: %w", err) + if ownerType == "org" { + projectItem, resp, err = client.Projects.GetOrganizationProjectItem(ctx, owner, projectNumber, itemID, opts) + } else { + projectItem, resp, err = client.Projects.GetUserProjectItem(ctx, owner, projectNumber, itemID, opts) } - resp, err := client.Do(ctx, httpRequest, &projectItem) if err != nil { return ghErrors.NewGitHubAPIErrorResponse(ctx, "failed to get project item", @@ -549,13 +566,6 @@ func GetProjectItem(getClient GetClientFn, t translations.TranslationHelperFunc) } defer func() { _ = resp.Body.Close() }() - if resp.StatusCode != http.StatusOK { - body, err := io.ReadAll(resp.Body) - if err != nil { - return nil, fmt.Errorf("failed to read response body: %w", err) - } - return mcp.NewToolResultError(fmt.Sprintf("failed to get project item: %s", string(body))), nil - } r, err := json.Marshal(projectItem) if err != nil { return nil, fmt.Errorf("failed to marshal response: %w", err) @@ -703,7 +713,7 @@ func UpdateProjectItem(getClient GetClientFn, t translations.TranslationHelperFu if err != nil { return mcp.NewToolResultError(err.Error()), nil } - itemID, err := RequiredInt(req, "item_id") + itemID, err := RequiredBigInt(req, "item_id") if err != nil { return mcp.NewToolResultError(err.Error()), nil } @@ -728,21 +738,15 @@ func UpdateProjectItem(getClient GetClientFn, t translations.TranslationHelperFu return mcp.NewToolResultError(err.Error()), nil } - var projectsURL string + var resp *github.Response + var updatedItem *github.ProjectV2Item + if ownerType == "org" { - projectsURL = fmt.Sprintf("orgs/%s/projectsV2/%d/items/%d", owner, projectNumber, itemID) + updatedItem, resp, err = client.Projects.UpdateOrganizationProjectItem(ctx, owner, projectNumber, itemID, updatePayload) } else { - projectsURL = fmt.Sprintf("users/%s/projectsV2/%d/items/%d", owner, projectNumber, itemID) - } - httpRequest, err := client.NewRequest("PATCH", projectsURL, updateProjectItemPayload{ - Fields: []updateProjectItem{*updatePayload}, - }) - if err != nil { - return nil, fmt.Errorf("failed to create request: %w", err) + updatedItem, resp, err = client.Projects.UpdateUserProjectItem(ctx, owner, projectNumber, itemID, updatePayload) } - updatedItem := projectV2Item{} - resp, err := client.Do(ctx, httpRequest, &updatedItem) if err != nil { return ghErrors.NewGitHubAPIErrorResponse(ctx, ProjectUpdateFailedError, @@ -841,56 +845,11 @@ func DeleteProjectItem(getClient GetClientFn, t translations.TranslationHelperFu } } -type fieldSelectionOptions struct { - // Specific list of field IDs to include in the response. If not provided, only the title field is included. - // The comma tag encodes the slice as comma-separated values: fields=102589,985201,169875 - Fields []int64 `url:"fields,omitempty,comma"` -} - -type updateProjectItemPayload struct { - Fields []updateProjectItem `json:"fields"` -} - -type updateProjectItem struct { - ID int `json:"id"` - Value any `json:"value"` -} - -type projectV2ItemFieldValue struct { - ID *int64 `json:"id,omitempty"` // The unique identifier for this field. - Name string `json:"name,omitempty"` // The display name of the field. - DataType string `json:"data_type,omitempty"` // The data type of the field (e.g., "text", "number", "date", "single_select", "multi_select"). - Value interface{} `json:"value,omitempty"` // The value of the field for a specific project item. -} - -type projectV2Item struct { - ArchivedAt *github.Timestamp `json:"archived_at,omitempty"` - Content *projectV2ItemContent `json:"content,omitempty"` - ContentType *string `json:"content_type,omitempty"` - CreatedAt *github.Timestamp `json:"created_at,omitempty"` - Creator *github.User `json:"creator,omitempty"` - Description *string `json:"description,omitempty"` - Fields []*projectV2ItemFieldValue `json:"fields,omitempty"` - ID *int64 `json:"id,omitempty"` - ItemURL *string `json:"item_url,omitempty"` - NodeID *string `json:"node_id,omitempty"` - ProjectURL *string `json:"project_url,omitempty"` - Title *string `json:"title,omitempty"` - UpdatedAt *github.Timestamp `json:"updated_at,omitempty"` -} - -type projectV2ItemContent struct { - Body *string `json:"body,omitempty"` - ClosedAt *github.Timestamp `json:"closed_at,omitempty"` - CreatedAt *github.Timestamp `json:"created_at,omitempty"` - ID *int64 `json:"id,omitempty"` - Number *int `json:"number,omitempty"` - Repository MinimalRepository `json:"repository,omitempty"` - State *string `json:"state,omitempty"` - StateReason *string `json:"stateReason,omitempty"` - Title *string `json:"title,omitempty"` - UpdatedAt *github.Timestamp `json:"updated_at,omitempty"` - URL *string `json:"url,omitempty"` +type pageInfo struct { + HasNextPage bool `json:"hasNextPage"` + HasPreviousPage bool `json:"hasPreviousPage"` + NextCursor string `json:"nextCursor,omitempty"` + PrevCursor string `json:"prevCursor,omitempty"` } func toNewProjectType(projType string) string { @@ -904,7 +863,27 @@ func toNewProjectType(projType string) string { } } -func buildUpdateProjectItem(input map[string]any) (*updateProjectItem, error) { +// validateAndConvertToInt64 ensures the value is a number and converts it to int64. +func validateAndConvertToInt64(value any) (int64, error) { + switch v := value.(type) { + case float64: + // Validate that the float64 can be safely converted to int64 + intVal := int64(v) + if float64(intVal) != v { + return 0, fmt.Errorf("value must be a valid integer (got %v)", v) + } + return intVal, nil + case int64: + return v, nil + case int: + return int64(v), nil + default: + return 0, fmt.Errorf("value must be a number (got %T)", v) + } +} + +// buildUpdateProjectItem constructs UpdateProjectItemOptions from the input map. +func buildUpdateProjectItem(input map[string]any) (*github.UpdateProjectItemOptions, error) { if input == nil { return nil, fmt.Errorf("updated_field must be an object") } @@ -914,229 +893,66 @@ func buildUpdateProjectItem(input map[string]any) (*updateProjectItem, error) { return nil, fmt.Errorf("updated_field.id is required") } - idFieldAsFloat64, ok := idField.(float64) // JSON numbers are float64 - if !ok { - return nil, fmt.Errorf("updated_field.id must be a number") + fieldID, err := validateAndConvertToInt64(idField) + if err != nil { + return nil, fmt.Errorf("updated_field.id: %w", err) } valueField, ok := input["value"] if !ok { return nil, fmt.Errorf("updated_field.value is required") } - payload := &updateProjectItem{ID: int(idFieldAsFloat64), Value: valueField} + + payload := &github.UpdateProjectItemOptions{ + Fields: []*github.UpdateProjectV2Field{{ + ID: fieldID, + Value: valueField, + }}, + } return payload, nil } -// addOptions adds the parameters in opts as URL query parameters to s. opts -// must be a struct whose fields may contain "url" tags. -func addOptions(s string, opts any) (string, error) { - v := reflect.ValueOf(opts) - if v.Kind() == reflect.Ptr && v.IsNil() { - return s, nil +func buildPageInfo(resp *github.Response) pageInfo { + return pageInfo{ + HasNextPage: resp.After != "", + HasPreviousPage: resp.Before != "", + NextCursor: resp.After, + PrevCursor: resp.Before, } +} - origURL, err := url.Parse(s) +func extractPaginationOptions(request mcp.CallToolRequest) (github.ListProjectsPaginationOptions, error) { + perPage, err := OptionalIntParamWithDefault(request, "per_page", MaxProjectsPerPage) if err != nil { - return s, err + return github.ListProjectsPaginationOptions{}, err + } + if perPage > MaxProjectsPerPage { + perPage = MaxProjectsPerPage } - origValues := origURL.Query() + after, err := OptionalParam[string](request, "after") + if err != nil { + return github.ListProjectsPaginationOptions{}, err + } - // Use the github.com/google/go-querystring library to parse the struct - newValues, err := query.Values(opts) + before, err := OptionalParam[string](request, "before") if err != nil { - return s, err + return github.ListProjectsPaginationOptions{}, err } - // Merge the values - for key, values := range newValues { - for _, value := range values { - origValues.Add(key, value) - } + opts := github.ListProjectsPaginationOptions{ + PerPage: &perPage, } - origURL.RawQuery = origValues.Encode() - return origURL.String(), nil -} + // Only set After/Before if they have non-empty values + if after != "" { + opts.After = &after + } -func ManageProjectItemsPrompt(t translations.TranslationHelperFunc) (tool mcp.Prompt, handler server.PromptHandlerFunc) { - return mcp.NewPrompt("ManageProjectItems", - mcp.WithPromptDescription(t("PROMPT_MANAGE_PROJECT_ITEMS_DESCRIPTION", "Interactive guide for managing GitHub Projects V2, including discovery, field management, querying, and updates.")), - mcp.WithArgument("owner", mcp.ArgumentDescription("The owner of the project (user or organization name)"), mcp.RequiredArgument()), - mcp.WithArgument("owner_type", mcp.ArgumentDescription("Type of owner: 'user' or 'org'"), mcp.RequiredArgument()), - mcp.WithArgument("task", mcp.ArgumentDescription("Optional: specific task to focus on (e.g., 'discover_projects', 'update_items', 'create_reports')")), - ), func(_ context.Context, request mcp.GetPromptRequest) (*mcp.GetPromptResult, error) { - owner := request.Params.Arguments["owner"] - ownerType := request.Params.Arguments["owner_type"] - - task := "" - if t, exists := request.Params.Arguments["task"]; exists { - task = fmt.Sprintf("%v", t) - } - - messages := []mcp.PromptMessage{ - { - Role: "system", - Content: mcp.NewTextContent("You are a GitHub Projects V2 management assistant. Your expertise includes:\n\n" + - "**Core Capabilities:**\n" + - "- Project discovery and field analysis\n" + - "- Item querying with advanced filters\n" + - "- Field value updates and management\n" + - "- Progress reporting and insights\n\n" + - "**Key Rules:**\n" + - "- ALWAYS use the 'query' parameter in **list_project_items** to filter results effectively\n" + - "- ALWAYS include 'fields' parameter with specific field IDs to retrieve field values\n" + - "- Use proper field IDs (not names) when updating items\n" + - "- Provide step-by-step workflows with concrete examples\n\n" + - "**Understanding Project Items:**\n" + - "- Project items reference underlying content (issues or pull requests)\n" + - "- Project tools provide: project fields, item metadata, and basic content info\n" + - "- For detailed information about an issue or pull request (comments, events, etc.), use issue/PR specific tools\n" + - "- The 'content' field in project items includes: repository, issue/PR number, title, state\n" + - "- Use this info to fetch full details: **get_issue**, **list_comments**, **list_issue_events**\n\n" + - "**Available Tools:**\n" + - "- **list_projects**: Discover available projects\n" + - "- **get_project**: Get detailed project information\n" + - "- **list_project_fields**: Get field definitions and IDs\n" + - "- **list_project_items**: Query items with filters and field selection\n" + - "- **get_project_item**: Get specific item details\n" + - "- **add_project_item**: Add issues/PRs to projects\n" + - "- **update_project_item**: Update field values\n" + - "- **delete_project_item**: Remove items from projects"), - }, - { - Role: "user", - Content: mcp.NewTextContent(fmt.Sprintf("I want to work with GitHub Projects for %s (owner_type: %s).%s\n\n"+ - "Help me get started with project management tasks.", - owner, - ownerType, - func() string { - if task != "" { - return fmt.Sprintf(" I'm specifically interested in: %s.", task) - } - return "" - }())), - }, - { - Role: "assistant", - Content: mcp.NewTextContent(fmt.Sprintf("Perfect! I'll help you manage GitHub Projects for %s. Let me guide you through the essential workflows.\n\n"+ - "**🔍 Step 1: Project Discovery**\n"+ - "First, let's see what projects are available using **list_projects**.", owner)), - }, - { - Role: "user", - Content: mcp.NewTextContent("Great! After seeing the projects, I want to understand how to work with project fields and items."), - }, - { - Role: "assistant", - Content: mcp.NewTextContent("**📋 Step 2: Understanding Project Structure**\n\n" + - "Once you select a project, I'll help you:\n\n" + - "1. **Get field information** using **list_project_fields**\n" + - " - Find field IDs, names, and data types\n" + - " - Understand available options for select fields\n" + - " - Identify required vs. optional fields\n\n" + - "2. **Query project items** using **list_project_items**\n" + - " - Filter by assignees: query=\"assignee:@me\"\n" + - " - Filter by status: query=\"status:In Progress\"\n" + - " - Filter by labels: query=\"label:bug\"\n" + - " - Include specific fields: fields=[\"198354254\", \"198354255\"]\n\n" + - "**💡 Pro Tip:** Always specify the 'fields' parameter to get field values, not just titles!"), - }, - { - Role: "user", - Content: mcp.NewTextContent("How do I update field values? What about the different field types?"), - }, - { - Role: "assistant", - Content: mcp.NewTextContent("**✏️ Step 3: Updating Field Values**\n\n" + - "Use **update_project_item** with the updated_field parameter. The format varies by field type:\n\n" + - "**Text fields:**\n" + - "```json\n" + - "{\"id\": 123456, \"value\": \"Updated text content\"}\n" + - "```\n\n" + - "**Single-select fields:**\n" + - "```json\n" + - "{\"id\": 198354254, \"value\": 18498754}\n" + - "```\n" + - "*(Use option ID, not option name)*\n\n" + - "**Date fields:**\n" + - "```json\n" + - "{\"id\": 789012, \"value\": \"2024-03-15\"}\n" + - "```\n\n" + - "**Number fields:**\n" + - "```json\n" + - "{\"id\": 345678, \"value\": 5}\n" + - "```\n\n" + - "**Clear a field:**\n" + - "```json\n" + - "{\"id\": 123456, \"value\": null}\n" + - "```\n\n" + - "**⚠️ Important:** Use the internal project item_id (not issue/PR number) for updates!"), - }, - { - Role: "user", - Content: mcp.NewTextContent("Can you show me a complete workflow example?"), - }, - { - Role: "assistant", - Content: mcp.NewTextContent(fmt.Sprintf("**🔄 Complete Workflow Example**\n\n"+ - "Here's how to find and update your assigned items:\n\n"+ - "**Step 1:** Discover projects\n\n"+ - "**list_projects** owner=\"%s\" owner_type=\"%s\"\n\n\n"+ - "**Step 2:** Get project fields (using project #123)\n\n"+ - "**list_project_fields** owner=\"%s\" owner_type=\"%s\" project_number=123\n\n"+ - "*(Note the Status field ID, e.g., 198354254)*\n\n"+ - "**Step 3:** Query your assigned items\n\n"+ - "**list_project_items**\n"+ - " owner=\"%s\"\n"+ - " owner_type=\"%s\"\n"+ - " project_number=123\n"+ - " query=\"assignee:@me\"\n"+ - " fields=[\"198354254\", \"other_field_ids\"]\n\n\n"+ - "**Step 4:** Update item status\n\n"+ - "**update_project_item**\n"+ - " owner=\"%s\"\n"+ - " owner_type=\"%s\"\n"+ - " project_number=123\n"+ - " item_id=789123\n"+ - " updated_field={\"id\": 198354254, \"value\": 18498754}\n\n\n"+ - "Let me start by listing your projects now!", owner, ownerType, owner, ownerType, owner, ownerType, owner, ownerType)), - }, - { - Role: "user", - Content: mcp.NewTextContent("What if I need more details about the items, like recent comments or linked pull requests?"), - }, - { - Role: "assistant", - Content: mcp.NewTextContent("**📝 Accessing Underlying Issue/PR Details**\n\n" + - "Project items contain basic content info, but for detailed information you need to use issue/PR tools:\n\n" + - "**From project items, extract:**\n" + - "- content.repository.name and content.repository.owner.login\n" + - "- content.number (the issue/PR number)\n" + - "- content_type (\"Issue\" or \"PullRequest\")\n\n" + - "**Then use these tools for details:**\n\n" + - "1. **Get full issue/PR details:**\n" + - " - **get_issue** owner=repo_owner repo=repo_name issue_number=123\n" + - " - Returns: full body, labels, assignees, milestone, etc.\n\n" + - "2. **Get recent comments:**\n" + - " - **list_comments** owner=repo_owner repo=repo_name issue_number=123\n" + - " - Add since parameter to filter recent comments\n\n" + - "3. **Get issue events:**\n" + - " - **list_issue_events** owner=repo_owner repo=repo_name issue_number=123\n" + - " - Shows timeline: assignments, label changes, status updates\n\n" + - "4. **For pull requests specifically:**\n" + - " - **get_pull_request** owner=repo_owner repo=repo_name pull_number=123\n" + - " - **list_pull_request_reviews** for review status\n\n" + - "**💡 Example:** To check for blockers in comments:\n" + - "1. Get project items with query=\"assignee:@me is:open\"\n" + - "2. For each item, extract repository and issue number from content\n" + - "3. Use **list_comments** to get recent comments\n" + - "4. Search comments for keywords like \"blocked\", \"blocker\", \"waiting\""), - }, - } - return &mcp.GetPromptResult{ - Messages: messages, - }, nil - } + if before != "" { + opts.Before = &before + } + + return opts, nil } diff --git a/pkg/github/projects_test.go b/pkg/github/projects_test.go index ed198a97a..6cc4f6cc4 100644 --- a/pkg/github/projects_test.go +++ b/pkg/github/projects_test.go @@ -1,3 +1,5 @@ +//go:build ignore + package github import ( @@ -9,7 +11,7 @@ import ( "github.com/github/github-mcp-server/internal/toolsnaps" "github.com/github/github-mcp-server/pkg/translations" - gh "github.com/google/go-github/v77/github" + gh "github.com/google/go-github/v79/github" "github.com/migueleliasweb/go-github-mock/src/mock" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -28,8 +30,9 @@ func Test_ListProjects(t *testing.T) { assert.Contains(t, tool.InputSchema.Properties, "per_page") assert.ElementsMatch(t, tool.InputSchema.Required, []string{"owner", "owner_type"}) - orgProjects := []map[string]any{{"id": 1, "title": "Org Project"}} - userProjects := []map[string]any{{"id": 2, "title": "User Project"}} + // API returns full ProjectV2 objects; we only need minimal fields for decoding. + orgProjects := []map[string]any{{"id": 1, "node_id": "NODE1", "title": "Org Project"}} + userProjects := []map[string]any{{"id": 2, "node_id": "NODE2", "title": "User Project"}} tests := []struct { name string @@ -44,7 +47,10 @@ func Test_ListProjects(t *testing.T) { mockedClient: mock.NewMockedHTTPClient( mock.WithRequestMatchHandler( mock.EndpointPattern{Pattern: "/orgs/{org}/projectsV2", Method: http.MethodGet}, - mockResponse(t, http.StatusOK, orgProjects), + http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) + _, _ = w.Write(mock.MustMarshal(orgProjects)) + }), ), ), requestArgs: map[string]interface{}{ @@ -59,7 +65,10 @@ func Test_ListProjects(t *testing.T) { mockedClient: mock.NewMockedHTTPClient( mock.WithRequestMatchHandler( mock.EndpointPattern{Pattern: "/users/{username}/projectsV2", Method: http.MethodGet}, - mockResponse(t, http.StatusOK, userProjects), + http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) + _, _ = w.Write(mock.MustMarshal(userProjects)) + }), ), ), requestArgs: map[string]interface{}{ @@ -153,10 +162,15 @@ func Test_ListProjects(t *testing.T) { require.False(t, result.IsError) textContent := getTextResult(t, result) - var arr []map[string]any - err = json.Unmarshal([]byte(textContent.Text), &arr) + var response map[string]any + err = json.Unmarshal([]byte(textContent.Text), &response) require.NoError(t, err) - assert.Equal(t, tc.expectedLength, len(arr)) + projects, ok := response["projects"].([]interface{}) + require.True(t, ok) + assert.Equal(t, tc.expectedLength, len(projects)) + // pageInfo should exist + _, hasPageInfo := response["pageInfo"].(map[string]interface{}) + assert.True(t, hasPageInfo) }) } } @@ -305,12 +319,8 @@ func Test_ListProjectFields(t *testing.T) { assert.Contains(t, tool.InputSchema.Properties, "per_page") assert.ElementsMatch(t, tool.InputSchema.Required, []string{"owner_type", "owner", "project_number"}) - orgFields := []map[string]any{ - {"id": 101, "name": "Status", "dataType": "single_select"}, - } - userFields := []map[string]any{ - {"id": 201, "name": "Priority", "dataType": "single_select"}, - } + orgFields := []map[string]any{{"id": 101, "name": "Status", "data_type": "single_select"}} + userFields := []map[string]any{{"id": 201, "name": "Priority", "data_type": "single_select"}} tests := []struct { name string @@ -325,7 +335,10 @@ func Test_ListProjectFields(t *testing.T) { mockedClient: mock.NewMockedHTTPClient( mock.WithRequestMatchHandler( mock.EndpointPattern{Pattern: "/orgs/{org}/projectsV2/{project}/fields", Method: http.MethodGet}, - mockResponse(t, http.StatusOK, orgFields), + http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) + _, _ = w.Write(mock.MustMarshal(orgFields)) + }), ), ), requestArgs: map[string]interface{}{ @@ -433,10 +446,14 @@ func Test_ListProjectFields(t *testing.T) { require.False(t, result.IsError) textContent := getTextResult(t, result) - var fields []map[string]any - err = json.Unmarshal([]byte(textContent.Text), &fields) + var response map[string]any + err = json.Unmarshal([]byte(textContent.Text), &response) require.NoError(t, err) + fields, ok := response["fields"].([]interface{}) + require.True(t, ok) assert.Equal(t, tc.expectedLength, len(fields)) + _, hasPageInfo := response["pageInfo"].(map[string]interface{}) + assert.True(t, hasPageInfo) }) } } @@ -653,8 +670,7 @@ func Test_ListProjectItems(t *testing.T) { mock.EndpointPattern{Pattern: "/orgs/{org}/projectsV2/{project}/items", Method: http.MethodGet}, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { q := r.URL.Query() - fieldParams := q.Get("fields") - if fieldParams == "123,456,789" { + if q.Get("fields") == "123,456,789" { w.WriteHeader(http.StatusOK) _, _ = w.Write(mock.MustMarshal(orgItems)) return @@ -786,10 +802,14 @@ func Test_ListProjectItems(t *testing.T) { require.False(t, result.IsError) textContent := getTextResult(t, result) - var items []map[string]any - err = json.Unmarshal([]byte(textContent.Text), &items) + var response map[string]any + err = json.Unmarshal([]byte(textContent.Text), &response) require.NoError(t, err) + items, ok := response["items"].([]interface{}) + require.True(t, ok) assert.Equal(t, tc.expectedLength, len(items)) + _, hasPageInfo := response["pageInfo"].(map[string]interface{}) + assert.True(t, hasPageInfo) }) } } @@ -852,8 +872,7 @@ func Test_GetProjectItem(t *testing.T) { mock.EndpointPattern{Pattern: "/orgs/{org}/projectsV2/{project}/items/{item_id}", Method: http.MethodGet}, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { q := r.URL.Query() - fieldParams := q.Get("fields") - if fieldParams == "123,456" { + if q.Get("fields") == "123,456" { w.WriteHeader(http.StatusOK) _, _ = w.Write(mock.MustMarshal(orgItem)) return @@ -1351,8 +1370,8 @@ func Test_UpdateProjectItem(t *testing.T) { "owner_type": "org", "project_number": float64(1), "item_id": float64(2), - "field_id": float64(1), - "new_field": map[string]any{ + "updated_field": map[string]any{ + "id": float64(1), "value": "X", }, }, @@ -1365,7 +1384,7 @@ func Test_UpdateProjectItem(t *testing.T) { "owner": "octo-org", "project_number": float64(1), "item_id": float64(2), - "new_field": map[string]any{ + "updated_field": map[string]any{ "id": float64(1), "value": "X", }, @@ -1379,7 +1398,7 @@ func Test_UpdateProjectItem(t *testing.T) { "owner": "octo-org", "owner_type": "org", "item_id": float64(2), - "new_field": map[string]any{ + "updated_field": map[string]any{ "id": float64(1), "value": "X", }, @@ -1393,7 +1412,7 @@ func Test_UpdateProjectItem(t *testing.T) { "owner": "octo-org", "owner_type": "org", "project_number": float64(1), - "new_field": map[string]any{ + "updated_field": map[string]any{ "id": float64(1), "value": "X", }, @@ -1401,19 +1420,18 @@ func Test_UpdateProjectItem(t *testing.T) { expectError: true, }, { - name: "missing field_value", + name: "missing updated_field", mockedClient: mock.NewMockedHTTPClient(), requestArgs: map[string]any{ "owner": "octo-org", "owner_type": "org", "project_number": float64(1), "item_id": float64(2), - "field_id": float64(2), }, expectError: true, }, { - name: "new_field not object", + name: "updated_field not object", mockedClient: mock.NewMockedHTTPClient(), requestArgs: map[string]any{ "owner": "octo-org", @@ -1425,7 +1443,7 @@ func Test_UpdateProjectItem(t *testing.T) { expectError: true, }, { - name: "new_field missing id", + name: "updated_field missing id", mockedClient: mock.NewMockedHTTPClient(), requestArgs: map[string]any{ "owner": "octo-org", @@ -1437,7 +1455,7 @@ func Test_UpdateProjectItem(t *testing.T) { expectError: true, }, { - name: "new_field missing value", + name: "updated_field missing value", mockedClient: mock.NewMockedHTTPClient(), requestArgs: map[string]any{ "owner": "octo-org", @@ -1475,14 +1493,14 @@ func Test_UpdateProjectItem(t *testing.T) { assert.Contains(t, text, "missing required parameter: project_number") case "missing item_id": assert.Contains(t, text, "missing required parameter: item_id") - case "missing field_value": + case "missing updated_field": assert.Contains(t, text, "missing required parameter: updated_field") - case "field_value not object": + case "updated_field not object": assert.Contains(t, text, "field_value must be an object") - case "field_value missing id": - assert.Contains(t, text, "missing required parameter: field_id") - case "field_value missing value": - assert.Contains(t, text, "field_value.value is required") + case "updated_field missing id": + assert.Contains(t, text, "updated_field.id is required") + case "updated_field missing value": + assert.Contains(t, text, "updated_field.value is required") } return } diff --git a/pkg/github/pullrequests.go b/pkg/github/pullrequests.go index 117f92ecf..69af69af7 100644 --- a/pkg/github/pullrequests.go +++ b/pkg/github/pullrequests.go @@ -1,3 +1,5 @@ +//go:build ignore + package github import ( @@ -8,7 +10,7 @@ import ( "net/http" "github.com/go-viper/mapstructure/v2" - "github.com/google/go-github/v77/github" + "github.com/google/go-github/v79/github" "github.com/mark3labs/mcp-go/mcp" "github.com/mark3labs/mcp-go/server" "github.com/shurcooL/githubv4" @@ -28,8 +30,8 @@ func PullRequestRead(getClient GetClientFn, t translations.TranslationHelperFunc }), mcp.WithString("method", mcp.Required(), - mcp.Description(`Action to specify what pull request data needs to be retrieved from GitHub. -Possible options: + mcp.Description(`Action to specify what pull request data needs to be retrieved from GitHub. +Possible options: 1. get - Get details of a specific pull request. 2. get_diff - Get the diff of a pull request. 3. get_status - Get status of a head commit in a pull request. This reflects status of builds and checks. diff --git a/pkg/github/pullrequests_test.go b/pkg/github/pullrequests_test.go index 4cc4480e9..02eaadf32 100644 --- a/pkg/github/pullrequests_test.go +++ b/pkg/github/pullrequests_test.go @@ -1,3 +1,5 @@ +//go:build ignore + package github import ( @@ -10,7 +12,7 @@ import ( "github.com/github/github-mcp-server/internal/githubv4mock" "github.com/github/github-mcp-server/internal/toolsnaps" "github.com/github/github-mcp-server/pkg/translations" - "github.com/google/go-github/v77/github" + "github.com/google/go-github/v79/github" "github.com/shurcooL/githubv4" "github.com/migueleliasweb/go-github-mock/src/mock" diff --git a/pkg/github/repositories.go b/pkg/github/repositories.go index 0d4d11bbf..4ece85e91 100644 --- a/pkg/github/repositories.go +++ b/pkg/github/repositories.go @@ -1,3 +1,5 @@ +//go:build ignore + package github import ( @@ -13,7 +15,7 @@ import ( ghErrors "github.com/github/github-mcp-server/pkg/errors" "github.com/github/github-mcp-server/pkg/raw" "github.com/github/github-mcp-server/pkg/translations" - "github.com/google/go-github/v77/github" + "github.com/google/go-github/v79/github" "github.com/mark3labs/mcp-go/mcp" "github.com/mark3labs/mcp-go/server" ) @@ -560,7 +562,7 @@ func GetFileContents(getClient GetClientFn, getRawClient raw.GetRawClientFn, t t ), nil } if fileContent == nil || fileContent.SHA == nil { - return mcp.NewToolResultError("file content SHA is nil"), nil + return mcp.NewToolResultError("file content SHA is nil, if a directory was requested, path parameters should end with a trailing slash '/'"), nil } fileSHA = *fileContent.SHA diff --git a/pkg/github/repositories_test.go b/pkg/github/repositories_test.go index 665af6b0a..ea784fe43 100644 --- a/pkg/github/repositories_test.go +++ b/pkg/github/repositories_test.go @@ -1,3 +1,5 @@ +//go:build ignore + package github import ( @@ -13,7 +15,7 @@ import ( "github.com/github/github-mcp-server/internal/toolsnaps" "github.com/github/github-mcp-server/pkg/raw" "github.com/github/github-mcp-server/pkg/translations" - "github.com/google/go-github/v77/github" + "github.com/google/go-github/v79/github" "github.com/mark3labs/mcp-go/mcp" "github.com/migueleliasweb/go-github-mock/src/mock" "github.com/stretchr/testify/assert" diff --git a/pkg/github/repository_resource.go b/pkg/github/repository_resource.go index a159111af..8fb1a52ed 100644 --- a/pkg/github/repository_resource.go +++ b/pkg/github/repository_resource.go @@ -14,7 +14,7 @@ import ( "github.com/github/github-mcp-server/pkg/raw" "github.com/github/github-mcp-server/pkg/translations" - "github.com/google/go-github/v77/github" + "github.com/google/go-github/v79/github" "github.com/mark3labs/mcp-go/mcp" "github.com/mark3labs/mcp-go/server" ) diff --git a/pkg/github/repository_resource_test.go b/pkg/github/repository_resource_test.go index f452912a0..96bf33b72 100644 --- a/pkg/github/repository_resource_test.go +++ b/pkg/github/repository_resource_test.go @@ -8,7 +8,7 @@ import ( "github.com/github/github-mcp-server/pkg/raw" "github.com/github/github-mcp-server/pkg/translations" - "github.com/google/go-github/v77/github" + "github.com/google/go-github/v79/github" "github.com/mark3labs/mcp-go/mcp" "github.com/migueleliasweb/go-github-mock/src/mock" "github.com/stretchr/testify/require" diff --git a/pkg/github/search.go b/pkg/github/search.go index 5084773b2..c909c10ca 100644 --- a/pkg/github/search.go +++ b/pkg/github/search.go @@ -1,3 +1,5 @@ +//go:build ignore + package github import ( @@ -8,7 +10,7 @@ import ( ghErrors "github.com/github/github-mcp-server/pkg/errors" "github.com/github/github-mcp-server/pkg/translations" - "github.com/google/go-github/v77/github" + "github.com/google/go-github/v79/github" "github.com/mark3labs/mcp-go/mcp" "github.com/mark3labs/mcp-go/server" ) diff --git a/pkg/github/search_test.go b/pkg/github/search_test.go index e14ba023f..d823e2070 100644 --- a/pkg/github/search_test.go +++ b/pkg/github/search_test.go @@ -1,3 +1,5 @@ +//go:build ignore + package github import ( @@ -8,7 +10,7 @@ import ( "github.com/github/github-mcp-server/internal/toolsnaps" "github.com/github/github-mcp-server/pkg/translations" - "github.com/google/go-github/v77/github" + "github.com/google/go-github/v79/github" "github.com/migueleliasweb/go-github-mock/src/mock" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/pkg/github/search_utils.go b/pkg/github/search_utils.go index 04cb2224f..4a710236b 100644 --- a/pkg/github/search_utils.go +++ b/pkg/github/search_utils.go @@ -1,3 +1,5 @@ +//go:build ignore + package github import ( @@ -8,7 +10,7 @@ import ( "net/http" "regexp" - "github.com/google/go-github/v77/github" + "github.com/google/go-github/v79/github" "github.com/mark3labs/mcp-go/mcp" ) diff --git a/pkg/github/search_utils_test.go b/pkg/github/search_utils_test.go index 85f953eed..7b68c4ca2 100644 --- a/pkg/github/search_utils_test.go +++ b/pkg/github/search_utils_test.go @@ -1,3 +1,5 @@ +//go:build ignore + package github import ( diff --git a/pkg/github/secret_scanning.go b/pkg/github/secret_scanning.go index 866c54617..192e0a410 100644 --- a/pkg/github/secret_scanning.go +++ b/pkg/github/secret_scanning.go @@ -1,3 +1,5 @@ +//go:build ignore + package github import ( @@ -9,7 +11,7 @@ import ( ghErrors "github.com/github/github-mcp-server/pkg/errors" "github.com/github/github-mcp-server/pkg/translations" - "github.com/google/go-github/v77/github" + "github.com/google/go-github/v79/github" "github.com/mark3labs/mcp-go/mcp" "github.com/mark3labs/mcp-go/server" ) diff --git a/pkg/github/secret_scanning_test.go b/pkg/github/secret_scanning_test.go index 4a9d50ab9..8f665ba8a 100644 --- a/pkg/github/secret_scanning_test.go +++ b/pkg/github/secret_scanning_test.go @@ -1,3 +1,5 @@ +//go:build ignore + package github import ( @@ -7,7 +9,7 @@ import ( "testing" "github.com/github/github-mcp-server/pkg/translations" - "github.com/google/go-github/v77/github" + "github.com/google/go-github/v79/github" "github.com/migueleliasweb/go-github-mock/src/mock" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/pkg/github/security_advisories.go b/pkg/github/security_advisories.go index 316b5d58c..2c4be1bb3 100644 --- a/pkg/github/security_advisories.go +++ b/pkg/github/security_advisories.go @@ -1,3 +1,5 @@ +//go:build ignore + package github import ( @@ -8,7 +10,7 @@ import ( "net/http" "github.com/github/github-mcp-server/pkg/translations" - "github.com/google/go-github/v77/github" + "github.com/google/go-github/v79/github" "github.com/mark3labs/mcp-go/mcp" "github.com/mark3labs/mcp-go/server" ) diff --git a/pkg/github/security_advisories_test.go b/pkg/github/security_advisories_test.go index e083cb166..f4dcf7f50 100644 --- a/pkg/github/security_advisories_test.go +++ b/pkg/github/security_advisories_test.go @@ -1,3 +1,5 @@ +//go:build ignore + package github import ( @@ -7,7 +9,7 @@ import ( "testing" "github.com/github/github-mcp-server/pkg/translations" - "github.com/google/go-github/v77/github" + "github.com/google/go-github/v79/github" "github.com/migueleliasweb/go-github-mock/src/mock" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/pkg/github/server.go b/pkg/github/server.go index ddf3b0f86..f474d06b4 100644 --- a/pkg/github/server.go +++ b/pkg/github/server.go @@ -6,36 +6,37 @@ import ( "fmt" "strconv" - "github.com/google/go-github/v77/github" - "github.com/mark3labs/mcp-go/mcp" - "github.com/mark3labs/mcp-go/server" + "github.com/github/github-mcp-server/pkg/utils" + "github.com/google/go-github/v79/github" + "github.com/google/jsonschema-go/jsonschema" + "github.com/modelcontextprotocol/go-sdk/mcp" ) // NewServer creates a new GitHub MCP server with the specified GH client and logger. -func NewServer(version string, opts ...server.ServerOption) *server.MCPServer { +func NewServer(version string, opts *mcp.ServerOptions) *mcp.Server { // Add default options - defaultOpts := []server.ServerOption{ - server.WithToolCapabilities(true), - server.WithResourceCapabilities(true, true), - server.WithLogging(), + opts = &mcp.ServerOptions{ + HasTools: true, + HasResources: true, + Logger: opts.Logger, } - opts = append(defaultOpts, opts...) // Create a new MCP server - s := server.NewMCPServer( - "github-mcp-server", - version, - opts..., - ) + s := mcp.NewServer(&mcp.Implementation{ + Name: "github-mcp-server", + Title: "GitHub MCP Server", + Version: version, + }, opts) + return s } // OptionalParamOK is a helper function that can be used to fetch a requested parameter from the request. // It returns the value, a boolean indicating if the parameter was present, and an error if the type is wrong. -func OptionalParamOK[T any](r mcp.CallToolRequest, p string) (value T, ok bool, err error) { +func OptionalParamOK[T any, A map[string]any](args A, p string) (value T, ok bool, err error) { // Check if the parameter is present in the request - val, exists := r.GetArguments()[p] + val, exists := args[p] if !exists { // Not present, return zero value, false, no error return @@ -66,16 +67,16 @@ func isAcceptedError(err error) bool { // 1. Checks if the parameter is present in the request. // 2. Checks if the parameter is of the expected type. // 3. Checks if the parameter is not empty, i.e: non-zero value -func RequiredParam[T comparable](r mcp.CallToolRequest, p string) (T, error) { +func RequiredParam[T comparable](args map[string]any, p string) (T, error) { var zero T // Check if the parameter is present in the request - if _, ok := r.GetArguments()[p]; !ok { + if _, ok := args[p]; !ok { return zero, fmt.Errorf("missing required parameter: %s", p) } // Check if the parameter is of the expected type - val, ok := r.GetArguments()[p].(T) + val, ok := args[p].(T) if !ok { return zero, fmt.Errorf("parameter %s is not of type %T", p, zero) } @@ -92,8 +93,8 @@ func RequiredParam[T comparable](r mcp.CallToolRequest, p string) (T, error) { // 1. Checks if the parameter is present in the request. // 2. Checks if the parameter is of the expected type. // 3. Checks if the parameter is not empty, i.e: non-zero value -func RequiredInt(r mcp.CallToolRequest, p string) (int, error) { - v, err := RequiredParam[float64](r, p) +func RequiredInt(args map[string]any, p string) (int, error) { + v, err := RequiredParam[float64](args, p) if err != nil { return 0, err } @@ -106,8 +107,8 @@ func RequiredInt(r mcp.CallToolRequest, p string) (int, error) { // 2. Checks if the parameter is of the expected type (float64). // 3. Checks if the parameter is not empty, i.e: non-zero value. // 4. Validates that the float64 value can be safely converted to int64 without truncation. -func RequiredBigInt(r mcp.CallToolRequest, p string) (int64, error) { - v, err := RequiredParam[float64](r, p) +func RequiredBigInt(args map[string]any, p string) (int64, error) { + v, err := RequiredParam[float64](args, p) if err != nil { return 0, err } @@ -124,28 +125,28 @@ func RequiredBigInt(r mcp.CallToolRequest, p string) (int64, error) { // It does the following checks: // 1. Checks if the parameter is present in the request, if not, it returns its zero-value // 2. If it is present, it checks if the parameter is of the expected type and returns it -func OptionalParam[T any](r mcp.CallToolRequest, p string) (T, error) { +func OptionalParam[T any](args map[string]any, p string) (T, error) { var zero T // Check if the parameter is present in the request - if _, ok := r.GetArguments()[p]; !ok { + if _, ok := args[p]; !ok { return zero, nil } // Check if the parameter is of the expected type - if _, ok := r.GetArguments()[p].(T); !ok { - return zero, fmt.Errorf("parameter %s is not of type %T, is %T", p, zero, r.GetArguments()[p]) + if _, ok := args[p].(T); !ok { + return zero, fmt.Errorf("parameter %s is not of type %T, is %T", p, zero, args[p]) } - return r.GetArguments()[p].(T), nil + return args[p].(T), nil } // OptionalIntParam is a helper function that can be used to fetch a requested parameter from the request. // It does the following checks: // 1. Checks if the parameter is present in the request, if not, it returns its zero-value // 2. If it is present, it checks if the parameter is of the expected type and returns it -func OptionalIntParam(r mcp.CallToolRequest, p string) (int, error) { - v, err := OptionalParam[float64](r, p) +func OptionalIntParam(args map[string]any, p string) (int, error) { + v, err := OptionalParam[float64](args, p) if err != nil { return 0, err } @@ -154,8 +155,8 @@ func OptionalIntParam(r mcp.CallToolRequest, p string) (int, error) { // OptionalIntParamWithDefault is a helper function that can be used to fetch a requested parameter from the request // similar to optionalIntParam, but it also takes a default value. -func OptionalIntParamWithDefault(r mcp.CallToolRequest, p string, d int) (int, error) { - v, err := OptionalIntParam(r, p) +func OptionalIntParamWithDefault(args map[string]any, p string, d int) (int, error) { + v, err := OptionalIntParam(args, p) if err != nil { return 0, err } @@ -167,10 +168,9 @@ func OptionalIntParamWithDefault(r mcp.CallToolRequest, p string, d int) (int, e // OptionalBoolParamWithDefault is a helper function that can be used to fetch a requested parameter from the request // similar to optionalBoolParam, but it also takes a default value. -func OptionalBoolParamWithDefault(r mcp.CallToolRequest, p string, d bool) (bool, error) { - args := r.GetArguments() +func OptionalBoolParamWithDefault(args map[string]any, p string, d bool) (bool, error) { _, ok := args[p] - v, err := OptionalParam[bool](r, p) + v, err := OptionalParam[bool](args, p) if err != nil { return false, err } @@ -184,13 +184,13 @@ func OptionalBoolParamWithDefault(r mcp.CallToolRequest, p string, d bool) (bool // It does the following checks: // 1. Checks if the parameter is present in the request, if not, it returns its zero-value // 2. If it is present, iterates the elements and checks each is a string -func OptionalStringArrayParam(r mcp.CallToolRequest, p string) ([]string, error) { +func OptionalStringArrayParam(args map[string]any, p string) ([]string, error) { // Check if the parameter is present in the request - if _, ok := r.GetArguments()[p]; !ok { + if _, ok := args[p]; !ok { return []string{}, nil } - switch v := r.GetArguments()[p].(type) { + switch v := args[p].(type) { case nil: return []string{}, nil case []string: @@ -206,7 +206,7 @@ func OptionalStringArrayParam(r mcp.CallToolRequest, p string) ([]string, error) } return strSlice, nil default: - return []string{}, fmt.Errorf("parameter %s could not be coerced to []string, is %T", p, r.GetArguments()[p]) + return []string{}, fmt.Errorf("parameter %s could not be coerced to []string, is %T", p, args[p]) } } @@ -234,13 +234,13 @@ func convertStringToBigInt(s string, def int64) (int64, error) { // It does the following checks: // 1. Checks if the parameter is present in the request, if not, it returns an empty slice // 2. If it is present, iterates the elements, checks each is a string, and converts them to int64 values -func OptionalBigIntArrayParam(r mcp.CallToolRequest, p string) ([]int64, error) { +func OptionalBigIntArrayParam(args map[string]any, p string) ([]int64, error) { // Check if the parameter is present in the request - if _, ok := r.GetArguments()[p]; !ok { + if _, ok := args[p]; !ok { return []int64{}, nil } - switch v := r.GetArguments()[p].(type) { + switch v := args[p].(type) { case nil: return []int64{}, nil case []string: @@ -260,61 +260,68 @@ func OptionalBigIntArrayParam(r mcp.CallToolRequest, p string) ([]int64, error) } return int64Slice, nil default: - return []int64{}, fmt.Errorf("parameter %s could not be coerced to []int64, is %T", p, r.GetArguments()[p]) + return []int64{}, fmt.Errorf("parameter %s could not be coerced to []int64, is %T", p, args[p]) } } // WithPagination adds REST API pagination parameters to a tool. // https://docs.github.com/en/rest/using-the-rest-api/using-pagination-in-the-rest-api -func WithPagination() mcp.ToolOption { - return func(tool *mcp.Tool) { - mcp.WithNumber("page", - mcp.Description("Page number for pagination (min 1)"), - mcp.Min(1), - )(tool) - - mcp.WithNumber("perPage", - mcp.Description("Results per page for pagination (min 1, max 100)"), - mcp.Min(1), - mcp.Max(100), - )(tool) +func WithPagination(schema *jsonschema.Schema) *jsonschema.Schema { + schema.Properties["page"] = &jsonschema.Schema{ + Type: "Number", + Description: "Page number for pagination (min 1)", + Minimum: jsonschema.Ptr(1.0), + } + + schema.Properties["perPage"] = &jsonschema.Schema{ + Type: "Number", + Description: "Results per page for pagination (min 1, max 100)", + Minimum: jsonschema.Ptr(1.0), + Maximum: jsonschema.Ptr(100.0), } + + return schema } // WithUnifiedPagination adds REST API pagination parameters to a tool. // GraphQL tools will use this and convert page/perPage to GraphQL cursor parameters internally. -func WithUnifiedPagination() mcp.ToolOption { - return func(tool *mcp.Tool) { - mcp.WithNumber("page", - mcp.Description("Page number for pagination (min 1)"), - mcp.Min(1), - )(tool) - - mcp.WithNumber("perPage", - mcp.Description("Results per page for pagination (min 1, max 100)"), - mcp.Min(1), - mcp.Max(100), - )(tool) - - mcp.WithString("after", - mcp.Description("Cursor for pagination. Use the endCursor from the previous page's PageInfo for GraphQL APIs."), - )(tool) +func WithUnifiedPagination(schema *jsonschema.Schema) *jsonschema.Schema { + schema.Properties["page"] = &jsonschema.Schema{ + Type: "Number", + Description: "Page number for pagination (min 1)", + Minimum: jsonschema.Ptr(1.0), + } + + schema.Properties["perPage"] = &jsonschema.Schema{ + Type: "Number", + Description: "Results per page for pagination (min 1, max 100)", + Minimum: jsonschema.Ptr(1.0), + Maximum: jsonschema.Ptr(100.0), } + + schema.Properties["after"] = &jsonschema.Schema{ + Type: "String", + Description: "Cursor for pagination. Use the endCursor from the previous page's PageInfo for GraphQL APIs.", + } + + return schema } // WithCursorPagination adds only cursor-based pagination parameters to a tool (no page parameter). -func WithCursorPagination() mcp.ToolOption { - return func(tool *mcp.Tool) { - mcp.WithNumber("perPage", - mcp.Description("Results per page for pagination (min 1, max 100)"), - mcp.Min(1), - mcp.Max(100), - )(tool) - - mcp.WithString("after", - mcp.Description("Cursor for pagination. Use the endCursor from the previous page's PageInfo for GraphQL APIs."), - )(tool) +func WithCursorPagination(schema *jsonschema.Schema) *jsonschema.Schema { + schema.Properties["perPage"] = &jsonschema.Schema{ + Type: "Number", + Description: "Results per page for pagination (min 1, max 100)", + Minimum: jsonschema.Ptr(1.0), + Maximum: jsonschema.Ptr(100.0), } + + schema.Properties["after"] = &jsonschema.Schema{ + Type: "String", + Description: "Cursor for pagination. Use the endCursor from the previous page's PageInfo for GraphQL APIs.", + } + + return schema } type PaginationParams struct { @@ -328,16 +335,16 @@ type PaginationParams struct { // In future, we may want to make the default values configurable, or even have this // function returned from `withPagination`, where the defaults are provided alongside // the min/max values. -func OptionalPaginationParams(r mcp.CallToolRequest) (PaginationParams, error) { - page, err := OptionalIntParamWithDefault(r, "page", 1) +func OptionalPaginationParams(args map[string]any) (PaginationParams, error) { + page, err := OptionalIntParamWithDefault(args, "page", 1) if err != nil { return PaginationParams{}, err } - perPage, err := OptionalIntParamWithDefault(r, "perPage", 30) + perPage, err := OptionalIntParamWithDefault(args, "perPage", 30) if err != nil { return PaginationParams{}, err } - after, err := OptionalParam[string](r, "after") + after, err := OptionalParam[string](args, "after") if err != nil { return PaginationParams{}, err } @@ -350,12 +357,12 @@ func OptionalPaginationParams(r mcp.CallToolRequest) (PaginationParams, error) { // OptionalCursorPaginationParams returns the "perPage" and "after" parameters from the request, // without the "page" parameter, suitable for cursor-based pagination only. -func OptionalCursorPaginationParams(r mcp.CallToolRequest) (CursorPaginationParams, error) { - perPage, err := OptionalIntParamWithDefault(r, "perPage", 30) +func OptionalCursorPaginationParams(args map[string]any) (CursorPaginationParams, error) { + perPage, err := OptionalIntParamWithDefault(args, "perPage", 30) if err != nil { return CursorPaginationParams{}, err } - after, err := OptionalParam[string](r, "after") + after, err := OptionalParam[string](args, "after") if err != nil { return CursorPaginationParams{}, err } @@ -411,8 +418,8 @@ func (p PaginationParams) ToGraphQLParams() (*GraphQLPaginationParams, error) { func MarshalledTextResult(v any) *mcp.CallToolResult { data, err := json.Marshal(v) if err != nil { - return mcp.NewToolResultErrorFromErr("failed to marshal text result to json", err) + return utils.NewToolResultErrorFromErr("failed to marshal text result to json", err) } - return mcp.NewToolResultText(string(data)) + return utils.NewToolResultText(string(data)) } diff --git a/pkg/github/server_test.go b/pkg/github/server_test.go index 77752d090..599be18ce 100644 --- a/pkg/github/server_test.go +++ b/pkg/github/server_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/github/github-mcp-server/pkg/raw" - "github.com/google/go-github/v77/github" + "github.com/google/go-github/v79/github" "github.com/shurcooL/githubv4" "github.com/stretchr/testify/assert" ) @@ -141,8 +141,7 @@ func Test_RequiredStringParam(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - request := createMCPRequest(tc.params) - result, err := RequiredParam[string](request, tc.paramName) + result, err := RequiredParam[string](tc.params, tc.paramName) if tc.expectError { assert.Error(t, err) @@ -194,8 +193,7 @@ func Test_OptionalStringParam(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - request := createMCPRequest(tc.params) - result, err := OptionalParam[string](request, tc.paramName) + result, err := OptionalParam[string](tc.params, tc.paramName) if tc.expectError { assert.Error(t, err) @@ -240,8 +238,7 @@ func Test_RequiredInt(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - request := createMCPRequest(tc.params) - result, err := RequiredInt(request, tc.paramName) + result, err := RequiredInt(tc.params, tc.paramName) if tc.expectError { assert.Error(t, err) @@ -292,8 +289,7 @@ func Test_OptionalIntParam(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - request := createMCPRequest(tc.params) - result, err := OptionalIntParam(request, tc.paramName) + result, err := OptionalIntParam(tc.params, tc.paramName) if tc.expectError { assert.Error(t, err) @@ -350,8 +346,7 @@ func Test_OptionalNumberParamWithDefault(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - request := createMCPRequest(tc.params) - result, err := OptionalIntParamWithDefault(request, tc.paramName, tc.defaultVal) + result, err := OptionalIntParamWithDefault(tc.params, tc.paramName, tc.defaultVal) if tc.expectError { assert.Error(t, err) @@ -403,8 +398,7 @@ func Test_OptionalBooleanParam(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - request := createMCPRequest(tc.params) - result, err := OptionalParam[bool](request, tc.paramName) + result, err := OptionalParam[bool](tc.params, tc.paramName) if tc.expectError { assert.Error(t, err) @@ -471,8 +465,7 @@ func TestOptionalStringArrayParam(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - request := createMCPRequest(tc.params) - result, err := OptionalStringArrayParam(request, tc.paramName) + result, err := OptionalStringArrayParam(tc.params, tc.paramName) if tc.expectError { assert.Error(t, err) @@ -554,8 +547,7 @@ func TestOptionalPaginationParams(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - request := createMCPRequest(tc.params) - result, err := OptionalPaginationParams(request) + result, err := OptionalPaginationParams(tc.params) if tc.expectError { assert.Error(t, err) diff --git a/pkg/github/tools.go b/pkg/github/tools.go index 36c22e7a8..c024a31e9 100644 --- a/pkg/github/tools.go +++ b/pkg/github/tools.go @@ -8,8 +8,8 @@ import ( "github.com/github/github-mcp-server/pkg/raw" "github.com/github/github-mcp-server/pkg/toolsets" "github.com/github/github-mcp-server/pkg/translations" - "github.com/google/go-github/v77/github" - "github.com/mark3labs/mcp-go/server" + "github.com/google/go-github/v79/github" + "github.com/modelcontextprotocol/go-sdk/mcp" "github.com/shurcooL/githubv4" ) @@ -164,147 +164,147 @@ func DefaultToolsetGroup(readOnly bool, getClient GetClientFn, getGQLClient GetG // Define all available features with their default state (disabled) // Create toolsets - repos := toolsets.NewToolset(ToolsetMetadataRepos.ID, ToolsetMetadataRepos.Description). - AddReadTools( - toolsets.NewServerTool(SearchRepositories(getClient, t)), - toolsets.NewServerTool(GetFileContents(getClient, getRawClient, t)), - toolsets.NewServerTool(ListCommits(getClient, t)), - toolsets.NewServerTool(SearchCode(getClient, t)), - toolsets.NewServerTool(GetCommit(getClient, t)), - toolsets.NewServerTool(ListBranches(getClient, t)), - toolsets.NewServerTool(ListTags(getClient, t)), - toolsets.NewServerTool(GetTag(getClient, t)), - toolsets.NewServerTool(ListReleases(getClient, t)), - toolsets.NewServerTool(GetLatestRelease(getClient, t)), - toolsets.NewServerTool(GetReleaseByTag(getClient, t)), - ). - AddWriteTools( - toolsets.NewServerTool(CreateOrUpdateFile(getClient, t)), - toolsets.NewServerTool(CreateRepository(getClient, t)), - toolsets.NewServerTool(ForkRepository(getClient, t)), - toolsets.NewServerTool(CreateBranch(getClient, t)), - toolsets.NewServerTool(PushFiles(getClient, t)), - toolsets.NewServerTool(DeleteFile(getClient, t)), - ). - AddResourceTemplates( - toolsets.NewServerResourceTemplate(GetRepositoryResourceContent(getClient, getRawClient, t)), - toolsets.NewServerResourceTemplate(GetRepositoryResourceBranchContent(getClient, getRawClient, t)), - toolsets.NewServerResourceTemplate(GetRepositoryResourceCommitContent(getClient, getRawClient, t)), - toolsets.NewServerResourceTemplate(GetRepositoryResourceTagContent(getClient, getRawClient, t)), - toolsets.NewServerResourceTemplate(GetRepositoryResourcePrContent(getClient, getRawClient, t)), - ) - git := toolsets.NewToolset(ToolsetMetadataGit.ID, ToolsetMetadataGit.Description). - AddReadTools( - toolsets.NewServerTool(GetRepositoryTree(getClient, t)), - ) - issues := toolsets.NewToolset(ToolsetMetadataIssues.ID, ToolsetMetadataIssues.Description). - AddReadTools( - toolsets.NewServerTool(IssueRead(getClient, getGQLClient, t, flags)), - toolsets.NewServerTool(SearchIssues(getClient, t)), - toolsets.NewServerTool(ListIssues(getGQLClient, t)), - toolsets.NewServerTool(ListIssueTypes(getClient, t)), - toolsets.NewServerTool(GetLabel(getGQLClient, t)), - ). - AddWriteTools( - toolsets.NewServerTool(IssueWrite(getClient, getGQLClient, t)), - toolsets.NewServerTool(AddIssueComment(getClient, t)), - toolsets.NewServerTool(AssignCopilotToIssue(getGQLClient, t)), - toolsets.NewServerTool(SubIssueWrite(getClient, t)), - ).AddPrompts( - toolsets.NewServerPrompt(AssignCodingAgentPrompt(t)), - toolsets.NewServerPrompt(IssueToFixWorkflowPrompt(t)), - ) - users := toolsets.NewToolset(ToolsetMetadataUsers.ID, ToolsetMetadataUsers.Description). - AddReadTools( - toolsets.NewServerTool(SearchUsers(getClient, t)), - ) - orgs := toolsets.NewToolset(ToolsetMetadataOrgs.ID, ToolsetMetadataOrgs.Description). - AddReadTools( - toolsets.NewServerTool(SearchOrgs(getClient, t)), - ) - pullRequests := toolsets.NewToolset(ToolsetMetadataPullRequests.ID, ToolsetMetadataPullRequests.Description). - AddReadTools( - toolsets.NewServerTool(PullRequestRead(getClient, t, flags)), - toolsets.NewServerTool(ListPullRequests(getClient, t)), - toolsets.NewServerTool(SearchPullRequests(getClient, t)), - ). - AddWriteTools( - toolsets.NewServerTool(MergePullRequest(getClient, t)), - toolsets.NewServerTool(UpdatePullRequestBranch(getClient, t)), - toolsets.NewServerTool(CreatePullRequest(getClient, t)), - toolsets.NewServerTool(UpdatePullRequest(getClient, getGQLClient, t)), - toolsets.NewServerTool(RequestCopilotReview(getClient, t)), - - // Reviews - toolsets.NewServerTool(PullRequestReviewWrite(getGQLClient, t)), - toolsets.NewServerTool(AddCommentToPendingReview(getGQLClient, t)), - ) - codeSecurity := toolsets.NewToolset(ToolsetMetadataCodeSecurity.ID, ToolsetMetadataCodeSecurity.Description). - AddReadTools( - toolsets.NewServerTool(GetCodeScanningAlert(getClient, t)), - toolsets.NewServerTool(ListCodeScanningAlerts(getClient, t)), - ) - secretProtection := toolsets.NewToolset(ToolsetMetadataSecretProtection.ID, ToolsetMetadataSecretProtection.Description). - AddReadTools( - toolsets.NewServerTool(GetSecretScanningAlert(getClient, t)), - toolsets.NewServerTool(ListSecretScanningAlerts(getClient, t)), - ) - dependabot := toolsets.NewToolset(ToolsetMetadataDependabot.ID, ToolsetMetadataDependabot.Description). - AddReadTools( - toolsets.NewServerTool(GetDependabotAlert(getClient, t)), - toolsets.NewServerTool(ListDependabotAlerts(getClient, t)), - ) - - notifications := toolsets.NewToolset(ToolsetMetadataNotifications.ID, ToolsetMetadataNotifications.Description). - AddReadTools( - toolsets.NewServerTool(ListNotifications(getClient, t)), - toolsets.NewServerTool(GetNotificationDetails(getClient, t)), - ). - AddWriteTools( - toolsets.NewServerTool(DismissNotification(getClient, t)), - toolsets.NewServerTool(MarkAllNotificationsRead(getClient, t)), - toolsets.NewServerTool(ManageNotificationSubscription(getClient, t)), - toolsets.NewServerTool(ManageRepositoryNotificationSubscription(getClient, t)), - ) - - discussions := toolsets.NewToolset(ToolsetMetadataDiscussions.ID, ToolsetMetadataDiscussions.Description). - AddReadTools( - toolsets.NewServerTool(ListDiscussions(getGQLClient, t)), - toolsets.NewServerTool(GetDiscussion(getGQLClient, t)), - toolsets.NewServerTool(GetDiscussionComments(getGQLClient, t)), - toolsets.NewServerTool(ListDiscussionCategories(getGQLClient, t)), - ) - - actions := toolsets.NewToolset(ToolsetMetadataActions.ID, ToolsetMetadataActions.Description). - AddReadTools( - toolsets.NewServerTool(ListWorkflows(getClient, t)), - toolsets.NewServerTool(ListWorkflowRuns(getClient, t)), - toolsets.NewServerTool(GetWorkflowRun(getClient, t)), - toolsets.NewServerTool(GetWorkflowRunLogs(getClient, t)), - toolsets.NewServerTool(ListWorkflowJobs(getClient, t)), - toolsets.NewServerTool(GetJobLogs(getClient, t, contentWindowSize)), - toolsets.NewServerTool(ListWorkflowRunArtifacts(getClient, t)), - toolsets.NewServerTool(DownloadWorkflowRunArtifact(getClient, t)), - toolsets.NewServerTool(GetWorkflowRunUsage(getClient, t)), - ). - AddWriteTools( - toolsets.NewServerTool(RunWorkflow(getClient, t)), - toolsets.NewServerTool(RerunWorkflowRun(getClient, t)), - toolsets.NewServerTool(RerunFailedJobs(getClient, t)), - toolsets.NewServerTool(CancelWorkflowRun(getClient, t)), - toolsets.NewServerTool(DeleteWorkflowRunLogs(getClient, t)), - ) - - securityAdvisories := toolsets.NewToolset(ToolsetMetadataSecurityAdvisories.ID, ToolsetMetadataSecurityAdvisories.Description). - AddReadTools( - toolsets.NewServerTool(ListGlobalSecurityAdvisories(getClient, t)), - toolsets.NewServerTool(GetGlobalSecurityAdvisory(getClient, t)), - toolsets.NewServerTool(ListRepositorySecurityAdvisories(getClient, t)), - toolsets.NewServerTool(ListOrgRepositorySecurityAdvisories(getClient, t)), - ) - - // Keep experiments alive so the system doesn't error out when it's always enabled - experiments := toolsets.NewToolset(ToolsetMetadataExperiments.ID, ToolsetMetadataExperiments.Description) + // repos := toolsets.NewToolset(ToolsetMetadataRepos.ID, ToolsetMetadataRepos.Description). + // AddReadTools( + // toolsets.NewServerTool(SearchRepositories(getClient, t)), + // toolsets.NewServerTool(GetFileContents(getClient, getRawClient, t)), + // toolsets.NewServerTool(ListCommits(getClient, t)), + // toolsets.NewServerTool(SearchCode(getClient, t)), + // toolsets.NewServerTool(GetCommit(getClient, t)), + // toolsets.NewServerTool(ListBranches(getClient, t)), + // toolsets.NewServerTool(ListTags(getClient, t)), + // toolsets.NewServerTool(GetTag(getClient, t)), + // toolsets.NewServerTool(ListReleases(getClient, t)), + // toolsets.NewServerTool(GetLatestRelease(getClient, t)), + // toolsets.NewServerTool(GetReleaseByTag(getClient, t)), + // ). + // AddWriteTools( + // toolsets.NewServerTool(CreateOrUpdateFile(getClient, t)), + // toolsets.NewServerTool(CreateRepository(getClient, t)), + // toolsets.NewServerTool(ForkRepository(getClient, t)), + // toolsets.NewServerTool(CreateBranch(getClient, t)), + // toolsets.NewServerTool(PushFiles(getClient, t)), + // toolsets.NewServerTool(DeleteFile(getClient, t)), + // ). + // AddResourceTemplates( + // toolsets.NewServerResourceTemplate(GetRepositoryResourceContent(getClient, getRawClient, t)), + // toolsets.NewServerResourceTemplate(GetRepositoryResourceBranchContent(getClient, getRawClient, t)), + // toolsets.NewServerResourceTemplate(GetRepositoryResourceCommitContent(getClient, getRawClient, t)), + // toolsets.NewServerResourceTemplate(GetRepositoryResourceTagContent(getClient, getRawClient, t)), + // toolsets.NewServerResourceTemplate(GetRepositoryResourcePrContent(getClient, getRawClient, t)), + // ) + // git := toolsets.NewToolset(ToolsetMetadataGit.ID, ToolsetMetadataGit.Description). + // AddReadTools( + // toolsets.NewServerTool(GetRepositoryTree(getClient, t)), + // ) + // issues := toolsets.NewToolset(ToolsetMetadataIssues.ID, ToolsetMetadataIssues.Description). + // AddReadTools( + // toolsets.NewServerTool(IssueRead(getClient, getGQLClient, t, flags)), + // toolsets.NewServerTool(SearchIssues(getClient, t)), + // toolsets.NewServerTool(ListIssues(getGQLClient, t)), + // toolsets.NewServerTool(ListIssueTypes(getClient, t)), + // toolsets.NewServerTool(GetLabel(getGQLClient, t)), + // ). + // AddWriteTools( + // toolsets.NewServerTool(IssueWrite(getClient, getGQLClient, t)), + // toolsets.NewServerTool(AddIssueComment(getClient, t)), + // toolsets.NewServerTool(AssignCopilotToIssue(getGQLClient, t)), + // toolsets.NewServerTool(SubIssueWrite(getClient, t)), + // ).AddPrompts( + // toolsets.NewServerPrompt(AssignCodingAgentPrompt(t)), + // toolsets.NewServerPrompt(IssueToFixWorkflowPrompt(t)), + // ) + // users := toolsets.NewToolset(ToolsetMetadataUsers.ID, ToolsetMetadataUsers.Description). + // AddReadTools( + // toolsets.NewServerTool(SearchUsers(getClient, t)), + // ) + // orgs := toolsets.NewToolset(ToolsetMetadataOrgs.ID, ToolsetMetadataOrgs.Description). + // AddReadTools( + // toolsets.NewServerTool(SearchOrgs(getClient, t)), + // ) + // pullRequests := toolsets.NewToolset(ToolsetMetadataPullRequests.ID, ToolsetMetadataPullRequests.Description). + // AddReadTools( + // toolsets.NewServerTool(PullRequestRead(getClient, t, flags)), + // toolsets.NewServerTool(ListPullRequests(getClient, t)), + // toolsets.NewServerTool(SearchPullRequests(getClient, t)), + // ). + // AddWriteTools( + // toolsets.NewServerTool(MergePullRequest(getClient, t)), + // toolsets.NewServerTool(UpdatePullRequestBranch(getClient, t)), + // toolsets.NewServerTool(CreatePullRequest(getClient, t)), + // toolsets.NewServerTool(UpdatePullRequest(getClient, getGQLClient, t)), + // toolsets.NewServerTool(RequestCopilotReview(getClient, t)), + + // // Reviews + // toolsets.NewServerTool(PullRequestReviewWrite(getGQLClient, t)), + // toolsets.NewServerTool(AddCommentToPendingReview(getGQLClient, t)), + // ) + // codeSecurity := toolsets.NewToolset(ToolsetMetadataCodeSecurity.ID, ToolsetMetadataCodeSecurity.Description). + // AddReadTools( + // toolsets.NewServerTool(GetCodeScanningAlert(getClient, t)), + // toolsets.NewServerTool(ListCodeScanningAlerts(getClient, t)), + // ) + // secretProtection := toolsets.NewToolset(ToolsetMetadataSecretProtection.ID, ToolsetMetadataSecretProtection.Description). + // AddReadTools( + // toolsets.NewServerTool(GetSecretScanningAlert(getClient, t)), + // toolsets.NewServerTool(ListSecretScanningAlerts(getClient, t)), + // ) + // dependabot := toolsets.NewToolset(ToolsetMetadataDependabot.ID, ToolsetMetadataDependabot.Description). + // AddReadTools( + // toolsets.NewServerTool(GetDependabotAlert(getClient, t)), + // toolsets.NewServerTool(ListDependabotAlerts(getClient, t)), + // ) + + // notifications := toolsets.NewToolset(ToolsetMetadataNotifications.ID, ToolsetMetadataNotifications.Description). + // AddReadTools( + // toolsets.NewServerTool(ListNotifications(getClient, t)), + // toolsets.NewServerTool(GetNotificationDetails(getClient, t)), + // ). + // AddWriteTools( + // toolsets.NewServerTool(DismissNotification(getClient, t)), + // toolsets.NewServerTool(MarkAllNotificationsRead(getClient, t)), + // toolsets.NewServerTool(ManageNotificationSubscription(getClient, t)), + // toolsets.NewServerTool(ManageRepositoryNotificationSubscription(getClient, t)), + // ) + + // discussions := toolsets.NewToolset(ToolsetMetadataDiscussions.ID, ToolsetMetadataDiscussions.Description). + // AddReadTools( + // toolsets.NewServerTool(ListDiscussions(getGQLClient, t)), + // toolsets.NewServerTool(GetDiscussion(getGQLClient, t)), + // toolsets.NewServerTool(GetDiscussionComments(getGQLClient, t)), + // toolsets.NewServerTool(ListDiscussionCategories(getGQLClient, t)), + // ) + + // actions := toolsets.NewToolset(ToolsetMetadataActions.ID, ToolsetMetadataActions.Description). + // AddReadTools( + // toolsets.NewServerTool(ListWorkflows(getClient, t)), + // toolsets.NewServerTool(ListWorkflowRuns(getClient, t)), + // toolsets.NewServerTool(GetWorkflowRun(getClient, t)), + // toolsets.NewServerTool(GetWorkflowRunLogs(getClient, t)), + // toolsets.NewServerTool(ListWorkflowJobs(getClient, t)), + // toolsets.NewServerTool(GetJobLogs(getClient, t, contentWindowSize)), + // toolsets.NewServerTool(ListWorkflowRunArtifacts(getClient, t)), + // toolsets.NewServerTool(DownloadWorkflowRunArtifact(getClient, t)), + // toolsets.NewServerTool(GetWorkflowRunUsage(getClient, t)), + // ). + // AddWriteTools( + // toolsets.NewServerTool(RunWorkflow(getClient, t)), + // toolsets.NewServerTool(RerunWorkflowRun(getClient, t)), + // toolsets.NewServerTool(RerunFailedJobs(getClient, t)), + // toolsets.NewServerTool(CancelWorkflowRun(getClient, t)), + // toolsets.NewServerTool(DeleteWorkflowRunLogs(getClient, t)), + // ) + + // securityAdvisories := toolsets.NewToolset(ToolsetMetadataSecurityAdvisories.ID, ToolsetMetadataSecurityAdvisories.Description). + // AddReadTools( + // toolsets.NewServerTool(ListGlobalSecurityAdvisories(getClient, t)), + // toolsets.NewServerTool(GetGlobalSecurityAdvisory(getClient, t)), + // toolsets.NewServerTool(ListRepositorySecurityAdvisories(getClient, t)), + // toolsets.NewServerTool(ListOrgRepositorySecurityAdvisories(getClient, t)), + // ) + + // // Keep experiments alive so the system doesn't error out when it's always enabled + // experiments := toolsets.NewToolset(ToolsetMetadataExperiments.ID, ToolsetMetadataExperiments.Description) contextTools := toolsets.NewToolset(ToolsetMetadataContext.ID, ToolsetMetadataContext.Description). AddReadTools( @@ -313,84 +313,83 @@ func DefaultToolsetGroup(readOnly bool, getClient GetClientFn, getGQLClient GetG toolsets.NewServerTool(GetTeamMembers(getGQLClient, t)), ) - gists := toolsets.NewToolset(ToolsetMetadataGists.ID, ToolsetMetadataGists.Description). - AddReadTools( - toolsets.NewServerTool(ListGists(getClient, t)), - toolsets.NewServerTool(GetGist(getClient, t)), - ). - AddWriteTools( - toolsets.NewServerTool(CreateGist(getClient, t)), - toolsets.NewServerTool(UpdateGist(getClient, t)), - ) + // gists := toolsets.NewToolset(ToolsetMetadataGists.ID, ToolsetMetadataGists.Description). + // AddReadTools( + // toolsets.NewServerTool(ListGists(getClient, t)), + // toolsets.NewServerTool(GetGist(getClient, t)), + // ). + // AddWriteTools( + // toolsets.NewServerTool(CreateGist(getClient, t)), + // toolsets.NewServerTool(UpdateGist(getClient, t)), + // ) + + // projects := toolsets.NewToolset(ToolsetMetadataProjects.ID, ToolsetMetadataProjects.Description). + // AddReadTools( + // toolsets.NewServerTool(ListProjects(getClient, t)), + // toolsets.NewServerTool(GetProject(getClient, t)), + // toolsets.NewServerTool(ListProjectFields(getClient, t)), + // toolsets.NewServerTool(GetProjectField(getClient, t)), + // toolsets.NewServerTool(ListProjectItems(getClient, t)), + // toolsets.NewServerTool(GetProjectItem(getClient, t)), + // ). + // AddWriteTools( + // toolsets.NewServerTool(AddProjectItem(getClient, t)), + // toolsets.NewServerTool(DeleteProjectItem(getClient, t)), + // toolsets.NewServerTool(UpdateProjectItem(getClient, t)), + // ) + // stargazers := toolsets.NewToolset(ToolsetMetadataStargazers.ID, ToolsetMetadataStargazers.Description). + // AddReadTools( + // toolsets.NewServerTool(ListStarredRepositories(getClient, t)), + // ). + // AddWriteTools( + // toolsets.NewServerTool(StarRepository(getClient, t)), + // toolsets.NewServerTool(UnstarRepository(getClient, t)), + // ) + // labels := toolsets.NewToolset(ToolsetLabels.ID, ToolsetLabels.Description). + // AddReadTools( + // // get + // toolsets.NewServerTool(GetLabel(getGQLClient, t)), + // // list labels on repo or issue + // toolsets.NewServerTool(ListLabels(getGQLClient, t)), + // ). + // AddWriteTools( + // // create or update + // toolsets.NewServerTool(LabelWrite(getGQLClient, t)), + // ) - projects := toolsets.NewToolset(ToolsetMetadataProjects.ID, ToolsetMetadataProjects.Description). - AddReadTools( - toolsets.NewServerTool(ListProjects(getClient, t)), - toolsets.NewServerTool(GetProject(getClient, t)), - toolsets.NewServerTool(ListProjectFields(getClient, t)), - toolsets.NewServerTool(GetProjectField(getClient, t)), - toolsets.NewServerTool(ListProjectItems(getClient, t)), - toolsets.NewServerTool(GetProjectItem(getClient, t)), - ). - AddWriteTools( - toolsets.NewServerTool(AddProjectItem(getClient, t)), - toolsets.NewServerTool(DeleteProjectItem(getClient, t)), - toolsets.NewServerTool(UpdateProjectItem(getClient, t)), - ).AddPrompts( - toolsets.NewServerPrompt(ManageProjectItemsPrompt(t)), - ) - stargazers := toolsets.NewToolset(ToolsetMetadataStargazers.ID, ToolsetMetadataStargazers.Description). - AddReadTools( - toolsets.NewServerTool(ListStarredRepositories(getClient, t)), - ). - AddWriteTools( - toolsets.NewServerTool(StarRepository(getClient, t)), - toolsets.NewServerTool(UnstarRepository(getClient, t)), - ) - labels := toolsets.NewToolset(ToolsetLabels.ID, ToolsetLabels.Description). - AddReadTools( - // get - toolsets.NewServerTool(GetLabel(getGQLClient, t)), - // list labels on repo or issue - toolsets.NewServerTool(ListLabels(getGQLClient, t)), - ). - AddWriteTools( - // create or update - toolsets.NewServerTool(LabelWrite(getGQLClient, t)), - ) // Add toolsets to the group tsg.AddToolset(contextTools) - tsg.AddToolset(repos) - tsg.AddToolset(git) - tsg.AddToolset(issues) - tsg.AddToolset(orgs) - tsg.AddToolset(users) - tsg.AddToolset(pullRequests) - tsg.AddToolset(actions) - tsg.AddToolset(codeSecurity) - tsg.AddToolset(secretProtection) - tsg.AddToolset(dependabot) - tsg.AddToolset(notifications) - tsg.AddToolset(experiments) - tsg.AddToolset(discussions) - tsg.AddToolset(gists) - tsg.AddToolset(securityAdvisories) - tsg.AddToolset(projects) - tsg.AddToolset(stargazers) - tsg.AddToolset(labels) + // tsg.AddToolset(repos) + // tsg.AddToolset(git) + // tsg.AddToolset(issues) + // tsg.AddToolset(orgs) + // tsg.AddToolset(users) + // tsg.AddToolset(pullRequests) + // tsg.AddToolset(actions) + // tsg.AddToolset(codeSecurity) + // tsg.AddToolset(secretProtection) + // tsg.AddToolset(dependabot) + // tsg.AddToolset(notifications) + // tsg.AddToolset(experiments) + // tsg.AddToolset(discussions) + // tsg.AddToolset(gists) + // tsg.AddToolset(securityAdvisories) + // tsg.AddToolset(projects) + // tsg.AddToolset(stargazers) + // tsg.AddToolset(labels) return tsg } // InitDynamicToolset creates a dynamic toolset that can be used to enable other toolsets, and so requires the server and toolset group as arguments -func InitDynamicToolset(s *server.MCPServer, tsg *toolsets.ToolsetGroup, t translations.TranslationHelperFunc) *toolsets.Toolset { +func InitDynamicToolset(s *mcp.Server, tsg *toolsets.ToolsetGroup, t translations.TranslationHelperFunc) *toolsets.Toolset { // Create a new dynamic toolset // Need to add the dynamic toolset last so it can be used to enable other toolsets dynamicToolSelection := toolsets.NewToolset(ToolsetMetadataDynamic.ID, ToolsetMetadataDynamic.Description). AddReadTools( - toolsets.NewServerTool(ListAvailableToolsets(tsg, t)), - toolsets.NewServerTool(GetToolsetsTools(tsg, t)), - toolsets.NewServerTool(EnableToolset(s, tsg, t)), + // toolsets.NewServerTool(ListAvailableToolsets(tsg, t)), + // toolsets.NewServerTool(GetToolsetsTools(tsg, t)), + // toolsets.NewServerTool(EnableToolset(s, tsg, t)), ) dynamicToolSelection.Enabled = true diff --git a/pkg/log/io.go b/pkg/log/io.go index 44b8dc17a..0f034c2a4 100644 --- a/pkg/log/io.go +++ b/pkg/log/io.go @@ -9,6 +9,8 @@ import ( // IOLogger is a wrapper around io.Reader and io.Writer that can be used // to log the data being read and written from the underlying streams type IOLogger struct { + io.ReadWriteCloser + reader io.Reader writer io.Writer logger *slog.Logger diff --git a/pkg/raw/raw.go b/pkg/raw/raw.go index aee8a9313..10bade5eb 100644 --- a/pkg/raw/raw.go +++ b/pkg/raw/raw.go @@ -6,7 +6,7 @@ import ( "net/http" "net/url" - gogithub "github.com/google/go-github/v77/github" + gogithub "github.com/google/go-github/v79/github" ) // GetRawClientFn is a function type that returns a RawClient instance. diff --git a/pkg/raw/raw_test.go b/pkg/raw/raw_test.go index 18dafe3e1..242029c8b 100644 --- a/pkg/raw/raw_test.go +++ b/pkg/raw/raw_test.go @@ -6,7 +6,7 @@ import ( "net/url" "testing" - "github.com/google/go-github/v77/github" + "github.com/google/go-github/v79/github" "github.com/migueleliasweb/go-github-mock/src/mock" "github.com/stretchr/testify/require" ) diff --git a/pkg/toolsets/toolsets.go b/pkg/toolsets/toolsets.go index 96f1fc3ca..7ff7a8d41 100644 --- a/pkg/toolsets/toolsets.go +++ b/pkg/toolsets/toolsets.go @@ -3,8 +3,7 @@ package toolsets import ( "fmt" - "github.com/mark3labs/mcp-go/mcp" - "github.com/mark3labs/mcp-go/server" + "github.com/modelcontextprotocol/go-sdk/mcp" ) type ToolsetDoesNotExistError struct { @@ -29,19 +28,36 @@ func NewToolsetDoesNotExistError(name string) *ToolsetDoesNotExistError { return &ToolsetDoesNotExistError{Name: name} } -func NewServerTool(tool mcp.Tool, handler server.ToolHandlerFunc) server.ServerTool { - return server.ServerTool{Tool: tool, Handler: handler} +type ServerTool struct { + Tool mcp.Tool + RegisterFunc func(s *mcp.Server) } -func NewServerResourceTemplate(resourceTemplate mcp.ResourceTemplate, handler server.ResourceTemplateHandlerFunc) server.ServerResourceTemplate { - return server.ServerResourceTemplate{ +func NewServerTool[In, Out any](tool mcp.Tool, handler mcp.ToolHandlerFor[In, Out]) ServerTool { + return ServerTool{Tool: tool, RegisterFunc: func(s *mcp.Server) { + mcp.AddTool(s, &tool, handler) + }} +} + +type ServerResourceTemplate struct { + Template mcp.ResourceTemplate + Handler mcp.ResourceHandler +} + +func NewServerResourceTemplate(resourceTemplate mcp.ResourceTemplate, handler mcp.ResourceHandler) ServerResourceTemplate { + return ServerResourceTemplate{ Template: resourceTemplate, Handler: handler, } } -func NewServerPrompt(prompt mcp.Prompt, handler server.PromptHandlerFunc) server.ServerPrompt { - return server.ServerPrompt{ +type ServerPrompt struct { + Prompt mcp.Prompt + Handler mcp.PromptHandler +} + +func NewServerPrompt(prompt mcp.Prompt, handler mcp.PromptHandler) ServerPrompt { + return ServerPrompt{ Prompt: prompt, Handler: handler, } @@ -53,16 +69,16 @@ type Toolset struct { Description string Enabled bool readOnly bool - writeTools []server.ServerTool - readTools []server.ServerTool + writeTools []ServerTool + readTools []ServerTool // resources are not tools, but the community seems to be moving towards namespaces as a broader concept // and in order to have multiple servers running concurrently, we want to avoid overlapping resources too. - resourceTemplates []server.ServerResourceTemplate + resourceTemplates []ServerResourceTemplate // prompts are also not tools but are namespaced similarly - prompts []server.ServerPrompt + prompts []ServerPrompt } -func (t *Toolset) GetActiveTools() []server.ServerTool { +func (t *Toolset) GetActiveTools() []ServerTool { if t.Enabled { if t.readOnly { return t.readTools @@ -72,63 +88,63 @@ func (t *Toolset) GetActiveTools() []server.ServerTool { return nil } -func (t *Toolset) GetAvailableTools() []server.ServerTool { +func (t *Toolset) GetAvailableTools() []ServerTool { if t.readOnly { return t.readTools } return append(t.readTools, t.writeTools...) } -func (t *Toolset) RegisterTools(s *server.MCPServer) { +func (t *Toolset) RegisterTools(s *mcp.Server) { if !t.Enabled { return } for _, tool := range t.readTools { - s.AddTool(tool.Tool, tool.Handler) + tool.RegisterFunc(s) } if !t.readOnly { for _, tool := range t.writeTools { - s.AddTool(tool.Tool, tool.Handler) + tool.RegisterFunc(s) } } } -func (t *Toolset) AddResourceTemplates(templates ...server.ServerResourceTemplate) *Toolset { +func (t *Toolset) AddResourceTemplates(templates ...ServerResourceTemplate) *Toolset { t.resourceTemplates = append(t.resourceTemplates, templates...) return t } -func (t *Toolset) AddPrompts(prompts ...server.ServerPrompt) *Toolset { +func (t *Toolset) AddPrompts(prompts ...ServerPrompt) *Toolset { t.prompts = append(t.prompts, prompts...) return t } -func (t *Toolset) GetActiveResourceTemplates() []server.ServerResourceTemplate { +func (t *Toolset) GetActiveResourceTemplates() []ServerResourceTemplate { if !t.Enabled { return nil } return t.resourceTemplates } -func (t *Toolset) GetAvailableResourceTemplates() []server.ServerResourceTemplate { +func (t *Toolset) GetAvailableResourceTemplates() []ServerResourceTemplate { return t.resourceTemplates } -func (t *Toolset) RegisterResourcesTemplates(s *server.MCPServer) { +func (t *Toolset) RegisterResourcesTemplates(s *mcp.Server) { if !t.Enabled { return } for _, resource := range t.resourceTemplates { - s.AddResourceTemplate(resource.Template, resource.Handler) + s.AddResourceTemplate(&resource.Template, resource.Handler) } } -func (t *Toolset) RegisterPrompts(s *server.MCPServer) { +func (t *Toolset) RegisterPrompts(s *mcp.Server) { if !t.Enabled { return } for _, prompt := range t.prompts { - s.AddPrompt(prompt.Prompt, prompt.Handler) + s.AddPrompt(&prompt.Prompt, prompt.Handler) } } @@ -137,10 +153,10 @@ func (t *Toolset) SetReadOnly() { t.readOnly = true } -func (t *Toolset) AddWriteTools(tools ...server.ServerTool) *Toolset { +func (t *Toolset) AddWriteTools(tools ...ServerTool) *Toolset { // Silently ignore if the toolset is read-only to avoid any breach of that contract for _, tool := range tools { - if *tool.Tool.Annotations.ReadOnlyHint { + if tool.Tool.Annotations.ReadOnlyHint { panic(fmt.Sprintf("tool (%s) is incorrectly annotated as read-only", tool.Tool.Name)) } } @@ -150,9 +166,9 @@ func (t *Toolset) AddWriteTools(tools ...server.ServerTool) *Toolset { return t } -func (t *Toolset) AddReadTools(tools ...server.ServerTool) *Toolset { +func (t *Toolset) AddReadTools(tools ...ServerTool) *Toolset { for _, tool := range tools { - if !*tool.Tool.Annotations.ReadOnlyHint { + if !tool.Tool.Annotations.ReadOnlyHint { panic(fmt.Sprintf("tool (%s) must be annotated as read-only", tool.Tool.Name)) } } @@ -248,7 +264,7 @@ func (tg *ToolsetGroup) EnableToolset(name string) error { return nil } -func (tg *ToolsetGroup) RegisterAll(s *server.MCPServer) { +func (tg *ToolsetGroup) RegisterAll(s *mcp.Server) { for _, toolset := range tg.Toolsets { toolset.RegisterTools(s) toolset.RegisterResourcesTemplates(s) diff --git a/pkg/utils/result.go b/pkg/utils/result.go new file mode 100644 index 000000000..c90a911de --- /dev/null +++ b/pkg/utils/result.go @@ -0,0 +1,49 @@ +package utils + +import "github.com/modelcontextprotocol/go-sdk/mcp" + +func NewToolResultText(message string) *mcp.CallToolResult { + return &mcp.CallToolResult{ + Content: []mcp.Content{ + &mcp.TextContent{ + Text: message, + }, + }, + } +} + +func NewToolResultError(message string) *mcp.CallToolResult { + return &mcp.CallToolResult{ + Content: []mcp.Content{ + &mcp.TextContent{ + Text: message, + }, + }, + IsError: true, + } +} + +func NewToolResultErrorFromErr(message string, err error) *mcp.CallToolResult { + return &mcp.CallToolResult{ + Content: []mcp.Content{ + &mcp.TextContent{ + Text: message + ": " + err.Error(), + }, + }, + IsError: true, + } +} + +func NewToolResultResource(message string, contents *mcp.ResourceContents) *mcp.CallToolResult { + return &mcp.CallToolResult{ + Content: []mcp.Content{ + &mcp.TextContent{ + Text: message, + }, + &mcp.EmbeddedResource{ + Resource: contents, + }, + }, + IsError: false, + } +} diff --git a/server.json b/server.json index 127e4bd05..544f1fbc4 100644 --- a/server.json +++ b/server.json @@ -2,6 +2,7 @@ "$schema": "https://static.modelcontextprotocol.io/schemas/2025-10-17/server.schema.json", "name": "io.github.github/github-mcp-server", "description": "Connect AI assistants to GitHub - manage repos, issues, PRs, and workflows through natural language.", + "title": "GitHub", "status": "active", "repository": { "url": "https://github.com/github/github-mcp-server", @@ -60,5 +61,19 @@ } ] } + ], + "remotes": [ + { + "type": "streamable-http", + "url": "https://api.githubcopilot.com/mcp/", + "headers": [ + { + "name": "Authorization", + "description": "Authentication token (PAT or App token)", + "isRequired": true, + "isSecret": true + } + ] + } ] -} \ No newline at end of file +} diff --git a/third-party-licenses.darwin.md b/third-party-licenses.darwin.md index d4d742c6e..3823082a9 100644 --- a/third-party-licenses.darwin.md +++ b/third-party-licenses.darwin.md @@ -16,8 +16,9 @@ Some packages may only be included on certain architectures or operating systems - [github.com/go-openapi/swag](https://pkg.go.dev/github.com/go-openapi/swag) ([Apache-2.0](https://github.com/go-openapi/swag/blob/v0.21.1/LICENSE)) - [github.com/go-viper/mapstructure/v2](https://pkg.go.dev/github.com/go-viper/mapstructure/v2) ([MIT](https://github.com/go-viper/mapstructure/blob/v2.4.0/LICENSE)) - [github.com/google/go-github/v71/github](https://pkg.go.dev/github.com/google/go-github/v71/github) ([BSD-3-Clause](https://github.com/google/go-github/blob/v71.0.0/LICENSE)) - - [github.com/google/go-github/v77/github](https://pkg.go.dev/github.com/google/go-github/v77/github) ([BSD-3-Clause](https://github.com/google/go-github/blob/v77.0.0/LICENSE)) + - [github.com/google/go-github/v79/github](https://pkg.go.dev/github.com/google/go-github/v79/github) ([BSD-3-Clause](https://github.com/google/go-github/blob/v79.0.0/LICENSE)) - [github.com/google/go-querystring/query](https://pkg.go.dev/github.com/google/go-querystring/query) ([BSD-3-Clause](https://github.com/google/go-querystring/blob/v1.1.0/LICENSE)) + - [github.com/google/jsonschema-go/jsonschema](https://pkg.go.dev/github.com/google/jsonschema-go/jsonschema) ([MIT](https://github.com/google/jsonschema-go/blob/v0.3.0/LICENSE)) - [github.com/google/uuid](https://pkg.go.dev/github.com/google/uuid) ([BSD-3-Clause](https://github.com/google/uuid/blob/v1.6.0/LICENSE)) - [github.com/gorilla/css/scanner](https://pkg.go.dev/github.com/gorilla/css/scanner) ([BSD-3-Clause](https://github.com/gorilla/css/blob/v1.0.1/LICENSE)) - [github.com/gorilla/mux](https://pkg.go.dev/github.com/gorilla/mux) ([BSD-3-Clause](https://github.com/gorilla/mux/blob/v1.8.0/LICENSE)) @@ -28,6 +29,7 @@ Some packages may only be included on certain architectures or operating systems - [github.com/mark3labs/mcp-go](https://pkg.go.dev/github.com/mark3labs/mcp-go) ([MIT](https://github.com/mark3labs/mcp-go/blob/v0.36.0/LICENSE)) - [github.com/microcosm-cc/bluemonday](https://pkg.go.dev/github.com/microcosm-cc/bluemonday) ([BSD-3-Clause](https://github.com/microcosm-cc/bluemonday/blob/v1.0.27/LICENSE.md)) - [github.com/migueleliasweb/go-github-mock/src/mock](https://pkg.go.dev/github.com/migueleliasweb/go-github-mock/src/mock) ([MIT](https://github.com/migueleliasweb/go-github-mock/blob/v1.3.0/LICENSE)) + - [github.com/modelcontextprotocol/go-sdk](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk) ([MIT](https://github.com/modelcontextprotocol/go-sdk/blob/v1.1.0/LICENSE)) - [github.com/pelletier/go-toml/v2](https://pkg.go.dev/github.com/pelletier/go-toml/v2) ([MIT](https://github.com/pelletier/go-toml/blob/v2.2.4/LICENSE)) - [github.com/sagikazarmark/locafero](https://pkg.go.dev/github.com/sagikazarmark/locafero) ([MIT](https://github.com/sagikazarmark/locafero/blob/v0.11.0/LICENSE)) - [github.com/shurcooL/githubv4](https://pkg.go.dev/github.com/shurcooL/githubv4) ([MIT](https://github.com/shurcooL/githubv4/blob/48295856cce7/LICENSE)) diff --git a/third-party-licenses.linux.md b/third-party-licenses.linux.md index d4d742c6e..3823082a9 100644 --- a/third-party-licenses.linux.md +++ b/third-party-licenses.linux.md @@ -16,8 +16,9 @@ Some packages may only be included on certain architectures or operating systems - [github.com/go-openapi/swag](https://pkg.go.dev/github.com/go-openapi/swag) ([Apache-2.0](https://github.com/go-openapi/swag/blob/v0.21.1/LICENSE)) - [github.com/go-viper/mapstructure/v2](https://pkg.go.dev/github.com/go-viper/mapstructure/v2) ([MIT](https://github.com/go-viper/mapstructure/blob/v2.4.0/LICENSE)) - [github.com/google/go-github/v71/github](https://pkg.go.dev/github.com/google/go-github/v71/github) ([BSD-3-Clause](https://github.com/google/go-github/blob/v71.0.0/LICENSE)) - - [github.com/google/go-github/v77/github](https://pkg.go.dev/github.com/google/go-github/v77/github) ([BSD-3-Clause](https://github.com/google/go-github/blob/v77.0.0/LICENSE)) + - [github.com/google/go-github/v79/github](https://pkg.go.dev/github.com/google/go-github/v79/github) ([BSD-3-Clause](https://github.com/google/go-github/blob/v79.0.0/LICENSE)) - [github.com/google/go-querystring/query](https://pkg.go.dev/github.com/google/go-querystring/query) ([BSD-3-Clause](https://github.com/google/go-querystring/blob/v1.1.0/LICENSE)) + - [github.com/google/jsonschema-go/jsonschema](https://pkg.go.dev/github.com/google/jsonschema-go/jsonschema) ([MIT](https://github.com/google/jsonschema-go/blob/v0.3.0/LICENSE)) - [github.com/google/uuid](https://pkg.go.dev/github.com/google/uuid) ([BSD-3-Clause](https://github.com/google/uuid/blob/v1.6.0/LICENSE)) - [github.com/gorilla/css/scanner](https://pkg.go.dev/github.com/gorilla/css/scanner) ([BSD-3-Clause](https://github.com/gorilla/css/blob/v1.0.1/LICENSE)) - [github.com/gorilla/mux](https://pkg.go.dev/github.com/gorilla/mux) ([BSD-3-Clause](https://github.com/gorilla/mux/blob/v1.8.0/LICENSE)) @@ -28,6 +29,7 @@ Some packages may only be included on certain architectures or operating systems - [github.com/mark3labs/mcp-go](https://pkg.go.dev/github.com/mark3labs/mcp-go) ([MIT](https://github.com/mark3labs/mcp-go/blob/v0.36.0/LICENSE)) - [github.com/microcosm-cc/bluemonday](https://pkg.go.dev/github.com/microcosm-cc/bluemonday) ([BSD-3-Clause](https://github.com/microcosm-cc/bluemonday/blob/v1.0.27/LICENSE.md)) - [github.com/migueleliasweb/go-github-mock/src/mock](https://pkg.go.dev/github.com/migueleliasweb/go-github-mock/src/mock) ([MIT](https://github.com/migueleliasweb/go-github-mock/blob/v1.3.0/LICENSE)) + - [github.com/modelcontextprotocol/go-sdk](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk) ([MIT](https://github.com/modelcontextprotocol/go-sdk/blob/v1.1.0/LICENSE)) - [github.com/pelletier/go-toml/v2](https://pkg.go.dev/github.com/pelletier/go-toml/v2) ([MIT](https://github.com/pelletier/go-toml/blob/v2.2.4/LICENSE)) - [github.com/sagikazarmark/locafero](https://pkg.go.dev/github.com/sagikazarmark/locafero) ([MIT](https://github.com/sagikazarmark/locafero/blob/v0.11.0/LICENSE)) - [github.com/shurcooL/githubv4](https://pkg.go.dev/github.com/shurcooL/githubv4) ([MIT](https://github.com/shurcooL/githubv4/blob/48295856cce7/LICENSE)) diff --git a/third-party-licenses.windows.md b/third-party-licenses.windows.md index e7117d82c..fa5cba4e0 100644 --- a/third-party-licenses.windows.md +++ b/third-party-licenses.windows.md @@ -16,8 +16,9 @@ Some packages may only be included on certain architectures or operating systems - [github.com/go-openapi/swag](https://pkg.go.dev/github.com/go-openapi/swag) ([Apache-2.0](https://github.com/go-openapi/swag/blob/v0.21.1/LICENSE)) - [github.com/go-viper/mapstructure/v2](https://pkg.go.dev/github.com/go-viper/mapstructure/v2) ([MIT](https://github.com/go-viper/mapstructure/blob/v2.4.0/LICENSE)) - [github.com/google/go-github/v71/github](https://pkg.go.dev/github.com/google/go-github/v71/github) ([BSD-3-Clause](https://github.com/google/go-github/blob/v71.0.0/LICENSE)) - - [github.com/google/go-github/v77/github](https://pkg.go.dev/github.com/google/go-github/v77/github) ([BSD-3-Clause](https://github.com/google/go-github/blob/v77.0.0/LICENSE)) + - [github.com/google/go-github/v79/github](https://pkg.go.dev/github.com/google/go-github/v79/github) ([BSD-3-Clause](https://github.com/google/go-github/blob/v79.0.0/LICENSE)) - [github.com/google/go-querystring/query](https://pkg.go.dev/github.com/google/go-querystring/query) ([BSD-3-Clause](https://github.com/google/go-querystring/blob/v1.1.0/LICENSE)) + - [github.com/google/jsonschema-go/jsonschema](https://pkg.go.dev/github.com/google/jsonschema-go/jsonschema) ([MIT](https://github.com/google/jsonschema-go/blob/v0.3.0/LICENSE)) - [github.com/google/uuid](https://pkg.go.dev/github.com/google/uuid) ([BSD-3-Clause](https://github.com/google/uuid/blob/v1.6.0/LICENSE)) - [github.com/gorilla/css/scanner](https://pkg.go.dev/github.com/gorilla/css/scanner) ([BSD-3-Clause](https://github.com/gorilla/css/blob/v1.0.1/LICENSE)) - [github.com/gorilla/mux](https://pkg.go.dev/github.com/gorilla/mux) ([BSD-3-Clause](https://github.com/gorilla/mux/blob/v1.8.0/LICENSE)) @@ -29,6 +30,7 @@ Some packages may only be included on certain architectures or operating systems - [github.com/mark3labs/mcp-go](https://pkg.go.dev/github.com/mark3labs/mcp-go) ([MIT](https://github.com/mark3labs/mcp-go/blob/v0.36.0/LICENSE)) - [github.com/microcosm-cc/bluemonday](https://pkg.go.dev/github.com/microcosm-cc/bluemonday) ([BSD-3-Clause](https://github.com/microcosm-cc/bluemonday/blob/v1.0.27/LICENSE.md)) - [github.com/migueleliasweb/go-github-mock/src/mock](https://pkg.go.dev/github.com/migueleliasweb/go-github-mock/src/mock) ([MIT](https://github.com/migueleliasweb/go-github-mock/blob/v1.3.0/LICENSE)) + - [github.com/modelcontextprotocol/go-sdk](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk) ([MIT](https://github.com/modelcontextprotocol/go-sdk/blob/v1.1.0/LICENSE)) - [github.com/pelletier/go-toml/v2](https://pkg.go.dev/github.com/pelletier/go-toml/v2) ([MIT](https://github.com/pelletier/go-toml/blob/v2.2.4/LICENSE)) - [github.com/sagikazarmark/locafero](https://pkg.go.dev/github.com/sagikazarmark/locafero) ([MIT](https://github.com/sagikazarmark/locafero/blob/v0.11.0/LICENSE)) - [github.com/shurcooL/githubv4](https://pkg.go.dev/github.com/shurcooL/githubv4) ([MIT](https://github.com/shurcooL/githubv4/blob/48295856cce7/LICENSE)) diff --git a/third-party/github.com/google/go-github/v77/github/LICENSE b/third-party/github.com/google/go-github/v79/github/LICENSE similarity index 100% rename from third-party/github.com/google/go-github/v77/github/LICENSE rename to third-party/github.com/google/go-github/v79/github/LICENSE diff --git a/third-party/github.com/google/jsonschema-go/jsonschema/LICENSE b/third-party/github.com/google/jsonschema-go/jsonschema/LICENSE new file mode 100644 index 000000000..1cb53e9df --- /dev/null +++ b/third-party/github.com/google/jsonschema-go/jsonschema/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 JSON Schema Go Project Authors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/third-party/github.com/modelcontextprotocol/go-sdk/LICENSE b/third-party/github.com/modelcontextprotocol/go-sdk/LICENSE new file mode 100644 index 000000000..508be9266 --- /dev/null +++ b/third-party/github.com/modelcontextprotocol/go-sdk/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Go MCP SDK Authors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE.