Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/meilisearch_mcp/__version__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.5.0"
6 changes: 5 additions & 1 deletion src/meilisearch_mcp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .keys import KeyManager
from .logging import MCPLogger
from .monitoring import MonitoringManager
from .__version__ import __version__

logger = MCPLogger()

Expand All @@ -20,7 +21,10 @@ def __init__(
"""Initialize Meilisearch client"""
self.url = url
self.api_key = api_key
self.client = Client(url, api_key)
# Add custom user agent to identify this as Meilisearch MCP
self.client = Client(
url, api_key, client_agents=("meilisearch-mcp", f"v{__version__}")
)
self.indexes = IndexManager(self.client)
self.documents = DocumentManager(self.client)
self.settings = SettingsManager(self.client)
Expand Down
33 changes: 33 additions & 0 deletions tests/test_user_agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import pytest
from unittest.mock import patch, MagicMock
from src.meilisearch_mcp.client import MeilisearchClient
from src.meilisearch_mcp.__version__ import __version__


def test_meilisearch_client_sets_custom_user_agent():
"""Test that MeilisearchClient initializes with custom user agent"""
with patch("src.meilisearch_mcp.client.Client") as mock_client:
# Create a MeilisearchClient instance
client = MeilisearchClient(url="http://localhost:7700", api_key="test_key")

# Verify that Client was called with the correct parameters
mock_client.assert_called_once_with(
"http://localhost:7700",
"test_key",
client_agents=("meilisearch-mcp", f"v{__version__}"),
)


def test_user_agent_includes_correct_version():
"""Test that the user agent includes the correct version from __version__.py"""
with patch("src.meilisearch_mcp.client.Client") as mock_client:
client = MeilisearchClient()
Comment on lines +23 to +24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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.

Suggested change
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.


# Extract the client_agents parameter from the call
call_args = mock_client.call_args
client_agents = call_args[1]["client_agents"]

# Verify format and version
assert client_agents[0] == "meilisearch-mcp"
assert client_agents[1] == "v0.5.0"
assert client_agents[1] == f"v{__version__}"