aiohttp-tiny-mcp 0.6.1__tar.gz → 0.7.1__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.
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/PKG-INFO +1 -1
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/pyproject.toml +1 -1
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/pyproject.toml.orig +1 -1
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/protocol/adapter.py +1 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/protocol/core.py +1 -0
- aiohttp_tiny_mcp-0.7.1/src/aiohttp_tiny_mcp/server/batch.py +39 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/server/dispatcher.py +21 -11
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/server/http.py +33 -12
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/server/registry.py +10 -0
- aiohttp_tiny_mcp-0.7.1/src/aiohttp_tiny_mcp/server/resource_auth.py +68 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/server/specs.py +7 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/server/sse.py +21 -3
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/server/subscriptions.py +7 -1
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/LICENSE +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/README.md +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/__init__.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/access_log.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/auth/__init__.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/auth/jwt.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/client/__init__.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/client/base.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/client/callback.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/client/http.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/client/loopback.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/client/oauth.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/client/oauth_helpers.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/client/stdio.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/console/__init__.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/console/agent-config.js +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/console/console.css +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/console/console.js +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/console/index.html +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/console/oauth-callback.html +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/extensions/__init__.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/extensions/skills.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/oauth/__init__.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/oauth/github.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/oauth/provider.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/oauth/server.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/oauth/tokens.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/protocol/__init__.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/protocol/models.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/protocol/schema.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/protocol/selection.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/protocol/v2024_11_05.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/protocol/v2025_03_26.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/protocol/v2025_06_18.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/protocol/v2025_11_25.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/protocol/v2026_07_28.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/py.typed +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/server/__init__.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/server/exchange.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/server/request_state.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/server/stdio.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/server/tasks.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/storage/__init__.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/storage/hub.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/storage/namespaces.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/storage/postgres.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/storage/redis.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/storage/sessions.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/storage/sqlite.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/testing.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/transport/__init__.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/transport/metadata.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/transport/sse.py +0 -0
|
@@ -97,6 +97,7 @@ class Adapter(ABC):
|
|
|
97
97
|
FailureKind.UNKNOWN_METHOD: (-32601, 200),
|
|
98
98
|
FailureKind.UNKNOWN_TARGET: (-32601, 200),
|
|
99
99
|
FailureKind.RESOURCE_NOT_FOUND: (-32002, 200),
|
|
100
|
+
FailureKind.ACCESS_DENIED: (-32003, 403),
|
|
100
101
|
FailureKind.HEADER_MISMATCH: (-32603, 200),
|
|
101
102
|
FailureKind.UNSUPPORTED_VERSION: (-32600, 400),
|
|
102
103
|
FailureKind.INPUT_UNSUPPORTED: (-32603, 200),
|
|
@@ -84,6 +84,7 @@ class FailureKind(StringEnum):
|
|
|
84
84
|
UNKNOWN_METHOD = "unknown_method"
|
|
85
85
|
UNKNOWN_TARGET = "unknown_target"
|
|
86
86
|
RESOURCE_NOT_FOUND = "resource_not_found"
|
|
87
|
+
ACCESS_DENIED = "access_denied"
|
|
87
88
|
INVALID_PARAMS = "invalid_params"
|
|
88
89
|
INVALID_ARGUMENTS = "invalid_arguments"
|
|
89
90
|
HEADER_MISMATCH = "header_mismatch"
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""Bounded execution of batch items with results in input order."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
from collections.abc import Awaitable, Callable, Sequence
|
|
7
|
+
from typing import TypeVar
|
|
8
|
+
|
|
9
|
+
from .tasks import stop
|
|
10
|
+
|
|
11
|
+
Item = TypeVar("Item")
|
|
12
|
+
Result = TypeVar("Result")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
async def run_batch(
|
|
16
|
+
items: Sequence[Item], execute: Callable[[Item], Awaitable[Result]], concurrency: int
|
|
17
|
+
) -> list[Result]:
|
|
18
|
+
"""Run at most concurrency items at once and finish all workers before returning."""
|
|
19
|
+
if concurrency == 1 or len(items) <= 1:
|
|
20
|
+
return [await execute(item) for item in items]
|
|
21
|
+
pending = iter(enumerate(items))
|
|
22
|
+
results: dict[int, Result] = {}
|
|
23
|
+
|
|
24
|
+
async def worker() -> None:
|
|
25
|
+
for index, item in pending:
|
|
26
|
+
results[index] = await execute(item)
|
|
27
|
+
|
|
28
|
+
workers = [
|
|
29
|
+
asyncio.create_task(worker()) for worker_index in range(min(concurrency, len(items)))
|
|
30
|
+
]
|
|
31
|
+
running = set(workers)
|
|
32
|
+
try:
|
|
33
|
+
while running:
|
|
34
|
+
finished, running = await asyncio.wait(running, return_when=asyncio.FIRST_COMPLETED)
|
|
35
|
+
for task in finished:
|
|
36
|
+
task.result()
|
|
37
|
+
finally:
|
|
38
|
+
await stop(*workers)
|
|
39
|
+
return [results[index] for index in range(len(items))]
|
|
@@ -24,6 +24,7 @@ from aiohttp_tiny_mcp.protocol.core import (
|
|
|
24
24
|
)
|
|
25
25
|
from aiohttp_tiny_mcp.protocol.models import (
|
|
26
26
|
CallToolResult,
|
|
27
|
+
CompleteParams,
|
|
27
28
|
CompleteResult,
|
|
28
29
|
Completion,
|
|
29
30
|
EmptyResult,
|
|
@@ -48,6 +49,7 @@ from aiohttp_tiny_mcp.protocol.models import (
|
|
|
48
49
|
from .exchange import Exchange
|
|
49
50
|
from .registry import Registry
|
|
50
51
|
from .request_state import RequestStates, protect_request_state, restore_request_state
|
|
52
|
+
from .resource_auth import resource_refusal, visible_resource
|
|
51
53
|
from .specs import ToolSpec
|
|
52
54
|
from .subscriptions import listen, subscribe, unsubscribe
|
|
53
55
|
|
|
@@ -244,12 +246,11 @@ class Dispatcher:
|
|
|
244
246
|
"resources/subscribe needs the session the handshake issued",
|
|
245
247
|
)
|
|
246
248
|
if wanted:
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
if definition is None or (
|
|
250
|
-
isinstance(definition, ResourceDef) and definition.uri != uri
|
|
251
|
-
):
|
|
249
|
+
spec = visible_resource(self.registry, ex.adapter, uri)
|
|
250
|
+
if spec is None:
|
|
252
251
|
return Failure(FailureKind.RESOURCE_NOT_FOUND, f"no resource matches {uri}")
|
|
252
|
+
if (refused := resource_refusal(spec, ex.principal)) is not None:
|
|
253
|
+
return Failure(FailureKind.ACCESS_DENIED, refused)
|
|
253
254
|
await (subscribe if wanted else unsubscribe)(ex.session, uri)
|
|
254
255
|
return Value(result=EmptyResult())
|
|
255
256
|
|
|
@@ -344,13 +345,10 @@ class Dispatcher:
|
|
|
344
345
|
if found is None:
|
|
345
346
|
return Failure(FailureKind.RESOURCE_NOT_FOUND, f"resource not found: {uri}")
|
|
346
347
|
spec, variables = found
|
|
347
|
-
|
|
348
|
-
if definition is None or (isinstance(definition, ResourceDef) and definition.uri != uri):
|
|
348
|
+
if visible_resource(self.registry, ex.adapter, uri) is None:
|
|
349
349
|
return Failure(FailureKind.RESOURCE_NOT_FOUND, f"resource not found: {uri}")
|
|
350
|
-
if
|
|
351
|
-
|
|
352
|
-
if pattern is None or pattern.fullmatch(uri) is None:
|
|
353
|
-
return Failure(FailureKind.RESOURCE_NOT_FOUND, f"resource not found: {uri}")
|
|
350
|
+
if (refused := resource_refusal(spec, ex.principal)) is not None:
|
|
351
|
+
return Failure(FailureKind.ACCESS_DENIED, refused)
|
|
354
352
|
try:
|
|
355
353
|
value = await spec.bound.call(variables, ex)
|
|
356
354
|
except ValidationError as e:
|
|
@@ -381,6 +379,18 @@ class Dispatcher:
|
|
|
381
379
|
return Value(result=prompt_result(value))
|
|
382
380
|
|
|
383
381
|
async def complete(self, ex: Exchange) -> Outcome:
|
|
382
|
+
if isinstance(ex.call.params, CompleteParams) and ex.call.params.ref.type == "ref/resource":
|
|
383
|
+
uri = ex.call.params.ref.uri or ""
|
|
384
|
+
spec = visible_resource(self.registry, ex.adapter, uri, template=True)
|
|
385
|
+
if spec is not None:
|
|
386
|
+
if (refused := resource_refusal(spec, ex.principal)) is not None:
|
|
387
|
+
return Failure(FailureKind.ACCESS_DENIED, refused)
|
|
388
|
+
elif self.registry.match_resource(uri) is not None or any(
|
|
389
|
+
candidate.template is not None
|
|
390
|
+
and uri in (candidate.template.uri_template, candidate.legacy_uri)
|
|
391
|
+
for candidate in self.registry.resources_templated
|
|
392
|
+
):
|
|
393
|
+
return Failure(FailureKind.RESOURCE_NOT_FOUND, f"resource not found: {uri}")
|
|
384
394
|
completer = self.registry.completer
|
|
385
395
|
if completer is None:
|
|
386
396
|
return Value(result=CompleteResult(completion=Completion(values=[])))
|
|
@@ -45,9 +45,11 @@ from aiohttp_tiny_mcp.storage.sessions import (
|
|
|
45
45
|
from aiohttp_tiny_mcp.transport.metadata import metadata_route
|
|
46
46
|
from aiohttp_tiny_mcp.transport.sse import SSEResponse
|
|
47
47
|
|
|
48
|
+
from .batch import run_batch
|
|
48
49
|
from .dispatcher import Dispatcher
|
|
49
50
|
from .exchange import Exchange, is_reply, relay_reply
|
|
50
51
|
from .registry import Registry
|
|
52
|
+
from .resource_auth import allowed_resource
|
|
51
53
|
from .subscriptions import relays, wanted
|
|
52
54
|
from .tasks import stop
|
|
53
55
|
|
|
@@ -101,7 +103,10 @@ class Endpoint:
|
|
|
101
103
|
allowed_origins: set[str] | None = None,
|
|
102
104
|
trust_proxy_origin_validation: bool = False,
|
|
103
105
|
compress: bool = True,
|
|
106
|
+
batch_concurrency: int = 4,
|
|
104
107
|
) -> None:
|
|
108
|
+
if type(batch_concurrency) is not int or batch_concurrency < 1:
|
|
109
|
+
raise ValueError("batch_concurrency must be a positive integer")
|
|
105
110
|
self.registry = registry
|
|
106
111
|
self.adapters = adapters or AdapterSet.default()
|
|
107
112
|
self.dispatcher = Dispatcher(registry)
|
|
@@ -109,6 +114,7 @@ class Endpoint:
|
|
|
109
114
|
self.origin_patterns = [origin_pattern(o) for o in allowed_origins or () if "*" in o]
|
|
110
115
|
self.trust_proxy_origin_validation = trust_proxy_origin_validation
|
|
111
116
|
self.compress = compress
|
|
117
|
+
self.batch_concurrency = batch_concurrency
|
|
112
118
|
|
|
113
119
|
@cached_property
|
|
114
120
|
def view(self) -> type[web.View]:
|
|
@@ -375,18 +381,17 @@ class Endpoint:
|
|
|
375
381
|
if will_reply and not self.accepts(request, "application/json"):
|
|
376
382
|
return web.Response(status=406, text="client does not accept application/json")
|
|
377
383
|
|
|
378
|
-
replies: list[tuple[int, Mapping[str, Any]]] = []
|
|
379
384
|
minted: str | None = None
|
|
380
|
-
|
|
385
|
+
|
|
386
|
+
async def execute(item: Call | DecodeFailure) -> tuple[int, Mapping[str, Any]] | None:
|
|
387
|
+
nonlocal minted
|
|
381
388
|
if isinstance(item, DecodeFailure):
|
|
382
389
|
if item.must_respond:
|
|
383
|
-
|
|
384
|
-
(
|
|
385
|
-
|
|
386
|
-
adapter.encode_failure(item.id, item.failure),
|
|
387
|
-
)
|
|
390
|
+
return (
|
|
391
|
+
adapter.http_status(item.failure),
|
|
392
|
+
adapter.encode_failure(item.id, item.failure),
|
|
388
393
|
)
|
|
389
|
-
|
|
394
|
+
return None
|
|
390
395
|
ex = Exchange(self.registry, request, adapter, item, held)
|
|
391
396
|
ex.principal = principal
|
|
392
397
|
outcome = await self.dispatcher.run(ex)
|
|
@@ -394,8 +399,11 @@ class Endpoint:
|
|
|
394
399
|
owner = principal.identity if principal is not None else None
|
|
395
400
|
minted = await self.open_session(adapter, item, outcome, owner)
|
|
396
401
|
if item.is_notification:
|
|
397
|
-
|
|
398
|
-
|
|
402
|
+
return None
|
|
403
|
+
return self.encode(adapter, item, outcome)
|
|
404
|
+
|
|
405
|
+
results = await run_batch(items, execute, self.batch_concurrency if pre.is_batch else 1)
|
|
406
|
+
replies = [result for result in results if result is not None]
|
|
399
407
|
|
|
400
408
|
if not replies:
|
|
401
409
|
return web.Response(status=202)
|
|
@@ -451,7 +459,9 @@ class Endpoint:
|
|
|
451
459
|
|
|
452
460
|
response = SSEResponse(compress=self.compress)
|
|
453
461
|
await response.prepare(request)
|
|
454
|
-
relay = asyncio.create_task(
|
|
462
|
+
relay = asyncio.create_task(
|
|
463
|
+
self.relay_notifications(request, response, adapter, principal=principal)
|
|
464
|
+
)
|
|
455
465
|
try:
|
|
456
466
|
while not relay.done():
|
|
457
467
|
await asyncio.wait({relay}, timeout=0.05)
|
|
@@ -463,7 +473,12 @@ class Endpoint:
|
|
|
463
473
|
return response
|
|
464
474
|
|
|
465
475
|
async def relay_notifications(
|
|
466
|
-
self,
|
|
476
|
+
self,
|
|
477
|
+
request: web.Request,
|
|
478
|
+
response: SSEResponse,
|
|
479
|
+
adapter: Adapter,
|
|
480
|
+
*,
|
|
481
|
+
principal: Principal | None = None,
|
|
467
482
|
) -> None:
|
|
468
483
|
"""Relay changes with their hub ids, re-reading subscriptions each pass."""
|
|
469
484
|
capabilities = adapter.capabilities(self.registry)
|
|
@@ -477,6 +492,12 @@ class Endpoint:
|
|
|
477
492
|
self.open_values(request, await self.stored(request)),
|
|
478
493
|
self.registry.broadcasts,
|
|
479
494
|
)
|
|
495
|
+
if "resourceSubscriptions" in accepted:
|
|
496
|
+
accepted["resourceSubscriptions"] = [
|
|
497
|
+
uri
|
|
498
|
+
for uri in accepted["resourceSubscriptions"]
|
|
499
|
+
if allowed_resource(self.registry, adapter, uri, principal)
|
|
500
|
+
]
|
|
480
501
|
for event in found:
|
|
481
502
|
if relays(event.message, accepted):
|
|
482
503
|
text = serialized(event.message).decode()
|
|
@@ -132,6 +132,11 @@ class Registry:
|
|
|
132
132
|
}
|
|
133
133
|
claimed: set[str] = set()
|
|
134
134
|
for uri, resource in resources.items():
|
|
135
|
+
if resource.scopes and self.auth is None:
|
|
136
|
+
raise TypeError(
|
|
137
|
+
f"{uri}: scopes were declared, but this registry has no auth= -- "
|
|
138
|
+
f"a scope nothing verifies is a check that never runs"
|
|
139
|
+
)
|
|
135
140
|
for address in {uri, resource.legacy_uri}:
|
|
136
141
|
if address is None:
|
|
137
142
|
continue
|
|
@@ -259,6 +264,11 @@ class Registry:
|
|
|
259
264
|
def resource(self, uri: str, fn: Callable[..., Awaitable[Any]] | None = None, **kw: Any):
|
|
260
265
|
def register(fn: Callable[..., Awaitable[Any]]):
|
|
261
266
|
spec = ResourceSpec.build(uri, fn, **kw)
|
|
267
|
+
if spec.scopes and self.auth is None:
|
|
268
|
+
raise TypeError(
|
|
269
|
+
f"{uri}: scopes were declared, but this registry has no auth= -- "
|
|
270
|
+
f"a scope nothing verifies is a check that never runs"
|
|
271
|
+
)
|
|
262
272
|
self.check(uri, spec.bound)
|
|
263
273
|
if spec.definition is not None:
|
|
264
274
|
if (
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"""Resource visibility and authorization shared by calls and notification streams."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
|
+
|
|
7
|
+
from aiohttp_tiny_mcp.auth import Principal
|
|
8
|
+
from aiohttp_tiny_mcp.protocol.models import ResourceDef, ResourceTemplateDef
|
|
9
|
+
|
|
10
|
+
if TYPE_CHECKING:
|
|
11
|
+
from aiohttp_tiny_mcp.protocol.adapter import Adapter, RegistryProtocol
|
|
12
|
+
|
|
13
|
+
from .specs import ResourceSpec
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def visible_resource(
|
|
17
|
+
registry: RegistryProtocol, adapter: Adapter, uri: str, *, template: bool = False
|
|
18
|
+
) -> ResourceSpec | None:
|
|
19
|
+
"""Resolve a resource using only the URI spelling exposed by this revision."""
|
|
20
|
+
if template:
|
|
21
|
+
for spec in registry.resources_templated:
|
|
22
|
+
if spec.template is None or uri not in (spec.template.uri_template, spec.legacy_uri):
|
|
23
|
+
continue
|
|
24
|
+
definition = adapter.describe_resource(spec)
|
|
25
|
+
if isinstance(definition, ResourceTemplateDef) and definition.uri_template == uri:
|
|
26
|
+
return spec
|
|
27
|
+
return None
|
|
28
|
+
found = registry.match_resource(uri)
|
|
29
|
+
if found is None:
|
|
30
|
+
return None
|
|
31
|
+
spec = found[0]
|
|
32
|
+
definition = adapter.describe_resource(spec)
|
|
33
|
+
if definition is None:
|
|
34
|
+
return None
|
|
35
|
+
if isinstance(definition, ResourceDef):
|
|
36
|
+
return spec if definition.uri == uri else None
|
|
37
|
+
pattern = spec.pattern
|
|
38
|
+
if spec.legacy_uri is not None and not adapter.supports_extensions:
|
|
39
|
+
pattern = spec.legacy_pattern
|
|
40
|
+
return spec if pattern is not None and pattern.fullmatch(uri) is not None else None
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def resource_refusal(spec: ResourceSpec, principal: Principal | None) -> str | None:
|
|
44
|
+
"""Describe a resource scope failure without invoking its handler or dependencies."""
|
|
45
|
+
if not spec.scopes:
|
|
46
|
+
return None
|
|
47
|
+
label = "resource"
|
|
48
|
+
if spec.definition is not None:
|
|
49
|
+
label = spec.definition.uri
|
|
50
|
+
elif spec.template is not None:
|
|
51
|
+
label = spec.template.uri_template
|
|
52
|
+
if principal is None:
|
|
53
|
+
return (
|
|
54
|
+
f"{label} requires the scopes {', '.join(sorted(spec.scopes))}, and this "
|
|
55
|
+
f"request carried no verified caller"
|
|
56
|
+
)
|
|
57
|
+
missing = principal.holds(spec.scopes)
|
|
58
|
+
if missing:
|
|
59
|
+
return f"{label} requires the scope {', '.join(sorted(missing))}"
|
|
60
|
+
return None
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def allowed_resource(
|
|
64
|
+
registry: RegistryProtocol, adapter: Adapter, uri: str, principal: Principal | None
|
|
65
|
+
) -> bool:
|
|
66
|
+
"""Check a concrete resource URI before including it in a notification stream."""
|
|
67
|
+
spec = visible_resource(registry, adapter, uri)
|
|
68
|
+
return spec is not None and resource_refusal(spec, principal) is None
|
|
@@ -156,6 +156,7 @@ class ResourceSpec(Model):
|
|
|
156
156
|
model_config = ConfigDict(arbitrary_types_allowed=True)
|
|
157
157
|
|
|
158
158
|
bound: Bound
|
|
159
|
+
scopes: frozenset[str] = Field(default_factory=frozenset)
|
|
159
160
|
definition: ResourceDef | None = None # fixed URI
|
|
160
161
|
template: ResourceTemplateDef | None = None # URI template
|
|
161
162
|
pattern: Any = None # compiled matcher for the template
|
|
@@ -180,13 +181,18 @@ class ResourceSpec(Model):
|
|
|
180
181
|
mime_type: str | None = None,
|
|
181
182
|
cache_ttl_ms: int | None = None,
|
|
182
183
|
cache_scope: Literal["public", "private"] | None = None,
|
|
184
|
+
scopes: Iterable[str] | None = None,
|
|
183
185
|
) -> ResourceSpec:
|
|
186
|
+
required = frozenset(scopes or ())
|
|
187
|
+
if required and cache_scope == "public":
|
|
188
|
+
raise ValueError("Resources with scopes cannot use public caching.")
|
|
184
189
|
bound = Bound.of(fn)
|
|
185
190
|
name = name or getattr(fn, "__name__", repr(fn))
|
|
186
191
|
description = described(description, fn) or None
|
|
187
192
|
if not cls.VAR.search(uri):
|
|
188
193
|
return cls(
|
|
189
194
|
bound=bound,
|
|
195
|
+
scopes=required,
|
|
190
196
|
mime_type=mime_type,
|
|
191
197
|
cache_ttl_ms=cache_ttl_ms,
|
|
192
198
|
cache_scope=cache_scope,
|
|
@@ -202,6 +208,7 @@ class ResourceSpec(Model):
|
|
|
202
208
|
parts.append(re.escape(uri[last:]))
|
|
203
209
|
return cls(
|
|
204
210
|
bound=bound,
|
|
211
|
+
scopes=required,
|
|
205
212
|
mime_type=mime_type,
|
|
206
213
|
cache_ttl_ms=cache_ttl_ms,
|
|
207
214
|
cache_scope=cache_scope,
|
|
@@ -39,10 +39,12 @@ from aiohttp_tiny_mcp.storage.sessions import (
|
|
|
39
39
|
)
|
|
40
40
|
from aiohttp_tiny_mcp.transport.sse import SSEResponse
|
|
41
41
|
|
|
42
|
+
from .batch import run_batch
|
|
42
43
|
from .dispatcher import Dispatcher
|
|
43
44
|
from .exchange import Exchange
|
|
44
45
|
from .http import Endpoint
|
|
45
46
|
from .registry import Registry
|
|
47
|
+
from .resource_auth import allowed_resource
|
|
46
48
|
from .subscriptions import relays, wanted
|
|
47
49
|
from .tasks import stop
|
|
48
50
|
|
|
@@ -64,6 +66,7 @@ class SseEndpoint:
|
|
|
64
66
|
allowed_origins: set[str] | None = None,
|
|
65
67
|
trust_proxy_origin_validation: bool = False,
|
|
66
68
|
compress: bool = True,
|
|
69
|
+
batch_concurrency: int = 4,
|
|
67
70
|
sse_path: str = "/sse",
|
|
68
71
|
message_path: str = "/messages",
|
|
69
72
|
) -> None:
|
|
@@ -75,8 +78,10 @@ class SseEndpoint:
|
|
|
75
78
|
adapters=self.adapters,
|
|
76
79
|
allowed_origins=allowed_origins,
|
|
77
80
|
trust_proxy_origin_validation=trust_proxy_origin_validation,
|
|
81
|
+
batch_concurrency=batch_concurrency,
|
|
78
82
|
)
|
|
79
83
|
self.compress = compress
|
|
84
|
+
self.batch_concurrency = batch_concurrency
|
|
80
85
|
self.sse_path = sse_path
|
|
81
86
|
self.message_path = message_path
|
|
82
87
|
|
|
@@ -127,7 +132,7 @@ class SseEndpoint:
|
|
|
127
132
|
await self.relay_until_disconnect(
|
|
128
133
|
request,
|
|
129
134
|
self.relay(response, events),
|
|
130
|
-
self.relay_shared(response, shared, session_id),
|
|
135
|
+
self.relay_shared(response, shared, session_id, principal=principal),
|
|
131
136
|
)
|
|
132
137
|
finally:
|
|
133
138
|
await hub.delete(where)
|
|
@@ -164,7 +169,12 @@ class SseEndpoint:
|
|
|
164
169
|
await self.write(response, "message", json.dumps(event.message, ensure_ascii=False))
|
|
165
170
|
|
|
166
171
|
async def relay_shared(
|
|
167
|
-
self,
|
|
172
|
+
self,
|
|
173
|
+
response: SSEResponse,
|
|
174
|
+
events: Subscription,
|
|
175
|
+
session_id: str,
|
|
176
|
+
*,
|
|
177
|
+
principal: Principal | None = None,
|
|
168
178
|
) -> None:
|
|
169
179
|
"""Write the list changes, resource updates and broadcasts this session wants.
|
|
170
180
|
|
|
@@ -184,6 +194,12 @@ class SseEndpoint:
|
|
|
184
194
|
accepted = wanted(
|
|
185
195
|
adapter.capabilities(self.registry), session, self.registry.broadcasts
|
|
186
196
|
)
|
|
197
|
+
if "resourceSubscriptions" in accepted:
|
|
198
|
+
accepted["resourceSubscriptions"] = [
|
|
199
|
+
uri
|
|
200
|
+
for uri in accepted["resourceSubscriptions"]
|
|
201
|
+
if allowed_resource(self.registry, adapter, uri, principal)
|
|
202
|
+
]
|
|
187
203
|
for event in found:
|
|
188
204
|
if relays(event.message, accepted):
|
|
189
205
|
text = serialized(event.message).decode()
|
|
@@ -225,10 +241,12 @@ class SseEndpoint:
|
|
|
225
241
|
await self.registry.hub.publish(where, self.adapter.encode_failure(None, e.failure))
|
|
226
242
|
return web.Response(status=202)
|
|
227
243
|
|
|
228
|
-
|
|
244
|
+
async def execute(item: Call | DecodeFailure) -> None:
|
|
229
245
|
await self.serve(
|
|
230
246
|
adapter, item, session_id, record, where, request=request, principal=principal
|
|
231
247
|
)
|
|
248
|
+
|
|
249
|
+
await run_batch(items, execute, self.batch_concurrency if pre.is_batch else 1)
|
|
232
250
|
return web.Response(status=202)
|
|
233
251
|
|
|
234
252
|
async def serve(
|
{aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/server/subscriptions.py
RENAMED
|
@@ -15,6 +15,8 @@ from aiohttp_tiny_mcp.protocol.models import EmptyResult, ListenParams, Meta, Me
|
|
|
15
15
|
from aiohttp_tiny_mcp.storage import hub as hubs
|
|
16
16
|
from aiohttp_tiny_mcp.storage.sessions import SUBSCRIPTIONS_KEY, Session
|
|
17
17
|
|
|
18
|
+
from .resource_auth import allowed_resource
|
|
19
|
+
|
|
18
20
|
if TYPE_CHECKING:
|
|
19
21
|
from .exchange import Exchange
|
|
20
22
|
|
|
@@ -116,7 +118,11 @@ async def listen(ex: Exchange) -> EmptyResult:
|
|
|
116
118
|
if requested.get(field) and caps.get(capability, {}).get("listChanged"):
|
|
117
119
|
accepted[field] = True
|
|
118
120
|
if caps.get("resources", {}).get("subscribe"):
|
|
119
|
-
uris = [
|
|
121
|
+
uris = [
|
|
122
|
+
uri
|
|
123
|
+
for uri in wanted.resource_subscriptions
|
|
124
|
+
if allowed_resource(ex.registry, ex.adapter, uri, ex.principal)
|
|
125
|
+
]
|
|
120
126
|
if uris:
|
|
121
127
|
accepted["resourceSubscriptions"] = list(dict.fromkeys(uris))
|
|
122
128
|
declared = broadcasts_for(ex)
|
|
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
|
{aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/client/oauth_helpers.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/console/agent-config.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/console/oauth-callback.html
RENAMED
|
File without changes
|
{aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/extensions/__init__.py
RENAMED
|
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
|
{aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/protocol/selection.py
RENAMED
|
File without changes
|
{aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/protocol/v2024_11_05.py
RENAMED
|
File without changes
|
{aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/protocol/v2025_03_26.py
RENAMED
|
File without changes
|
{aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/protocol/v2025_06_18.py
RENAMED
|
File without changes
|
{aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/protocol/v2025_11_25.py
RENAMED
|
File without changes
|
{aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/protocol/v2026_07_28.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/server/request_state.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/storage/namespaces.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/transport/__init__.py
RENAMED
|
File without changes
|
{aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.1}/src/aiohttp_tiny_mcp/transport/metadata.py
RENAMED
|
File without changes
|
|
File without changes
|