aiohttp-tiny-mcp 0.6.1__tar.gz → 0.7.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.
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/PKG-INFO +1 -1
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/pyproject.toml +1 -1
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/pyproject.toml.orig +1 -1
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/protocol/adapter.py +1 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/protocol/core.py +1 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/server/dispatcher.py +21 -11
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/server/http.py +16 -2
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/server/registry.py +10 -0
- aiohttp_tiny_mcp-0.7.0/src/aiohttp_tiny_mcp/server/resource_auth.py +68 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/server/specs.py +7 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/server/sse.py +14 -2
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/server/subscriptions.py +7 -1
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/LICENSE +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/README.md +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/__init__.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/access_log.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/auth/__init__.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/auth/jwt.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/client/__init__.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/client/base.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/client/callback.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/client/http.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/client/loopback.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/client/oauth.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/client/oauth_helpers.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/client/stdio.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/console/__init__.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/console/agent-config.js +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/console/console.css +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/console/console.js +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/console/index.html +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/console/oauth-callback.html +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/extensions/__init__.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/extensions/skills.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/oauth/__init__.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/oauth/github.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/oauth/provider.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/oauth/server.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/oauth/tokens.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/protocol/__init__.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/protocol/models.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/protocol/schema.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/protocol/selection.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/protocol/v2024_11_05.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/protocol/v2025_03_26.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/protocol/v2025_06_18.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/protocol/v2025_11_25.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/protocol/v2026_07_28.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/py.typed +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/server/__init__.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/server/exchange.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/server/request_state.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/server/stdio.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/server/tasks.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/storage/__init__.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/storage/hub.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/storage/namespaces.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/storage/postgres.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/storage/redis.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/storage/sessions.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/storage/sqlite.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/testing.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/transport/__init__.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/transport/metadata.py +0 -0
- {aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/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"
|
|
@@ -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=[])))
|
|
@@ -48,6 +48,7 @@ from aiohttp_tiny_mcp.transport.sse import SSEResponse
|
|
|
48
48
|
from .dispatcher import Dispatcher
|
|
49
49
|
from .exchange import Exchange, is_reply, relay_reply
|
|
50
50
|
from .registry import Registry
|
|
51
|
+
from .resource_auth import allowed_resource
|
|
51
52
|
from .subscriptions import relays, wanted
|
|
52
53
|
from .tasks import stop
|
|
53
54
|
|
|
@@ -451,7 +452,9 @@ class Endpoint:
|
|
|
451
452
|
|
|
452
453
|
response = SSEResponse(compress=self.compress)
|
|
453
454
|
await response.prepare(request)
|
|
454
|
-
relay = asyncio.create_task(
|
|
455
|
+
relay = asyncio.create_task(
|
|
456
|
+
self.relay_notifications(request, response, adapter, principal=principal)
|
|
457
|
+
)
|
|
455
458
|
try:
|
|
456
459
|
while not relay.done():
|
|
457
460
|
await asyncio.wait({relay}, timeout=0.05)
|
|
@@ -463,7 +466,12 @@ class Endpoint:
|
|
|
463
466
|
return response
|
|
464
467
|
|
|
465
468
|
async def relay_notifications(
|
|
466
|
-
self,
|
|
469
|
+
self,
|
|
470
|
+
request: web.Request,
|
|
471
|
+
response: SSEResponse,
|
|
472
|
+
adapter: Adapter,
|
|
473
|
+
*,
|
|
474
|
+
principal: Principal | None = None,
|
|
467
475
|
) -> None:
|
|
468
476
|
"""Relay changes with their hub ids, re-reading subscriptions each pass."""
|
|
469
477
|
capabilities = adapter.capabilities(self.registry)
|
|
@@ -477,6 +485,12 @@ class Endpoint:
|
|
|
477
485
|
self.open_values(request, await self.stored(request)),
|
|
478
486
|
self.registry.broadcasts,
|
|
479
487
|
)
|
|
488
|
+
if "resourceSubscriptions" in accepted:
|
|
489
|
+
accepted["resourceSubscriptions"] = [
|
|
490
|
+
uri
|
|
491
|
+
for uri in accepted["resourceSubscriptions"]
|
|
492
|
+
if allowed_resource(self.registry, adapter, uri, principal)
|
|
493
|
+
]
|
|
480
494
|
for event in found:
|
|
481
495
|
if relays(event.message, accepted):
|
|
482
496
|
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,
|
|
@@ -43,6 +43,7 @@ from .dispatcher import Dispatcher
|
|
|
43
43
|
from .exchange import Exchange
|
|
44
44
|
from .http import Endpoint
|
|
45
45
|
from .registry import Registry
|
|
46
|
+
from .resource_auth import allowed_resource
|
|
46
47
|
from .subscriptions import relays, wanted
|
|
47
48
|
from .tasks import stop
|
|
48
49
|
|
|
@@ -127,7 +128,7 @@ class SseEndpoint:
|
|
|
127
128
|
await self.relay_until_disconnect(
|
|
128
129
|
request,
|
|
129
130
|
self.relay(response, events),
|
|
130
|
-
self.relay_shared(response, shared, session_id),
|
|
131
|
+
self.relay_shared(response, shared, session_id, principal=principal),
|
|
131
132
|
)
|
|
132
133
|
finally:
|
|
133
134
|
await hub.delete(where)
|
|
@@ -164,7 +165,12 @@ class SseEndpoint:
|
|
|
164
165
|
await self.write(response, "message", json.dumps(event.message, ensure_ascii=False))
|
|
165
166
|
|
|
166
167
|
async def relay_shared(
|
|
167
|
-
self,
|
|
168
|
+
self,
|
|
169
|
+
response: SSEResponse,
|
|
170
|
+
events: Subscription,
|
|
171
|
+
session_id: str,
|
|
172
|
+
*,
|
|
173
|
+
principal: Principal | None = None,
|
|
168
174
|
) -> None:
|
|
169
175
|
"""Write the list changes, resource updates and broadcasts this session wants.
|
|
170
176
|
|
|
@@ -184,6 +190,12 @@ class SseEndpoint:
|
|
|
184
190
|
accepted = wanted(
|
|
185
191
|
adapter.capabilities(self.registry), session, self.registry.broadcasts
|
|
186
192
|
)
|
|
193
|
+
if "resourceSubscriptions" in accepted:
|
|
194
|
+
accepted["resourceSubscriptions"] = [
|
|
195
|
+
uri
|
|
196
|
+
for uri in accepted["resourceSubscriptions"]
|
|
197
|
+
if allowed_resource(self.registry, adapter, uri, principal)
|
|
198
|
+
]
|
|
187
199
|
for event in found:
|
|
188
200
|
if relays(event.message, accepted):
|
|
189
201
|
text = serialized(event.message).decode()
|
{aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/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.0}/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.0}/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.0}/src/aiohttp_tiny_mcp/console/oauth-callback.html
RENAMED
|
File without changes
|
{aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/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.0}/src/aiohttp_tiny_mcp/protocol/selection.py
RENAMED
|
File without changes
|
{aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/protocol/v2024_11_05.py
RENAMED
|
File without changes
|
{aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/protocol/v2025_03_26.py
RENAMED
|
File without changes
|
{aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/protocol/v2025_06_18.py
RENAMED
|
File without changes
|
{aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/protocol/v2025_11_25.py
RENAMED
|
File without changes
|
{aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/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.0}/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.0}/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.0}/src/aiohttp_tiny_mcp/transport/__init__.py
RENAMED
|
File without changes
|
{aiohttp_tiny_mcp-0.6.1 → aiohttp_tiny_mcp-0.7.0}/src/aiohttp_tiny_mcp/transport/metadata.py
RENAMED
|
File without changes
|
|
File without changes
|