holon-sh 0.0.1.dev24__tar.gz → 0.0.1.dev25__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.dev24 → holon_sh-0.0.1.dev25}/PKG-INFO +1 -1
- {holon_sh-0.0.1.dev24 → holon_sh-0.0.1.dev25}/holon/ext/events/_server.py +11 -12
- {holon_sh-0.0.1.dev24 → holon_sh-0.0.1.dev25}/pyproject.toml +1 -1
- {holon_sh-0.0.1.dev24 → holon_sh-0.0.1.dev25}/tests/test_events.py +26 -23
- {holon_sh-0.0.1.dev24 → holon_sh-0.0.1.dev25}/.gitignore +0 -0
- {holon_sh-0.0.1.dev24 → holon_sh-0.0.1.dev25}/LICENSE +0 -0
- {holon_sh-0.0.1.dev24 → holon_sh-0.0.1.dev25}/README.md +0 -0
- {holon_sh-0.0.1.dev24 → holon_sh-0.0.1.dev25}/holon/client.py +0 -0
- {holon_sh-0.0.1.dev24 → holon_sh-0.0.1.dev25}/holon/context.py +0 -0
- {holon_sh-0.0.1.dev24 → holon_sh-0.0.1.dev25}/holon/ext/__init__.py +0 -0
- {holon_sh-0.0.1.dev24 → holon_sh-0.0.1.dev25}/holon/ext/events/__init__.py +0 -0
- {holon_sh-0.0.1.dev24 → holon_sh-0.0.1.dev25}/holon/ext/events/_client.py +0 -0
- {holon_sh-0.0.1.dev24 → holon_sh-0.0.1.dev25}/holon/ext/events/_wire.py +0 -0
- {holon_sh-0.0.1.dev24 → holon_sh-0.0.1.dev25}/holon/ext/files/__init__.py +0 -0
- {holon_sh-0.0.1.dev24 → holon_sh-0.0.1.dev25}/holon/ext/files/_client.py +0 -0
- {holon_sh-0.0.1.dev24 → holon_sh-0.0.1.dev25}/holon/ext/files/_server.py +0 -0
- {holon_sh-0.0.1.dev24 → holon_sh-0.0.1.dev25}/holon/ext/files/_wire.py +0 -0
- {holon_sh-0.0.1.dev24 → holon_sh-0.0.1.dev25}/holon/py.typed +0 -0
- {holon_sh-0.0.1.dev24 → holon_sh-0.0.1.dev25}/holon/serve.py +0 -0
- {holon_sh-0.0.1.dev24 → holon_sh-0.0.1.dev25}/scripts/verify_distribution.py +0 -0
- {holon_sh-0.0.1.dev24 → holon_sh-0.0.1.dev25}/tests/fixtures/caller/holon/apps/__init__.py +0 -0
- {holon_sh-0.0.1.dev24 → holon_sh-0.0.1.dev25}/tests/test_elicit.py +0 -0
- {holon_sh-0.0.1.dev24 → holon_sh-0.0.1.dev25}/tests/test_files.py +0 -0
- {holon_sh-0.0.1.dev24 → holon_sh-0.0.1.dev25}/tests/test_package.py +0 -0
- {holon_sh-0.0.1.dev24 → holon_sh-0.0.1.dev25}/tests/test_runtime.py +0 -0
- {holon_sh-0.0.1.dev24 → holon_sh-0.0.1.dev25}/tests/test_serve.py +0 -0
|
@@ -370,7 +370,7 @@ class Events(Extension):
|
|
|
370
370
|
self._epoch = secrets.token_hex(6)
|
|
371
371
|
self._types: dict[str, EventType[Any, Any]] = {}
|
|
372
372
|
self._held: Counter[str] = Counter()
|
|
373
|
-
self._sending
|
|
373
|
+
self._sending = 0
|
|
374
374
|
self._sent = asyncio.Event()
|
|
375
375
|
self._leases: dict[str, _Hold] = {}
|
|
376
376
|
self._loop: asyncio.AbstractEventLoop | None = None
|
|
@@ -595,7 +595,10 @@ class Events(Extension):
|
|
|
595
595
|
"ResourceExhausted",
|
|
596
596
|
{"limit": "subscriptions", "max": _MAX_SUBSCRIPTIONS},
|
|
597
597
|
)
|
|
598
|
-
if
|
|
598
|
+
if (
|
|
599
|
+
request.caller
|
|
600
|
+
and self._held[request.caller] >= _MAX_SUBSCRIPTIONS_PER_CALLER
|
|
601
|
+
):
|
|
599
602
|
raise MCPError(
|
|
600
603
|
RESOURCE_EXHAUSTED,
|
|
601
604
|
"ResourceExhausted",
|
|
@@ -676,20 +679,16 @@ class Events(Extension):
|
|
|
676
679
|
hold.lease.cancel()
|
|
677
680
|
self._close(hold)
|
|
678
681
|
|
|
679
|
-
# Waits for room to send `size` bytes.
|
|
682
|
+
# Waits for room to send `size` bytes.
|
|
680
683
|
@asynccontextmanager
|
|
681
|
-
async def _send_budget(self, size: int
|
|
682
|
-
while
|
|
683
|
-
(sending := self._sending.total()) and sending + size > _MAX_SENDING_BYTES
|
|
684
|
-
) or (
|
|
685
|
-
(mine := self._sending[caller]) and mine + size > _MAX_SENDING_BYTES // 4
|
|
686
|
-
):
|
|
684
|
+
async def _send_budget(self, size: int) -> AsyncIterator[None]:
|
|
685
|
+
while self._sending and self._sending + size > _MAX_SENDING_BYTES:
|
|
687
686
|
await self._sent.wait()
|
|
688
|
-
self._sending
|
|
687
|
+
self._sending += size
|
|
689
688
|
try:
|
|
690
689
|
yield
|
|
691
690
|
finally:
|
|
692
|
-
|
|
691
|
+
self._sending -= size
|
|
693
692
|
self._sent.set()
|
|
694
693
|
self._sent = asyncio.Event()
|
|
695
694
|
|
|
@@ -708,7 +707,7 @@ class Events(Extension):
|
|
|
708
707
|
method=f"notifications/events/{method}", params=body
|
|
709
708
|
)
|
|
710
709
|
with anyio.move_on_after(2 * _HEARTBEAT) as waited:
|
|
711
|
-
async with self._send_budget(size
|
|
710
|
+
async with self._send_budget(size):
|
|
712
711
|
await ctx.session.send_notification(
|
|
713
712
|
cast(ServerNotification, notification),
|
|
714
713
|
related_request_id=ctx.request_id,
|
|
@@ -21,7 +21,6 @@ from mcp.types import (
|
|
|
21
21
|
JSONRPC_VERSION,
|
|
22
22
|
LATEST_PROTOCOL_VERSION,
|
|
23
23
|
PROTOCOL_VERSION_META_KEY,
|
|
24
|
-
CallToolResult,
|
|
25
24
|
ErrorData,
|
|
26
25
|
)
|
|
27
26
|
from pydantic import BaseModel
|
|
@@ -452,6 +451,25 @@ async def test_a_poll_that_gives_up_while_it_is_set_up_stops_its_setup_and_holds
|
|
|
452
451
|
assert "result" in await call(http, port, "events/poll", changed_on("b2"))
|
|
453
452
|
|
|
454
453
|
|
|
454
|
+
@asynchronous
|
|
455
|
+
async def test_a_signed_in_caller_is_held_to_its_limit_and_callers_without_an_identity_only_to_the_limit_in_all(
|
|
456
|
+
monkeypatch,
|
|
457
|
+
):
|
|
458
|
+
monkeypatch.setattr(_server, "_MAX_SUBSCRIPTIONS_PER_CALLER", 1)
|
|
459
|
+
async with (
|
|
460
|
+
served(declare()[0]) as port,
|
|
461
|
+
httpx2.AsyncClient(headers={"x-holon-context": signed_in("ann")}) as ann,
|
|
462
|
+
httpx2.AsyncClient() as anonymous,
|
|
463
|
+
):
|
|
464
|
+
assert "result" in await call(ann, port, "events/poll", changed_on("b1"))
|
|
465
|
+
refused = await call(ann, port, "events/poll", changed_on("b2"))
|
|
466
|
+
assert refused["error"]["data"] == {"limit": "subscriptionsPerCaller", "max": 1}
|
|
467
|
+
for board in ("b1", "b2"):
|
|
468
|
+
assert "result" in await call(
|
|
469
|
+
anonymous, port, "events/poll", changed_on(board)
|
|
470
|
+
)
|
|
471
|
+
|
|
472
|
+
|
|
455
473
|
@asynchronous
|
|
456
474
|
async def test_a_subscription_can_be_retried_after_setup_times_out(
|
|
457
475
|
monkeypatch,
|
|
@@ -471,18 +489,9 @@ async def test_a_subscription_can_be_retried_after_setup_times_out(
|
|
|
471
489
|
|
|
472
490
|
|
|
473
491
|
@asynchronous
|
|
474
|
-
async def
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
def tell(text):
|
|
478
|
-
said.append(text)
|
|
479
|
-
say(changed, "b1", text)
|
|
480
|
-
|
|
481
|
-
async def snapshot(context, params):
|
|
482
|
-
state = {"said": list(said), "cursor": changed.cursor()}
|
|
483
|
-
return CallToolResult(content=[], structured_content=state)
|
|
484
|
-
|
|
485
|
-
server = Server("boards", on_call_tool=snapshot)
|
|
492
|
+
async def test_a_low_level_server_serves_the_events():
|
|
493
|
+
events, changed = declare()
|
|
494
|
+
server = Server("boards")
|
|
486
495
|
events.serve(server)
|
|
487
496
|
manager = StreamableHTTPSessionManager(server, stateless=True)
|
|
488
497
|
port, stop = await serve(
|
|
@@ -491,15 +500,9 @@ async def test_a_subscription_from_the_cursor_read_with_a_snapshot_hears_every_c
|
|
|
491
500
|
lifespan=lambda app: manager.run(),
|
|
492
501
|
)
|
|
493
502
|
)
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
boards = Apps(IDENTITY, {}, {"boards": binding}).boards
|
|
497
|
-
state = (await boards.call_tool("snapshot")).structured_content
|
|
498
|
-
tell("after the snapshot")
|
|
499
|
-
async with client(port).subscribe(
|
|
500
|
-
"board.changed", {"board": "b1"}, cursor=state["cursor"]
|
|
503
|
+
async with client(port, path="/mcp/").subscribe(
|
|
504
|
+
"board.changed", {"board": "b1"}
|
|
501
505
|
) as changes:
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
assert await take(changes, 2) == ["after the snapshot", "once subscribed"]
|
|
506
|
+
say(changed, "b1", "hello")
|
|
507
|
+
assert await take(changes, 1) == ["hello"]
|
|
505
508
|
await stop()
|
|
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
|