Home / Function/ test_mcp_tracing() — langchain Function Reference

test_mcp_tracing() — langchain Function Reference

Architecture documentation for the test_mcp_tracing() function in test_chat_models.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  4458bece_22a6_ecd4_2b86_b612f46a6c71["test_mcp_tracing()"]
  18428dc5_a41b_90c6_88ad_615296ee3311["test_chat_models.py"]
  4458bece_22a6_ecd4_2b86_b612f46a6c71 -->|defined in| 18428dc5_a41b_90c6_88ad_615296ee3311
  style 4458bece_22a6_ecd4_2b86_b612f46a6c71 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/anthropic/tests/unit_tests/test_chat_models.py lines 1441–1484

def test_mcp_tracing() -> None:
    # Test we exclude sensitive information from traces
    mcp_servers = [
        {
            "type": "url",
            "url": "https://mcp.deepwiki.com/mcp",
            "name": "deepwiki",
            "authorization_token": "PLACEHOLDER",
        },
    ]

    llm = ChatAnthropic(
        model=MODEL_NAME,
        betas=["mcp-client-2025-04-04"],
        mcp_servers=mcp_servers,
    )

    tracer = FakeTracer()
    mock_client = MagicMock()

    def mock_create(*args: Any, **kwargs: Any) -> Message:
        return Message(
            id="foo",
            content=[TextBlock(type="text", text="bar")],
            model="baz",
            role="assistant",
            stop_reason=None,
            stop_sequence=None,
            usage=Usage(input_tokens=2, output_tokens=1),
            type="message",
        )

    mock_client.messages.create = mock_create
    input_message = HumanMessage("Test query")
    with patch.object(llm, "_client", mock_client):
        _ = llm.invoke([input_message], config={"callbacks": [tracer]})

    # Test headers are not traced
    assert len(tracer.chat_model_start_inputs) == 1
    assert "PLACEHOLDER" not in str(tracer.chat_model_start_inputs)

    # Test headers are correctly propagated to request
    payload = llm._get_request_payload([input_message])
    assert payload["mcp_servers"][0]["authorization_token"] == "PLACEHOLDER"  # noqa: S105

Domain

Subdomains

Frequently Asked Questions

What does test_mcp_tracing() do?
test_mcp_tracing() is a function in the langchain codebase, defined in libs/partners/anthropic/tests/unit_tests/test_chat_models.py.
Where is test_mcp_tracing() defined?
test_mcp_tracing() is defined in libs/partners/anthropic/tests/unit_tests/test_chat_models.py at line 1441.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free