Skip to content

Add 'add' tool to mcp-server command#3447

Merged
pelikhan merged 6 commits into
mainfrom
copilot/add-tool-to-mcp-server-command
Nov 7, 2025
Merged

Add 'add' tool to mcp-server command#3447
pelikhan merged 6 commits into
mainfrom
copilot/add-tool-to-mcp-server-command

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 7, 2025

This PR adds the add tool to the MCP server command, allowing users to add workflows from remote repositories through the MCP protocol.

Changes Made

  1. Added add tool to MCP server (pkg/cli/mcp_server.go):

    • Created addArgs struct with minimal parameters: workflows (required), number, and name
    • Implemented tool handler that calls the add CLI command with appropriate arguments
    • Added concise description matching the style of other MCP server tools: "Add workflows from remote repositories to .github/workflows"
    • Updated command documentation to list the new add tool
  2. Updated existing tests (pkg/cli/mcp_server_test.go):

    • Updated TestMCPServer_ListTools to include add in the expected tools list
  3. Added new integration tests (pkg/cli/mcp_server_add_test.go):

    • TestMCPServer_AddTool: Verifies the add tool is exposed with proper description
    • TestMCPServer_AddToolInvocation: Tests actual tool invocation with workflows parameter
    • Tests error handling when required parameters are missing

Tool Parameters

The add tool supports the following minimal parameters:

  • workflows (required): Array of workflow specifications to add (e.g., 'owner/repo/workflow-name' or 'owner/repo/workflow-name@version')
  • number: Create multiple numbered copies (corresponds to -c flag)
  • name: Specify custom name for the workflow (corresponds to -n flag)

Testing

  • ✅ Unit tests: make test-unit
  • ✅ Integration tests: TestMCPServer_AddTool
  • ✅ Linting: make lint
  • ✅ Formatting: make fmt
  • ✅ Security: CodeQL scan (no issues found)

The tool is fully functional and follows the same patterns as other tools in the MCP server (status, compile, logs, audit, mcp-inspect).

Original prompt

Add tool to "mcp-server" command that wraps the "add" command.


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

@pelikhan
Copy link
Copy Markdown
Collaborator

pelikhan commented Nov 7, 2025

@copilot continue working

Copilot AI and others added 2 commits November 7, 2025 15:44
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Nov 7, 2025

@copilot continue working

Completed! Added the add tool to the mcp-server command in commit 17273fb.

The tool wraps the gh aw add command and supports all major parameters:

  • workflows (required): Array of workflow specifications to add
  • number: Create multiple numbered copies (corresponds to -c flag)
  • name: Custom workflow name (corresponds to -n flag)
  • engine: Override AI engine (corresponds to -a flag)
  • force: Overwrite existing files
  • append: Append content to workflow
  • verbose: Enable verbose output

All tests pass and no security issues were found. The tool is listed in the help text and available via MCP protocol.

Copilot AI changed the title [WIP] Add tool to wrap add command in mcp-server Add 'add' tool to mcp-server command Nov 7, 2025
Comment thread pkg/cli/mcp_server.go Outdated
Comment on lines +471 to +491

Workflow specifications:
- Two parts: "owner/repo[@version]" (lists available workflows in the repository)
- Three parts: "owner/repo/workflow-name[@version]" (implicitly looks in workflows/ directory)
- Four+ parts: "owner/repo/workflows/workflow-name.md[@version]" (requires explicit .md extension)
- Wildcard: "owner/repo/*[@version]" (adds all workflows from the repository)
- Version can be tag, branch, or SHA

Examples:
- ["githubnext/agentics"] - List available workflows
- ["githubnext/agentics/ci-doctor"] - Add specific workflow
- ["githubnext/agentics/ci-doctor@v1.0.0"] - Add with version
- ["githubnext/agentics/*"] - Add all workflows

The tool will:
1. Install the required repository if not already installed
2. Copy the workflow file(s) to .github/workflows/
3. Update .gitattributes to exclude .lock.yml files from diffs
4. Compile the workflow to generate .lock.yml file

Note: This tool does not support PR creation (--pr flag) or interactive mode.`,
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 remove text

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.

Removed verbose description text in commit 591d7b9. The tool description is now concise and matches the style of other MCP server tools: "Add workflows from remote repositories to .github/workflows"

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan
Copy link
Copy Markdown
Collaborator

pelikhan commented Nov 7, 2025

@copilot remove force, verbose, append arguments from tool signature

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Nov 7, 2025

@copilot remove force, verbose, append arguments from tool signature

Removed force, verbose, and append arguments in commit 96f7970. The add tool now only accepts essential parameters: workflows (required), number, name, and engine.

Copy link
Copy Markdown
Collaborator

@pelikhan pelikhan left a comment

Choose a reason for hiding this comment

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

@copilot remove "engine" argument from tool as well

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Nov 7, 2025

@copilot remove "engine" argument from tool as well

Removed engine argument in commit e0014d9. The add tool now only accepts: workflows (required), number, and name.

Copilot AI requested a review from pelikhan November 7, 2025 16:32
@pelikhan pelikhan marked this pull request as ready for review November 7, 2025 16:34
Copilot AI review requested due to automatic review settings November 7, 2025 16:34
@pelikhan pelikhan merged commit 3d58490 into main Nov 7, 2025
66 of 70 checks passed
@pelikhan pelikhan deleted the copilot/add-tool-to-mcp-server-command branch November 7, 2025 16:37
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 MCP server support for the add command, enabling AI agents to add workflows from remote repositories through the Model Context Protocol.

Key changes:

  • Adds new "add" tool to the MCP server that wraps the CLI add command
  • Implements basic parameter support for workflows, number of copies, and custom naming
  • Includes comprehensive integration tests to verify tool exposure and invocation
  • Updates the expected tools list in existing tests

Reviewed Changes

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

File Description
pkg/cli/mcp_server.go Adds the "add" tool to MCP server with argument handling and command execution wrapper
pkg/cli/mcp_server_add_test.go New integration tests verifying the add tool is properly exposed and functional via MCP
pkg/cli/mcp_server_test.go Updates expected tools list to include the new "add" tool
.github/workflows/go.mod Minor formatting cleanup (removes empty require block, reorders go version)

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

Comment thread pkg/cli/mcp_server.go
Comment on lines +456 to +460
type addArgs struct {
Workflows []string `json:"workflows" jsonschema:"Workflows to add (e.g., 'owner/repo/workflow-name' or 'owner/repo/workflow-name@version')"`
Number int `json:"number,omitempty" jsonschema:"Create multiple numbered copies (corresponds to -c flag, default: 1)"`
Name string `json:"name,omitempty" jsonschema:"Specify name for the added workflow - without .md extension (corresponds to -n flag)"`
}
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

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

The MCP add tool is missing support for several important CLI flags that are available in the add command:

  • --engine/-a - Override AI engine (claude, codex, copilot, custom)
  • --pr - Create a pull request with the workflow changes
  • --force - Overwrite existing workflow files
  • --append - Append extra content to the end of agentic workflow on installation
  • --no-gitattributes - Skip updating .gitattributes file

These flags provide important functionality that MCP users may need, particularly --pr and --force which are commonly used. Consider adding these as optional parameters in the addArgs struct to provide feature parity with the CLI command.

Copilot uses AI. Check for mistakes.
Comment thread pkg/cli/mcp_server.go
Comment on lines +464 to +465
Description: "Add workflows from remote repositories to .github/workflows",
}, func(ctx context.Context, req *mcp.CallToolRequest, args addArgs) (*mcp.CallToolResult, any, error) {
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

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

The tool description is too brief and doesn't provide enough context for AI agents using this tool. Following the pattern from other tools in this file (e.g., status, logs, mcp-inspect), the description should include:

  • Examples of workflow specifications (e.g., "owner/repo/workflow-name" or "owner/repo/workflow-name@version")
  • Explanation of what happens when just a repository is specified (lists available workflows)
  • Information about version specifications (tag, branch, or SHA)
  • Details about the workflow file destination (.github/workflows)

Example:

Description: `Add workflows from remote repositories to .github/workflows.

Workflow specifications:
- Two parts: "owner/repo[@version]" (lists available workflows in the repository)
- Three parts: "owner/repo/workflow-name[@version]" (implicitly looks in workflows/ directory)
- Four+ parts: "owner/repo/workflows/workflow-name.md[@version]" (requires explicit .md extension)
- GitHub URL: "https://github.com/owner/repo/blob/branch/path/to/workflow.md"
- Wildcard: "owner/repo/*[@version]" (adds all workflows from the repository)
- Version can be tag, branch, or SHA

The number parameter creates multiple numbered copies of the workflow.
The name parameter specifies a custom name for the added workflow file (without .md extension).`,
Suggested change
Description: "Add workflows from remote repositories to .github/workflows",
}, func(ctx context.Context, req *mcp.CallToolRequest, args addArgs) (*mcp.CallToolResult, any, error) {
Description: `Add workflows from remote repositories to .github/workflows.

Copilot uses AI. Check for mistakes.
Comment thread pkg/cli/mcp_server.go
Comment on lines +457 to +459
Workflows []string `json:"workflows" jsonschema:"Workflows to add (e.g., 'owner/repo/workflow-name' or 'owner/repo/workflow-name@version')"`
Number int `json:"number,omitempty" jsonschema:"Create multiple numbered copies (corresponds to -c flag, default: 1)"`
Name string `json:"name,omitempty" jsonschema:"Specify name for the added workflow - without .md extension (corresponds to -n flag)"`
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

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

The JSON schema descriptions for the arguments should be more detailed to help AI agents understand how to use them properly:

  • Workflows - Should explain the format options (owner/repo, owner/repo/workflow-name, with optional @Version, etc.)
  • Number - Should clarify that it corresponds to the -c flag and creates multiple numbered copies
  • Name - Should clarify that it should not include the .md extension

Example:

Workflows []string `json:"workflows" jsonschema:"Workflow specifications to add (e.g., 'owner/repo', 'owner/repo/workflow-name', 'owner/repo/workflow-name@version', or GitHub URL). Specify just 'owner/repo' to list available workflows."`
Number    int      `json:"number,omitempty" jsonschema:"Create multiple numbered copies of the workflow (corresponds to -c flag, default: 1)"`
Name      string   `json:"name,omitempty" jsonschema:"Custom name for the added workflow file without .md extension (corresponds to -n flag). Only applies to the first workflow when adding multiple."`
Suggested change
Workflows []string `json:"workflows" jsonschema:"Workflows to add (e.g., 'owner/repo/workflow-name' or 'owner/repo/workflow-name@version')"`
Number int `json:"number,omitempty" jsonschema:"Create multiple numbered copies (corresponds to -c flag, default: 1)"`
Name string `json:"name,omitempty" jsonschema:"Specify name for the added workflow - without .md extension (corresponds to -n flag)"`
Workflows []string `json:"workflows" jsonschema:"Workflow specifications to add (e.g., 'owner/repo', 'owner/repo/workflow-name', 'owner/repo/workflow-name@version', or GitHub URL). Specify just 'owner/repo' to list available workflows."`
Number int `json:"number,omitempty" jsonschema:"Create multiple numbered copies of the workflow (corresponds to -c flag, default: 1)"`
Name string `json:"name,omitempty" jsonschema:"Custom name for the added workflow file without .md extension (corresponds to -n flag). Only applies to the first workflow when adding multiple."`

Copilot uses AI. Check for mistakes.
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