{"modulePath":"github.com/github/github-mcp-server/v2","version":"v2.2.0","isLatest":false,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package toolvalidation\n\nPackage toolvalidation provides source-level (AST) validators for MCP tool registrations. It is intended to be consumed from \\_test.go files in any package that registers mcp.Tool literals (including downstream repositories such as github-mcp-server-remote) so the same guardrails apply everywhere without duplicating the parsing logic.\n\n## Constants\n\n```go\nconst MCPImportPath = \"github.com/modelcontextprotocol/go-sdk/mcp\"\n```\nMCPImportPath is the canonical module path of the MCP go-sdk. Source files that import this path under any alias (including the default \\`mcp\\`) are candidates for tool-literal validation.\n\n## Functions\n\n```go\nfunc FormatReadOnlyHintViolations(violations []ReadOnlyHintViolation) string\n```\nFormatReadOnlyHintViolations renders a single multi-line error message suitable for passing to t.Fatal. Returns \"\" when violations is empty.\n\n## Types\n\n```go\ntype ReadOnlyHintViolation struct {\n\t// File is the path to the offending source file, made relative to the\n\t// scan directory when possible.\n\tFile string\n\t// Line is the 1-indexed line number of the offending literal.\n\tLine int\n\t// ToolName is the value of the Name field on the mcp.Tool literal, or\n\t// \"\u003cunknown\u003e\" when it cannot be statically extracted.\n\tToolName string\n\t// Reason is a human-readable explanation of why the literal failed.\n\tReason string\n}\n```\nReadOnlyHintViolation describes a single mcp.Tool composite literal that failed the ReadOnlyHint check.\n\n```go\nfunc ScanReadOnlyHint(dir string) ([]ReadOnlyHintViolation, error)\n```\nScanReadOnlyHint parses every non-test .go file in dir (a single package directory) and returns a violation for each mcp.Tool composite literal that does not explicitly set Annotations.ReadOnlyHint.\n\nThe Go runtime cannot distinguish an unset bool field from one explicitly set to false, so this AST-level check exists to prevent future tool registrations from silently defaulting ReadOnlyHint to false — which has triggered downstream agents to prompt for human approval on safe read operations.\n\nCallers typically invoke this from a \\_test.go file:\n\n\tdir, _ := os.Getwd()\n\tviolations, err := toolvalidation.ScanReadOnlyHint(dir)\n\n```go\nfunc (v ReadOnlyHintViolation) String() string\n```\nString renders a violation in the format used by FormatReadOnlyHintViolations: \"\\\u003cfile\u003e:\\\u003cline\u003e tool=\\\u003cname\u003e: \\\u003creason\u003e\".\n\n","path":"github.com/github/github-mcp-server/v2/pkg/toolvalidation","name":"toolvalidation","synopsis":"Package toolvalidation provides source-level (AST) validators for MCP tool registrations.","isRedistributable":true}
