@@ -303,6 +303,69 @@ async def test_get_connection_settings_format(self, server):
303303 assert "********" in text or "Not set" in text
304304 else :
305305 assert "Not set" in text
306+
307+
308+ class TestIssue16GetDocumentsJsonSerialization :
309+ """Test for issue #16 - get-documents should return JSON, not Python object representations"""
310+
311+ @pytest .fixture
312+ async def server (self ):
313+ """Create server instance for issue #16 tests"""
314+ url = os .getenv ("MEILI_HTTP_ADDR" , "http://localhost:7700" )
315+ api_key = os .getenv ("MEILI_MASTER_KEY" )
316+ server = create_server (url , api_key )
317+ yield server
318+ await server .cleanup ()
319+
320+ async def test_get_documents_returns_json_not_python_object (self , server ):
321+ """Test that get-documents returns JSON-formatted text, not Python object string representation (issue #16)"""
322+ import time
323+ test_index = f"test_issue16_{ int (time .time () * 1000 )} "
324+
325+ # Create index and add a test document
326+ await simulate_mcp_call (server , "create-index" , {"uid" : test_index })
327+
328+ test_document = {"id" : 1 , "title" : "Test Document" , "content" : "Test content" }
329+ await simulate_mcp_call (server , "add-documents" , {
330+ "indexUid" : test_index ,
331+ "documents" : [test_document ]
332+ })
333+
334+ # Wait for indexing
335+ import asyncio
336+ await asyncio .sleep (0.5 )
337+
338+ # Get documents with explicit parameters
339+ result = await simulate_mcp_call (server , "get-documents" , {
340+ "indexUid" : test_index ,
341+ "offset" : 0 ,
342+ "limit" : 10
343+ })
344+
345+ assert len (result ) == 1
346+ assert result [0 ].type == "text"
347+
348+ response_text = result [0 ].text
349+
350+ # Issue #16 assertion: Should NOT contain Python object representation
351+ assert "<meilisearch.models.document.DocumentsResults object at" not in response_text
352+ assert "DocumentsResults" not in response_text
353+
354+ # Should contain proper JSON structure
355+ assert "Documents:" in response_text
356+ assert "Test Document" in response_text # Actual document content should be accessible
357+ assert "Test content" in response_text
358+
359+ # Should be valid JSON after the "Documents:" prefix
360+ json_part = response_text .replace ("Documents:" , "" ).strip ()
361+ import json
362+ try :
363+ parsed_data = json .loads (json_part )
364+ assert isinstance (parsed_data , dict )
365+ assert "results" in parsed_data
366+ assert len (parsed_data ["results" ]) > 0
367+ except json .JSONDecodeError :
368+ pytest .fail (f"get-documents returned non-JSON data: { response_text } " )
306369
307370 async def test_update_connection_settings_persistence (self , server ):
308371 """Test that connection updates persist for MCP client sessions"""
0 commit comments