Skip to content

Commit b125fbc

Browse files
Merge branch 'main' into feat/audio-content
2 parents f9e6d56 + 5441767 commit b125fbc

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
@@ -147,7 +147,7 @@ def __init__(
147147
}
148148
self.notification_handlers: dict[type, Callable[..., Awaitable[None]]] = {}
149149
self.notification_options = NotificationOptions()
150-
logger.debug(f"Initializing server '{name}'")
150+
logger.debug("Initializing server %r", name)
151151

152152
def create_initialization_options(
153153
self,
@@ -513,7 +513,7 @@ async def run(
513513

514514
async with anyio.create_task_group() as tg:
515515
async for message in session.incoming_messages:
516-
logger.debug(f"Received message: {message}")
516+
logger.debug("Received message: %s", message)
517517

518518
tg.start_soon(
519519
self._handle_message,
@@ -546,7 +546,9 @@ async def _handle_message(
546546
await self._handle_notification(notify)
547547

548548
for warning in w:
549-
logger.info(f"Warning: {warning.category.__name__}: {warning.message}")
549+
logger.info(
550+
"Warning: %s: %s", warning.category.__name__, warning.message
551+
)
550552

551553
async def _handle_request(
552554
self,
@@ -556,10 +558,9 @@ async def _handle_request(
556558
lifespan_context: LifespanResultT,
557559
raise_exceptions: bool,
558560
):
559-
logger.info(f"Processing request of type {type(req).__name__}")
560-
if type(req) in self.request_handlers:
561-
handler = self.request_handlers[type(req)]
562-
logger.debug(f"Dispatching request of type {type(req).__name__}")
561+
logger.info("Processing request of type %s", type(req).__name__)
562+
if handler := self.request_handlers.get(type(req)): # type: ignore
563+
logger.debug("Dispatching request of type %s", type(req).__name__)
563564

564565
token = None
565566
try:
@@ -605,16 +606,13 @@ async def _handle_request(
605606
logger.debug("Response sent")
606607

607608
async def _handle_notification(self, notify: Any):
608-
if type(notify) in self.notification_handlers:
609-
assert type(notify) in self.notification_handlers
610-
611-
handler = self.notification_handlers[type(notify)]
612-
logger.debug(f"Dispatching notification of type {type(notify).__name__}")
609+
if handler := self.notification_handlers.get(type(notify)): # type: ignore
610+
logger.debug("Dispatching notification of type %s", type(notify).__name__)
613611

614612
try:
615613
await handler(notify)
616-
except Exception as err:
617-
logger.error(f"Uncaught exception in notification handler: {err}")
614+
except Exception:
615+
logger.exception("Uncaught exception in notification handler")
618616

619617

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

0 commit comments

Comments
 (0)