Skip to content

Add GitHub tool/toolset validator for allowed tools configuration#2770

Merged
pelikhan merged 5 commits into
mainfrom
copilot/add-toolset-validator
Oct 30, 2025
Merged

Add GitHub tool/toolset validator for allowed tools configuration#2770
pelikhan merged 5 commits into
mainfrom
copilot/add-toolset-validator

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 30, 2025

GitHub Tool/Toolset Validator Implementation ✅

This PR adds validation to ensure that when users specify individual GitHub tools using the allowed field, the corresponding toolsets are enabled in the configuration.

Recent Updates (addressing review feedback)

Changed to use ParsedTools - Now uses workflowData.ParsedTools.GitHub instead of accessing raw Tools map directly for better type safety.

Moved mapping to embedded JSON - The tool-to-toolset mapping is now loaded from an embedded JSON file (data/github_tool_to_toolset.json) instead of being a large map literal in code.

Fixed toolsets field parsing - Now supports both toolset (singular) and toolsets (plural) field names to handle common user configurations.

Problem Solved

When users specify tools like list_workflows in the allowed field but forget to enable the actions toolset, the workflow would compile but fail at runtime. This validator catches the issue at compile time with clear error messages.

Solution Overview

  1. Tool-to-Toolset Mapping - JSON file mapping 50+ GitHub tools to their toolsets
  2. Validation Function - Checks that all allowed tools have their toolsets enabled
  3. Clear Error Messages - Provides actionable fix suggestions
  4. Compiler Integration - Validation runs automatically during workflow compilation

Example Error Message

ERROR: GitHub tools specified in 'allowed' field require toolsets that are not enabled:

  Toolset 'actions' is required by:
    - list_workflows

  Toolset 'discussions' is required by:
    - create_discussion

Suggested fix: Add the missing toolsets to your GitHub tool configuration:

tools:
  github:
    toolsets:
      - default
      - actions
      - discussions

Test Coverage

  • ✅ 17 unit tests covering all scenarios
  • ✅ 3 integration tests (Copilot, Claude, Remote mode)
  • ✅ 3 error message formatting tests
  • ✅ 2 mapping consistency tests
  • ✅ All tests pass
  • ✅ Manual verification complete

Files Added

  • pkg/workflow/github_tool_to_toolset.go - Validation logic with embedded JSON loader
  • pkg/workflow/data/github_tool_to_toolset.json - Tool to toolset mapping data
  • pkg/workflow/github_tool_to_toolset_test.go - Unit tests
  • pkg/workflow/github_toolset_validation_error.go - Error type
  • pkg/workflow/github_toolset_validation_integration_test.go - Integration tests

Files Modified

  • pkg/workflow/compiler.go - Added validation using ParsedTools
  • pkg/workflow/tools_types.go - Support both toolset/toolsets field names

Quality Checks

  • ✅ Build passes
  • ✅ All linter checks pass
  • ✅ Code formatted with gofmt
  • ✅ Backwards compatible
Original prompt

Add a github tool / toolset validator.

for each allowed tool in the frontmatter, validate that its corresponding toolset is enabled in the current configuration.

Raise error if toolset is missing


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits October 30, 2025 05:04
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add GitHub toolset validator for allowed tools Add GitHub tool/toolset validator for allowed tools configuration Oct 30, 2025
Copilot AI requested a review from pelikhan October 30, 2025 05:10
Comment thread pkg/workflow/compiler.go Outdated

// Validate GitHub tools against enabled toolsets
log.Printf("Validating GitHub tools against enabled toolsets")
if githubTool, hasGitHub := workflowData.Tools["github"]; hasGitHub {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@copilot use hasGithub or parsed tools instead

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated to use workflowData.ParsedTools.GitHub for type safety. Also fixed parsing to support both toolset and toolsets field names. (67cee68)

Comment thread pkg/workflow/github_tool_to_toolset.go Outdated

// GitHubToolToToolsetMap maps individual GitHub MCP tools to their respective toolsets
// This mapping is based on the documentation in .github/instructions/github-mcp-server.instructions.md
var GitHubToolToToolsetMap = map[string]string{
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@copilot move to embedded JSON file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved to embedded JSON file at pkg/workflow/data/github_tool_to_toolset.json. The mapping is now loaded via go:embed directive in the init function. (67cee68)

- Use workflowData.ParsedTools.GitHub instead of raw Tools map
- Support both 'toolset' and 'toolsets' field names in parseGitHubTool
- Move GitHub tool-to-toolset mapping to embedded JSON file
- Addresses review feedback from @pelikhan

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI requested a review from pelikhan October 30, 2025 11:21
@pelikhan pelikhan marked this pull request as ready for review October 30, 2025 11:24
Copilot AI review requested due to automatic review settings October 30, 2025 11:24
@github-actions
Copy link
Copy Markdown
Contributor

Agentic Changeset Generator triggered by this pull request.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds compile-time validation to ensure that when users specify individual GitHub tools via the allowed field, their corresponding toolsets are enabled in the workflow configuration. Previously, misconfigured workflows would compile successfully but fail at runtime.

Key Changes:

  • Implemented tool-to-toolset validation with clear error messaging
  • Moved tool-to-toolset mapping to embedded JSON for maintainability
  • Added support for both toolset and toolsets field names in configurations

Reviewed Changes

Copilot reviewed 9 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pkg/workflow/compiler.go Integrated validation step during workflow compilation using ParsedTools
pkg/workflow/tools_types.go Added parsing support for plural toolsets field name
pkg/workflow/github_tool_to_toolset.go Core validation logic with embedded JSON loader
pkg/workflow/data/github_tool_to_toolset.json Tool-to-toolset mapping data (50+ GitHub tools)
pkg/workflow/github_toolset_validation_error.go Custom error type with formatted output and fix suggestions
pkg/workflow/github_tool_to_toolset_test.go Unit tests covering validation scenarios and mapping consistency
pkg/workflow/github_toolset_validation_integration_test.go Integration tests for Copilot, Claude, and remote mode
pkg/workflow/permissions_validator.go Removed unused containsToolset helper function
.github/workflows/technical-doc-writer.lock.yml Updated actions/setup-node to newer version

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/workflow/compiler.go
Comment on lines +205 to +213
// Check for both "toolset" and "toolsets" (plural is more common in user configs)
if toolset, ok := configMap["toolsets"].([]any); ok {
config.Toolset = make([]string, 0, len(toolset))
for _, item := range toolset {
if str, ok := item.(string); ok {
config.Toolset = append(config.Toolset, str)
}
}
} else if toolset, ok := configMap["toolset"].([]any); ok {
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

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

The code for parsing toolsets (lines 207-212) and toolset (lines 214-218, not shown but identical) is duplicated. Consider extracting this logic into a helper function to reduce duplication and improve maintainability.

Copilot uses AI. Check for mistakes.
Comment on lines +5 to +6

"get_repository": "repos",
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

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

[nitpick] The JSON file contains inconsistent blank lines (e.g., line 5) between groupings. While this doesn't affect functionality, removing these blank lines would make the file more consistent and easier to maintain, as JSON doesn't require blank lines for readability.

Copilot uses AI. Check for mistakes.
@pelikhan pelikhan merged commit 26df517 into main Oct 30, 2025
4 checks passed
@pelikhan pelikhan deleted the copilot/add-toolset-validator branch October 30, 2025 12:04
@lpcox lpcox mentioned this pull request May 10, 2026
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants