diff --git a/src/meilisearch_mcp/__version__.py b/src/meilisearch_mcp/__version__.py new file mode 100644 index 0000000..3d18726 --- /dev/null +++ b/src/meilisearch_mcp/__version__.py @@ -0,0 +1 @@ +__version__ = "0.5.0" diff --git a/src/meilisearch_mcp/client.py b/src/meilisearch_mcp/client.py index 7f175a4..c7c5b5a 100644 --- a/src/meilisearch_mcp/client.py +++ b/src/meilisearch_mcp/client.py @@ -9,6 +9,7 @@ from .keys import KeyManager from .logging import MCPLogger from .monitoring import MonitoringManager +from .__version__ import __version__ logger = MCPLogger() @@ -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) diff --git a/tests/test_user_agent.py b/tests/test_user_agent.py new file mode 100644 index 0000000..9e701a5 --- /dev/null +++ b/tests/test_user_agent.py @@ -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() + + # 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__}"