mirror of
https://github.com/aljazceru/mcp-python-sdk.git
synced 2025-12-19 14:54:24 +01:00
Merge pull request #15 from modelcontextprotocol/davidsp/type-fixes
Type Fixes
This commit is contained in:
@@ -20,6 +20,8 @@ from mcp_python.types import (
|
|||||||
CompleteRequest,
|
CompleteRequest,
|
||||||
ErrorData,
|
ErrorData,
|
||||||
JSONRPCMessage,
|
JSONRPCMessage,
|
||||||
|
ListPromptsRequest,
|
||||||
|
ListPromptsResult,
|
||||||
ListResourcesRequest,
|
ListResourcesRequest,
|
||||||
ListResourcesResult,
|
ListResourcesResult,
|
||||||
LoggingLevel,
|
LoggingLevel,
|
||||||
@@ -57,8 +59,6 @@ class Server:
|
|||||||
return request_ctx.get()
|
return request_ctx.get()
|
||||||
|
|
||||||
def list_prompts(self):
|
def list_prompts(self):
|
||||||
from mcp_python.types import ListPromptsRequest, ListPromptsResult
|
|
||||||
|
|
||||||
def decorator(func: Callable[[], Awaitable[list[Prompt]]]):
|
def decorator(func: Callable[[], Awaitable[list[Prompt]]]):
|
||||||
logger.debug(f"Registering handler for PromptListRequest")
|
logger.debug(f"Registering handler for PromptListRequest")
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ class Server:
|
|||||||
|
|
||||||
async def handler(req: GetPromptRequest):
|
async def handler(req: GetPromptRequest):
|
||||||
prompt_get = await func(req.params.name, req.params.arguments)
|
prompt_get = await func(req.params.name, req.params.arguments)
|
||||||
messages = []
|
messages: list[SamplingMessage] = []
|
||||||
for message in prompt_get.messages:
|
for message in prompt_get.messages:
|
||||||
match message.content:
|
match message.content:
|
||||||
case str() as text_content:
|
case str() as text_content:
|
||||||
|
|||||||
@@ -7,10 +7,9 @@ from anyio.streams.memory import MemoryObjectReceiveStream, MemoryObjectSendStre
|
|||||||
|
|
||||||
from mcp_python.types import JSONRPCMessage
|
from mcp_python.types import JSONRPCMessage
|
||||||
|
|
||||||
|
|
||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
async def stdio_server(
|
async def stdio_server(
|
||||||
stdin: anyio.AsyncFile | None = None, stdout: anyio.AsyncFile | None = None
|
stdin: anyio.AsyncFile[str] | None = None, stdout: anyio.AsyncFile[str] | None = None
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Server transport for stdio: this communicates with an MCP client by reading from the current process' stdin and writing to stdout.
|
Server transport for stdio: this communicates with an MCP client by reading from the current process' stdin and writing to stdout.
|
||||||
|
|||||||
@@ -41,23 +41,23 @@ class NotificationParams(BaseModel):
|
|||||||
This parameter name is reserved by MCP to allow clients and servers to attach additional metadata to their notifications.
|
This parameter name is reserved by MCP to allow clients and servers to attach additional metadata to their notifications.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
RequestParamsT = TypeVar("RequestParamsT", bound=RequestParams)
|
RequestParamsT = TypeVar("RequestParamsT", bound=RequestParams)
|
||||||
NotificationParamsT = TypeVar("NotificationParamsT", bound=NotificationParams)
|
NotificationParamsT = TypeVar("NotificationParamsT", bound=NotificationParams)
|
||||||
|
MethodT = TypeVar("MethodT", bound=str)
|
||||||
|
|
||||||
|
|
||||||
class Request(BaseModel, Generic[RequestParamsT]):
|
class Request(BaseModel, Generic[RequestParamsT, MethodT]):
|
||||||
"""Base class for JSON-RPC requests."""
|
"""Base class for JSON-RPC requests."""
|
||||||
|
|
||||||
method: str
|
method: MethodT
|
||||||
params: RequestParamsT
|
params: RequestParamsT
|
||||||
model_config = ConfigDict(extra="allow")
|
model_config = ConfigDict(extra="allow")
|
||||||
|
|
||||||
|
|
||||||
class Notification(BaseModel, Generic[NotificationParamsT]):
|
class Notification(BaseModel, Generic[NotificationParamsT, MethodT]):
|
||||||
"""Base class for JSON-RPC notifications."""
|
"""Base class for JSON-RPC notifications."""
|
||||||
|
|
||||||
method: str
|
method: MethodT
|
||||||
model_config = ConfigDict(extra="allow")
|
model_config = ConfigDict(extra="allow")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ packages = ["mcp_python"]
|
|||||||
|
|
||||||
[tool.pyright]
|
[tool.pyright]
|
||||||
include = ["mcp_python", "tests"]
|
include = ["mcp_python", "tests"]
|
||||||
typeCheckingMode = "strict"
|
|
||||||
venvPath = "."
|
venvPath = "."
|
||||||
venv = ".venv"
|
venv = ".venv"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user