-
Notifications
You must be signed in to change notification settings - Fork 80
feat: add search_documents tool for Redis documentation queries #87
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
+856
−5
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a2f65d9
feat: add search_documents tool for Redis documentation queries
vchomakov 6fd8955
chore(deps): update aiohttp minimum version to 3.13.0
vchomakov e27461e
docs: document docs search tool in README
vchomakov 9046edb
test: add unit tests for docs search tool
vchomakov abaa9e1
refactor: rename docs search tool to search_redis_documents
vchomakov 6d6ad05
docs: remove docs search tool config from README
vchomakov 230e1a5
refactor: use MCP server version in docs tool user agent
vchomakov 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
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,136 @@ | ||
| import pytest | ||
|
|
||
| import src.tools.misc as misc | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_search_redis_documents_url_not_configured(monkeypatch): | ||
| """Return a clear error if MCP_DOCS_SEARCH_URL is not set for search_redis_documents.""" | ||
| monkeypatch.setattr(misc, "MCP_DOCS_SEARCH_URL", "") | ||
|
|
||
| result = await misc.search_redis_documents("What is Redis?") | ||
|
|
||
| assert isinstance(result, dict) | ||
| assert ( | ||
| result["error"] == "MCP_DOCS_SEARCH_URL environment variable is not configured" | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_search_redis_documents_empty_question(monkeypatch): | ||
| """Reject empty/whitespace-only questions for search_redis_documents.""" | ||
| monkeypatch.setattr(misc, "MCP_DOCS_SEARCH_URL", "https://example.com/docs") | ||
|
|
||
| result = await misc.search_redis_documents(" ") | ||
|
|
||
| assert isinstance(result, dict) | ||
| assert result["error"] == "Question parameter cannot be empty" | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_search_redis_documents_success_json_response(monkeypatch): | ||
| """Return parsed JSON when the docs API responds with JSON for search_redis_documents.""" | ||
|
|
||
| class DummyResponse: | ||
| async def __aenter__(self): | ||
| return self | ||
|
|
||
| async def __aexit__(self, exc_type, exc, tb): | ||
| return False | ||
|
|
||
| async def json(self): | ||
| return {"results": [{"title": "Redis Intro"}]} | ||
|
|
||
| class DummySession: | ||
| async def __aenter__(self): | ||
| return self | ||
|
|
||
| async def __aexit__(self, exc_type, exc, tb): | ||
| return False | ||
|
|
||
| def get(self, *_, **__): # pragma: no cover - trivial wrapper | ||
| return DummyResponse() | ||
|
|
||
| monkeypatch.setattr(misc, "MCP_DOCS_SEARCH_URL", "https://example.com/docs") | ||
| monkeypatch.setattr(misc.aiohttp, "ClientSession", DummySession) | ||
|
|
||
| result = await misc.search_redis_documents("What is a Redis stream?") | ||
|
|
||
| assert isinstance(result, dict) | ||
| assert result["results"][0]["title"] == "Redis Intro" | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_search_redis_documents_non_json_response(monkeypatch): | ||
| """If the response is not JSON, surface the text content in an error from search_redis_documents.""" | ||
|
|
||
| class DummyContentTypeError(Exception): | ||
| pass | ||
|
|
||
| class DummyResponse: | ||
| async def __aenter__(self): | ||
| return self | ||
|
|
||
| async def __aexit__(self, exc_type, exc, tb): | ||
| return False | ||
|
|
||
| async def json(self): | ||
| raise DummyContentTypeError("Not JSON") | ||
|
|
||
| async def text(self): | ||
| return "<html>not json</html>" | ||
|
|
||
| class DummySession: | ||
| async def __aenter__(self): | ||
| return self | ||
|
|
||
| async def __aexit__(self, exc_type, exc, tb): | ||
| return False | ||
|
|
||
| def get(self, *_, **__): # pragma: no cover - trivial wrapper | ||
| return DummyResponse() | ||
|
|
||
| monkeypatch.setattr(misc, "MCP_DOCS_SEARCH_URL", "https://example.com/docs") | ||
| # Patch aiohttp.ContentTypeError to our dummy so the except block matches | ||
| monkeypatch.setattr(misc.aiohttp, "ContentTypeError", DummyContentTypeError) | ||
| monkeypatch.setattr(misc.aiohttp, "ClientSession", DummySession) | ||
|
|
||
| result = await misc.search_redis_documents("Explain Redis JSON") | ||
|
|
||
| assert isinstance(result, dict) | ||
| assert "Non-JSON response" in result["error"] | ||
| assert "not json" in result["error"] | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_search_redis_documents_http_client_error(monkeypatch): | ||
| """HTTP client errors from search_redis_documents are caught and returned in an error dict.""" | ||
|
|
||
| class DummyClientError(Exception): | ||
| pass | ||
|
|
||
| class ErrorResponse: | ||
| async def __aenter__(self): | ||
| raise DummyClientError("boom") | ||
|
|
||
| async def __aexit__(self, exc_type, exc, tb): | ||
| return False | ||
|
|
||
| class DummySession: | ||
| async def __aenter__(self): | ||
| return self | ||
|
|
||
| async def __aexit__(self, exc_type, exc, tb): | ||
| return False | ||
|
|
||
| def get(self, *_, **__): # pragma: no cover - trivial wrapper | ||
| return ErrorResponse() | ||
|
|
||
| monkeypatch.setattr(misc, "MCP_DOCS_SEARCH_URL", "https://example.com/docs") | ||
| monkeypatch.setattr(misc.aiohttp, "ClientError", DummyClientError) | ||
| monkeypatch.setattr(misc.aiohttp, "ClientSession", DummySession) | ||
|
|
||
| result = await misc.search_redis_documents("What is Redis?") | ||
|
|
||
| assert isinstance(result, dict) | ||
| assert result["error"] == "HTTP client error: boom" |
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.
Uh oh!
There was an error while loading. Please reload this page.