|
20 | 20 | from contextlib import AsyncExitStack |
21 | 21 |
|
22 | 22 | import pytest |
| 23 | +import requests |
23 | 24 | from mcp import ClientSession, types |
24 | 25 | from mcp.client.streamable_http import streamablehttp_client |
25 | 26 |
|
@@ -346,30 +347,9 @@ async def read_cells(self): |
346 | 347 | @requires_session |
347 | 348 | async def list_cells(self, max_retries=3): |
348 | 349 | """List cells with retry mechanism for Windows compatibility""" |
349 | | - for attempt in range(max_retries): |
350 | | - try: |
351 | | - result = await self._session.call_tool("list_cells") # type: ignore |
352 | | - text_result = self._extract_text_content(result) |
353 | | - logging.debug(f"list_cells attempt {attempt + 1}: text_result type={type(text_result)}, len={len(text_result) if text_result else 0}") |
354 | | - logging.debug(f"list_cells attempt {attempt + 1}: text_result[:500]={repr(text_result[:500]) if text_result else 'None'}") |
355 | | - has_index_type = ("Index\tType" in text_result) if text_result else False |
356 | | - logging.debug(f"list_cells attempt {attempt + 1}: has_index_type={has_index_type}") |
357 | | - if text_result is not None and not text_result.startswith("Error") and "Index\tType" in text_result: |
358 | | - return text_result |
359 | | - else: |
360 | | - logging.warning(f"list_cells returned unexpected result on attempt {attempt + 1}/{max_retries}") |
361 | | - if attempt < max_retries - 1: |
362 | | - await asyncio.sleep(0.5) |
363 | | - except Exception as e: |
364 | | - logging.error(f"list_cells failed on attempt {attempt + 1}/{max_retries}: {e}") |
365 | | - if attempt < max_retries - 1: |
366 | | - await asyncio.sleep(0.5) |
367 | | - else: |
368 | | - logging.error("list_cells failed after all retries") |
369 | | - return "Error: Failed to retrieve cell list after all retries" |
370 | | - |
371 | | - return "Error: Failed to retrieve cell list after all retries" |
372 | | - |
| 350 | + result = await self._session.call_tool("list_cells") # type: ignore |
| 351 | + return self._extract_text_content(result) |
| 352 | + |
373 | 353 | @requires_session |
374 | 354 | async def list_kernels(self): |
375 | 355 | """List all available kernels""" |
@@ -437,24 +417,3 @@ async def execute_code(self, code, timeout=60): |
437 | 417 | structured["result"] = [result_val] |
438 | 418 |
|
439 | 419 | return structured |
440 | | - |
441 | | - @requires_session |
442 | | - async def append_execute_code_cell(self, cell_source): |
443 | | - """Append and execute a code cell at the end of the notebook.""" |
444 | | - return await self.insert_execute_code_cell(-1, cell_source) |
445 | | - |
446 | | - @requires_session |
447 | | - async def append_markdown_cell(self, cell_source): |
448 | | - """Append a markdown cell at the end of the notebook.""" |
449 | | - return await self.insert_cell(-1, "markdown", cell_source) |
450 | | - |
451 | | - # Helper method to get cell count from list_cells output |
452 | | - @requires_session |
453 | | - async def get_cell_count(self): |
454 | | - """Get the number of cells by parsing list_cells output""" |
455 | | - cell_list = await self.list_cells() |
456 | | - if "Error" in cell_list or "Index\tType" not in cell_list: |
457 | | - return 0 |
458 | | - lines = cell_list.split('\n') |
459 | | - data_lines = [line for line in lines if '\t' in line and not line.startswith('Index') and not line.startswith('-')] |
460 | | - return len(data_lines) |
0 commit comments