Skip to content

Commit b6e4576

Browse files
committed
type instead of try/except
1 parent e402103 commit b6e4576

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

src/mcp/server/lowlevel/server.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ async def _handle_message(
514514

515515
async def _handle_request(
516516
self,
517-
message: RequestResponder,
517+
message: RequestResponder[types.ClientRequest, types.ServerResult],
518518
req: Any,
519519
session: ServerSession,
520520
lifespan_context: LifespanResultT,
@@ -526,12 +526,6 @@ async def _handle_request(
526526
logger.debug(f"Dispatching request of type {type(req).__name__}")
527527

528528
token = None
529-
headers = {}
530-
try:
531-
# TODO: This try/catch and ignoring the type is wrong.
532-
headers = message.request.root.headers # type: ignore
533-
except Exception:
534-
pass
535529
try:
536530
# Set our global state that can be retrieved via
537531
# app.get_request_context()
@@ -541,7 +535,7 @@ async def _handle_request(
541535
message.request_meta,
542536
session,
543537
lifespan_context,
544-
headers,
538+
message.request.root.headers or {},
545539
)
546540
)
547541
response = await handler(req)

src/mcp/types.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class Request(BaseModel, Generic[RequestParamsT, MethodT]):
7474

7575
method: MethodT
7676
params: RequestParamsT
77+
headers: dict[str, str] | None = None
7778
model_config = ConfigDict(extra="allow")
7879

7980

@@ -118,7 +119,6 @@ class JSONRPCRequest(Request):
118119
jsonrpc: Literal["2.0"]
119120
id: RequestId
120121
params: dict[str, Any] | None = None
121-
headers: dict[str, str] | None = None
122122

123123

124124
class JSONRPCNotification(Notification):

0 commit comments

Comments
 (0)