holon-sh 0.0.1.dev16__tar.gz → 0.0.1.dev17__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.
- {holon_sh-0.0.1.dev16 → holon_sh-0.0.1.dev17}/PKG-INFO +1 -1
- {holon_sh-0.0.1.dev16 → holon_sh-0.0.1.dev17}/holon/ext/events/_server.py +11 -69
- {holon_sh-0.0.1.dev16 → holon_sh-0.0.1.dev17}/holon/serve.py +1 -8
- {holon_sh-0.0.1.dev16 → holon_sh-0.0.1.dev17}/pyproject.toml +1 -1
- {holon_sh-0.0.1.dev16 → holon_sh-0.0.1.dev17}/tests/test_events.py +4 -40
- {holon_sh-0.0.1.dev16 → holon_sh-0.0.1.dev17}/.gitignore +0 -0
- {holon_sh-0.0.1.dev16 → holon_sh-0.0.1.dev17}/LICENSE +0 -0
- {holon_sh-0.0.1.dev16 → holon_sh-0.0.1.dev17}/README.md +0 -0
- {holon_sh-0.0.1.dev16 → holon_sh-0.0.1.dev17}/holon/client.py +0 -0
- {holon_sh-0.0.1.dev16 → holon_sh-0.0.1.dev17}/holon/context.py +0 -0
- {holon_sh-0.0.1.dev16 → holon_sh-0.0.1.dev17}/holon/ext/__init__.py +0 -0
- {holon_sh-0.0.1.dev16 → holon_sh-0.0.1.dev17}/holon/ext/events/__init__.py +0 -0
- {holon_sh-0.0.1.dev16 → holon_sh-0.0.1.dev17}/holon/ext/events/_client.py +0 -0
- {holon_sh-0.0.1.dev16 → holon_sh-0.0.1.dev17}/holon/ext/events/_wire.py +0 -0
- {holon_sh-0.0.1.dev16 → holon_sh-0.0.1.dev17}/holon/ext/files/__init__.py +0 -0
- {holon_sh-0.0.1.dev16 → holon_sh-0.0.1.dev17}/holon/ext/files/_client.py +0 -0
- {holon_sh-0.0.1.dev16 → holon_sh-0.0.1.dev17}/holon/ext/files/_server.py +0 -0
- {holon_sh-0.0.1.dev16 → holon_sh-0.0.1.dev17}/holon/ext/files/_wire.py +0 -0
- {holon_sh-0.0.1.dev16 → holon_sh-0.0.1.dev17}/holon/py.typed +0 -0
- {holon_sh-0.0.1.dev16 → holon_sh-0.0.1.dev17}/scripts/verify_distribution.py +0 -0
- {holon_sh-0.0.1.dev16 → holon_sh-0.0.1.dev17}/tests/fixtures/caller/holon/apps/__init__.py +0 -0
- {holon_sh-0.0.1.dev16 → holon_sh-0.0.1.dev17}/tests/test_context.py +0 -0
- {holon_sh-0.0.1.dev16 → holon_sh-0.0.1.dev17}/tests/test_elicit.py +0 -0
- {holon_sh-0.0.1.dev16 → holon_sh-0.0.1.dev17}/tests/test_files.py +0 -0
- {holon_sh-0.0.1.dev16 → holon_sh-0.0.1.dev17}/tests/test_package.py +0 -0
- {holon_sh-0.0.1.dev16 → holon_sh-0.0.1.dev17}/tests/test_runtime.py +0 -0
- {holon_sh-0.0.1.dev16 → holon_sh-0.0.1.dev17}/tests/test_serve.py +0 -0
|
@@ -22,10 +22,7 @@ import anyio
|
|
|
22
22
|
from mcp.server.context import CallNext, HandlerResult, ServerRequestContext
|
|
23
23
|
from mcp.server.extension import Extension, MethodBinding
|
|
24
24
|
from mcp.server.lowlevel.server import Server
|
|
25
|
-
from mcp.server.streamable_http_manager import StreamableHTTPSessionManager
|
|
26
|
-
from mcp.server.transport_security import RequestBodyLimitMiddleware
|
|
27
25
|
from mcp.shared.exceptions import MCPError
|
|
28
|
-
from mcp.shared.inbound import MCP_METHOD_HEADER
|
|
29
26
|
from mcp.shared.subscriptions import SUBSCRIPTION_ID_META_KEY
|
|
30
27
|
from mcp.types import (
|
|
31
28
|
INTERNAL_ERROR,
|
|
@@ -38,7 +35,6 @@ from mcp.types import (
|
|
|
38
35
|
)
|
|
39
36
|
from pydantic import Field, StrictInt, StrictStr, TypeAdapter, ValidationError
|
|
40
37
|
from pydantic_core import to_json, to_jsonable_python
|
|
41
|
-
from starlette.types import ASGIApp, Receive, Scope, Send
|
|
42
38
|
|
|
43
39
|
from holon.context import RequestContext, get_context
|
|
44
40
|
from holon.ext.events._wire import (
|
|
@@ -55,8 +51,6 @@ from holon.ext.events._wire import (
|
|
|
55
51
|
logger = logging.getLogger(__package__)
|
|
56
52
|
|
|
57
53
|
_MAX_POLL_EVENTS = 1000
|
|
58
|
-
# Set on a request that came through `Events.asgi`, whose answer can be a stream.
|
|
59
|
-
_STREAMS = "holon.ext.events.streams"
|
|
60
54
|
# What each event type keeps of what it emits: seconds, events, and bytes of JSON data.
|
|
61
55
|
_KEEP_AGE = 600.0
|
|
62
56
|
_KEEP_EVENTS = 10_000
|
|
@@ -358,42 +352,11 @@ class EventType(Generic[A, D]):
|
|
|
358
352
|
await asyncio.shield(entry.teardown)
|
|
359
353
|
|
|
360
354
|
|
|
361
|
-
# The SDK's private handler, which streams a 2026-07-28 request even on a JSON endpoint, when this SDK has it.
|
|
362
|
-
def _streaming(manager: StreamableHTTPSessionManager) -> ASGIApp | None:
|
|
363
|
-
try:
|
|
364
|
-
from mcp.server._streamable_http_modern import handle_modern_request
|
|
365
|
-
except ImportError:
|
|
366
|
-
return None
|
|
367
|
-
expected = ["app", "security_settings", "json_response", "lifespan_state"]
|
|
368
|
-
expected += ["scope", "receive", "send"]
|
|
369
|
-
taken = list(inspect.signature(handle_modern_request).parameters)
|
|
370
|
-
if taken != expected or not hasattr(manager, "_lifespan_state"):
|
|
371
|
-
return None
|
|
372
|
-
|
|
373
|
-
async def stream(scope: Scope, receive: Receive, send: Send) -> None:
|
|
374
|
-
await handle_modern_request(
|
|
375
|
-
manager.app,
|
|
376
|
-
manager.security_settings,
|
|
377
|
-
False,
|
|
378
|
-
manager._lifespan_state,
|
|
379
|
-
scope,
|
|
380
|
-
receive,
|
|
381
|
-
send,
|
|
382
|
-
)
|
|
383
|
-
|
|
384
|
-
return RequestBodyLimitMiddleware(stream, manager.max_request_body_size)
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
def _streams(ctx: ServerRequestContext[Any, Any]) -> bool:
|
|
388
|
-
# Over stdio every request can stream; over HTTP, only one that came through `Events.asgi`.
|
|
389
|
-
return ctx.request is None or bool(ctx.request.scope.get(_STREAMS))
|
|
390
|
-
|
|
391
|
-
|
|
392
355
|
class Events(Extension):
|
|
393
356
|
"""The event types an app serves as MCP Events.
|
|
394
357
|
|
|
395
358
|
Pass it to ``MCPServer(extensions=[events], middleware=[events])``, or call :meth:`serve` on a low-level
|
|
396
|
-
``Server``.
|
|
359
|
+
``Server``. Push needs an endpoint whose answers can stream: over Streamable HTTP, not ``json_response=True``.
|
|
397
360
|
"""
|
|
398
361
|
|
|
399
362
|
identifier = EVENTS_EXTENSION
|
|
@@ -498,25 +461,6 @@ class Events(Extension):
|
|
|
498
461
|
}
|
|
499
462
|
return result
|
|
500
463
|
|
|
501
|
-
def asgi(self, manager: StreamableHTTPSessionManager) -> ASGIApp:
|
|
502
|
-
"""The endpoint of ``manager``, with push.
|
|
503
|
-
|
|
504
|
-
Mount it where ``manager.handle_request`` would be, inside any authentication.
|
|
505
|
-
"""
|
|
506
|
-
streaming = _streaming(manager)
|
|
507
|
-
|
|
508
|
-
async def app(scope: Scope, receive: Receive, send: Send) -> None:
|
|
509
|
-
method = dict(scope.get("headers", [])).get(MCP_METHOD_HEADER.encode())
|
|
510
|
-
if scope["type"] == "http" and not manager.json_response:
|
|
511
|
-
scope = {**scope, _STREAMS: True}
|
|
512
|
-
elif scope["type"] == "http" and streaming and method is not None:
|
|
513
|
-
scope = {**scope, _STREAMS: True}
|
|
514
|
-
if method == b"events/stream":
|
|
515
|
-
return await streaming(scope, receive, send)
|
|
516
|
-
await manager.handle_request(scope, receive, send)
|
|
517
|
-
|
|
518
|
-
return app
|
|
519
|
-
|
|
520
464
|
async def _list(
|
|
521
465
|
self, ctx: ServerRequestContext[Any, Any], params: PaginatedRequestParams
|
|
522
466
|
) -> HandlerResult:
|
|
@@ -525,14 +469,12 @@ class Events(Extension):
|
|
|
525
469
|
if not cursor.isdigit():
|
|
526
470
|
raise MCPError(INVALID_PARAMS, "Invalid cursor for events/list")
|
|
527
471
|
start = int(cursor)
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
listed.append({**each._descriptor, "delivery": delivery})
|
|
535
|
-
result: dict[str, Any] = {"events": listed}
|
|
472
|
+
listed = list(self._types.values())[start : start + _LIST_PAGE_SIZE]
|
|
473
|
+
result: dict[str, Any] = {
|
|
474
|
+
"events": [
|
|
475
|
+
{**each._descriptor, "delivery": each._delivery} for each in listed
|
|
476
|
+
]
|
|
477
|
+
}
|
|
536
478
|
if start + _LIST_PAGE_SIZE < len(self._types):
|
|
537
479
|
result["nextCursor"] = str(start + _LIST_PAGE_SIZE)
|
|
538
480
|
return result
|
|
@@ -540,7 +482,7 @@ class Events(Extension):
|
|
|
540
482
|
async def _poll(
|
|
541
483
|
self, ctx: ServerRequestContext[Any, Any], params: _SubscribeParams
|
|
542
484
|
) -> HandlerResult:
|
|
543
|
-
request = await self._subscription(params, "poll"
|
|
485
|
+
request = await self._subscription(params, "poll")
|
|
544
486
|
declared = request.type
|
|
545
487
|
opened = declared._sequence
|
|
546
488
|
await self._lease(request)
|
|
@@ -576,13 +518,13 @@ class Events(Extension):
|
|
|
576
518
|
|
|
577
519
|
# Checked in the order of https://github.com/modelcontextprotocol/experimental-ext-triggers-events/blob/main/docs/design-sketch-proposal.md#error-codes
|
|
578
520
|
async def _subscription(
|
|
579
|
-
self, params: _SubscribeParams, delivery: Delivery
|
|
521
|
+
self, params: _SubscribeParams, delivery: Delivery
|
|
580
522
|
) -> _Request:
|
|
581
523
|
self._loop = self._loop or asyncio.get_running_loop()
|
|
582
524
|
declared = self._types.get(params.name)
|
|
583
525
|
if declared is None:
|
|
584
526
|
raise MCPError.from_error_data(_NOT_FOUND)
|
|
585
|
-
if delivery not in declared._delivery
|
|
527
|
+
if delivery not in declared._delivery:
|
|
586
528
|
raise MCPError(
|
|
587
529
|
UNSUPPORTED,
|
|
588
530
|
"Unsupported",
|
|
@@ -745,7 +687,7 @@ class Events(Extension):
|
|
|
745
687
|
async def _stream(
|
|
746
688
|
self, ctx: ServerRequestContext[Any, Any], params: _SubscribeParams
|
|
747
689
|
) -> HandlerResult:
|
|
748
|
-
request = await self._subscription(params, "push"
|
|
690
|
+
request = await self._subscription(params, "push")
|
|
749
691
|
declared = request.type
|
|
750
692
|
await declared._settled(request.id)
|
|
751
693
|
hold = self._open(request)
|
|
@@ -28,7 +28,6 @@ from starlette.responses import FileResponse, PlainTextResponse, Response
|
|
|
28
28
|
from starlette.types import ASGIApp, Receive, Scope, Send
|
|
29
29
|
|
|
30
30
|
from holon.context import _Request, _request
|
|
31
|
-
from holon.ext.events import Events
|
|
32
31
|
|
|
33
32
|
__all__ = ["App", "load", "serve"]
|
|
34
33
|
|
|
@@ -92,13 +91,7 @@ def _asgi(app: App) -> ASGIApp:
|
|
|
92
91
|
enable_dns_rebinding_protection=False
|
|
93
92
|
),
|
|
94
93
|
)
|
|
95
|
-
|
|
96
|
-
events = next(
|
|
97
|
-
(each for each in server.middleware if isinstance(each, Events)), None
|
|
98
|
-
)
|
|
99
|
-
mcp = AuthContextMiddleware(
|
|
100
|
-
manager.handle_request if events is None else events.asgi(manager)
|
|
101
|
-
)
|
|
94
|
+
mcp = AuthContextMiddleware(server.session_manager.handle_request)
|
|
102
95
|
platform = os.environ.get("HOLON_PLATFORM") == "1"
|
|
103
96
|
|
|
104
97
|
async def dispatch(scope: Scope, receive: Receive, send: Send) -> None:
|
|
@@ -2,7 +2,6 @@ import asyncio
|
|
|
2
2
|
import base64
|
|
3
3
|
import json
|
|
4
4
|
import socket
|
|
5
|
-
import sys
|
|
6
5
|
from contextlib import asynccontextmanager
|
|
7
6
|
from functools import partial, wraps
|
|
8
7
|
|
|
@@ -30,7 +29,7 @@ from starlette.applications import Starlette
|
|
|
30
29
|
from starlette.routing import Mount
|
|
31
30
|
|
|
32
31
|
from holon.client import Apps
|
|
33
|
-
from holon.ext.events import Events, EventType,
|
|
32
|
+
from holon.ext.events import Events, EventType, _server
|
|
34
33
|
from holon.serve import App, _asgi
|
|
35
34
|
|
|
36
35
|
IDENTITY = {"name": "watcher", "version": "1", "requires": {"boards": {}}}
|
|
@@ -493,42 +492,7 @@ async def test_a_subscription_can_be_retried_after_setup_times_out(
|
|
|
493
492
|
|
|
494
493
|
|
|
495
494
|
@asynchronous
|
|
496
|
-
async def
|
|
497
|
-
events, changed = declare()
|
|
498
|
-
bare = MCPServer("boards", extensions=[events])
|
|
499
|
-
# An SDK without the private stream path `Events.asgi` uses on a JSON endpoint.
|
|
500
|
-
monkeypatch.setitem(sys.modules, "mcp.server._streamable_http_modern", None)
|
|
501
|
-
wrapped = MCPServer("boards", extensions=[events])
|
|
502
|
-
wrapped.streamable_http_app(stateless_http=True, json_response=True)
|
|
503
|
-
manager = wrapped.session_manager
|
|
504
|
-
for app, path in [
|
|
505
|
-
(bare.streamable_http_app(stateless_http=True, json_response=True), "/mcp"),
|
|
506
|
-
(
|
|
507
|
-
Starlette(
|
|
508
|
-
routes=[Mount("/mcp", app=events.asgi(manager))],
|
|
509
|
-
lifespan=lambda app: manager.run(),
|
|
510
|
-
),
|
|
511
|
-
"/mcp/",
|
|
512
|
-
),
|
|
513
|
-
]:
|
|
514
|
-
port, stop = await serve(app)
|
|
515
|
-
boards = client(port, path=path)
|
|
516
|
-
async with boards.subscribe("board.changed", {"board": "b1"}) as changes:
|
|
517
|
-
assert changes.delivery == "poll"
|
|
518
|
-
say(changed, "b1", "polled")
|
|
519
|
-
assert await take(changes, 1) == ["polled"]
|
|
520
|
-
await changes.cancel()
|
|
521
|
-
assert await anext(changes, None) is None
|
|
522
|
-
with pytest.raises(NoCompatibleDeliveryMode):
|
|
523
|
-
async with boards.subscribe(
|
|
524
|
-
"board.changed", {"board": "b1"}, delivery="push"
|
|
525
|
-
):
|
|
526
|
-
pass
|
|
527
|
-
await stop()
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
@asynchronous
|
|
531
|
-
async def test_a_subscription_from_the_cursor_read_with_a_snapshot_hears_every_change_after_it_on_a_json_endpoint():
|
|
495
|
+
async def test_a_subscription_from_the_cursor_read_with_a_snapshot_hears_every_change_after_it():
|
|
532
496
|
events, said = Events(), []
|
|
533
497
|
changed: EventType[Board, Change] = events.event(
|
|
534
498
|
"board.changed", input_schema=Board, payload_schema=Change.model_json_schema()
|
|
@@ -544,10 +508,10 @@ async def test_a_subscription_from_the_cursor_read_with_a_snapshot_hears_every_c
|
|
|
544
508
|
|
|
545
509
|
server = Server("boards", on_call_tool=snapshot)
|
|
546
510
|
events.serve(server)
|
|
547
|
-
manager = StreamableHTTPSessionManager(server, stateless=True
|
|
511
|
+
manager = StreamableHTTPSessionManager(server, stateless=True)
|
|
548
512
|
port, stop = await serve(
|
|
549
513
|
Starlette(
|
|
550
|
-
routes=[Mount("/mcp", app=
|
|
514
|
+
routes=[Mount("/mcp", app=manager.handle_request)],
|
|
551
515
|
lifespan=lambda app: manager.run(),
|
|
552
516
|
)
|
|
553
517
|
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|