wigolo-llamaindex 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,65 @@
1
+
2
+ # Build & runtime
3
+ node_modules/
4
+ dist/
5
+ *.tgz
6
+
7
+ # Single-file binary build (build:binary) — artifacts never committed
8
+ packaging/binary/dist/
9
+ /pkg.build.json
10
+
11
+ # Database files
12
+ *.db
13
+ *.db-journal
14
+ *.db-wal
15
+
16
+ # wigolo data
17
+ .wigolo/
18
+
19
+ # Secrets
20
+ .env
21
+
22
+ # Test coverage
23
+ coverage/
24
+
25
+ # Benchmark output (generated)
26
+ benchmarks/extraction/output/
27
+ benchmarks/extraction/.compare-cache/
28
+
29
+ # Git worktrees
30
+ .worktrees/
31
+
32
+ # OS
33
+ .DS_Store
34
+ Thumbs.db
35
+
36
+ # IDE
37
+ .idea/
38
+ .vscode/
39
+ *.swp
40
+ *.swo
41
+
42
+
43
+ CLAUDE.md
44
+ docs/
45
+
46
+ # IDE / tool configs
47
+ .claude/
48
+ .cursor/
49
+ .github/copilot-instructions.md
50
+
51
+ # Python bytecode
52
+ __pycache__/
53
+ *.pyc
54
+
55
+ # Private strategy doc (never commit)
56
+ competitive-blueprint.md
57
+
58
+
59
+ # local demo tooling (VHS tapes + build scripts), not shipped
60
+ .demo/
61
+
62
+ # SDK dev artifacts (each SDK also ships its own .gitignore)
63
+ .venv/
64
+ .pytest_cache/
65
+ *.egg-info
@@ -0,0 +1,145 @@
1
+ Metadata-Version: 2.4
2
+ Name: wigolo-llamaindex
3
+ Version: 0.2.0
4
+ Summary: LlamaIndex reader for wigolo — local-first web search MCP server
5
+ Project-URL: Homepage, https://github.com/KnockOutEZ/wigolo
6
+ Project-URL: Repository, https://github.com/KnockOutEZ/wigolo/tree/main/packages/wigolo-llamaindex
7
+ Project-URL: Issues, https://github.com/KnockOutEZ/wigolo/issues
8
+ Author: KnockOutEZ
9
+ License-Expression: AGPL-3.0-only
10
+ Keywords: llama-index,llamaindex,mcp,rag,reader,web-search
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: Other/Proprietary License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Software Development :: Libraries
20
+ Requires-Python: >=3.10
21
+ Requires-Dist: llama-index-core>=0.11.0
22
+ Requires-Dist: pydantic>=2.0.0
23
+ Provides-Extra: dev
24
+ Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
25
+ Requires-Dist: pytest-mock>=3.14; extra == 'dev'
26
+ Requires-Dist: pytest>=8.0; extra == 'dev'
27
+ Description-Content-Type: text/markdown
28
+
29
+ # wigolo-llamaindex
30
+
31
+ LlamaIndex reader for [wigolo](https://github.com/KnockOutEZ/wigolo) — a local-first web search MCP server for AI coding agents.
32
+
33
+ ## Installation
34
+
35
+ ```bash
36
+ pip install wigolo-llamaindex
37
+ ```
38
+
39
+ Requires wigolo to be available via npx:
40
+ ```bash
41
+ npm install -g wigolo
42
+ # or use npx (default, no install needed)
43
+ ```
44
+
45
+ ## Quick Start
46
+
47
+ ### Fetch URLs into Documents
48
+
49
+ ```python
50
+ from wigolo_llamaindex import WigoloMcpClient, WigoloWebReader
51
+
52
+ async def main():
53
+ async with WigoloMcpClient() as client:
54
+ reader = WigoloWebReader(client=client)
55
+ docs = await reader.aload_data(urls=[
56
+ "https://docs.python.org/3/library/asyncio.html",
57
+ "https://docs.python.org/3/library/typing.html",
58
+ ])
59
+ for doc in docs:
60
+ print(f"{doc.metadata['title']}: {len(doc.text)} chars")
61
+ ```
62
+
63
+ ### Search and Load
64
+
65
+ ```python
66
+ from wigolo_llamaindex import WigoloMcpClient, WigoloSearchReader
67
+
68
+ async def main():
69
+ async with WigoloMcpClient() as client:
70
+ reader = WigoloSearchReader(
71
+ client=client,
72
+ max_results=5,
73
+ include_domains=["docs.python.org"],
74
+ )
75
+ docs = await reader.aload_data(query="Python asyncio best practices")
76
+ ```
77
+
78
+ ### Use in a RAG Pipeline
79
+
80
+ ```python
81
+ from llama_index.core import VectorStoreIndex
82
+ from wigolo_llamaindex import WigoloMcpClient, WigoloWebReader
83
+
84
+ async def build_index():
85
+ async with WigoloMcpClient() as client:
86
+ reader = WigoloWebReader(client=client)
87
+ docs = await reader.aload_data(urls=[
88
+ "https://react.dev/learn",
89
+ "https://react.dev/reference/react",
90
+ ])
91
+ index = VectorStoreIndex.from_documents(docs)
92
+ return index
93
+ ```
94
+
95
+ ### Section Extraction
96
+
97
+ ```python
98
+ reader = WigoloWebReader(client=client, section="API Reference")
99
+ docs = await reader.aload_data(urls=["https://docs.example.com/api"])
100
+ # Only loads the "API Reference" section from each page
101
+ ```
102
+
103
+ ## API Reference
104
+
105
+ ### WigoloMcpClient
106
+
107
+ Async MCP client that communicates with wigolo via subprocess.
108
+
109
+ - `command` — executable (default: `"npx"`)
110
+ - `args` — arguments (default: `["wigolo"]`)
111
+ - `timeout` — seconds (default: `30.0`)
112
+ - Supports `async with` context manager
113
+
114
+ ### WigoloWebReader
115
+
116
+ Fetches URLs and converts to Documents.
117
+
118
+ - `client` — `WigoloMcpClient` instance
119
+ - `render_js` — "auto", "always", "never" (default: "auto")
120
+ - `section` — extract only a specific heading section
121
+ - `max_chars` — cap content length
122
+ - `use_auth` — use stored browser session
123
+
124
+ Methods:
125
+ - `load_data(urls: list[str]) -> list[Document]`
126
+ - `aload_data(urls: list[str]) -> list[Document]`
127
+ - `lazy_load_data(urls: list[str]) -> Iterator[Document]`
128
+
129
+ ### WigoloSearchReader
130
+
131
+ Searches the web and converts results to Documents.
132
+
133
+ - `client` — `WigoloMcpClient` instance
134
+ - `max_results` — default 5
135
+ - `include_domains` / `exclude_domains` — domain filters
136
+ - `category` — "general", "code", "docs", "news", "papers"
137
+
138
+ Methods:
139
+ - `load_data(query: str) -> list[Document]`
140
+ - `aload_data(query: str) -> list[Document]`
141
+ - `lazy_load_data(query: str) -> Iterator[Document]`
142
+
143
+ ## License
144
+
145
+ [GNU AGPL-3.0-only](../../LICENSE) — same license as the parent wigolo project. Full terms in the root `LICENSE`.
@@ -0,0 +1,117 @@
1
+ # wigolo-llamaindex
2
+
3
+ LlamaIndex reader for [wigolo](https://github.com/KnockOutEZ/wigolo) — a local-first web search MCP server for AI coding agents.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install wigolo-llamaindex
9
+ ```
10
+
11
+ Requires wigolo to be available via npx:
12
+ ```bash
13
+ npm install -g wigolo
14
+ # or use npx (default, no install needed)
15
+ ```
16
+
17
+ ## Quick Start
18
+
19
+ ### Fetch URLs into Documents
20
+
21
+ ```python
22
+ from wigolo_llamaindex import WigoloMcpClient, WigoloWebReader
23
+
24
+ async def main():
25
+ async with WigoloMcpClient() as client:
26
+ reader = WigoloWebReader(client=client)
27
+ docs = await reader.aload_data(urls=[
28
+ "https://docs.python.org/3/library/asyncio.html",
29
+ "https://docs.python.org/3/library/typing.html",
30
+ ])
31
+ for doc in docs:
32
+ print(f"{doc.metadata['title']}: {len(doc.text)} chars")
33
+ ```
34
+
35
+ ### Search and Load
36
+
37
+ ```python
38
+ from wigolo_llamaindex import WigoloMcpClient, WigoloSearchReader
39
+
40
+ async def main():
41
+ async with WigoloMcpClient() as client:
42
+ reader = WigoloSearchReader(
43
+ client=client,
44
+ max_results=5,
45
+ include_domains=["docs.python.org"],
46
+ )
47
+ docs = await reader.aload_data(query="Python asyncio best practices")
48
+ ```
49
+
50
+ ### Use in a RAG Pipeline
51
+
52
+ ```python
53
+ from llama_index.core import VectorStoreIndex
54
+ from wigolo_llamaindex import WigoloMcpClient, WigoloWebReader
55
+
56
+ async def build_index():
57
+ async with WigoloMcpClient() as client:
58
+ reader = WigoloWebReader(client=client)
59
+ docs = await reader.aload_data(urls=[
60
+ "https://react.dev/learn",
61
+ "https://react.dev/reference/react",
62
+ ])
63
+ index = VectorStoreIndex.from_documents(docs)
64
+ return index
65
+ ```
66
+
67
+ ### Section Extraction
68
+
69
+ ```python
70
+ reader = WigoloWebReader(client=client, section="API Reference")
71
+ docs = await reader.aload_data(urls=["https://docs.example.com/api"])
72
+ # Only loads the "API Reference" section from each page
73
+ ```
74
+
75
+ ## API Reference
76
+
77
+ ### WigoloMcpClient
78
+
79
+ Async MCP client that communicates with wigolo via subprocess.
80
+
81
+ - `command` — executable (default: `"npx"`)
82
+ - `args` — arguments (default: `["wigolo"]`)
83
+ - `timeout` — seconds (default: `30.0`)
84
+ - Supports `async with` context manager
85
+
86
+ ### WigoloWebReader
87
+
88
+ Fetches URLs and converts to Documents.
89
+
90
+ - `client` — `WigoloMcpClient` instance
91
+ - `render_js` — "auto", "always", "never" (default: "auto")
92
+ - `section` — extract only a specific heading section
93
+ - `max_chars` — cap content length
94
+ - `use_auth` — use stored browser session
95
+
96
+ Methods:
97
+ - `load_data(urls: list[str]) -> list[Document]`
98
+ - `aload_data(urls: list[str]) -> list[Document]`
99
+ - `lazy_load_data(urls: list[str]) -> Iterator[Document]`
100
+
101
+ ### WigoloSearchReader
102
+
103
+ Searches the web and converts results to Documents.
104
+
105
+ - `client` — `WigoloMcpClient` instance
106
+ - `max_results` — default 5
107
+ - `include_domains` / `exclude_domains` — domain filters
108
+ - `category` — "general", "code", "docs", "news", "papers"
109
+
110
+ Methods:
111
+ - `load_data(query: str) -> list[Document]`
112
+ - `aload_data(query: str) -> list[Document]`
113
+ - `lazy_load_data(query: str) -> Iterator[Document]`
114
+
115
+ ## License
116
+
117
+ [GNU AGPL-3.0-only](../../LICENSE) — same license as the parent wigolo project. Full terms in the root `LICENSE`.
@@ -0,0 +1,44 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "wigolo-llamaindex"
7
+ version = "0.2.0"
8
+ description = "LlamaIndex reader for wigolo — local-first web search MCP server"
9
+ readme = "README.md"
10
+ license = "AGPL-3.0-only"
11
+ requires-python = ">=3.10"
12
+ authors = [{ name = "KnockOutEZ" }]
13
+ keywords = ["llama-index", "llamaindex", "mcp", "web-search", "reader", "rag"]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Intended Audience :: Developers",
17
+ "License :: Other/Proprietary License",
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3.10",
20
+ "Programming Language :: Python :: 3.11",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Programming Language :: Python :: 3.13",
23
+ "Topic :: Software Development :: Libraries",
24
+ ]
25
+ dependencies = [
26
+ "llama-index-core>=0.11.0",
27
+ "pydantic>=2.0.0",
28
+ ]
29
+
30
+ [project.optional-dependencies]
31
+ dev = [
32
+ "pytest>=8.0",
33
+ "pytest-asyncio>=0.24",
34
+ "pytest-mock>=3.14",
35
+ ]
36
+
37
+ [project.urls]
38
+ Homepage = "https://github.com/KnockOutEZ/wigolo"
39
+ Repository = "https://github.com/KnockOutEZ/wigolo/tree/main/packages/wigolo-llamaindex"
40
+ Issues = "https://github.com/KnockOutEZ/wigolo/issues"
41
+
42
+ [tool.pytest.ini_options]
43
+ asyncio_mode = "auto"
44
+ testpaths = ["tests"]
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,153 @@
1
+ """Shared test fixtures for wigolo-llamaindex."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from typing import Any
7
+ from unittest.mock import AsyncMock, MagicMock
8
+
9
+ import pytest
10
+
11
+
12
+ MOCK_INITIALIZE_RESPONSE = {
13
+ "jsonrpc": "2.0",
14
+ "id": 1,
15
+ "result": {
16
+ "protocolVersion": "2025-03-26",
17
+ "serverInfo": {"name": "wigolo", "version": "0.4.0"},
18
+ "capabilities": {"tools": {}},
19
+ },
20
+ }
21
+
22
+ MOCK_FETCH_RESPONSE = {
23
+ "jsonrpc": "2.0",
24
+ "id": 3,
25
+ "result": {
26
+ "content": [
27
+ {
28
+ "type": "text",
29
+ "text": json.dumps(
30
+ {
31
+ "url": "https://example.com",
32
+ "title": "Example Page",
33
+ "markdown": "# Example\nThis is example content with useful information.",
34
+ "metadata": {"description": "An example page", "author": "Test Author"},
35
+ "links": ["https://example.com/page2"],
36
+ "images": ["https://example.com/img.png"],
37
+ "cached": False,
38
+ }
39
+ ),
40
+ }
41
+ ],
42
+ "isError": False,
43
+ },
44
+ }
45
+
46
+ MOCK_SEARCH_RESPONSE = {
47
+ "jsonrpc": "2.0",
48
+ "id": 3,
49
+ "result": {
50
+ "content": [
51
+ {
52
+ "type": "text",
53
+ "text": json.dumps(
54
+ {
55
+ "results": [
56
+ {
57
+ "title": "Search Result 1",
58
+ "url": "https://example.com/result1",
59
+ "snippet": "First result snippet",
60
+ "markdown_content": "# Result 1\nDetailed content from first result.",
61
+ "relevance_score": 0.95,
62
+ },
63
+ {
64
+ "title": "Search Result 2",
65
+ "url": "https://example.com/result2",
66
+ "snippet": "Second result snippet",
67
+ "markdown_content": "# Result 2\nDetailed content from second result.",
68
+ "relevance_score": 0.85,
69
+ },
70
+ ],
71
+ "query": "test query",
72
+ "engines_used": ["duckduckgo"],
73
+ "total_time_ms": 750,
74
+ }
75
+ ),
76
+ }
77
+ ],
78
+ "isError": False,
79
+ },
80
+ }
81
+
82
+ MOCK_FETCH_ERROR_RESPONSE = {
83
+ "jsonrpc": "2.0",
84
+ "id": 3,
85
+ "result": {
86
+ "content": [
87
+ {
88
+ "type": "text",
89
+ "text": json.dumps(
90
+ {
91
+ "url": "https://bad.example.com",
92
+ "title": "",
93
+ "markdown": "",
94
+ "metadata": {},
95
+ "links": [],
96
+ "images": [],
97
+ "cached": False,
98
+ "error": "Connection refused",
99
+ }
100
+ ),
101
+ }
102
+ ],
103
+ "isError": True,
104
+ },
105
+ }
106
+
107
+
108
+ def make_mock_process(responses: list[dict[str, Any]]) -> MagicMock:
109
+ """Create a mock subprocess with canned JSON-RPC responses."""
110
+ proc = MagicMock()
111
+ proc.returncode = None
112
+ proc.pid = 99999
113
+
114
+ response_lines = [json.dumps(r) + "\n" for r in responses]
115
+ read_index = {"i": 0}
116
+
117
+ async def mock_readline() -> bytes:
118
+ idx = read_index["i"]
119
+ if idx < len(response_lines):
120
+ read_index["i"] += 1
121
+ return response_lines[idx].encode()
122
+ return b""
123
+
124
+ proc.stdout = MagicMock()
125
+ proc.stdout.readline = mock_readline
126
+
127
+ proc.stdin = MagicMock()
128
+ proc.stdin.write = MagicMock()
129
+ proc.stdin.drain = AsyncMock()
130
+
131
+ proc.stderr = MagicMock()
132
+ proc.stderr.readline = AsyncMock(return_value=b"")
133
+
134
+ proc.wait = AsyncMock(return_value=0)
135
+ proc.terminate = MagicMock()
136
+ proc.kill = MagicMock()
137
+
138
+ return proc
139
+
140
+
141
+ @pytest.fixture
142
+ def mock_fetch_process():
143
+ return make_mock_process([MOCK_INITIALIZE_RESPONSE, MOCK_FETCH_RESPONSE])
144
+
145
+
146
+ @pytest.fixture
147
+ def mock_search_process():
148
+ return make_mock_process([MOCK_INITIALIZE_RESPONSE, MOCK_SEARCH_RESPONSE])
149
+
150
+
151
+ @pytest.fixture
152
+ def mock_error_process():
153
+ return make_mock_process([MOCK_INITIALIZE_RESPONSE, MOCK_FETCH_ERROR_RESPONSE])
@@ -0,0 +1,167 @@
1
+ """Unit tests for the MCP subprocess client."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import asyncio
6
+ import json
7
+ from unittest.mock import AsyncMock, patch
8
+
9
+ import pytest
10
+
11
+ from wigolo_llamaindex.client import WigoloMcpClient, WigoloClientError
12
+ from tests.conftest import (
13
+ MOCK_INITIALIZE_RESPONSE,
14
+ MOCK_FETCH_RESPONSE,
15
+ MOCK_SEARCH_RESPONSE,
16
+ make_mock_process,
17
+ )
18
+
19
+
20
+ class TestClientInit:
21
+ """Test client initialization."""
22
+
23
+ def test_default_command(self):
24
+ client = WigoloMcpClient()
25
+ assert client.command == "npx"
26
+ assert client.args == ["wigolo"]
27
+
28
+ def test_custom_command(self):
29
+ client = WigoloMcpClient(command="node", args=["./dist/index.js"])
30
+ assert client.command == "node"
31
+ assert client.args == ["./dist/index.js"]
32
+
33
+ def test_default_timeout(self):
34
+ client = WigoloMcpClient()
35
+ assert client.timeout == 30.0
36
+
37
+ def test_custom_timeout(self):
38
+ client = WigoloMcpClient(timeout=120.0)
39
+ assert client.timeout == 120.0
40
+
41
+ def test_not_connected_initially(self):
42
+ client = WigoloMcpClient()
43
+ assert client.is_connected is False
44
+
45
+
46
+ class TestClientConnect:
47
+ """Test client connection lifecycle."""
48
+
49
+ @pytest.mark.asyncio
50
+ async def test_connect_sets_connected(self):
51
+ mock_proc = make_mock_process([MOCK_INITIALIZE_RESPONSE])
52
+ with patch("asyncio.create_subprocess_exec", new_callable=AsyncMock, return_value=mock_proc):
53
+ client = WigoloMcpClient()
54
+ await client.connect()
55
+ assert client.is_connected is True
56
+ await client.disconnect()
57
+
58
+ @pytest.mark.asyncio
59
+ async def test_connect_sends_initialize(self):
60
+ mock_proc = make_mock_process([MOCK_INITIALIZE_RESPONSE])
61
+ with patch("asyncio.create_subprocess_exec", new_callable=AsyncMock, return_value=mock_proc):
62
+ client = WigoloMcpClient()
63
+ await client.connect()
64
+ write_calls = mock_proc.stdin.write.call_args_list
65
+ assert len(write_calls) >= 1
66
+ first_msg = json.loads(write_calls[0][0][0])
67
+ assert first_msg["method"] == "initialize"
68
+ await client.disconnect()
69
+
70
+ @pytest.mark.asyncio
71
+ async def test_disconnect_terminates_process(self):
72
+ mock_proc = make_mock_process([MOCK_INITIALIZE_RESPONSE])
73
+ with patch("asyncio.create_subprocess_exec", new_callable=AsyncMock, return_value=mock_proc):
74
+ client = WigoloMcpClient()
75
+ await client.connect()
76
+ await client.disconnect()
77
+ mock_proc.terminate.assert_called_once()
78
+
79
+ @pytest.mark.asyncio
80
+ async def test_disconnect_noop_when_not_connected(self):
81
+ client = WigoloMcpClient()
82
+ await client.disconnect()
83
+
84
+ @pytest.mark.asyncio
85
+ async def test_connect_timeout_raises(self):
86
+ mock_proc = make_mock_process([])
87
+ mock_proc.stdout.readline = AsyncMock(side_effect=asyncio.TimeoutError)
88
+ with patch("asyncio.create_subprocess_exec", new_callable=AsyncMock, return_value=mock_proc):
89
+ client = WigoloMcpClient(timeout=0.1)
90
+ with pytest.raises(WigoloClientError):
91
+ await client.connect()
92
+
93
+
94
+ class TestClientCallTool:
95
+ """Test tool invocation."""
96
+
97
+ @pytest.mark.asyncio
98
+ async def test_call_fetch_tool(self):
99
+ mock_proc = make_mock_process([MOCK_INITIALIZE_RESPONSE, MOCK_FETCH_RESPONSE])
100
+ with patch("asyncio.create_subprocess_exec", new_callable=AsyncMock, return_value=mock_proc):
101
+ client = WigoloMcpClient()
102
+ await client.connect()
103
+ result = await client.call_tool("fetch", {"url": "https://example.com"})
104
+ assert result["title"] == "Example Page"
105
+ assert "# Example" in result["markdown"]
106
+ await client.disconnect()
107
+
108
+ @pytest.mark.asyncio
109
+ async def test_call_search_tool(self):
110
+ mock_proc = make_mock_process([MOCK_INITIALIZE_RESPONSE, MOCK_SEARCH_RESPONSE])
111
+ with patch("asyncio.create_subprocess_exec", new_callable=AsyncMock, return_value=mock_proc):
112
+ client = WigoloMcpClient()
113
+ await client.connect()
114
+ result = await client.call_tool("search", {"query": "test"})
115
+ assert len(result["results"]) == 2
116
+ await client.disconnect()
117
+
118
+ @pytest.mark.asyncio
119
+ async def test_call_tool_not_connected_raises(self):
120
+ client = WigoloMcpClient()
121
+ with pytest.raises(WigoloClientError, match="not connected"):
122
+ await client.call_tool("fetch", {"url": "https://example.com"})
123
+
124
+ @pytest.mark.asyncio
125
+ async def test_call_tool_increments_ids(self):
126
+ mock_proc = make_mock_process([
127
+ MOCK_INITIALIZE_RESPONSE,
128
+ MOCK_FETCH_RESPONSE,
129
+ {**MOCK_FETCH_RESPONSE, "id": 4},
130
+ ])
131
+ with patch("asyncio.create_subprocess_exec", new_callable=AsyncMock, return_value=mock_proc):
132
+ client = WigoloMcpClient()
133
+ await client.connect()
134
+ await client.call_tool("fetch", {"url": "https://a.com"})
135
+ await client.call_tool("fetch", {"url": "https://b.com"})
136
+ write_calls = mock_proc.stdin.write.call_args_list
137
+ ids = set()
138
+ for c in write_calls:
139
+ raw = c[0][0] if isinstance(c[0][0], str) else c[0][0].decode()
140
+ msg = json.loads(raw)
141
+ if "id" in msg:
142
+ ids.add(msg["id"])
143
+ assert len(ids) >= 3
144
+ await client.disconnect()
145
+
146
+
147
+ class TestClientContextManager:
148
+ """Test async context manager."""
149
+
150
+ @pytest.mark.asyncio
151
+ async def test_async_with_connects_and_disconnects(self):
152
+ mock_proc = make_mock_process([MOCK_INITIALIZE_RESPONSE])
153
+ with patch("asyncio.create_subprocess_exec", new_callable=AsyncMock, return_value=mock_proc):
154
+ client = WigoloMcpClient()
155
+ async with client:
156
+ assert client.is_connected is True
157
+ mock_proc.terminate.assert_called_once()
158
+
159
+ @pytest.mark.asyncio
160
+ async def test_async_with_disconnects_on_exception(self):
161
+ mock_proc = make_mock_process([MOCK_INITIALIZE_RESPONSE])
162
+ with patch("asyncio.create_subprocess_exec", new_callable=AsyncMock, return_value=mock_proc):
163
+ client = WigoloMcpClient()
164
+ with pytest.raises(RuntimeError):
165
+ async with client:
166
+ raise RuntimeError("test")
167
+ mock_proc.terminate.assert_called_once()