Skip to content

Refactor MCP update tool to call Go function directly with context support#14360

Closed
Copilot wants to merge 3 commits intomainfrom
copilot/refactor-update-tool-command
Closed

Refactor MCP update tool to call Go function directly with context support#14360
Copilot wants to merge 3 commits intomainfrom
copilot/refactor-update-tool-command

Conversation

Copy link
Contributor

Copilot AI commented Feb 7, 2026

The MCP update tool spawned a subprocess for each invocation, adding overhead and preventing proper cancellation handling. This refactors it to call the Go function directly with full context support.

Changes

  • Added context-aware function chain: Created UpdateWorkflowsWithExtensionCheckContext() and context-aware versions of all downstream functions (UpdateActionsContext, UpdateWorkflowsContext, RunFixContext, checkExtensionUpdateContext, createUpdatePRContext)

  • Refactored MCP handler: Replaced execCmd() subprocess spawning with direct call to UpdateWorkflowsWithExtensionCheckContext(). Added captureStderr() helper to intercept console output for MCP responses.

  • Backward compatibility: Original functions remain as deprecated wrappers calling context versions with context.Background()

  • Cancellation support: Added context checks at key points throughout the update chain to respect MCP request cancellation

Example

// Before: spawning subprocess
cmd := execCmd(ctx, cmdArgs...)
output, err := cmd.CombinedOutput()

// After: direct function call with context
output, err := captureStderr(func() error {
    return UpdateWorkflowsWithExtensionCheckContext(
        ctx, 
        args.Workflows,
        args.Major,
        args.Force,
        // ... other params
    )
})

Thread Safety

  • No global state dependencies (only logger instances)
  • captureStderr() uses proper goroutine + channel synchronization
  • Channel lifecycle explicitly managed (reader goroutine owns closure)
Original prompt

Refactor the MCP-server command implementation of the update tool so that it calls the Go functin directly instead of spawning a separate process. Ensure that it invokes the command with a context, avoids data races, and does not rely on any global objects.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits February 7, 2026 14:24
…pport

- Add context.Context parameter to UpdateWorkflowsWithExtensionCheck and downstream functions
- Create context-aware versions: UpdateWorkflowsWithExtensionCheckContext, UpdateActionsContext, UpdateWorkflowsContext, RunFixContext, checkExtensionUpdateContext, createUpdatePRContext
- Keep deprecated wrappers for backward compatibility
- Refactor MCP update tool handler to call UpdateWorkflowsWithExtensionCheckContext directly
- Add captureStderr helper function to capture console output for MCP responses
- Add cancellation checks throughout the update chain
- Fix linter warnings with nolint directives for deprecated wrappers

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
- Add comprehensive tests for context cancellation handling
- Test UpdateWorkflowsWithExtensionCheckContext with cancellation and timeout
- Test captureStderr helper function
- Test all context-aware functions: UpdateActionsContext, UpdateWorkflowsContext, RunFixContext, checkExtensionUpdateContext
- All tests pass successfully

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor MCP-server command implementation of update tool Refactor MCP update tool to call Go function directly with context support Feb 7, 2026
Copilot AI requested a review from pelikhan February 7, 2026 14:32
@pelikhan pelikhan closed this Feb 7, 2026
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