-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat: support setting title and description for server #1793
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,6 +83,62 @@ async def run_server(): | |
| assert received_initialized | ||
|
|
||
|
|
||
| @pytest.mark.anyio | ||
| async def test_server_session_initialize_with_title_and_description(): | ||
| """Test that server_title and server_description are passed through to serverInfo.""" | ||
| server_to_client_send, server_to_client_receive = anyio.create_memory_object_stream[SessionMessage](1) | ||
| client_to_server_send, client_to_server_receive = anyio.create_memory_object_stream[SessionMessage](1) | ||
|
|
||
| async def message_handler( | ||
| message: RequestResponder[types.ServerRequest, types.ClientResult] | types.ServerNotification | Exception, | ||
| ) -> None: | ||
| if isinstance(message, Exception): | ||
| raise message | ||
|
|
||
| async def run_server(): | ||
| async with ServerSession( | ||
| client_to_server_receive, | ||
| server_to_client_send, | ||
| InitializationOptions( | ||
| server_name="test-server", | ||
| server_version="1.0.0", | ||
| server_title="Test Server Title", | ||
| server_description="A description of what this server does.", | ||
| capabilities=ServerCapabilities(), | ||
| ), | ||
| ) as server_session: | ||
| async for message in server_session.incoming_messages: # pragma: no branch | ||
| if isinstance(message, Exception): # pragma: no cover | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove pragma, instead just fail if there's an exception |
||
| raise message | ||
|
|
||
| if isinstance(message, ClientNotification) and isinstance( | ||
| message.root, InitializedNotification | ||
| ): # pragma: no branch | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove all pragmas if possible, use asserts with failures instead |
||
| return | ||
|
|
||
| result: types.InitializeResult | None = None | ||
| try: | ||
| async with ( | ||
| ClientSession( | ||
| server_to_client_receive, | ||
| client_to_server_send, | ||
| message_handler=message_handler, | ||
| ) as client_session, | ||
| anyio.create_task_group() as tg, | ||
| ): | ||
| tg.start_soon(run_server) | ||
|
|
||
| result = await client_session.initialize() | ||
| except anyio.ClosedResourceError: # pragma: no cover | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove exception catching and either accept it through asserts or fail |
||
| pass | ||
|
|
||
| assert result is not None | ||
| assert result.serverInfo.name == "test-server" | ||
| assert result.serverInfo.title == "Test Server Title" | ||
| assert result.serverInfo.version == "1.0.0" | ||
| assert result.serverInfo.description == "A description of what this server does." | ||
|
|
||
|
|
||
| @pytest.mark.anyio | ||
| async def test_server_capabilities(): | ||
| server = Server("test") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to bottom to avoid positional kwarg errors