Skip to content

fix(agentserver): preserve MCP approval request links - #49037

Open
JiahuiGu (Jiahui-Gu) wants to merge 2 commits into
Azure:mainfrom
Jiahui-Gu:fix/mcp-approval-request-link
Open

JiahuiGu (Jiahui-Gu) wants to merge 2 commits into
Azure:mainfrom
Jiahui-Gu:fix/mcp-approval-request-link

Conversation

@Jiahui-Gu

@Jiahui-Gu JiahuiGu (Jiahui-Gu) commented Sep 16, 2026

Copy link
Copy Markdown

Description

Fixes #49066.

MCP call builders cannot accept the standard Responses approval_request_id field, so callers cannot preserve the relationship between an MCP execution and its approval request.

Add an optional keyword argument to the synchronous and asynchronous add_output_item_mcp_call factories and their builders. Preserve the supplied ID in response.output_item.added, response.output_item.done, and accumulated terminal response output. Calls without an approval ID remain unchanged. The field is defined by the OpenAI Responses MCP contract.

33 focused sync/async builder and generator tests pass, covering successful and failed calls, terminal output retention, absent links and empty-ID rejection. The API snapshot and hash metadata are updated with APIView 0.3.31.

All SDK Contribution checklist:

  • The pull request does not introduce breaking changes.
  • CHANGELOG is updated.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title is clear and informative.
  • Commits are focused and have informative messages.

Testing Guidelines

  • Includes test coverage for the change.

@github-actions github-actions Bot added Community Contribution Community members are working on the issue customer-reported Issues that are reported by GitHub users external to the Azure organization. Hosted Agents sdk/agentserver/* labels Sep 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution JiahuiGu (@Jiahui-Gu)! We will review the pull request and get back to you soon.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
7 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
7 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

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.

🟡 Changes recommended

The async API lacks the new parameter, and the committed API snapshot is stale.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds MCP approval-request identity preservation to synchronous response streaming.

Changes:

  • Adds and validates optional approval_request_id.
  • Preserves it across added, done, and terminal output items.
  • Adds focused tests and changelog documentation.
File summaries
File Description
test_mcp_approval_link.py Tests approval-link retention and validation.
CHANGELOG.md Documents the fix.
_event_stream.py Exposes the new synchronous builder argument.
_builders/_tools.py Validates and emits the approval ID.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

name: str,
*,
item_id: str | None = None,
approval_request_id: str | None = None,

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in fd2ab09. The async factory accepts and forwards approval_request_id. The same parameterized tests now cover sync/async success and failure, added/done/terminal retention, absent IDs and empty-ID rejection; 33 builder/generator tests pass.

Comment on lines +539 to +540
:keyword approval_request_id: Explicit ID of the approval request for this MCP call.
:keyword type approval_request_id: str | None

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Regenerated api.md through APIView 0.3.31 and the repository Export-APIViewMarkdown tool, then generated api.metadata.yml with extract_apiview_metadata.py. It includes sync/async factories and inherited builder signatures. Unrelated model-literal generator churn was excluded; the normalized content hash matches the committed API snapshot. Included in fd2ab09.

Copilot AI review requested due to automatic review settings September 16, 2026 09:22

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.

🟢 Approval recommended

The implementation consistently covers both stream variants, terminal accumulation, validation, tests, and API documentation.

Review details
  • Files reviewed: 7/7 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Community Contribution Community members are working on the issue customer-reported Issues that are reported by GitHub users external to the Azure organization. Hosted Agents sdk/agentserver/*

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[AgentServer Responses] MCP call builders cannot preserve approval_request_id

2 participants