Skip to content

Commit 118a643

Browse files
authored
Merge branch 'main' into enforce-120-length
2 parents bcd2734 + 5441767 commit 118a643

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/mcp/server/lowlevel/server.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def __init__(
143143
}
144144
self.notification_handlers: dict[type, Callable[..., Awaitable[None]]] = {}
145145
self.notification_options = NotificationOptions()
146-
logger.debug(f"Initializing server '{name}'")
146+
logger.debug("Initializing server %r", name)
147147

148148
def create_initialization_options(
149149
self,
@@ -483,7 +483,7 @@ async def run(
483483

484484
async with anyio.create_task_group() as tg:
485485
async for message in session.incoming_messages:
486-
logger.debug(f"Received message: {message}")
486+
logger.debug("Received message: %s", message)
487487

488488
tg.start_soon(
489489
self._handle_message,
@@ -510,7 +510,9 @@ async def _handle_message(
510510
await self._handle_notification(notify)
511511

512512
for warning in w:
513-
logger.info(f"Warning: {warning.category.__name__}: {warning.message}")
513+
logger.info(
514+
"Warning: %s: %s", warning.category.__name__, warning.message
515+
)
514516

515517
async def _handle_request(
516518
self,
@@ -520,10 +522,9 @@ async def _handle_request(
520522
lifespan_context: LifespanResultT,
521523
raise_exceptions: bool,
522524
):
523-
logger.info(f"Processing request of type {type(req).__name__}")
524-
if type(req) in self.request_handlers:
525-
handler = self.request_handlers[type(req)]
526-
logger.debug(f"Dispatching request of type {type(req).__name__}")
525+
logger.info("Processing request of type %s", type(req).__name__)
526+
if handler := self.request_handlers.get(type(req)): # type: ignore
527+
logger.debug("Dispatching request of type %s", type(req).__name__)
527528

528529
token = None
529530
try:
@@ -567,16 +568,13 @@ async def _handle_request(
567568
logger.debug("Response sent")
568569

569570
async def _handle_notification(self, notify: Any):
570-
if type(notify) in self.notification_handlers:
571-
assert type(notify) in self.notification_handlers
572-
573-
handler = self.notification_handlers[type(notify)]
574-
logger.debug(f"Dispatching notification of type {type(notify).__name__}")
571+
if handler := self.notification_handlers.get(type(notify)): # type: ignore
572+
logger.debug("Dispatching notification of type %s", type(notify).__name__)
575573

576574
try:
577575
await handler(notify)
578-
except Exception as err:
579-
logger.error(f"Uncaught exception in notification handler: {err}")
576+
except Exception:
577+
logger.exception("Uncaught exception in notification handler")
580578

581579

582580
async def _ping_handler(request: types.PingRequest) -> types.ServerResult:

0 commit comments

Comments
 (0)