Skip to content

fix(mcp): fix issues with the MCP server mode#272

Open
dmcilvaney wants to merge 4 commits into
microsoft:mainfrom
dmcilvaney:damcilva/mcp_fixes
Open

fix(mcp): fix issues with the MCP server mode#272
dmcilvaney wants to merge 4 commits into
microsoft:mainfrom
dmcilvaney:damcilva/mcp_fixes

Conversation

@dmcilvaney

Copy link
Copy Markdown
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

Copilot AI review requested due to automatic review settings July 9, 2026 18:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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

Comment thread internal/app/azldev/core/mcp/mcpserver.go
Copilot AI review requested due to automatic review settings July 9, 2026 19:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.

@Tonisal-byte Tonisal-byte left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Comment thread internal/app/azldev/core/mcp/mcpserver.go Outdated
Copilot AI review requested due to automatic review settings July 10, 2026 01:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Comment thread internal/app/azldev/core/mcp/mcpserver.go
Comment thread internal/app/azldev/core/mcp/mcpserver.go
Copilot AI review requested due to automatic review settings July 10, 2026 17:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Comment thread internal/app/azldev/core/mcp/mcpserver.go
- 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.
@dmcilvaney dmcilvaney force-pushed the damcilva/mcp_fixes branch from 31c0fe6 to 6a590a4 Compare July 10, 2026 17:42
Copilot AI review requested due to automatic review settings July 10, 2026 18:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

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

4 participants