|
| 1 | +# Phase 1: MCP Protocol Tests |
| 2 | + |
| 3 | +> **Status:** pending |
| 4 | +> **Depends on:** none |
| 5 | +
|
| 6 | +## Overview |
| 7 | + |
| 8 | +Tests that verify the MCP server's tool registration, parameter schemas, input validation, and error handling when the scraper is not initialized. These run without LinkedIn credentials. |
| 9 | + |
| 10 | +## Implementation |
| 11 | + |
| 12 | +**Files:** |
| 13 | + |
| 14 | +- Create: `tests/test_mcp_server.py` |
| 15 | +- Modify: `tests/conftest.py` — add `mcp_client` async fixture |
| 16 | +- Modify: `pyproject.toml` — add `asyncio_mode = "auto"` |
| 17 | + |
| 18 | +**What to test:** |
| 19 | + |
| 20 | +### 1. Tool Registration (`TestToolRegistration`) |
| 21 | + |
| 22 | +- Exactly 11 tools registered, names match expected set |
| 23 | +- Each tool's required params and defaults verified: |
| 24 | + - `scrape_profile`: requires `profile_url` |
| 25 | + - `search_profiles`: requires `query`, `max_results` defaults to 5, 8 total params |
| 26 | + - `get_session_status`: no params |
| 27 | + - `reset_session`: no params |
| 28 | + - `scrape_company`: requires `company_url` |
| 29 | + - `search_posts`: requires `keywords`, `scroll_pause` defaults to 2.0, `max_comments` defaults to 10 |
| 30 | + - `scrape_incoming_connections`: `max_results` defaults to 10 |
| 31 | + - `scrape_outgoing_connections`: `max_results` defaults to 10 |
| 32 | + - `scrape_conversations_list`: `max_results` defaults to 10 |
| 33 | + - `scrape_conversation`: `participant_name` optional/nullable |
| 34 | + - `send_connection_request`: requires `profile_url`, `note` optional |
| 35 | + |
| 36 | +### 2. Parameter Validation (`TestParameterValidation`) |
| 37 | + |
| 38 | +- Empty `profile_url` on `scrape_profile` → `ToolError` |
| 39 | +- Empty `query` on `search_profiles` → `ToolError` |
| 40 | +- Empty `company_url` on `scrape_company` → `ToolError` |
| 41 | +- Empty `keywords` on `search_posts` → `ToolError` |
| 42 | +- Empty `profile_url` on `send_connection_request` → `ToolError` |
| 43 | + |
| 44 | +### 3. Uninitialized Scraper (`TestUninitializedScraper`) |
| 45 | + |
| 46 | +- Direct `get_scraper()` call raises `RuntimeError` |
| 47 | +- Each of 10 tools (except `reset_session`) returns error string containing "Scraper not initialized" |
| 48 | +- `reset_session` succeeds even when uninitialized (returns "reset successfully") |
| 49 | + |
| 50 | +**What to build:** |
| 51 | + |
| 52 | +Key fixture — `mcp_client` in conftest.py: |
| 53 | + |
| 54 | +```python |
| 55 | +@pytest.fixture |
| 56 | +async def mcp_client() -> AsyncGenerator[Client, None]: |
| 57 | + async with Client(mcp_app) as client: |
| 58 | + yield client |
| 59 | +``` |
| 60 | + |
| 61 | +Key fixture — ensuring no scraper (defined inside `TestUninitializedScraper`): |
| 62 | + |
| 63 | +```python |
| 64 | +@pytest.fixture(autouse=True) |
| 65 | +def _ensure_no_scraper() -> Generator[None, None, None]: |
| 66 | + original = mcp_server._scraper_instance |
| 67 | + mcp_server._scraper_instance = None |
| 68 | + yield |
| 69 | + mcp_server._scraper_instance = original |
| 70 | +``` |
| 71 | + |
| 72 | +Helper for extracting text from `CallToolResult`: |
| 73 | + |
| 74 | +```python |
| 75 | +def _result_text(result: Any) -> str: |
| 76 | + assert result.content |
| 77 | + return result.content[0].text |
| 78 | +``` |
| 79 | + |
| 80 | +Helper for tool schema inspection: |
| 81 | + |
| 82 | +```python |
| 83 | +def _find_tool(tools: list[Any], name: str) -> Any: |
| 84 | + for t in tools: |
| 85 | + if t.name == name: |
| 86 | + return t |
| 87 | + raise AssertionError(f"Tool '{name}' not found") |
| 88 | +``` |
| 89 | + |
| 90 | +**Commit:** `test(mcp): add protocol, validation, and uninitialized state tests` |
| 91 | + |
| 92 | +## Done When |
| 93 | + |
| 94 | +- [ ] 11+ tool registration tests pass |
| 95 | +- [ ] 5 parameter validation tests pass |
| 96 | +- [ ] 12 uninitialized scraper tests pass |
| 97 | +- [ ] All run without LINKEDIN_COOKIE: `uv run python -m pytest tests/test_mcp_server.py -m "not integration"` |
| 98 | +- [ ] `make check` passes |
0 commit comments