Skip to content

Commit d071440

Browse files
SachinSachin
authored andcommitted
Log prompt validation errors without unnecessary traceback
When a prompt is called without a required argument, the ValueError is an expected validation failure. Previously it was logged with logger.exception() which includes a full traceback, cluttering server logs. Now ValueError is caught separately and logged with logger.warning() (message only), while truly unexpected exceptions still get the full traceback via logger.exception(). Fixes #3342
1 parent 57394b0 commit d071440

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/mcp/server/mcpserver/server.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,12 @@ async def get_prompt(
12981298
)
12991299
except MCPError:
13001300
raise
1301+
except ValueError as e:
1302+
# Expected validation errors (e.g. missing required arguments)
1303+
# don't need a full traceback — a warning with the message is
1304+
# enough for server operators to diagnose the problem.
1305+
logger.warning(f"Error getting prompt {name}: {e}")
1306+
raise
13011307
except Exception as e:
13021308
logger.exception(f"Error getting prompt {name}")
13031309
raise ValueError(str(e)) from e

0 commit comments

Comments
 (0)