Skip to content

types: Setting default value for method: Literal #1292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 3 additions & 28 deletions src/mcp/client/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ async def initialize(self) -> types.InitializeResult:
result = await self.send_request(
types.ClientRequest(
types.InitializeRequest(
method="initialize",
params=types.InitializeRequestParams(
protocolVersion=types.LATEST_PROTOCOL_VERSION,
capabilities=types.ClientCapabilities(
Expand All @@ -170,20 +169,14 @@ async def initialize(self) -> types.InitializeResult:
if result.protocolVersion not in SUPPORTED_PROTOCOL_VERSIONS:
raise RuntimeError(f"Unsupported protocol version from the server: {result.protocolVersion}")

await self.send_notification(
types.ClientNotification(types.InitializedNotification(method="notifications/initialized"))
)
await self.send_notification(types.ClientNotification(types.InitializedNotification()))

return result

async def send_ping(self) -> types.EmptyResult:
"""Send a ping request."""
return await self.send_request(
types.ClientRequest(
types.PingRequest(
method="ping",
)
),
types.ClientRequest(types.PingRequest()),
types.EmptyResult,
)

Expand All @@ -198,7 +191,6 @@ async def send_progress_notification(
await self.send_notification(
types.ClientNotification(
types.ProgressNotification(
method="notifications/progress",
params=types.ProgressNotificationParams(
progressToken=progress_token,
progress=progress,
Expand All @@ -214,7 +206,6 @@ async def set_logging_level(self, level: types.LoggingLevel) -> types.EmptyResul
return await self.send_request(
types.ClientRequest(
types.SetLevelRequest(
method="logging/setLevel",
params=types.SetLevelRequestParams(level=level),
)
),
Expand All @@ -226,7 +217,6 @@ async def list_resources(self, cursor: str | None = None) -> types.ListResources
return await self.send_request(
types.ClientRequest(
types.ListResourcesRequest(
method="resources/list",
params=types.PaginatedRequestParams(cursor=cursor) if cursor is not None else None,
)
),
Expand All @@ -238,7 +228,6 @@ async def list_resource_templates(self, cursor: str | None = None) -> types.List
return await self.send_request(
types.ClientRequest(
types.ListResourceTemplatesRequest(
method="resources/templates/list",
params=types.PaginatedRequestParams(cursor=cursor) if cursor is not None else None,
)
),
Expand All @@ -250,7 +239,6 @@ async def read_resource(self, uri: AnyUrl) -> types.ReadResourceResult:
return await self.send_request(
types.ClientRequest(
types.ReadResourceRequest(
method="resources/read",
params=types.ReadResourceRequestParams(uri=uri),
)
),
Expand All @@ -262,7 +250,6 @@ async def subscribe_resource(self, uri: AnyUrl) -> types.EmptyResult:
return await self.send_request(
types.ClientRequest(
types.SubscribeRequest(
method="resources/subscribe",
params=types.SubscribeRequestParams(uri=uri),
)
),
Expand All @@ -274,7 +261,6 @@ async def unsubscribe_resource(self, uri: AnyUrl) -> types.EmptyResult:
return await self.send_request(
types.ClientRequest(
types.UnsubscribeRequest(
method="resources/unsubscribe",
params=types.UnsubscribeRequestParams(uri=uri),
)
),
Expand All @@ -293,7 +279,6 @@ async def call_tool(
result = await self.send_request(
types.ClientRequest(
types.CallToolRequest(
method="tools/call",
params=types.CallToolRequestParams(
name=name,
arguments=arguments,
Expand Down Expand Up @@ -337,7 +322,6 @@ async def list_prompts(self, cursor: str | None = None) -> types.ListPromptsResu
return await self.send_request(
types.ClientRequest(
types.ListPromptsRequest(
method="prompts/list",
params=types.PaginatedRequestParams(cursor=cursor) if cursor is not None else None,
)
),
Expand All @@ -349,7 +333,6 @@ async def get_prompt(self, name: str, arguments: dict[str, str] | None = None) -
return await self.send_request(
types.ClientRequest(
types.GetPromptRequest(
method="prompts/get",
params=types.GetPromptRequestParams(name=name, arguments=arguments),
)
),
Expand All @@ -370,7 +353,6 @@ async def complete(
return await self.send_request(
types.ClientRequest(
types.CompleteRequest(
method="completion/complete",
params=types.CompleteRequestParams(
ref=ref,
argument=types.CompletionArgument(**argument),
Expand All @@ -386,7 +368,6 @@ async def list_tools(self, cursor: str | None = None) -> types.ListToolsResult:
result = await self.send_request(
types.ClientRequest(
types.ListToolsRequest(
method="tools/list",
params=types.PaginatedRequestParams(cursor=cursor) if cursor is not None else None,
)
),
Expand All @@ -402,13 +383,7 @@ async def list_tools(self, cursor: str | None = None) -> types.ListToolsResult:

async def send_roots_list_changed(self) -> None:
"""Send a roots/list_changed notification."""
await self.send_notification(
types.ClientNotification(
types.RootsListChangedNotification(
method="notifications/roots/list_changed",
)
)
)
await self.send_notification(types.ClientNotification(types.RootsListChangedNotification()))

async def _received_request(self, responder: RequestResponder[types.ServerRequest, types.ClientResult]) -> None:
ctx = RequestContext[ClientSession, Any](
Expand Down
41 changes: 5 additions & 36 deletions src/mcp/server/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ async def send_log_message(
await self.send_notification(
types.ServerNotification(
types.LoggingMessageNotification(
method="notifications/message",
params=types.LoggingMessageNotificationParams(
level=level,
data=data,
Expand All @@ -202,7 +201,6 @@ async def send_resource_updated(self, uri: AnyUrl) -> None:
await self.send_notification(
types.ServerNotification(
types.ResourceUpdatedNotification(
method="notifications/resources/updated",
params=types.ResourceUpdatedNotificationParams(uri=uri),
)
)
Expand All @@ -225,7 +223,6 @@ async def create_message(
return await self.send_request(
request=types.ServerRequest(
types.CreateMessageRequest(
method="sampling/createMessage",
params=types.CreateMessageRequestParams(
messages=messages,
systemPrompt=system_prompt,
Expand All @@ -247,11 +244,7 @@ async def create_message(
async def list_roots(self) -> types.ListRootsResult:
"""Send a roots/list request."""
return await self.send_request(
types.ServerRequest(
types.ListRootsRequest(
method="roots/list",
)
),
types.ServerRequest(types.ListRootsRequest()),
types.ListRootsResult,
)

Expand All @@ -273,7 +266,6 @@ async def elicit(
return await self.send_request(
types.ServerRequest(
types.ElicitRequest(
method="elicitation/create",
params=types.ElicitRequestParams(
message=message,
requestedSchema=requestedSchema,
Expand All @@ -287,11 +279,7 @@ async def elicit(
async def send_ping(self) -> types.EmptyResult:
"""Send a ping request."""
return await self.send_request(
types.ServerRequest(
types.PingRequest(
method="ping",
)
),
types.ServerRequest(types.PingRequest()),
types.EmptyResult,
)

Expand All @@ -307,7 +295,6 @@ async def send_progress_notification(
await self.send_notification(
types.ServerNotification(
types.ProgressNotification(
method="notifications/progress",
params=types.ProgressNotificationParams(
progressToken=progress_token,
progress=progress,
Expand All @@ -321,33 +308,15 @@ async def send_progress_notification(

async def send_resource_list_changed(self) -> None:
"""Send a resource list changed notification."""
await self.send_notification(
types.ServerNotification(
types.ResourceListChangedNotification(
method="notifications/resources/list_changed",
)
)
)
await self.send_notification(types.ServerNotification(types.ResourceListChangedNotification()))

async def send_tool_list_changed(self) -> None:
"""Send a tool list changed notification."""
await self.send_notification(
types.ServerNotification(
types.ToolListChangedNotification(
method="notifications/tools/list_changed",
)
)
)
await self.send_notification(types.ServerNotification(types.ToolListChangedNotification()))

async def send_prompt_list_changed(self) -> None:
"""Send a prompt list changed notification."""
await self.send_notification(
types.ServerNotification(
types.PromptListChangedNotification(
method="notifications/prompts/list_changed",
)
)
)
await self.send_notification(types.ServerNotification(types.PromptListChangedNotification()))

async def _handle_incoming(self, req: ServerRequestResponder) -> None:
await self._incoming_message_stream_writer.send(req)
Expand Down
Loading
Loading