Skip to content

Python: [Bug]: FoundryAgent (Responses API) Does Not Surface oauth_consent_request as a CUSTOM AG-UI Event #5054

@djw-bsn

Description

@djw-bsn

Description

When a Foundry agent is backed by an MCP server that requires OAuth consent, FoundryAgent (which uses the Responses API) silently drops the oauth_consent_request stream events. The consent link is never surfaced to the caller.

This is a regression from AzureAIClient (Assistants API), which correctly emits a CUSTOM AG-UI event with name="oauth_consent_request" that callers can intercept.


Environment

Client agent_framework.foundry.FoundryAgent (new)
Upstream API Azure OpenAI Responses API
MCP server Databricks Genie MCP server requiring OAuth consent
AG-UI layer agent_framework_ag_ui

Steps to Reproduce

  1. Configure a Foundry agent with an MCP server that requires OAuth consent (e.g. Databricks Genie MCP server)
  2. Instantiate the agent using FoundryAgent / FoundryChatClient
  3. Send a request that triggers MCP tool listing - causing the MCP server to require OAuth

Expected Behaviour

A CUSTOM AG-UI event is emitted with:

{
  "type": "CUSTOM",
  "name": "oauth_consent_request",
  "value": {
    "consent_link": "https://[consent-host]/login?data=..."
  }
}

This is the behaviour produced by AzureAIClient (Assistants API path) and is what downstream callers depend on to surface the consent link to the user.


Actual Behaviour

The Responses API stream delivers two OAuth-related events:

response.output_item.added  ->  item.type = 'oauth_consent_request'  (contains consent_link)
response.oauth_consent_requested  ->  (also contains consent_link)

Both fall through to the case _: catchall in RawOpenAIChatClient's streaming event handler:

case _:
    logger.debug("Unparsed event of type: %s: %s", event.type, event)

Neither event is translated into a CUSTOM AG-UI event. The consent link is never surfaced to the caller. The stream completes normally with no output and no error.


Evidence

Broken (FoundryAgent - Responses API)

[DEBUG] agent_framework.openai - Unparsed event of type: response.output_item.added:
    ResponseOutputItemAddedEvent(item=ResponseOutputMessage(..., type='oauth_consent_request',
    consent_link='https://[consent-host]/login?data=...'), ...)

[DEBUG] agent_framework.openai - Unparsed event of type: response.oauth_consent_requested:
    ResponseAudioDeltaEvent(..., consent_link='https://...', ...)

[DEBUG] backend - Stream completed normally

No CUSTOM event. No consent link surfaced. Stream exits silently.

Working (AzureAIClient - Assistants API)

[DEBUG] agent_framework_ag_ui - Emitting CUSTOM AG-UI event: name='oauth_consent_request' value={'consent_link': 'https://[consent-host]/login?data=...'}

CUSTOM AG-UI event emitted correctly. Consent link surfaced and forwarded to the frontend.


Root Cause

RawOpenAIChatClient's streaming event handler (the match event.type block) has no case for:

  • "response.oauth_consent_requested"
  • "response.output_item.added" where item.type == "oauth_consent_request"

These event types are present in the commented-out section of the handler (confirming awareness), but no implementation exists:

# ResponseMcpListToolsCompletedEvent,
# ResponseMcpListToolsFailedEvent,
# ResponseMcpListToolsInProgressEvent,

The agent_framework_ag_ui layer does handle the equivalent signal from the Assistants API and emits a CUSTOM event - but the Responses API path has no equivalent handling.


Impact

Any agent migrated from AzureAIClient -> FoundryAgent that uses an MCP server with OAuth consent will silently break. The migration is actively encouraged (the deprecation warning on AzureAIClient reads: "Use OpenAIChatClient with an AsyncAzureOpenAI client, or FoundryChatClient for Foundry projects"), making this a migration blocker.


Fix Required

In RawOpenAIChatClient's streaming event handler, add handling for the OAuth consent events and emit an appropriate signal - either:

  1. A CUSTOM AG-UI event with name="oauth_consent_request" and value={"consent_link": "..."}, consistent with the Assistants API behaviour; or
  2. A dedicated exception type (e.g. OAuthConsentRequiredException) that callers can catch

Option 1 is preferred for backward compatibility with existing callers.

case "response.oauth_consent_requested":
    consent_link = getattr(event, "consent_link", None)
    if consent_link:
        contents.append(
            Content.custom(name="oauth_consent_request", value={"consent_link": consent_link})
        )

Workaround

Revert to AzureAIClient for any agent that requires MCP OAuth consent until this is resolved.

# Temporary workaround - revert to deprecated client
from agent_framework.azure import AzureAIClient

Code Sample

Error Messages / Stack Traces

Package Versions

agent-framework-core==1.0.0rc6, agent-framework-foundry==1.0.0rc6, agent_framework_ag_ui==1.0.0b260330

Python Version

Python 3.12

Additional Context

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingpython

Type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions