Skip to content

Make branch parameter optional in create_pull_request and push_to_pull_request_branch MCP tools#1327

Merged
pelikhan merged 5 commits intomainfrom
copilot/update-mcp-tool-handlers
Oct 7, 2025
Merged

Make branch parameter optional in create_pull_request and push_to_pull_request_branch MCP tools#1327
pelikhan merged 5 commits intomainfrom
copilot/update-mcp-tool-handlers

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 7, 2025

Summary

Updates the create_pull_request and push_to_pull_request_branch MCP tool handlers to make the "branch" parameter optional. When the branch parameter is not provided or is empty, the current git branch is automatically resolved using git rev-parse --abbrev-ref HEAD.

Problem

Previously, both MCP tools required an explicit "branch" parameter:

// create_pull_request - branch was required
{
  "title": "My PR",
  "body": "Description",
  "branch": "feature-branch"  // Required - would fail without this
}

// push_to_pull_request_branch - branch was required
{
  "message": "Update files",
  "branch": "feature-branch"  // Required - would fail without this
}

This created unnecessary friction when the AI agent was already working on a specific branch and just wanted to create a PR or push changes from the current branch.

Solution

The branch parameter is now optional for both tools. When omitted, the MCP server automatically resolves the current git branch:

// create_pull_request - branch is now optional
{
  "title": "My PR",
  "body": "Description"
  // branch parameter omitted - will use current branch
}

// push_to_pull_request_branch - branch is now optional
{
  "message": "Update files"
  // branch parameter omitted - will use current branch
}

Implementation Details

  1. Added getCurrentBranch() helper function that executes git rev-parse --abbrev-ref HEAD to resolve the current branch name

  2. Created custom handlers for both tools:

    • createPullRequestHandler() - Resolves current branch when not provided
    • pushToPullRequestBranchHandler() - Resolves current branch when not provided
  3. Updated tool schemas:

    • Removed "branch" from required fields
    • Updated descriptions to indicate the parameter is optional
    • Documented the fallback behavior

Backward Compatibility

The changes are fully backward compatible. Existing calls that provide an explicit "branch" parameter will continue to work unchanged:

// This still works exactly as before
{
  "title": "My PR",
  "body": "Description",
  "branch": "custom-branch"  // Explicit branch still works
}

Testing

  • Added comprehensive test coverage for the optional parameter behavior
  • Verified schema changes are correctly applied
  • All 439 JavaScript tests pass
  • All Go unit tests pass
  • Manual verification of branch resolution logic

Files Changed

  • pkg/workflow/js/safe_outputs_mcp_server.cjs - Core implementation
  • pkg/workflow/js/safe_outputs_mcp_server_defaults.test.cjs - Test coverage
Original prompt

Update create_pull_request and push_to_pull_request_branch MCP tool handlers such that "branch" is optional. If branch is missing, the current branch is used.

  • update the mcp server tool descriptions
  • update the mcp server to resolve the current git branch when processing the message in the mcp handler.

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits October 7, 2025 20:46
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
const fs = require("fs");
const path = require("path");
const crypto = require("crypto");
const { execSync } = require("child_process");
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 exec.getExecOutput who is defined in @actions/core (it is already ambient in the actions/github-script execution environment)

Copilot AI and others added 2 commits October 7, 2025 20:57
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] Update MCP tool handlers to use current branch if missing Make branch parameter optional in create_pull_request and push_to_pull_request_branch MCP tools Oct 7, 2025
Copilot AI requested a review from pelikhan October 7, 2025 21:01
@pelikhan pelikhan marked this pull request as ready for review October 7, 2025 21:04
@pelikhan pelikhan merged commit cc6830f into main Oct 7, 2025
1 of 2 checks passed
@pelikhan pelikhan deleted the copilot/update-mcp-tool-handlers branch October 7, 2025 21:04
Copilot AI requested a review from pelikhan October 7, 2025 21:05
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.

2 participants