Azure / Azure/azure-sdk-for-python

MCPTool: No way to pass dynamic bearer tokens for MCP server authentication

Offen
#44,584 4 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
AI Projects customer-reported needs-team-attention question Service Attention
Vorherrschende Sprache
Python
Sterne
5.6k
Forks
3.4k
Ø Merge
2 T.
Gemergte PRs (30 T.)
217

Beschreibung

## Description

When using `MCPTool` from `azure-ai-projects` to connect to an MCP server that requires bearer token authentication, there's no viable way to pass dynamic tokens that are generated at runtime.

## Current Behavior

Passing an `Authorization` header directly to `MCPTool` results in:

```
HttpResponseError: (invalid_payload) Headers that can include sensitive information are not allowed in the headers property for MCP tools. Use project_connection_id instead.
```

## Problem

The suggested alternative `project_connection_id` references a pre-configured connection in the Azure AI Foundry project. However, this approach doesn't work for scenarios where:

1. Bearer tokens are generated dynamically at runtime
2. Tokens have short expiration times and need to be refreshed frequently
3. The authentication flow is handled by the client application, not by Azure

## Expected Behavior

There should be a way to pass dynamic authentication headers to MCP servers, such as:

1. Allow sensitive headers when explicitly opted-in (e.g., `allow_sensitive_headers=True`)
2. Support a callback/function that provides the token at request time
3. Support inline token refresh mechanisms

## Code Example

```python
from azure.ai.projects.models import MCPTool

# This fails with the error above
mcp_tool = MCPTool(
server_label="custom-mcp",
server_url="https://example.com/api/mcp",
require_approval="never",
headers={"Authorization": f"Bearer {dynamic_token}"},
)
```

## Environment

- Package: `azure-ai-projects>=2.0.0b1`
- Python: 3.x

## Additional Context

This limitation prevents using `MCPTool` with any MCP server that requires client-generated bearer tokens for authentication.

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne mit der im Issue beschriebenen Verwendung von MCPTool und dem Validierungsverhalten für sensitive-header und verfolge anschließend, wie headers und project_connection_id verarbeitet werden. Fertig ist die Aufgabe, wenn MCP servers vom Client generierte bearer tokens empfangen können, die zur Laufzeit erneuert werden können, ohne nicht unterstützte sensitive headers offenzulegen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
azure, python
Bereich
api, authentication, backend
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.