OSS release prep#2568
Merged
SamMorrowDrums merged 3 commits intoMay 29, 2026
Merged
Conversation
Adds a source-level (AST) validation test that walks every non-test Go file in pkg/github and fails if any mcp.Tool composite literal omits Annotations.ReadOnlyHint. The existing TestAllToolsHaveRequiredMetadata can only assert that Annotations is non-nil at runtime: Go cannot distinguish an unset bool field from one explicitly set to false. The new test closes that gap so future read-intent tools cannot silently default to ReadOnlyHint=false, which has caused downstream agents to prompt for human approval on safe read operations. All 97 current mcp.Tool registrations pass. Fault-injected by removing ReadOnlyHint from issue_read and confirmed the test reports the exact file, line, tool name, and reason. Refs #2483
- Resolve each file's local alias for github.com/modelcontextprotocol/go-sdk/mcp via file.Imports rather than hard-coding the "mcp" qualifier, so the check also covers files that import the SDK under a non-default alias. - Detect positional (unkeyed) composite literals and report a dedicated diagnostic instead of producing misleading "missing field" violations. - Drop the brittle 'expected to discover at least one mcp.Tool literal' assertion: if registrations move behind constructors/factories the AST walker legitimately finds nothing. - Use strconv.Unquote to decode tool-name string literals (handles escapes in interpreted strings); fall back to the raw lexeme on parse error.
…package Move the AST-based ReadOnlyHint scan introduced in #2486 out of pkg/github's test file and into a new exported package, pkg/toolvalidation, so downstream consumers (notably github/github-mcp-server-remote, which uses this repo as a library) can apply the same guardrail to their own tool registrations with a one-line test: violations, err := toolvalidation.ScanReadOnlyHint(pkgDir) Changes: - New pkg/toolvalidation/readonlyhint.go with ScanReadOnlyHint, FormatReadOnlyHintViolations, and the ReadOnlyHintViolation type. - Dedicated unit tests for the scanner using in-memory fixtures (compliant, missing-hint, missing-annotations, non-literal, aliased import, positional fields, file without mcp import). - pkg/github/tools_static_validation_test.go shrunk to a thin wrapper that calls ScanReadOnlyHint against its own package directory; the existing behavior for pkg/github is preserved. No production-code, schema, or toolsnap changes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Release-prep PR that cherry-picks the AST-based ReadOnlyHint guardrail from #2486 and refactors it into a new exported package, pkg/toolvalidation, so the remote server can reuse the same check.
Changes:
- New
pkg/toolvalidationpackage withScanReadOnlyHint,FormatReadOnlyHintViolations, andReadOnlyHintViolation, using only stdlib parsing. - Unit tests covering compliant/missing/positional/aliased/no-import fixtures plus formatter and missing-directory error.
pkg/github/tools_static_validation_test.goshrunk to a thin wrapper that scans the package and fails with formatted violations.
Show a summary per file
| File | Description |
|---|---|
| pkg/toolvalidation/readonlyhint.go | New exported AST scanner that flags mcp.Tool literals missing explicit Annotations.ReadOnlyHint. |
| pkg/toolvalidation/readonlyhint_test.go | Fixture-driven unit tests for scanner + formatter behavior. |
| pkg/github/tools_static_validation_test.go | Thin wrapper applying the shared scanner to pkg/github. |
Copilot's findings
- Files reviewed: 3/3 changed files
- Comments generated: 0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Release prep PR — currently contains the cherry-picked work from #2486 plus a small refactor to make the new
ReadOnlyHintguardrail reusable fromgithub/github-mcp-server-remote(and any other downstream consumer of this repo as a library). More small prep items can stack here before the next release.Contents
1.
test(github): enforce explicit ReadOnlyHint on every mcp.Tool literalCherry-picked from #2486 (author: @jluocsa, authorship preserved). AST scan that fails the build if any
mcp.Tool{...}literal inpkg/githubomits an explicitAnnotations.ReadOnlyHint. Closes the runtime gap noted inTestAllToolsHaveRequiredMetadata(Go can't distinguish unset bool fromfalse).Refs #2483 (item 3).
2.
test(github): address reviewer feedback on ReadOnlyHint checkCherry-picked from #2486 (author: @jluocsa, authorship preserved).
3.
refactor(toolvalidation): extract ReadOnlyHint scanner into reusable packageNew change. Moves the AST scan out of
pkg/github's test file and into a new exported package,pkg/toolvalidation, so the remote server (which imports this repo) can apply the same guardrail with a one-line test:This follows the repo's stated convention that functions usable as a library from
github-mcp-server-remoteshould be exported.Refactor details
pkg/toolvalidation/readonlyhint.gowithScanReadOnlyHint,FormatReadOnlyHintViolations, and theReadOnlyHintViolationtype — stdlib only.pkg/toolvalidation/readonlyhint_test.gowith dedicated unit tests using in-memory fixtures: compliant literal, missing hint, missing annotations, non-literal annotations, aliased import (import sdk "..."), positional fields, and a file with no MCP import. This gives the validator real coverage it didn't have when it lived inline.pkg/github/tools_static_validation_test.goshrunk from 271 → 36 lines, behavior preserved.Verification
script/lint→ 0 issuesscript/test→ all packages pass, including the newpkg/toolvalidationand the thinpkg/githubwrapperFollow-up
I'll open a parallel PR against
github/github-mcp-server-remoteonce this lands (or against a prerelease tag) that bumps the go.mod to this commit and adds the thin one-line test there.Co-authored-by: John CSA 103165870+jluocsa@users.noreply.github.com