Plan, apply and roll back changes to a production ontology, with a blast radius report and a proof an auditor can re-check.
Rust ai-nativedescription-logicsformal-verificationinfrastructure-as-codeisabelle-languageknowledge-graphleanlean4mcpmcp-serverontologyowlowl2reasoningrustshaclsparqltheorem-proving
fix(python): make mcp an extra, so the library does not install a server
Fabio Rovai2718b7da69cb
diff --git a/python/pyproject.toml b/python/pyproject.tomlindex a6c16e6d..622e52d7 100644--- a/python/pyproject.toml+++ b/python/pyproject.toml@@ -4,7 +4,7 @@ build-backend = "hatchling.build"[project]name = "open-ontologies-lite"-version = "0.4.0"+version = "0.5.0"description = "Lightweight Python bridge to the Oxigraph RDF/OWL engine, MCP server included. No Rust toolchain, no compilation."readme = "README.md"requires-python = ">=3.10"@@ -16,12 +16,22 @@ classifiers = ["License :: OSI Approved :: MIT License","Topic :: Scientific/Engineering",]+# The library half needs a triple store and nothing else. `mcp` is imported in+# exactly one module, server.py, and requiring it here made every consumer of+# the library install an MCP server stack they had not asked for. That is not+# only weight: `mcp` pulls a starlette major that current fastapi does not+# accept, so installing this package into a project that uses fastapi removes+# fastapi. Measured against semantica 0.6.6, whose pyproject declares+# `fastapi>=0.109.2`: installing 0.4.0 uninstalled it, and every import of+# `semantica/explorer` failed afterwards.dependencies = ["pyoxigraph>=0.5,<0.6",- "mcp>=1.2,<2",][project.optional-dependencies]+# The MCP server entry point, `open-ontologies-lite` on the command line and+# `python -m open_ontologies_lite`. The library API needs none of it.+server = ["mcp>=1.2,<2"]shacl = ["pyshacl>=0.26"]align = ["hnswlib>=0.8"]dev = ["pytest>=8"]diff --git a/python/src/open_ontologies_lite/server.py b/python/src/open_ontologies_lite/server.pyindex e15016a2..40145d1c 100644--- a/python/src/open_ontologies_lite/server.py+++ b/python/src/open_ontologies_lite/server.py@@ -8,7 +8,14 @@ Python over the prebuilt pyoxigraph (Oxigraph) wheel. Run with:from __future__ import annotations-from mcp.server.fastmcp import FastMCP+try:+ from mcp.server.fastmcp import FastMCP+except ModuleNotFoundError as exc: # pragma: no cover - import-time guard+ raise ModuleNotFoundError(+ "The MCP server needs the `server` extra: "+ "pip install 'open-ontologies-lite[server]'. The library API "+ "(OntologyEngine, vocab_check, shacl_validate) does not."+ ) from excfrom . import __version__from .engine import OntologyEnginediff --git a/python/tests/test_library_needs_no_server_stack.py b/python/tests/test_library_needs_no_server_stack.pynew file mode 100644index 00000000..b2edf63b--- /dev/null+++ b/python/tests/test_library_needs_no_server_stack.py@@ -0,0 +1,42 @@+"""The library API must import without the MCP server stack.++`mcp` is imported in exactly one module, server.py. Requiring it as a core+dependency made every consumer of the library install an MCP server they had+not asked for, and it is not merely weight: `mcp` pulls a starlette major that+current fastapi does not accept, so installing this package into a project+using fastapi removes fastapi. Measured against semantica 0.6.6, which declares+`fastapi>=0.109.2`: installing 0.4.0 uninstalled it and every import of+`semantica/explorer` failed afterwards.+"""++import subprocess+import sys+++LIBRARY_IMPORTS = (+ "from open_ontologies_lite import OntologyEngine, vocab_check, resolve_format; "+ "OntologyEngine().load("+ "'<http://x/A> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://x/B> .', "+ "'ntriples'); "+ "print('ok')"+)+++def test_the_library_api_imports_with_mcp_unavailable():+ """Run in a fresh process with `mcp` forced to be missing."""+ # `sys.modules[name] = None` makes `import name` raise ImportError, which+ # is what an uninstalled package looks like from inside the interpreter.+ blocker = "import sys; sys.modules['mcp'] = None\n"+ result = subprocess.run(+ [sys.executable, "-c", blocker + LIBRARY_IMPORTS],+ capture_output=True,+ text=True,+ )+ assert result.returncode == 0, result.stderr+ assert "ok" in result.stdout+++def test_the_server_module_says_which_extra_it_needs():+ import open_ontologies_lite++ assert "mcp" not in getattr(open_ontologies_lite, "__all__", [])