-
Notifications
You must be signed in to change notification settings - Fork 7
feat: add SSE transport support and refactor CLI arg parsing #6
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
Merged
+201
−3
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| """Tests for the main() entrypoint CLI argument parsing.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| from unittest.mock import MagicMock, patch | ||
|
|
||
| import pytest | ||
|
|
||
| import server as server_mod | ||
| from server import build_arg_parser | ||
|
|
||
|
|
||
| class TestMainArgParsing: | ||
| """Tests for CLI argument parsing in main().""" | ||
|
|
||
| def _parse_args(self, argv: list[str]) -> argparse.Namespace: | ||
| """Parse args using the real CLI parser from server.py.""" | ||
| return build_arg_parser().parse_args(argv) | ||
|
|
||
| def test_default_transport_is_stdio(self): | ||
| """Default transport should be stdio.""" | ||
| args = self._parse_args([]) | ||
| assert args.transport == "stdio" | ||
|
|
||
| def test_default_port_is_8765(self): | ||
| """Default SSE port should be 8765.""" | ||
| args = self._parse_args([]) | ||
| assert args.port == 8765 | ||
|
|
||
| def test_default_host_is_localhost(self): | ||
| """Default SSE host should be 127.0.0.1.""" | ||
| args = self._parse_args([]) | ||
| assert args.host == "127.0.0.1" | ||
|
|
||
| def test_sse_transport_flag(self): | ||
| """--transport sse should set transport to sse.""" | ||
| args = self._parse_args(["--transport", "sse"]) | ||
| assert args.transport == "sse" | ||
|
|
||
| def test_custom_port(self): | ||
| """--port should accept a custom port number.""" | ||
| args = self._parse_args(["--transport", "sse", "--port", "9000"]) | ||
| assert args.port == 9000 | ||
|
|
||
| def test_custom_host(self): | ||
| """--host should accept a custom host.""" | ||
| args = self._parse_args(["--transport", "sse", "--host", "0.0.0.0"]) | ||
| assert args.host == "0.0.0.0" | ||
|
|
||
| def test_invalid_transport_raises_error(self): | ||
| """Invalid transport should raise SystemExit.""" | ||
| with pytest.raises(SystemExit): | ||
| self._parse_args(["--transport", "invalid"]) | ||
|
|
||
|
|
||
| class TestMainRunsBehavior: | ||
| """Tests that main() calls mcp.run() with the correct arguments.""" | ||
|
|
||
| def test_stdio_calls_run_with_stdio(self): | ||
| """main() with no args should call mcp.run(transport='stdio').""" | ||
| with patch("sys.argv", ["code-memory"]): | ||
| with patch.object(server_mod, "mcp") as mock_mcp: | ||
| mock_mcp.settings = MagicMock() | ||
| server_mod.main() | ||
| mock_mcp.run.assert_called_once_with(transport="stdio") | ||
|
|
||
| def test_sse_calls_run_with_sse(self): | ||
| """main() with --transport sse should call mcp.run(transport='sse').""" | ||
| with patch("sys.argv", ["code-memory", "--transport", "sse"]): | ||
| with patch.object(server_mod, "mcp") as mock_mcp: | ||
| mock_mcp.settings = MagicMock() | ||
| server_mod.main() | ||
| mock_mcp.run.assert_called_once_with(transport="sse") | ||
|
|
||
| def test_sse_sets_port_on_settings(self): | ||
| """main() with --transport sse --port 9000 should set mcp.settings.port.""" | ||
| with patch("sys.argv", ["code-memory", "--transport", "sse", "--port", "9000"]): | ||
| with patch.object(server_mod, "mcp") as mock_mcp: | ||
| mock_mcp.settings = MagicMock() | ||
| server_mod.main() | ||
| assert mock_mcp.settings.port == 9000 | ||
|
|
||
| def test_sse_sets_host_on_settings(self): | ||
| """main() with --transport sse --host 0.0.0.0 should set mcp.settings.host.""" | ||
| with patch("sys.argv", ["code-memory", "--transport", "sse", "--host", "0.0.0.0"]): | ||
| with patch.object(server_mod, "mcp") as mock_mcp: | ||
| mock_mcp.settings = MagicMock() | ||
| server_mod.main() | ||
| assert mock_mcp.settings.host == "0.0.0.0" | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
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.
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.
from server import build_arg_parserimportsserver.pyat test module import time. Sinceserver.pyimportsdb.py, which importssqlite_vecat module import time, these arg-parsing tests will error (not skip) in environments wheresqlite_vecisn't installed. To make the tests robust, either importserverlazily inside the tests afterpytest.importorskip(...), or movebuild_arg_parser()into a lightweight module that doesn’t import the full server stack.