Skip to content

Commit 40ad4c9

Browse files
Copilotstephentoub
andcommitted
Address PR feedback: simplify TryGetOuterToolExecutionActivity, remove comments, use pattern matching
- Invert if statement in TryGetOuterToolExecutionActivity to avoid multiple return false - Remove "Per MCP" comment in McpSessionHandler - Use pattern matching `is "tcp"` instead of `== "tcp"` - Remove redundant DisplayName setting (StartActivity already sets it via CreateActivityName) Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
1 parent 44cf972 commit 40ad4c9

2 files changed

Lines changed: 4 additions & 16 deletions

File tree

src/ModelContextProtocol.Core/Diagnostics.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,10 @@ internal static bool ShouldInstrumentMessage(JsonRpcMessage message) =>
105105
/// <returns>true if an outer tool execution activity was found and can be reused; false otherwise.</returns>
106106
internal static bool TryGetOuterToolExecutionActivity([NotNullWhen(true)] out Activity? activity)
107107
{
108-
activity = Activity.Current;
109-
if (activity is null)
110-
{
111-
return false;
112-
}
113-
114-
// Check if the current activity name indicates a tool execution (e.g., "execute_tool toolName")
115-
if (activity.OperationName.StartsWith("execute_tool ", StringComparison.Ordinal))
108+
if (Activity.Current is { } currentActivity &&
109+
currentActivity.OperationName.StartsWith("execute_tool ", StringComparison.Ordinal))
116110
{
111+
activity = currentActivity;
117112
return true;
118113
}
119114

src/ModelContextProtocol.Core/McpSessionHandler.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ public McpSessionHandler(
8484
{
8585
Throw.IfNull(transport);
8686

87-
// Per MCP semantic conventions: "pipe" for stdio, "tcp" or "quic" for HTTP
88-
// https://github.com/open-telemetry/semantic-conventions/blob/main/docs/gen-ai/mcp.md#recording-mcp-transport
8987
_transportKind = transport switch
9088
{
9189
StdioClientSessionTransport or StdioServerTransport => "pipe",
@@ -666,7 +664,7 @@ private void AddTags(ref TagList tags, Activity? activity, JsonRpcMessage messag
666664
tags.Add("mcp.method.name", method);
667665
tags.Add("network.transport", _transportKind);
668666

669-
if (_transportKind == "tcp")
667+
if (_transportKind is "tcp")
670668
{
671669
tags.Add("network.protocol.name", "http");
672670
}
@@ -684,11 +682,6 @@ private void AddTags(ref TagList tags, Activity? activity, JsonRpcMessage messag
684682
{
685683
activity.AddTag("jsonrpc.request.id", withId.Id.Id?.ToString());
686684
}
687-
688-
if (!usingOuterActivity && target is not null)
689-
{
690-
activity.DisplayName = $"{method} {target}";
691-
}
692685
}
693686

694687
switch (method)

0 commit comments

Comments
 (0)