-
Notifications
You must be signed in to change notification settings - Fork 23
Add custom user agent for Meilisearch MCP server #45
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
- Add client_agents parameter to identify meilisearch-mcp in requests - Create __version__.py module to centralize version information - Add tests to verify user agent is properly configured - Helps with analytics tracking and debugging This implementation uses the Meilisearch Python SDK's built-in client_agents parameter to identify requests from the MCP server. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
WalkthroughA new version file was added to define the package version. The client implementation was updated to include this version in a custom user agent string. Additionally, new tests were introduced to verify that the user agent is correctly set, including the version information during client initialization. Changes
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: 1
🧹 Nitpick comments (6)
src/meilisearch_mcp/__version__.py (1)
1-2: Add a minimal module docstring for clarityEven for one-liner version files, adding a short docstring makes the intent explicit and keeps pydoc output cleaner.
+"""Package version, kept in a single place to avoid duplication.""" __version__ = "0.5.0"src/meilisearch_mcp/client.py (2)
1-1:httpximport appears unused – remove to keep linting cleanThe module no longer references
httpx. Dropping the import avoids Ruff/flake8F401warnings.-import httpx
24-27: Tuple works, but SDK expects an iterable – consider list for future-proofing
meilisearch.Clientaccepts anyIterable[str]; a tuple is fine today, yet almost every example (and the internalClient._client_agentshandling) uses a list. Switching keeps consistency with upstream docs and avoids accidental immutability surprises if the list gets extended later.- self.client = Client( - url, api_key, client_agents=("meilisearch-mcp", f"v{__version__}") - ) + self.client = Client( + url, + api_key, + client_agents=["meilisearch-mcp", f"v{__version__}"], + )tests/test_user_agent.py (3)
1-4: Remove unused imports to satisfy Ruff and keep the test file tidy
pytestandMagicMockare never referenced directly and triggerF401.-import pytest -from unittest.mock import patch, MagicMock +from unittest.mock import patch
10-18: Eliminate unused localclientvariableThe created instance isn’t reused; omitting the assignment silences
F841.- # Create a MeilisearchClient instance - client = MeilisearchClient(url="http://localhost:7700", api_key="test_key") + # Create a MeilisearchClient instance + MeilisearchClient(url="http://localhost:7700", api_key="test_key")
24-29: Same unused variable issue in second test- client = MeilisearchClient() + MeilisearchClient()
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/meilisearch_mcp/__version__.py(1 hunks)src/meilisearch_mcp/client.py(2 hunks)tests/test_user_agent.py(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
tests/test_user_agent.py (1)
src/meilisearch_mcp/client.py (1)
MeilisearchClient(17-124)
🪛 Ruff (0.11.9)
tests/test_user_agent.py
1-1: pytest imported but unused
Remove unused import: pytest
(F401)
2-2: unittest.mock.MagicMock imported but unused
Remove unused import: unittest.mock.MagicMock
(F401)
11-11: Local variable client is assigned to but never used
Remove assignment to unused variable client
(F841)
24-24: Local variable client is assigned to but never used
Remove assignment to unused variable client
(F841)
| with patch("src.meilisearch_mcp.client.Client") as mock_client: | ||
| client = MeilisearchClient() |
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.
Patch target should be the import path actually used by the code
MeilisearchClient lives in meilisearch_mcp.client, not src.meilisearch_mcp.client once the package is installed. Patching the real module path avoids import-path-dependent breakage.
-with patch("src.meilisearch_mcp.client.Client") as mock_client:
+with patch("meilisearch_mcp.client.Client") as mock_client:📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| with patch("src.meilisearch_mcp.client.Client") as mock_client: | |
| client = MeilisearchClient() | |
| with patch("meilisearch_mcp.client.Client") as mock_client: | |
| client = MeilisearchClient() |
🧰 Tools
🪛 Ruff (0.11.9)
24-24: Local variable client is assigned to but never used
Remove assignment to unused variable client
(F841)
🤖 Prompt for AI Agents
In tests/test_user_agent.py around lines 23 to 24, the patch target is
incorrectly set to "src.meilisearch_mcp.client.Client" which is not the actual
import path used by the installed package. Change the patch target to
"meilisearch_mcp.client.Client" to match the real module path and avoid
import-path-dependent breakage.
Docstrings generation was requested by @tpayet. * #45 (comment) The following files were modified: * `src/meilisearch_mcp/client.py` * `tests/test_user_agent.py`
|
Note Generated docstrings for this pull request at #46 |
Summary
__version__.pymoduleChanges
MeilisearchClientto passclient_agentsparameter when initializing the Meilisearch Python SDK client__version__.pyto centralize version information (currently v0.5.0)Implementation Details
The Meilisearch Python SDK supports customizing the user agent through the
client_agentsparameter. This change leverages that feature to identify requests coming from the MCP server.The resulting user agent will be formatted as:
This helps with:
Test plan
__version__.py🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Tests