Skip to content

Commit 93d4b76

Browse files
authored
Merge pull request #1 from meilisearch/add-test
Add basic testing on every PR
2 parents 1b15592 + c87c9ca commit 93d4b76

File tree

15 files changed

+391
-370
lines changed

15 files changed

+391
-370
lines changed

.github/workflows/test.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Test and Lint
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
push:
7+
branches: [ main ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v4
17+
with:
18+
python-version: '3.10'
19+
20+
- name: Install dependencies
21+
run: |
22+
python -m pip install --upgrade pip
23+
pip install pytest black mcp
24+
pip install -e .
25+
26+
- name: Format code with black
27+
run: |
28+
black src/
29+
black tests/
30+
31+
- name: Run tests
32+
run: |
33+
pytest tests/ -v

pyproject.toml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,24 @@ dependencies = [
1111
]
1212

1313
[build-system]
14-
requires = ["hatchling"]
15-
build-backend = "hatchling.build"
14+
requires = ["setuptools>=42"]
15+
build-backend = "setuptools.build_meta"
1616

1717
[project.scripts]
1818
meilisearch-mcp = "meilisearch_mcp.server:main"
1919

2020
[tool.hatch.build.targets.wheel]
21-
packages = ["src/meilisearch_mcp"]
21+
packages = ["src/meilisearch_mcp"]
22+
23+
[tool.pytest.ini_options]
24+
pythonpath = [
25+
"."
26+
]
27+
testpaths = [
28+
"tests"
29+
]
30+
31+
[tool.black]
32+
line-length = 88
33+
target-version = ['py310']
34+
include = '\.pyi?$'

requirements-dev.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pytest>=7.0.0
2+
black>=23.0.0
3+
mcp>=0.1.0

src/meilisearch_mcp/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from .server import main
22

3-
if __name__ == '__main__':
4-
main()
3+
if __name__ == "__main__":
4+
main()

src/meilisearch_mcp/client.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313

1414
logger = MCPLogger()
1515

16+
1617
class MeilisearchClient:
17-
def __init__(self, url: str = "http://localhost:7700", api_key: Optional[str] = None):
18+
def __init__(
19+
self, url: str = "http://localhost:7700", api_key: Optional[str] = None
20+
):
1821
"""Initialize Meilisearch client"""
1922
self.url = url
2023
self.api_key = api_key
@@ -26,7 +29,7 @@ def __init__(self, url: str = "http://localhost:7700", api_key: Optional[str] =
2629
self.tasks = TaskManager(self.client)
2730
self.keys = KeyManager(self.client)
2831
self.monitoring = MonitoringManager(self.client)
29-
32+
3033
async def health_check(self) -> bool:
3134
"""Check if Meilisearch is healthy"""
3235
try:
@@ -43,23 +46,25 @@ async def get_stats(self) -> Dict[str, Any]:
4346
"""Get database stats"""
4447
# return self.client.get_stats()
4548
return "This method has not yet been implemented in the Meilisearch client."
46-
49+
4750
async def get_indexes(self) -> Dict[str, Any]:
4851
"""Get all indexes"""
4952
indexes = self.client.get_indexes()
5053
# Convert Index objects to serializable dictionaries
5154
serialized_indexes = []
52-
for index in indexes['results']:
53-
serialized_indexes.append({
54-
"uid": index.uid,
55-
"primaryKey": index.primary_key,
56-
"createdAt": index.created_at,
57-
"updatedAt": index.updated_at
58-
})
59-
55+
for index in indexes["results"]:
56+
serialized_indexes.append(
57+
{
58+
"uid": index.uid,
59+
"primaryKey": index.primary_key,
60+
"createdAt": index.created_at,
61+
"updatedAt": index.updated_at,
62+
}
63+
)
64+
6065
return {
6166
"results": serialized_indexes,
62-
"offset": indexes['offset'],
63-
"limit": indexes['limit'],
64-
"total": indexes['total']
65-
}
67+
"offset": indexes["offset"],
68+
"limit": indexes["limit"],
69+
"total": indexes["total"],
70+
}

src/meilisearch_mcp/documents.py

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from typing import Dict, Any, List, Optional, Union
22
from meilisearch import Client
33

4+
45
class DocumentManager:
56
"""Manage documents within Meilisearch indexes"""
6-
7+
78
def __init__(self, client: Client):
89
self.client = client
910

@@ -12,23 +13,19 @@ async def get_documents(
1213
index_uid: str,
1314
offset: Optional[int] = None,
1415
limit: Optional[int] = None,
15-
fields: Optional[List[str]] = None
16+
fields: Optional[List[str]] = None,
1617
) -> Dict[str, Any]:
1718
"""Get documents from an index"""
1819
try:
1920
index = self.client.index(index_uid)
20-
return index.get_documents({
21-
'offset': offset,
22-
'limit': limit,
23-
'fields': fields
24-
})
21+
return index.get_documents(
22+
{"offset": offset, "limit": limit, "fields": fields}
23+
)
2524
except Exception as e:
2625
raise Exception(f"Failed to get documents: {str(e)}")
2726

2827
async def get_document(
29-
self,
30-
index_uid: str,
31-
document_id: Union[str, int]
28+
self, index_uid: str, document_id: Union[str, int]
3229
) -> Dict[str, Any]:
3330
"""Get a single document"""
3431
try:
@@ -41,7 +38,7 @@ async def add_documents(
4138
self,
4239
index_uid: str,
4340
documents: List[Dict[str, Any]],
44-
primary_key: Optional[str] = None
41+
primary_key: Optional[str] = None,
4542
) -> Dict[str, Any]:
4643
"""Add documents to an index"""
4744
try:
@@ -51,9 +48,7 @@ async def add_documents(
5148
raise Exception(f"Failed to add documents: {str(e)}")
5249

5350
async def update_documents(
54-
self,
55-
index_uid: str,
56-
documents: List[Dict[str, Any]]
51+
self, index_uid: str, documents: List[Dict[str, Any]]
5752
) -> Dict[str, Any]:
5853
"""Update documents in an index"""
5954
try:
@@ -63,9 +58,7 @@ async def update_documents(
6358
raise Exception(f"Failed to update documents: {str(e)}")
6459

6560
async def delete_document(
66-
self,
67-
index_uid: str,
68-
document_id: Union[str, int]
61+
self, index_uid: str, document_id: Union[str, int]
6962
) -> Dict[str, Any]:
7063
"""Delete a single document"""
7164
try:
@@ -75,9 +68,7 @@ async def delete_document(
7568
raise Exception(f"Failed to delete document: {str(e)}")
7669

7770
async def delete_documents(
78-
self,
79-
index_uid: str,
80-
document_ids: List[Union[str, int]]
71+
self, index_uid: str, document_ids: List[Union[str, int]]
8172
) -> Dict[str, Any]:
8273
"""Delete multiple documents by ID"""
8374
try:
@@ -86,13 +77,10 @@ async def delete_documents(
8677
except Exception as e:
8778
raise Exception(f"Failed to delete documents: {str(e)}")
8879

89-
async def delete_all_documents(
90-
self,
91-
index_uid: str
92-
) -> Dict[str, Any]:
80+
async def delete_all_documents(self, index_uid: str) -> Dict[str, Any]:
9381
"""Delete all documents in an index"""
9482
try:
9583
index = self.client.index(index_uid)
9684
return index.delete_all_documents()
9785
except Exception as e:
98-
raise Exception(f"Failed to delete all documents: {str(e)}")
86+
raise Exception(f"Failed to delete all documents: {str(e)}")

src/meilisearch_mcp/indexes.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,24 @@
22
from dataclasses import dataclass
33
from meilisearch import Client
44

5+
56
@dataclass
67
class IndexConfig:
78
"""Index configuration model"""
9+
810
uid: str
911
primary_key: Optional[str] = None
10-
12+
13+
1114
class IndexManager:
1215
"""Manage Meilisearch indexes"""
13-
16+
1417
def __init__(self, client: Client):
1518
self.client = client
1619

17-
async def create_index(self, uid: str, primary_key: Optional[str] = None) -> Dict[str, Any]:
20+
async def create_index(
21+
self, uid: str, primary_key: Optional[str] = None
22+
) -> Dict[str, Any]:
1823
"""Create a new index"""
1924
try:
2025
return self.client.create_index(uid, {"primaryKey": primary_key})
@@ -45,7 +50,7 @@ async def delete_index(self, uid: str) -> Dict[str, Any]:
4550
async def update_index(self, uid: str, primary_key: str) -> Dict[str, Any]:
4651
"""Update index primary key"""
4752
try:
48-
return self.client.update_index(uid, {'primaryKey': primary_key})
53+
return self.client.update_index(uid, {"primaryKey": primary_key})
4954
except Exception as e:
5055
raise Exception(f"Failed to update index: {str(e)}")
5156

@@ -54,4 +59,4 @@ async def swap_indexes(self, indexes: List[List[str]]) -> Dict[str, Any]:
5459
try:
5560
return self.client.swap_indexes(indexes)
5661
except Exception as e:
57-
raise Exception(f"Failed to swap indexes: {str(e)}")
62+
raise Exception(f"Failed to swap indexes: {str(e)}")

src/meilisearch_mcp/keys.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
from meilisearch import Client
33
from datetime import datetime
44

5+
56
class KeyManager:
67
"""Manage Meilisearch API keys"""
7-
8+
89
def __init__(self, client: Client):
910
self.client = client
1011

11-
async def get_keys(self,
12-
parameters: Optional[Dict[str, Any]] = None
13-
) -> Dict[str, Any]:
12+
async def get_keys(
13+
self, parameters: Optional[Dict[str, Any]] = None
14+
) -> Dict[str, Any]:
1415
"""Get list of API keys"""
1516
try:
1617
return self.client.get_keys(parameters)
@@ -24,19 +25,14 @@ async def get_key(self, key: str) -> Dict[str, Any]:
2425
except Exception as e:
2526
raise Exception(f"Failed to get key: {str(e)}")
2627

27-
async def create_key(self,
28-
options: Dict[str, Any]
29-
) -> Dict[str, Any]:
28+
async def create_key(self, options: Dict[str, Any]) -> Dict[str, Any]:
3029
"""Create a new API key"""
3130
try:
3231
return self.client.create_key(options)
3332
except Exception as e:
3433
raise Exception(f"Failed to create key: {str(e)}")
3534

36-
async def update_key(self,
37-
key: str,
38-
options: Dict[str, Any]
39-
) -> Dict[str, Any]:
35+
async def update_key(self, key: str, options: Dict[str, Any]) -> Dict[str, Any]:
4036
"""Update an existing API key"""
4137
try:
4238
return self.client.update_key(key, options)
@@ -48,4 +44,4 @@ async def delete_key(self, key: str) -> None:
4844
try:
4945
return self.client.delete_key(key)
5046
except Exception as e:
51-
raise Exception(f"Failed to delete key: {str(e)}")
47+
raise Exception(f"Failed to delete key: {str(e)}")

0 commit comments

Comments
 (0)