fix(mcp): fix issues with the MCP server mode#272
Open
dmcilvaney wants to merge 4 commits into
Open
Conversation
dmcilvaney
commented
Jul 9, 2026
Contributor
- Serialize tool handlers to prevent concurrent corruption of captured output
- Mark read-only tools with readOnlyHint for client auto-approval
- Clarify MCP tool exposure guidance for managed project state
- Report correct server name (azldev) and build-stamped version
- Drain tool output concurrently to avoid pipe buffer deadlock
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves azldev’s MCP server mode by making tool execution safer under concurrency, improving client metadata (read-only hints), and reporting accurate server identity/version.
Changes:
- Serialize MCP tool execution to avoid concurrent stdout-capture corruption and drain captured output concurrently to prevent pipe-buffer deadlocks.
- Add an azldev-level “read-only MCP tool” annotation and mirror it into the MCP tool schema (
readOnlyHint) for client auto-approval. - Report the MCP server name/version from the root command name and build-stamped version.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| scenario/snapshots/TestMCPServerMode_1.snap.json | Updates scenario snapshot to reflect read-only hint exposure for tools. |
| internal/app/azldev/core/mcp/mcpserver.go | Serializes tool handlers, reports server name/version correctly, propagates read-only hints, and introduces concurrent stdout capture draining. |
| internal/app/azldev/core/mcp/mcpserver_internal_test.go | Adds regression tests for large-output capture deadlock and error propagation. |
| internal/app/azldev/command.go | Introduces a read-only MCP annotation and helper to mark commands as read-only MCP tools. |
| internal/app/azldev/cmds/pkg/list.go | Marks pkg list as a read-only MCP tool. |
| internal/app/azldev/cmds/image/list.go | Marks image list as a read-only MCP tool. |
| internal/app/azldev/cmds/config/schema.go | Marks config schema as a read-only MCP tool. |
| internal/app/azldev/cmds/config/dump.go | Marks config dump as a read-only MCP tool. |
| internal/app/azldev/cmds/component/list.go | Marks component list as a read-only MCP tool. |
| internal/app/azldev/cmds/component/history.go | Marks component history as a read-only MCP tool. |
| internal/app/azldev/cmds/component/changed.go | Marks component changed as a read-only MCP tool. |
Tonisal-byte
approved these changes
Jul 9, 2026
liunan-ms
approved these changes
Jul 10, 2026
- Serialize tool handlers to prevent concurrent corruption of captured output - Mark read-only tools with readOnlyHint for client auto-approval - Clarify MCP tool exposure guidance for managed project state - Report correct server name (azldev) and build-stamped version - Drain tool output concurrently to avoid pipe buffer deadlock
captureStdout mutates the process-global os.Stdout while draining command output through a pipe. If the captured action panicked, the normal cleanup path was skipped, leaving os.Stdout redirected and the drain goroutine waiting on a writer that would never close. Run cleanup from a defer, still closing the writer before waiting for the drain goroutine, and add a panic regression test that verifies os.Stdout is restored.
31c0fe6 to
6a590a4
Compare
Comment on lines
+198
to
+202
| capturedText, execErr := captureStdout(func() error { | ||
| env.SetReportFile(os.Stdout) // os.Stdout is the capture pipe for the duration of this call | ||
|
|
||
| return cmd.Root().Execute() | ||
| }) |
Comment on lines
+195
to
+197
| // (specs, locks, config) on their own: read-only commands (marked with | ||
| // [azldev.ExportAsReadOnlyMCPTool]), or ones that write solely to a caller-provided output | ||
| // path, such as 'docs markdown' or 'component diff-sources --output-file'. |
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.