Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/core-candidate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ jobs:
assert core_path == installed.locate_file("apcore/__init__.py").resolve()
assert toolkit_path == toolkit_expected.resolve()
if os.environ["CORE_MODE"] == "candidate":
assert installed.version == "1.0.0a2"
assert installed.version == "1.0.0a3"
origin = json.loads(installed.read_text("direct_url.json") or "{}")
assert origin.get("url") == Path(os.environ["CORE_INSTALL"]).resolve().as_uri()
assert callable(getattr(Executor, "stream_with_completion", None))
Expand Down Expand Up @@ -340,7 +340,7 @@ jobs:
assert.ok(coreEntry.startsWith(core + sep));
assert.equal(toolkitEntry, realpathSync(resolve(process.env.TOOLKIT_ROOT, 'dist/index.js')));
if (process.env.CORE_MODE === 'candidate') {
assert.equal(coreVersion, '1.0.0-alpha.2');
assert.equal(coreVersion, '1.0.0-alpha.3');
assert.equal(typeof Executor.prototype.streamWithCompletion, 'function');
assert.equal(typeof APCore.prototype.streamWithCompletion, 'function');
} else {
Expand Down Expand Up @@ -406,8 +406,8 @@ jobs:
crate="${crates[0]}"
version="${crate##*/apcore-}"
version="${version%.crate}"
if [[ "$version" != 1.0.0-alpha.2 ]]; then
echo "Expected the alpha.2 Core crate." >&2
if [[ "$version" != 1.0.0-alpha.3 ]]; then
echo "Expected the alpha.3 Core crate." >&2
exit 1
fi
if [[ "$CORE_MODE" == candidate && -n "$EXPECTED_SHA256" ]]; then
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ permissions:
contents: read

env:
CORE_REF: 3b5fb5defb7e32900da4e826a848bb23258cd91e
CORE_REF: 9ba719587d9a288c22b8b5ff2a10a187a9a21cee

jobs:
test:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ permissions:
env:
# The released lockfiles already reference these prereleases. Bootstrap CI
# from the reviewed Core commit while those versions are unpublished.
CORE_REF: 0384a3d4e7688c47eaa1feea6032fb4739813f20
CORE_CRATE_VERSION: 1.0.0-alpha.2
CORE_CRATE_SHA256: 54e630a6f3c82ee9e01aec1f58ad14a06e21d8082414a1f4d398bce2f45b4de3
CORE_REF: 9ba719587d9a288c22b8b5ff2a10a187a9a21cee
CORE_CRATE_VERSION: 1.0.0-alpha.3
CORE_CRATE_SHA256: 2813101192ceac629d58114dfafd4f6b519eb7dea2313cb253e1410a2ac52f65

jobs:
source:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/typescript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ permissions:
contents: read

env:
CORE_REF: 3b5fb5defb7e32900da4e826a848bb23258cd91e
CORE_REF: 9ba719587d9a288c22b8b5ff2a10a187a9a21cee

jobs:
test:
Expand Down
2 changes: 1 addition & 1 deletion a2a/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ classifiers = [
"Framework :: AsyncIO",
]
dependencies = [
"apcore[config,discovery]==1.0.0a2",
"apcore[config,discovery]==1.0.0a3",
"apcore-toolkit==0.15.1a2",
"a2a-sdk[http-server]>=1.1.2",
"starlette>=0.40.0",
Expand Down
4 changes: 2 additions & 2 deletions a2a/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion a2a/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ default = []
openapi = ["apcore-toolkit/http-proxy"]

[dependencies]
apcore = { version = "=1.0.0-alpha.2", default-features = false, features = ["discovery", "sys-modules"] }
apcore = { version = "=1.0.0-alpha.3", default-features = false, features = ["discovery", "sys-modules"] }
# `default-features = false` so `http-proxy` — a *default* feature of the
# toolkit — is reached through this crate's `openapi` feature instead of being
# enabled unconditionally. The unconditional import (`deep_resolve_refs`) is
Expand Down
2 changes: 1 addition & 1 deletion a2a/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"dependencies": {
"@a2a-js/sdk": ">=1.0.1",
"apcore-js": "1.0.0-alpha.2",
"apcore-js": "1.0.0-alpha.3",
"apcore-toolkit": "0.15.1-alpha.2",
"express": "^5.1.0",
"jsonwebtoken": "^9.0.3",
Expand Down
12 changes: 6 additions & 6 deletions a2a/typescript/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cli/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ classifiers = [
"Environment :: Console",
]
dependencies = [
"apcore[config,discovery]==1.0.0a2",
"apcore[config,discovery]==1.0.0a3",
"apcore-toolkit[http-proxy]==0.15.1a2",
"click>=8.1",
"jsonschema>=4.20",
Expand Down
4 changes: 2 additions & 2 deletions cli/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cli/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ name = "apcore_cli"
path = "src/lib.rs"

[dependencies]
apcore = { version = "=1.0.0-alpha.2", default-features = false, features = ["config"] }
apcore = { version = "=1.0.0-alpha.3", default-features = false, features = ["config"] }
async-trait = "0.1"
clap = { version = "4", features = ["derive", "env", "string"] }
serde = { version = "1", features = ["derive"] }
Expand Down
4 changes: 2 additions & 2 deletions cli/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"node": ">=20.0.0"
},
"peerDependencies": {
"apcore-js": "1.0.0-alpha.2",
"apcore-js": "1.0.0-alpha.3",
"apcore-toolkit": "0.15.1-alpha.2"
},
"dependencies": {
Expand All @@ -47,7 +47,7 @@
"@typescript-eslint/eslint-plugin": "^8.59.0",
"@typescript-eslint/parser": "^8.59.0",
"@vitest/coverage-v8": "^5.1.0",
"apcore-js": "1.0.0-alpha.2",
"apcore-js": "1.0.0-alpha.3",
"apcore-toolkit": "0.15.1-alpha.2",
"apdev-js": "^0.2.4",
"eslint": "^10.2.1",
Expand Down
12 changes: 6 additions & 6 deletions cli/typescript/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions mcp/docs/features/approval-phase-b.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ Phase B requires Core's scoped approval gate and a store that can atomically ver

Core checks its access and approval gates on the retry. The handler matches the trusted principal, `caller_id`, target module, and business arguments. It consumes the grant when it authorizes one invocation. A further attempt needs its own approval.

With Core's optional post-validation policy enabled, the handler also binds approval to the selected module version and the validated arguments presented for review. A retry sends the original input, and Core applies the current trusted transformations and validation before checking the bound scope. A changed effective value or module version needs a new approval. Custom stores enforce the entire supplied scope with the same atomic consumption operation.

Use the record ID for polling, review notifications, and audit correlation. Restrict the resume token to the pending result and the caller's resumption request.

## ApprovalStore Interface
Expand Down
2 changes: 1 addition & 1 deletion mcp/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ classifiers = [
"Topic :: Scientific/Engineering :: Artificial Intelligence",
]
dependencies = [
"apcore[config,discovery]==1.0.0a2",
"apcore[config,discovery]==1.0.0a3",
"mcp>=1.26,<2.0",
"jsonschema>=4.20,<5",
"referencing>=0.30,<1",
Expand Down
22 changes: 21 additions & 1 deletion mcp/python/src/apcore_mcp/adapters/approval.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,23 @@ def _argument_snapshot(arguments: dict[str, Any]) -> str:


def _scope_for(request: ApprovalRequest, snapshot: str) -> ApprovalScope:
digest = getattr(request, "canonical_args_digest", None)
if digest is not None:
version = getattr(request, "module_version", None)
if not isinstance(digest, str) or not re.fullmatch(r"[0-9a-f]{64}", digest):
raise ValueError("Invalid final approval argument digest")
if version is not None and not isinstance(version, str):
raise ValueError("Invalid final approval module version")
encoded = json.dumps([version, digest], separators=(",", ":")).encode("utf-8")
# The prefix separates final-scope records from existing argument-object digests.
material = b"apcore-final-scope-v1\0" + encoded
else:
material = snapshot.encode("utf-8")
return ApprovalScope(
_approval_principal(request.context.identity),
request.caller_id,
request.module_id,
sha256(snapshot.encode("utf-8")).hexdigest(),
sha256(material).hexdigest(),
)


Expand Down Expand Up @@ -207,6 +219,10 @@ def __init__(self, store: Any, *, notify_callback: Any | None = None) -> None:
def scoped_approval_available(self) -> bool:
return _CORE_SCOPED_APPROVAL and isinstance(self._store, ScopedApprovalStore)

@property
def supports_final_scope(self) -> bool:
return self.scoped_approval_available

async def request_approval(self, request: ApprovalRequest) -> ApprovalResult:
if not self.scoped_approval_available:
return ApprovalResult(status="rejected", reason=_NO_PHASE_B)
Expand Down Expand Up @@ -330,6 +346,10 @@ class _MCPScopedApprovalGate:
def __init__(self, handler: _ScopedMCPApprovalHandler) -> None:
self._handler = handler

@property
def supports_final_scope(self) -> bool:
return getattr(self._handler, "supports_final_scope", None) is True

def _delivery_for(self, request: ApprovalRequest) -> _ApprovalDelivery | None:
delivery = _approval_delivery.get()
if (
Expand Down
26 changes: 26 additions & 0 deletions mcp/python/tests/server/test_approval_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import json
from types import SimpleNamespace
from typing import Any
from unittest.mock import AsyncMock

Expand Down Expand Up @@ -287,6 +288,31 @@ def _make_approval_request() -> Any:
)


@_requires_scoped_core
@pytest.mark.asyncio
async def test_final_scope_binds_module_version_and_cannot_resume_as_legacy() -> None:
store = InMemoryApprovalStore()
handler = StorageBackedApprovalHandler(store)
request = _make_approval_request()
fields = vars(request) | {"module_version": "1.2.3", "canonical_args_digest": "a" * 64}
final_request = SimpleNamespace(**fields)
pending = await handler.request_approval(final_request)
assert pending.status == "pending"
assert await store.resolve(pending.audit_id, approved=True)

for changed in (
request,
SimpleNamespace(**(fields | {"module_version": "1.2.4"})),
SimpleNamespace(**(fields | {"canonical_args_digest": "b" * 64})),
):
result = await handler.check_approval_for_call(pending.approval_id, changed)
assert result.status == "rejected"

assert (await handler.check_approval_for_call(pending.approval_id, final_request)).status == "approved"
assert (await handler.check_approval_for_call(pending.approval_id, final_request)).status == "rejected"
assert handler.supports_final_scope is True


@_requires_scoped_core
@pytest.mark.asyncio
async def test_request_approval_returns_rejected_when_save_pending_raises() -> None:
Expand Down
31 changes: 24 additions & 7 deletions mcp/python/tests/server/test_scoped_approval_wire.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import httpx
import pytest
from apcore import AlwaysDenyHandler, Executor, Identity, ModuleAnnotations, Registry
from apcore import AlwaysDenyHandler, Executor, Identity, Middleware, ModuleAnnotations, PolicyVerdict, Registry
from mcp.server.lowlevel import Server
from mcp.shared import session as mcp_session
from starlette.responses import JSONResponse
Expand Down Expand Up @@ -60,10 +60,11 @@ def test_phase_b_preserves_a_supplied_executors_existing_handler() -> None:

@_requires_scoped_core
@pytest.mark.parametrize("tool_type", [Report, StreamingReport])
async def test_pending_credentials_and_status_round_trip_through_core(tool_type, caplog) -> None:
@pytest.mark.parametrize("post_validation", [False, True])
async def test_pending_credentials_and_status_round_trip_through_core(tool_type, post_validation, caplog) -> None:
registry = Registry()
report = tool_type()
registry.register(_TOOL, report)
registry.register(_TOOL, report, version="1.2.3")
store = InMemoryApprovalStore()
notifications = []
audit_events = []
Expand All @@ -73,7 +74,23 @@ def emit(self, event):
if event.event_type == "apcore.approval.decision":
audit_events.append(event.data)

executor = Executor(registry, event_emitter=EventRecorder())
class RequireFinalApproval:
async def evaluate(self, request):
assert request.module_version == "1.2.3"
return PolicyVerdict("require_approval")

class Normalize(Middleware):
async def before(self, _module_id, inputs, _context):
return {**inputs, "count": inputs["count"] + 10}

executor = Executor(
registry,
event_emitter=EventRecorder(),
policy_evaluator=RequireFinalApproval() if post_validation else None,
)
if post_validation:
executor.use(Normalize())
effective = {"count": 11 if post_validation else 1}

async def notify(approval_id, module_id, arguments):
notifications.append((approval_id, module_id, arguments))
Expand All @@ -88,7 +105,7 @@ async def notify(approval_id, module_id, arguments):
public_id, credential = approval["approvalId"], approval["resumeToken"]
assert public_id != credential
assert report.inputs == []
assert notifications == [(public_id, _TOOL, {"count": 1})]
assert notifications == [(public_id, _TOOL, effective)]
assert credential not in repr(pending.content)
poll = await session.call_tool("__apcore_approval_check", {"approval_id": public_id})
assert json.loads(poll.content[0].text)["status"] == "pending"
Expand All @@ -108,8 +125,8 @@ async def notify(approval_id, module_id, arguments):
first, second = await asyncio.gather(*requests)
assert sorted(result.isError for result in (first, second)) == [False, True]
result = next(result for result in (first, second) if not result.isError)
assert result.structuredContent == {"count": 1}
assert report.inputs == [{"count": 1}]
assert result.structuredContent == effective
assert report.inputs == [effective]
if credential in caplog.text:
pytest.fail("Approval credential entered debug logs")
assert credential not in repr(audit_events)
Expand Down
Loading
Loading