Skip to content

Commit 8f81fec

Browse files
committed
refactor: de-isolate the mcp extra from the dev environment
- drop the ty: ignore on the mcp SDK imports in server.py - run the MCP tests unconditionally instead of importorskip-ing them - update the config.py env-file hint (no more `test` group) - docs: mcp is part of osw[all]; replace the anyio design note
1 parent c1ef65e commit 8f81fec

9 files changed

Lines changed: 12 additions & 36 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ OpenSemanticLab data model.
4141

4242
## CLI and MCP tools
4343

44-
Installing `osw` also installs an `osw` command line client, and the separate
44+
Installing `osw` also installs an `osw` command line client, and the
4545
`osw[mcp]` extra adds an MCP server that exposes a live instance to agent
4646
clients such as Claude Code:
4747

‎docs/cli-and-mcp.md‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ no install of its own.
2929

3030
</details>
3131

32-
`osw[mcp]` is not part of `osw[all]`, see [Design notes](#design-notes). The
33-
other extras are listed in the
32+
`osw[mcp]` is also part of `osw[all]`. The other extras are listed in the
3433
[Get Started guide](get-started.md#optional-extras).
3534

3635
Both adapters need an instance and credentials. The quickest start is a
@@ -314,12 +313,9 @@ Why the two adapters are shaped the way they are:
314313
- **stdio only.** SSE is deprecated upstream, and HTTP would need a
315314
per-connection auth model this server does not have: it holds one set of wiki
316315
credentials, which every client would share.
317-
- **`osw[mcp]` outside `osw[all]`.** It needs `anyio>=4.9`, which conflicts with
318-
the pin the `osw[workflow]` extra requires for prefect 2.x, so the two cannot
319-
share an environment
320-
([#139](https://github.com/OpenSemanticLab/osw-python/issues/139)).
321-
Installing the server standalone, for example via `uvx`, avoids the question
322-
entirely.
316+
- **`mcp` is an extra, not a base dependency.** The SDK pulls in a server stack
317+
(starlette, uvicorn, sse-starlette) that nothing in the Python API or the CLI
318+
needs, so only users who actually run the server pay for it.
323319

324320
## Notes for developers
325321

‎docs/get-started.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
| `osw[S3]` | Interact with S3 stores per S3FileController |
3131
| `osw[dataimport]` | Additional tools to import data |
3232
| `osw[UI]` | To use a helper UI to work with entity slots |
33+
| `osw[mcp]` | [MCP server](cli-and-mcp.md#mcp-server) for agent clients |
3334
| `osw[all]` | All of the above |
34-
| `osw[mcp]` | [MCP server](cli-and-mcp.md#mcp-server) for agent clients, not part of `osw[all]` |
3535

3636
Install multiple extras with `pip install osw[opt1,opt2]`.
3737

‎src/osw/mcp/server.py‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@
1212
import sys
1313
from typing import Any, Optional
1414

15-
# ty cannot resolve these: the mcp extra is uninstallable alongside the dev
16-
# group (anyio conflict, issue #139), so it is absent from the env ty runs in.
17-
# The rest of this module is type-checked; drop the ignores once #139 is fixed.
18-
from mcp.server import MCPServer # ty: ignore[unresolved-import]
19-
from mcp.types import ToolAnnotations # ty: ignore[unresolved-import]
15+
from mcp.server import MCPServer
16+
from mcp.types import ToolAnnotations
2017

2118
import osw
2219
import osw.service.ops

‎src/osw/service/config.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,7 @@ def _load_env_file() -> None:
226226
name = next((n for n in ENV_FILE if os.getenv(n) == path), ENV_FILE[0])
227227
raise RuntimeError(
228228
f"{name} is set (to '{path}') but python-dotenv is not installed. "
229-
"Install the osw[mcp] extra, or the `test` dependency group, to "
230-
"use an env file."
229+
"Install the osw[mcp] extra to use an env file."
231230
)
232231
if path:
233232
dotenv.load_dotenv(path)

‎tests/integration/test_mcp_server.py‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111

1212
import pytest
1313

14-
pytest.importorskip("mcp", reason="requires the osw[mcp] extra")
15-
pytest.importorskip("dotenv", reason="requires the osw[mcp] extra")
16-
1714
import osw.service.ops # noqa: F401 (registers the operations)
1815
from osw.service import config
1916
from osw.service.context import Context, Policy

‎tests/test_mcp_registration.py‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88

99
from __future__ import annotations
1010

11-
import pytest
12-
13-
pytest.importorskip("mcp", reason="requires the osw[mcp] extra")
14-
1511
from mcp.types import ToolAnnotations
1612

1713
from osw.mcp.server import _annotations, _meta, tool_kwargs

‎tests/test_mcp_server.py‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
import pytest
1515
import yaml
1616

17-
pytest.importorskip("mcp", reason="requires the osw[mcp] extra")
18-
pytest.importorskip("dotenv", reason="requires the osw[mcp] extra")
19-
2017
from osw.mcp import server
2118
from osw.service import config
2219
from osw.service.registry import iter_operations

‎tests/test_no_paths_on_mcp_surface.py‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
"""Guard tests: no filesystem path may ever reach the MCP surface.
22
3-
Runs in the plain dev env (no mcp extra needed): importing ``osw.cli.ops``
4-
(to register the CLI-only, path-taking operations, so the negative check
5-
below cannot pass vacuously) and ``osw.service.ops`` touches neither the
6-
``mcp`` SDK nor the network. Only ``test_mcp_server_never_imports_cli``
7-
needs the ``mcp`` extra (it imports ``osw.mcp.server`` itself), and
8-
self-skips without it.
3+
Offline: importing ``osw.cli.ops`` (to register the CLI-only, path-taking
4+
operations, so the negative check below cannot pass vacuously) and
5+
``osw.service.ops`` touches the network nowhere.
96
"""
107

118
from __future__ import annotations
@@ -15,8 +12,6 @@
1512
import sys
1613
from unittest.mock import MagicMock
1714

18-
import pytest
19-
2015
# Registers every operation, including the CLI-only path-taking ones, so
2116
# osw.service.registry.REGISTRY is fully populated for the checks below.
2217
import osw.cli.ops
@@ -72,7 +67,6 @@ def test_bound_operations_do_not_expose_ctx():
7267

7368

7469
def test_mcp_server_never_imports_cli():
75-
pytest.importorskip("mcp", reason="requires the osw[mcp] extra")
7670
result = subprocess.run(
7771
[
7872
sys.executable,

0 commit comments

Comments
 (0)