-
Notifications
You must be signed in to change notification settings - Fork 23
Fix: Remove unnecessary async declarations from synchronous methods #42
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
Conversation
WalkthroughAll asynchronous ( Changes
Sequence Diagram(s)sequenceDiagram
participant TestSuite
participant MCPServer
participant MeilisearchClient
TestSuite->>MCPServer: Call handler (e.g., create_index)
MCPServer->>MeilisearchClient: Synchronous method call (e.g., create_index)
MeilisearchClient-->>MCPServer: Response
MCPServer-->>TestSuite: Result
Note over MCPServer,MeilisearchClient: All method calls are now synchronous (no await/async)
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/meilisearch_mcp/keys.py (1)
21-26: Consider improving exception chaining for better debugging.While the async-to-sync conversion is correct, consider using exception chaining to preserve the original error context:
- raise Exception(f"Failed to get key: {str(e)}") + raise Exception(f"Failed to get key: {str(e)}") from eThis pattern should be applied to all exception handlers in this class.
Also applies to: 28-33, 35-40, 42-47
🧰 Tools
🪛 Ruff (0.11.9)
26-26: Within an
exceptclause, raise exceptions withraise ... from errorraise ... from Noneto distinguish them from errors in exception handling(B904)
src/meilisearch_mcp/indexes.py (1)
20-27: LGTM! All index management methods correctly converted to synchronous.The conversion from
async deftodefis appropriate for all methods since they only call synchronous client methods without anyawaitstatements. The logic and error handling remain consistent.Consider applying exception chaining for better debugging context (same pattern as suggested for KeyManager):
- raise Exception(f"Failed to create index: {str(e)}") + raise Exception(f"Failed to create index: {str(e)}") from eAlso applies to: 29-34, 36-41, 43-48, 50-55, 57-62
🧰 Tools
🪛 Ruff (0.11.9)
27-27: Within an
exceptclause, raise exceptions withraise ... from errorraise ... from Noneto distinguish them from errors in exception handling(B904)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
src/meilisearch_mcp/client.py(2 hunks)src/meilisearch_mcp/documents.py(7 hunks)src/meilisearch_mcp/indexes.py(2 hunks)src/meilisearch_mcp/keys.py(2 hunks)src/meilisearch_mcp/monitoring.py(3 hunks)src/meilisearch_mcp/server.py(17 hunks)src/meilisearch_mcp/settings.py(2 hunks)src/meilisearch_mcp/tasks.py(2 hunks)tests/test_mcp_client.py(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
tests/test_mcp_client.py (1)
src/meilisearch_mcp/server.py (1)
cleanup(645-648)
src/meilisearch_mcp/server.py (8)
src/meilisearch_mcp/indexes.py (2)
create_index(20-27)delete_index(43-48)src/meilisearch_mcp/client.py (5)
get_indexes(100-120)health_check(31-37)get_version(39-41)get_stats(43-45)search(47-98)src/meilisearch_mcp/documents.py (2)
get_documents(11-58)add_documents(70-81)src/meilisearch_mcp/settings.py (2)
get_settings(27-33)update_settings(35-43)src/meilisearch_mcp/tasks.py (3)
get_task(22-28)get_tasks(30-38)cancel_tasks(40-46)src/meilisearch_mcp/keys.py (3)
get_keys(12-19)create_key(28-33)delete_key(42-47)src/meilisearch_mcp/monitoring.py (3)
get_health_status(35-63)get_index_metrics(65-78)get_system_information(80-93)src/meilisearch_mcp/logging.py (1)
info(116-117)
src/meilisearch_mcp/indexes.py (1)
src/meilisearch_mcp/client.py (1)
get_indexes(100-120)
🪛 Ruff (0.11.9)
src/meilisearch_mcp/settings.py
33-33: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling
(B904)
src/meilisearch_mcp/tasks.py
28-28: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling
(B904)
46-46: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling
(B904)
src/meilisearch_mcp/indexes.py
34-34: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling
(B904)
41-41: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling
(B904)
48-48: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling
(B904)
55-55: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling
(B904)
src/meilisearch_mcp/keys.py
26-26: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling
(B904)
33-33: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling
(B904)
40-40: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling
(B904)
🪛 Pylint (3.3.7)
src/meilisearch_mcp/client.py
[refactor] 47-47: Too many arguments (7/5)
(R0913)
[refactor] 47-47: Too many positional arguments (7/5)
(R0917)
src/meilisearch_mcp/documents.py
[refactor] 11-11: Too many branches (13/12)
(R0912)
🔇 Additional comments (21)
tests/test_mcp_client.py (1)
104-104: LGTM!The removal of
awaitcorrectly aligns with the synchronouscleanup()method implementation inserver.py.src/meilisearch_mcp/monitoring.py (3)
35-35: Correct removal of unnecessary async declaration.The method only calls synchronous client methods and contains no await statements, making the async declaration redundant.
65-65: Appropriate conversion to synchronous method.The method performs only synchronous operations with the Meilisearch client.
80-80: Correct synchronous conversion.The method only makes synchronous calls to the Meilisearch client.
src/meilisearch_mcp/settings.py (3)
27-27: Proper conversion to synchronous method.The method only calls synchronous client operations.
35-36: Correct synchronous conversion.The method performs only synchronous Meilisearch client operations.
45-45: Appropriate async removal.The method contains no asynchronous operations.
src/meilisearch_mcp/server.py (3)
53-53: Correct removal of async from synchronous method.The method only performs synchronous operations like updating instance variables and creating a new client.
381-608: Consistent removal of await calls throughout the handler.All await keywords have been correctly removed from calls to the now-synchronous Meilisearch client and manager methods. The MCP handler itself appropriately remains async as required by the protocol.
645-645: Appropriate synchronous conversion.The cleanup method only performs synchronous logging operations.
src/meilisearch_mcp/tasks.py (4)
22-22: Correct synchronous conversion.The method only calls synchronous client operations.
30-31: Appropriate async removal.The method performs only synchronous operations.
40-40: Proper conversion to synchronous method.The method contains no asynchronous operations.
48-48: Correct synchronous conversion.The method only performs synchronous client operations.
src/meilisearch_mcp/keys.py (1)
12-19: LGTM! Correct removal of unnecessary async declaration.The conversion from
async deftodefis appropriate since this method only calls synchronous client methods without anyawaitstatements.🧰 Tools
🪛 Ruff (0.11.9)
19-19: Within an
exceptclause, raise exceptions withraise ... from errorraise ... from Noneto distinguish them from errors in exception handling(B904)
src/meilisearch_mcp/client.py (4)
31-37: LGTM! Correct removal of unnecessary async declaration.The conversion from
async deftodefis appropriate since this method only calls synchronous client methods.
39-41: LGTM! Clean synchronous implementations.These simple wrapper methods are correctly converted to synchronous functions.
Also applies to: 43-45
47-98: LGTM! Complex search logic correctly converted to synchronous.The search method properly handles both single-index and multi-index searches without any asynchronous operations. The conversion to synchronous execution is appropriate.
🧰 Tools
🪛 Ruff (0.11.9)
98-98: Within an
exceptclause, raise exceptions withraise ... from errorraise ... from Noneto distinguish them from errors in exception handling(B904)
🪛 Pylint (3.3.7)
[refactor] 47-47: Too many arguments (7/5)
(R0913)
[refactor] 47-47: Too many positional arguments (7/5)
(R0917)
[refactor] 77-95: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it
(R1705)
100-120: LGTM! Index serialization logic correctly synchronous.The method properly serializes index objects and handles the conversion without any asynchronous operations.
src/meilisearch_mcp/documents.py (2)
11-58: LGTM! Complex document retrieval logic correctly converted to synchronous.The conversion from
async deftodefis appropriate. The method handles document serialization without any asynchronous operations, making the synchronous approach correct.🧰 Tools
🪛 Ruff (0.11.9)
58-58: Within an
exceptclause, raise exceptions withraise ... from errorraise ... from Noneto distinguish them from errors in exception handling(B904)
🪛 Pylint (3.3.7)
[refactor] 33-56: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it
(R1705)
[refactor] 11-11: Too many branches (13/12)
(R0912)
[refactor] 19-58: Too many nested blocks (7/5)
(R1702)
60-68: LGTM! All document management methods correctly converted to synchronous.These methods properly call synchronous client operations without any
awaitstatements. The conversion is consistent and appropriate across all document operations.Also applies to: 70-81, 83-91, 93-101, 103-111, 113-119
🧰 Tools
🪛 Ruff (0.11.9)
68-68: Within an
exceptclause, raise exceptions withraise ... from errorraise ... from Noneto distinguish them from errors in exception handling(B904)
Summary
asyncdeclarations from all manager methods that don't contain anyawaitstatementscleanup()methodProblem
The codebase had all manager methods marked as
asynceven though they were using the synchronous Meilisearch Python client and contained no actual asynchronous operations. This created confusion about the execution model and added unnecessary overhead.Solution
Removed
asynckeyword from all manager methods in:indexes.py(6 methods)documents.py(7 methods)settings.py(3 methods)tasks.py(4 methods)keys.py(5 methods)monitoring.py(3 methods)client.py(5 methods)server.py(2 methods:update_connectionandcleanup)Removed corresponding
awaitkeywords from all calls to these methods inserver.pyFixed test fixture in
test_mcp_client.pyto not await thecleanup()methodTest Results
Impact
This is a pure refactoring with no functional changes.
🤖 Generated with Claude Code
Co-Authored-By: Claude [email protected]
Summary by CodeRabbit