Skip to content

Python: Add server identity to telemetry - #10571

Open
Eduard van Valkenburg (eavanvalkenburg) wants to merge 5 commits into
microsoft:mainfrom
kshitij-microsoft:kchawla/mcp-server-identity-telemetry
Open

Eduard van Valkenburg (eavanvalkenburg) wants to merge 5 commits into
microsoft:mainfrom
kshitij-microsoft:kchawla/mcp-server-identity-telemetry

Conversation

@eavanvalkenburg

Copy link
Copy Markdown
Member

Motivation & Context

Description & Review Guide

  • What are the major changes?
  • What is the impact of these changes?
  • What do you want reviewers to focus on?

Related Issue

Fixes #

AI Assistance

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details:

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Preserve the configured MCP server name and filtered HTTP URL on generated tool functions and execution spans. Add focused identity regression tests.

Authored-by: GitHub Copilot for VS Code

Model: GPT-6.1 Sol

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The MCP server identity change adds _mcp_server_name to MCP function additional_properties, so the exact-match assertion in test_plain_mcp_tool_remains_unlabeled now expects it.

Authored-by: GitHub Copilot for VS Code

Model: Claude Sonnet 5.5
…te_tool spans

Derive the standard endpoint attributes from the sanitized MCP server URL (no path), consistent with MCP client spans, and document that microsoft.tool.server.name is the configured alias rather than server.service.name. Add a discovery-to-exported-span test covering both sensitive-data modes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Current main rejects tool calls on a caller-supplied HTTP session until its header identity is bound. Bind it in the discovery-to-span test so the test exercises the span path.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings December 3, 2026 13:37
@github-actions github-actions Bot added the python Usage: [Issues, PRs], Target: Python label Dec 3, 2026
@github-actions github-actions Bot changed the title Add server identity to telemetry Python: Add server identity to telemetry Dec 3, 2026

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

Caller-supplied MCP URLs bypass sanitization, allowing credential and token leaks or exceptions that prevent tool execution.

1 open issue
What changed in this PR

Adds MCP server identity to Python tool-execution telemetry so calls can be attributed to their configured server.

Changes:

  • Attach server names and sanitized URLs during MCP tool discovery.
  • Emit endpoint attributes, with URL paths gated by sensitive-data capture.
  • Add identity and redaction tests; update security-test expectations.
File Description
python/​packages/​core/​tests/​test_security.py Update expected MCP metadata.
python/​packages/​core/​tests/​core/​test_mcp_observability.py Test server identity, URL sanitization, and path redaction.
python/​packages/​core/​agent_framework/​observability.py Add server identity and endpoint span attributes.
python/​packages/​core/​agent_framework/​_mcp.py Sanitize server URLs and attach discovery metadata.

Review effort: Balanced

Comment on lines +2741 to +2750
# The path can embed credentials (for example ``/token/<secret>/mcp``), so it is only emitted when
# sensitive-data capture is enabled. Otherwise only scheme, host and port are recorded.
if not OBSERVABILITY_SETTINGS.SENSITIVE_DATA_ENABLED:
server_url = _strip_url_path(server_url)
attributes[OtelAttr.URL_FULL] = server_url
# Standard endpoint attributes, consistent with the MCP client spans. Neither carries the path.
parsed = urlparse(server_url)
if parsed.hostname:
attributes[OtelAttr.ADDRESS] = parsed.hostname
attributes[OtelAttr.PORT] = parsed.port or (443 if parsed.scheme == "https" else 80)
return f"{parts.scheme}://{netloc}{parts.path}"


def _mcp_server_identity_properties(tool: Any) -> dict[str, str]:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this should not be any, the scope of usage of this function is quite limited, so we should type it more clearly.

_MCP_REMOTE_NAME_KEY: tool.name,
_MCP_NORMALIZED_NAME_KEY: normalized_name,
_MCP_IS_TOOL_KEY: True,
**_mcp_server_identity_properties(self),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this is called for each tool, can we move it into the outer scope and call it once?

# ``service.name``, so it is deliberately not mapped to ``server.service.name``. The URL is stored already
# stripped of credentials and query string; its path is dropped at emit time unless sensitive-data capture is
# enabled.
MCP_SERVER_NAME_PROPERTY = "_mcp_server_name"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

these two should be private, so:

Suggested change
MCP_SERVER_NAME_PROPERTY = "_mcp_server_name"
_MCP_SERVER_NAME_PROPERTY = "_mcp_server_name"

Comment on lines +2741 to +2744
# The path can embed credentials (for example ``/token/<secret>/mcp``), so it is only emitted when
# sensitive-data capture is enabled. Otherwise only scheme, host and port are recorded.
if not OBSERVABILITY_SETTINGS.SENSITIVE_DATA_ENABLED:
server_url = _strip_url_path(server_url)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm not sure why we would send the path parts with potential creds even when sensitive data is enabled, can't we just strip that from the URL once in the setting and then treat it the same here?

This branch has not been deployed

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

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants