nlalpha-capability 0.2.0__tar.gz → 0.3.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: nlalpha-capability
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: NLAlpha capability discovery MCP server.
5
5
  Project-URL: Homepage, https://github.com/ruimarj/nlalpha-capability
6
6
  Project-URL: Repository, https://github.com/ruimarj/nlalpha-capability
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "nlalpha-capability"
7
- version = "0.2.0"
7
+ version = "0.3.0"
8
8
  description = "NLAlpha capability discovery MCP server."
9
9
  readme = "README.md"
10
10
  license = "AGPL-3.0-or-later"
@@ -2,6 +2,7 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ import asyncio
5
6
  from contextlib import asynccontextmanager
6
7
  from dataclasses import asdict
7
8
  from importlib.metadata import version
@@ -26,6 +27,28 @@ from nlalpha.core.telemetry import configure_telemetry, shutdown, get_meter, set
26
27
 
27
28
  logger = logging.getLogger("nlalpha-capability")
28
29
 
30
+
31
+ @asynccontextmanager
32
+ async def _session_manager_lifespan(mcp):
33
+ stop = asyncio.Event()
34
+ started = asyncio.Event()
35
+
36
+ async def run():
37
+ async with mcp.session_manager.run():
38
+ started.set()
39
+ await stop.wait()
40
+
41
+ task = asyncio.create_task(run())
42
+ task.add_done_callback(lambda _: started.set())
43
+ await started.wait()
44
+ if task.done():
45
+ task.result()
46
+ try:
47
+ yield
48
+ finally:
49
+ stop.set()
50
+ await task
51
+
29
52
  _meter = get_meter()
30
53
  _domains_counter = _meter.create_counter("nlalpha.capability.domains.listed")
31
54
  _helpers_histogram = _meter.create_histogram("nlalpha.capability.helpers.count")
@@ -189,17 +212,19 @@ def create_app(*, allowed_hosts: list[str] | tuple[str, ...] | None = None,
189
212
  for tool in (list_capability_domains, list_capabilities_by_domain, list_family_helpers,
190
213
  list_capability_providers, diagnose_providers, about, confess):
191
214
  mcp.add_tool(tool)
215
+ http_app = mcp.streamable_http_app()
216
+
192
217
  @asynccontextmanager
193
218
  async def lifespan(app):
194
219
  """Invoke only the explicitly injected process cleanup on application shutdown."""
195
- try:
196
- yield
197
- finally:
198
- if on_shutdown is not None:
199
- on_shutdown()
200
-
201
- sse_app = mcp.sse_app()
202
- app = Starlette(routes=[Route("/health", _health), *sse_app.routes], lifespan=lifespan)
220
+ async with _session_manager_lifespan(mcp):
221
+ try:
222
+ yield
223
+ finally:
224
+ if on_shutdown is not None:
225
+ on_shutdown()
226
+
227
+ app = Starlette(routes=[Route("/health", _health), *http_app.routes], lifespan=lifespan)
203
228
  app.state.mcp = mcp
204
229
  return app
205
230