Repository navigation
Conversation
…LIT_SERVER_API_KEY - Avoid TypeError in issubclass() when handler parameter annotations are GenericAlias, Union, Optional, or inspect._empty, and skip re-instantiating existing BaseModel values. - Enforce LIT_SERVER_API_KEY via constant-time secrets.compare_digest on the ASGI-mounted MCP request handler when configured. Signed-off-by: Dr. Mohammed Lubbad <engmlubbad@gmail.com>
mlubbad
requested review from
Abdul-0x4A,
andyland,
dmitsf,
ethanwharris,
k223kim and
tchaton
as code owners
November 27, 2026 08:29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
As a LitServe user exposing endpoints over MCP, two issues affect production deployments:
Optional[MyModel],Union[...],dict[str, Any], or untyped parameters wherep.annotationisinspect._empty) raiseTypeError: issubclass() arg 1 must be a classinside_call_handler.LIT_SERVER_API_KEYis configured to protect the server, FastAPI routes enforceX-Api-Key, whereas the ASGI-mounted_MCPRequestHandleraccepted unauthenticated HTTP requests.Root Cause & Fix
_is_pydantic_model_class(annotation)wrappingisinstance(annotation, type) and issubclass(annotation, BaseModel)with aTypeErrorguard, and avoid re-wrapping values that are alreadyBaseModelinstances.LIT_SERVER_API_KEYin_MCPRequestHandler.__call__against thex-api-keyheader usingsecrets.compare_digest, returning HTTP401when missing or invalid.Verification
python3 -m py_compile src/litserve/mcp.py) andruff check src/litserve/mcp.py.Before submitting
LIT_SERVER_API_KEYbehavior)