Skip to content

Commit 0074659

Browse files
early returns
1 parent 5477c8e commit 0074659

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

sentry_sdk/integrations/mcp.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -432,11 +432,13 @@ async def _instrument_v2_tool_call(
432432
Instrument a tool call as observed by the MCP Server middleware.
433433
Creates and manages the MCP span and attaches all attributes on the span.
434434
"""
435-
if ctx.params is None:
435+
if ctx.params is None or ctx.params.get("name") is None:
436436
return await call_next(ctx)
437437

438438
handler_name = ctx.params["name"]
439-
arguments = ctx.params["arguments"]
439+
arguments = ctx.params.get("arguments")
440+
if arguments is None:
441+
arguments = {}
440442

441443
# Get request ID, session ID, and transport from context
442444
request_id, session_id, mcp_transport = _get_request_context_data(ctx=ctx)
@@ -679,11 +681,13 @@ async def _instrument_v2_prompt_get(
679681
Instrument a prompt retrieval as observed by the MCP Server middleware.
680682
Creates and manages the MCP span and attaches all attributes on the span.
681683
"""
682-
if ctx.params is None:
684+
if ctx.params is None or ctx.params.get("name") is None:
683685
return await call_next(ctx)
684686

685687
handler_name = ctx.params["name"]
686-
arguments = ctx.params["arguments"]
688+
arguments = ctx.params.get("arguments")
689+
if arguments is None:
690+
arguments = {}
687691

688692
# Get request ID, session ID, and transport from context
689693
request_id, session_id, mcp_transport = _get_request_context_data(ctx=ctx)
@@ -903,7 +907,7 @@ async def _instrument_v2_resource_read(
903907
Instrument getting a resource as observed by the MCP Server middleware.
904908
Creates and manages the MCP span and attaches all attributes on the span.
905909
"""
906-
if ctx.params is None:
910+
if ctx.params is None or ctx.params.get("uri") is None:
907911
return await call_next(ctx)
908912

909913
handler_name = ctx.params["uri"]

0 commit comments

Comments
 (0)