Repository navigation
Add context cancellation checks to MCP tool handlers - #6311
Merged
Merged
Conversation
Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add context cancellation checks to MCP tool handlers
Add context cancellation checks to MCP tool handlers
Dec 13, 2025
pelikhan
marked this pull request as ready for review
December 13, 2025 08:19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MCP tool handlers receive a context but don't check for cancellation before performing I/O and subprocess operations. This causes handlers to continue executing after client disconnection.
Changes
ctx.Done()checks to all 7 tool handlers (status,compile,logs,audit,mcp-inspect,add,update)compilehandler after Docker image preparation (potentially slow operation)ctx.Err()when cancellation detectedImplementation
Subprocess commands already use
exec.CommandContext(ctx, ...)so cancellation propagates automatically. The explicit checks provide early exit before spawning processes.Test Coverage
Added
TestMCPServer_ContextCancellationthat validates handlers exit gracefully with pre-cancelled contexts.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
https://api.github.com/user/usr/bin/gh gh api user --jq .login --show-toplevel ache/go/1.25.0/x64/pkg/tool/linurefs/tags/v2 9de148c36c6c1b17c9aae9dba1805ed669d1c62fda11916fa64/log.json te(http block)/usr/bin/gh gh api user --jq .login(http block)/usr/bin/gh gh api user --jq .login /run/containerd/io.containerd.runtime.v2.task/moby/9f6ba46a12b0f14a9562a2613f217cff8f5bee92d819d1e648afd9d30f4aff72/init.pid 9f6ba46a12b0f14a9562a2613f217cff8f5bee92d819d1e648afd9d30f4aff72 4768951/b356=> -unreachable=fal/usr/bin/jq /tmp/go-build611.[0] 199435/b327/vet.cfg sh -c mplates from .github to pkg/cli/templates..." /opt/hostedtoolcache/go/1.25.0/x64/pkg/tool/linu/home/REDACTED/work/gh-aw/gh-aw/pkg/logger/logger.status /usr/bin/git -unreachable=falgrep /tmp/go-build611-q /opt/hostedtoolccreate git(http block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.