Skip to content

Commit e29b7fe

Browse files
committed
refactor: Centralize version management in _version.py and implement lazy loading for APCoreMCP.
1 parent 213d95f commit e29b7fe

4 files changed

Lines changed: 24 additions & 8 deletions

File tree

src/apcore_mcp/__init__.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from apcore_mcp.adapters.errors import ErrorMapper
1717
from apcore_mcp.adapters.id_normalizer import ModuleIDNormalizer
1818
from apcore_mcp.adapters.schema import SchemaConverter
19-
from apcore_mcp.apcore_mcp import APCoreMCP
2019
from apcore_mcp.auth import Authenticator, AuthMiddleware, ClaimMapping, JWTAuthenticator
2120
from apcore_mcp.constants import ERROR_CODES, MODULE_ID_PATTERN, REGISTRY_EVENTS
2221
from apcore_mcp.converters.openai import OpenAIConverter
@@ -65,7 +64,19 @@
6564
"MCP_ELICIT_KEY",
6665
]
6766

68-
__version__ = "0.10.0"
67+
from apcore_mcp._version import VERSION
68+
69+
__version__ = VERSION
70+
71+
72+
def __getattr__(name: str) -> object:
73+
if name == "APCoreMCP":
74+
from apcore_mcp.apcore_mcp import APCoreMCP
75+
76+
globals()["APCoreMCP"] = APCoreMCP
77+
return APCoreMCP
78+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
79+
6980

7081
logger = logging.getLogger(__name__)
7182

src/apcore_mcp/_version.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""Single source of truth for the package version."""
2+
3+
VERSION = "0.10.0"

src/apcore_mcp/apcore_mcp.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def __init__(
104104
logging.getLogger("apcore_mcp").setLevel(getattr(logging, log_level.upper()))
105105

106106
# Resolve backend: str/Path → Registry with discover(), otherwise pass through
107-
if isinstance(extensions_dir_or_backend, (str, Path)):
107+
if isinstance(extensions_dir_or_backend, str | Path):
108108
from apcore import Registry
109109

110110
backend: object = Registry(extensions_dir=str(extensions_dir_or_backend))
@@ -153,11 +153,11 @@ def _build_server_components(self) -> tuple[Any, Any, list, Any, Any]:
153153
Returns:
154154
Tuple of (server, router, tools, init_options, version).
155155
"""
156-
from apcore_mcp import __version__
156+
from apcore_mcp._version import VERSION
157157
from apcore_mcp.server.factory import MCPServerFactory
158158
from apcore_mcp.server.router import ExecutionRouter
159159

160-
version = self._version or __version__
160+
version = self._version or VERSION
161161

162162
factory = MCPServerFactory()
163163
server = factory.create_server(name=self._name, version=version)
@@ -194,7 +194,9 @@ def _build_explorer_routes(
194194
logger.info("Tool Explorer enabled at %s", explorer_prefix)
195195
return [mount]
196196

197-
def _build_auth_middleware(self, *, explorer: bool = False, explorer_prefix: str = "/explorer") -> list[tuple[type, dict]] | None:
197+
def _build_auth_middleware(
198+
self, *, explorer: bool = False, explorer_prefix: str = "/explorer"
199+
) -> list[tuple[type, dict]] | None:
198200
"""Build auth middleware list if authenticator is configured."""
199201
if self._authenticator is None:
200202
return None

tests/test_apcore_mcp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
from apcore_mcp.apcore_mcp import APCoreMCP
1111

12-
1312
# ---------------------------------------------------------------------------
1413
# Stubs
1514
# ---------------------------------------------------------------------------
@@ -58,6 +57,7 @@ async def call_async(self, module_id: str, inputs: dict[str, Any]) -> Any:
5857
# Helpers to build common patches for serve/async_serve
5958
# ---------------------------------------------------------------------------
6059

60+
6161
def _make_serve_patches():
6262
"""Return patches for the lazy imports inside APCoreMCP.serve()."""
6363
return (
@@ -118,7 +118,7 @@ def test_from_path_object(self) -> None:
118118

119119
mock_registry = StubRegistry()
120120
with patch("apcore.Registry", return_value=mock_registry) as mock_cls:
121-
mcp = APCoreMCP(Path("/tmp/extensions"))
121+
APCoreMCP(Path("/tmp/extensions"))
122122
mock_cls.assert_called_once_with(extensions_dir="/tmp/extensions")
123123

124124
def test_custom_name(self) -> None:

0 commit comments

Comments
 (0)