Skip to content

Commit e304743

Browse files
committed
fix: widen Context.log level to full LoggingLevel
The MCP spec defines 8 RFC-5424 syslog severity levels (debug, info, notice, warning, error, critical, alert, emergency). Context.log previously only accepted 4 of them via a local Literal, even though ServerSession.send_log_message and LoggingMessageNotificationParams already accept the full LoggingLevel type. The debug/info/warning/error convenience methods are unchanged; they cover the common cases. Callers needing the other levels go through ctx.log() directly. Github-Issue: #397
1 parent b7d51fd commit e304743

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/mcp/server/mcpserver/context.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from collections.abc import Iterable
4-
from typing import TYPE_CHECKING, Any, Generic, Literal
4+
from typing import TYPE_CHECKING, Any, Generic
55

66
from pydantic import AnyUrl, BaseModel
77

@@ -14,6 +14,7 @@
1414
elicit_with_validation,
1515
)
1616
from mcp.server.lowlevel.helper_types import ReadResourceContents
17+
from mcp.types import LoggingLevel
1718

1819
if TYPE_CHECKING:
1920
from mcp.server.mcpserver.server import MCPServer
@@ -186,15 +187,16 @@ async def elicit_url(
186187

187188
async def log(
188189
self,
189-
level: Literal["debug", "info", "warning", "error"],
190+
level: LoggingLevel,
190191
data: Any,
191192
*,
192193
logger_name: str | None = None,
193194
) -> None:
194195
"""Send a log message to the client.
195196
196197
Args:
197-
level: Log level (debug, info, warning, error)
198+
level: Log level (debug, info, notice, warning, error, critical,
199+
alert, emergency)
198200
data: The data to be logged. Any JSON serializable type is allowed
199201
(string, dict, list, number, bool, etc.) per the MCP specification.
200202
logger_name: Optional logger name

0 commit comments

Comments
 (0)