From 11d6f16f48161d73ef70d7a6cbb966d8a4bd3bf5 Mon Sep 17 00:00:00 2001 From: tercel Date: Mon, 30 Nov 2026 11:50:36 +0800 Subject: [PATCH] fix(surfaces): close Beta.1 candidate audit gaps Signed-off-by: tercel --- .github/workflows/python.yml | 2 +- .github/workflows/rust.yml | 4 +- .github/workflows/typescript.yml | 2 +- Cargo.lock | 2 +- a2a/python/src/apcore_a2a/artifacts.py | 11 ++-- a2a/rust/Cargo.lock | 4 +- a2a/typescript/pnpm-lock.yaml | 4 +- a2a/typescript/src/artifact-links.ts | 9 +++- .../tests/server/artifact-links.test.ts | 22 ++++++++ cli/rust/Cargo.lock | 4 +- cli/typescript/pnpm-lock.yaml | 4 +- mcp/docs/features/error-mapper.md | 2 + mcp/python/pyproject.toml | 2 +- mcp/python/src/apcore_mcp/adapters/errors.py | 20 +++++++ mcp/python/src/apcore_mcp/apcore_mcp.py | 4 +- mcp/python/src/apcore_mcp/constants.py | 2 + mcp/python/src/apcore_mcp/server/factory.py | 15 +++--- mcp/python/tests/adapters/test_errors.py | 28 ++++++++++ mcp/rust/Cargo.lock | 4 +- mcp/rust/src/adapters/errors.rs | 54 +++++++++++++++++++ mcp/rust/src/apcore_mcp.rs | 4 +- mcp/typescript/pnpm-lock.yaml | 4 +- mcp/typescript/src/adapters/errors.ts | 22 ++++++++ mcp/typescript/src/artifacts.ts | 31 ++++++++--- mcp/typescript/src/index.ts | 4 +- mcp/typescript/src/types.ts | 2 + mcp/typescript/tests/adapters/errors.test.ts | 14 +++++ .../tests/server/artifact-wire.test.ts | 35 +++++++++++- pnpm-lock.yaml | 4 +- pyproject.toml | 2 +- toolkit/rust/Cargo.lock | 2 +- toolkit/typescript/pnpm-lock.yaml | 2 +- uv.lock | 11 ++-- 33 files changed, 280 insertions(+), 56 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 7645a08c..be416927 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -18,7 +18,7 @@ permissions: contents: read env: - CORE_REF: 403482c27d5f88d3f070a01ecd1cb103ebfc97f9 + CORE_REF: 3f6c785fab4a4a7140637fbb21039f1d65d0274b jobs: test: diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index c51304dc..e23c740e 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -26,9 +26,9 @@ permissions: env: # Bootstrap the registry-shaped lockfiles from the reviewed Core commit # while the matching prerelease is unpublished. - CORE_REF: 403482c27d5f88d3f070a01ecd1cb103ebfc97f9 + CORE_REF: 3f6c785fab4a4a7140637fbb21039f1d65d0274b CORE_CRATE_VERSION: 1.0.0-beta.1 - CORE_CRATE_SHA256: 19dc73726e9aac784e05bb9e99ee3de032b720cde10e2fefa0b5b4a93017d96c + CORE_CRATE_SHA256: 49109b2f64808f66f3663d5ac713ae4c3ed7008a812f302244042ab13125b494 jobs: source: diff --git a/.github/workflows/typescript.yml b/.github/workflows/typescript.yml index ed094c33..64a66e8e 100644 --- a/.github/workflows/typescript.yml +++ b/.github/workflows/typescript.yml @@ -18,7 +18,7 @@ permissions: contents: read env: - CORE_REF: 403482c27d5f88d3f070a01ecd1cb103ebfc97f9 + CORE_REF: 3f6c785fab4a4a7140637fbb21039f1d65d0274b jobs: test: diff --git a/Cargo.lock b/Cargo.lock index 39c16ac5..7be86be1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -141,7 +141,7 @@ checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" name = "apcore" version = "1.0.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19dc73726e9aac784e05bb9e99ee3de032b720cde10e2fefa0b5b4a93017d96c" +checksum = "49109b2f64808f66f3663d5ac713ae4c3ed7008a812f302244042ab13125b494" dependencies = [ "async-stream", "async-trait", diff --git a/a2a/python/src/apcore_a2a/artifacts.py b/a2a/python/src/apcore_a2a/artifacts.py index 837230d0..bff9ced4 100644 --- a/a2a/python/src/apcore_a2a/artifacts.py +++ b/a2a/python/src/apcore_a2a/artifacts.py @@ -40,7 +40,10 @@ # Pilot support is limited to direct declarations. These schema applicators # can place a second annotation on the same instance path. _SCHEMA_APPLICATORS = frozenset( - {"$ref", "$dynamicRef", "allOf", "anyOf", "oneOf", "if", "then", "else", "dependentSchemas", "patternProperties"} + { + "$ref", "$dynamicRef", "$recursiveRef", "allOf", "anyOf", "oneOf", "if", "then", "else", + "dependentSchemas", "dependencies", "patternProperties", + } ) _REFERENCE_ASSERTIONS = frozenset({"x-artifact-ref", "x-media-types", "x-max-bytes"}) _REFERENCE_FIELDS = frozenset({"type", "title", "description"}) @@ -190,20 +193,18 @@ def _link_fields(schema: Any) -> tuple[tuple[str, dict[str, Any] | None], ...]: for name, declaration in properties.items(): if not isinstance(declaration, dict) or declaration.get("x-a2a-artifact") is not True: continue - if declaration.get("x-sensitive"): + if declaration.get("x-sensitive") or not _SCHEMA_APPLICATORS.isdisjoint(declaration): continue if not _REFERENCE_ASSERTIONS.isdisjoint(declaration): if ( ArtifactRef is not None - and "$recursiveRef" not in schema - and "dependencies" not in schema and declaration.get("type") in (None, "object") and all( key in _REFERENCE_FIELDS or (isinstance(key, str) and key.startswith("x-")) for key in declaration ) ): fields.append((name, declaration)) - elif declaration.get("type") == "string" and _SCHEMA_APPLICATORS.isdisjoint(declaration): + elif declaration.get("type") == "string": fields.append((name, None)) return tuple(fields) diff --git a/a2a/rust/Cargo.lock b/a2a/rust/Cargo.lock index 3c2c3cf0..dcce14c7 100644 --- a/a2a/rust/Cargo.lock +++ b/a2a/rust/Cargo.lock @@ -94,7 +94,7 @@ dependencies = [ name = "apcore" version = "1.0.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19dc73726e9aac784e05bb9e99ee3de032b720cde10e2fefa0b5b4a93017d96c" +checksum = "49109b2f64808f66f3663d5ac713ae4c3ed7008a812f302244042ab13125b494" dependencies = [ "async-stream", "async-trait", @@ -155,7 +155,7 @@ dependencies = [ name = "apcore-toolkit" version = "0.16.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59a229ba91ee7684424bd6b4e74c120b7ea427b17a4c20e3bbf5c56e46295fce" +checksum = "5c0b2b1f0ff80d81f70a7a21ea8c5a40631030677b70e5e0fedde0ec39384265" dependencies = [ "apcore", "async-trait", diff --git a/a2a/typescript/pnpm-lock.yaml b/a2a/typescript/pnpm-lock.yaml index ec5941bb..d86cf772 100644 --- a/a2a/typescript/pnpm-lock.yaml +++ b/a2a/typescript/pnpm-lock.yaml @@ -657,7 +657,7 @@ packages: resolution: {integrity: sha512-Thbli+OlOj+iMPYFBVBfJ3OmCAnaSyNn4M1vz9T6Gka5Jt9ba/HIR56joy65tY6kx/FCF5VXNB819Y7/GUrBGA==} apcore-js@1.0.0-beta.1: - resolution: {integrity: sha512-uRfWfWg/RvaGuj0QMb6LSSGEQiVJiD/tPPv+RTWuKZgBQwdta5UFLIlV/hdLe7Gfhlg+0KeywMIdtvvFtGNT0Q==} + resolution: {integrity: sha512-korVWIY+YubukyJKCpCE7/8lan0AqNjIz1v6GR0qkXqr2oydMdxvrforn05uP6zLyd3yTtc5jS9YPOMplshfAg==} engines: {node: '>=20.0.0'} peerDependencies: typescript: ^5.5.0 @@ -666,7 +666,7 @@ packages: optional: true apcore-toolkit@0.16.0-beta.1: - resolution: {integrity: sha512-aejP75mEwPcittHawzyJOhWupyFCy7wAxNwVA9teZ41XTPH0irUTiOLrIRxWoRPSCEgZEChOlbzHxkQyqnjhVA==} + resolution: {integrity: sha512-Zd1fnHCbX9fIBdUx/zAJl2WglG8o7/eUpg+ueDq7kNYwSse5VAuv5EUL/AcEDIdrfPw7ymDfZfG2CCCv2a2zwg==} engines: {node: '>=20.10.0'} peerDependencies: '@sinclair/typebox': '>=0.31.0' diff --git a/a2a/typescript/src/artifact-links.ts b/a2a/typescript/src/artifact-links.ts index 7e820809..75d15822 100644 --- a/a2a/typescript/src/artifact-links.ts +++ b/a2a/typescript/src/artifact-links.ts @@ -182,7 +182,14 @@ export function captureArtifactDeclaration(registry: unknown, executor: unknown, for (const { name, canonical } of fields) { if (!Object.hasOwn(output, name)) continue; const value = output[name]; - const reference = canonical ? apcore.parseArtifactRef(value) : null; + let reference: ArtifactRef | null = null; + if (canonical) { + try { + reference = apcore.parseArtifactRef(value); + } catch { + continue; + } + } const id = reference?.id ?? value; if (typeof id !== "string" || !ARTIFACT_ID.test(id)) continue; const declarations = found.get(id); diff --git a/a2a/typescript/tests/server/artifact-links.test.ts b/a2a/typescript/tests/server/artifact-links.test.ts index c3b82861..52416343 100644 --- a/a2a/typescript/tests/server/artifact-links.test.ts +++ b/a2a/typescript/tests/server/artifact-links.test.ts @@ -3,6 +3,7 @@ import { Type } from "@sinclair/typebox"; import request from "supertest"; import { describe, expect, it, vi } from "vitest"; import { ArtifactLinkPolicy, asyncServe, type HostedArtifact } from "../../src/index.js"; +import { captureArtifactDeclaration } from "../../src/artifact-links.js"; import type { AsyncServeOptions } from "../../src/serve.js"; const skill = "test.download"; @@ -45,6 +46,27 @@ async function send(executor: Executor, options: AsyncServeOptions) { } describe("hosted artifact links", () => { + it("keeps other valid candidates when an individual reference cannot be parsed", async () => { + const registry = new Registry(); + const field = { type: "object", "x-artifact-ref": true, "x-a2a-artifact": true }; + class Reference { + id = "initial"; + media_type = "text/plain"; + size_bytes = 4; + } + const data = { + primary: new Reference(), + secondary: { id: "secondary", media_type: "text/plain", size_bytes: 4 }, + }; + await registry.register(skill, { + ...downloadModule(), + outputSchema: { type: "object", properties: { primary: field, secondary: field } }, + execute: () => data, + }); + const capture = captureArtifactDeclaration(registry, new Executor({ registry }), skill, new Identity("alice", "user")); + expect(capture?.candidates(data)).toEqual(new Map([["secondary", [data.secondary]]])); + }); + it("uses authenticated identity and final validated output, deduplicates and preserves structured data", async () => { const registry = new Registry(); await registry.register(skill, downloadModule()); diff --git a/cli/rust/Cargo.lock b/cli/rust/Cargo.lock index bf2a0ba5..caca453d 100644 --- a/cli/rust/Cargo.lock +++ b/cli/rust/Cargo.lock @@ -135,7 +135,7 @@ checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" name = "apcore" version = "1.0.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19dc73726e9aac784e05bb9e99ee3de032b720cde10e2fefa0b5b4a93017d96c" +checksum = "49109b2f64808f66f3663d5ac713ae4c3ed7008a812f302244042ab13125b494" dependencies = [ "async-stream", "async-trait", @@ -198,7 +198,7 @@ dependencies = [ name = "apcore-toolkit" version = "0.16.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59a229ba91ee7684424bd6b4e74c120b7ea427b17a4c20e3bbf5c56e46295fce" +checksum = "5c0b2b1f0ff80d81f70a7a21ea8c5a40631030677b70e5e0fedde0ec39384265" dependencies = [ "apcore", "async-trait", diff --git a/cli/typescript/pnpm-lock.yaml b/cli/typescript/pnpm-lock.yaml index ad023afc..a4eb1c05 100644 --- a/cli/typescript/pnpm-lock.yaml +++ b/cli/typescript/pnpm-lock.yaml @@ -732,7 +732,7 @@ packages: resolution: {integrity: sha512-7UvmKalWRt1wgjL1RrGxoSJW/0QZFIegpeGvZG9kjp8vrRu55XTHbwnqq2GpXm9uLbcuhxm3IqX9OB4MZR1b2A==} apcore-js@1.0.0-beta.1: - resolution: {integrity: sha512-uRfWfWg/RvaGuj0QMb6LSSGEQiVJiD/tPPv+RTWuKZgBQwdta5UFLIlV/hdLe7Gfhlg+0KeywMIdtvvFtGNT0Q==} + resolution: {integrity: sha512-korVWIY+YubukyJKCpCE7/8lan0AqNjIz1v6GR0qkXqr2oydMdxvrforn05uP6zLyd3yTtc5jS9YPOMplshfAg==} engines: {node: '>=20.0.0'} peerDependencies: typescript: ^5.5.0 @@ -741,7 +741,7 @@ packages: optional: true apcore-toolkit@0.16.0-beta.1: - resolution: {integrity: sha512-aejP75mEwPcittHawzyJOhWupyFCy7wAxNwVA9teZ41XTPH0irUTiOLrIRxWoRPSCEgZEChOlbzHxkQyqnjhVA==} + resolution: {integrity: sha512-Zd1fnHCbX9fIBdUx/zAJl2WglG8o7/eUpg+ueDq7kNYwSse5VAuv5EUL/AcEDIdrfPw7ymDfZfG2CCCv2a2zwg==} engines: {node: '>=20.10.0'} peerDependencies: '@sinclair/typebox': '>=0.31.0' diff --git a/mcp/docs/features/error-mapper.md b/mcp/docs/features/error-mapper.md index dc25b980..29a53053 100644 --- a/mcp/docs/features/error-mapper.md +++ b/mcp/docs/features/error-mapper.md @@ -132,6 +132,8 @@ Only errors derived from `ModuleError` (which are designed to be user-facing) ar - On success: dict with keys `isError: True`, `errorType: str` (from error.code), `message: str`, `details: dict|None` - CALL_DEPTH_EXCEEDED, CIRCULAR_CALL, CALL_FREQUENCY_EXCEEDED → sanitized "Internal error occurred" message - ACL_DENIED → sanitized "Access denied", details: null +- POLICY_DENIED → "Access denied" with a fixed recovery hint, `retryable: false`, `userFixable: true`, and `details: null` +- POLICY_EVALUATION_ERROR → "Policy evaluation failed" with `retryable: true`, `userFixable: false`, and `details: null` - SCHEMA_VALIDATION_ERROR → multi-line bulleted message with field-level errors; details preserved - APPROVAL_PENDING → safe status text. The initiating holder receives any private resume token through the [Phase B result metadata](approval-phase-b.md#complete-flow). - APPROVAL_TIMEOUT → `retryable: true` diff --git a/mcp/python/pyproject.toml b/mcp/python/pyproject.toml index 2adabbe4..234f5363 100644 --- a/mcp/python/pyproject.toml +++ b/mcp/python/pyproject.toml @@ -41,7 +41,7 @@ dependencies = [ # a runtime dependency — this is the extra the "install 'apcore-mcp[markdown]'" # WARN logs point at. markdown = [ - "apcore-toolkit>=0.14.2", + "apcore-toolkit==0.16.0b1", ] # The OpenAPI backend. `[http-proxy]` resolves httpx, which both `load_spec` diff --git a/mcp/python/src/apcore_mcp/adapters/errors.py b/mcp/python/src/apcore_mcp/adapters/errors.py index 59750df4..87dffbbc 100644 --- a/mcp/python/src/apcore_mcp/adapters/errors.py +++ b/mcp/python/src/apcore_mcp/adapters/errors.py @@ -177,6 +177,26 @@ def _handle_apcore_error(self, error: Exception) -> dict[str, Any]: # declared type once here instead of guarding each call site. details: dict[str, Any] | None = raw_details if isinstance(raw_details, dict) else None + if code == ERROR_CODES["POLICY_DENIED"]: + return { + "isError": True, + "errorType": code, + "message": "Access denied", + "details": None, + "retryable": False, + "userFixable": True, + "aiGuidance": "Review the request against the host's policy before trying again.", + } + if code == ERROR_CODES["POLICY_EVALUATION_ERROR"]: + return { + "isError": True, + "errorType": code, + "message": "Policy evaluation failed", + "details": None, + "retryable": True, + "userFixable": False, + } + # Convert internal errors to generic message if code in self._INTERNAL_ERROR_CODES: return { diff --git a/mcp/python/src/apcore_mcp/apcore_mcp.py b/mcp/python/src/apcore_mcp/apcore_mcp.py index 471de9fe..3becb8ab 100644 --- a/mcp/python/src/apcore_mcp/apcore_mcp.py +++ b/mcp/python/src/apcore_mcp/apcore_mcp.py @@ -993,7 +993,7 @@ def serve( allow_execute: bool = False, explorer_title: str = "APCore MCP Explorer", explorer_project_name: str | None = "apcore-mcp", - explorer_project_url: str | None = "https://github.com/aiperceivable/apcore-mcp-python", + explorer_project_url: str | None = "https://github.com/aiperceivable/apcore-surfaces/tree/main/mcp/python", output_format: str | None = None, ) -> None: """Launch the MCP server (blocking). @@ -1072,7 +1072,7 @@ async def async_serve( allow_execute: bool = False, explorer_title: str = "APCore MCP Explorer", explorer_project_name: str | None = "apcore-mcp", - explorer_project_url: str | None = "https://github.com/aiperceivable/apcore-mcp-python", + explorer_project_url: str | None = "https://github.com/aiperceivable/apcore-surfaces/tree/main/mcp/python", output_format: str | None = None, ) -> AsyncIterator[Starlette]: """Build an MCP Starlette ASGI app for embedding into a larger service. diff --git a/mcp/python/src/apcore_mcp/constants.py b/mcp/python/src/apcore_mcp/constants.py index 2ace856f..d778d25e 100644 --- a/mcp/python/src/apcore_mcp/constants.py +++ b/mcp/python/src/apcore_mcp/constants.py @@ -14,6 +14,8 @@ "MODULE_DISABLED": "MODULE_DISABLED", "SCHEMA_VALIDATION_ERROR": "SCHEMA_VALIDATION_ERROR", "ACL_DENIED": "ACL_DENIED", + "POLICY_DENIED": "POLICY_DENIED", + "POLICY_EVALUATION_ERROR": "POLICY_EVALUATION_ERROR", "CALL_DEPTH_EXCEEDED": "CALL_DEPTH_EXCEEDED", "CIRCULAR_CALL": "CIRCULAR_CALL", "CALL_FREQUENCY_EXCEEDED": "CALL_FREQUENCY_EXCEEDED", diff --git a/mcp/python/src/apcore_mcp/server/factory.py b/mcp/python/src/apcore_mcp/server/factory.py index 3cfb1567..353ad4b4 100644 --- a/mcp/python/src/apcore_mcp/server/factory.py +++ b/mcp/python/src/apcore_mcp/server/factory.py @@ -1041,24 +1041,23 @@ def _attach_artifact_links( properties = schema.get("properties") if not isinstance(properties, dict): return - direct_reference_root = ( - schema.get("type") == "object" - and not schema.get("x-sensitive") - and _ARTIFACT_ROOT_APPLICATORS.isdisjoint(schema) - ) + if ( + schema.get("type") != "object" + or schema.get("x-sensitive") + or not _ARTIFACT_ROOT_APPLICATORS.isdisjoint(schema) + ): + return emitted: set[str] = set() for name, definition in properties.items(): if not isinstance(definition, dict) or definition.get("x-mcp-artifact") is not True: continue - if definition.get("x-sensitive") is True: + if definition.get("x-sensitive") or not _ARTIFACT_ROOT_APPLICATORS.isdisjoint(definition): continue value = result.structuredContent.get(name) reference = None if not _ARTIFACT_REFERENCE_ASSERTIONS.isdisjoint(definition): if ( ArtifactRef is None - or not direct_reference_root - or definition.get("x-sensitive") or not isinstance(value, dict) or definition.get("type") not in (None, "object") or any( diff --git a/mcp/python/tests/adapters/test_errors.py b/mcp/python/tests/adapters/test_errors.py index ad7bd6e8..0b5c419b 100644 --- a/mcp/python/tests/adapters/test_errors.py +++ b/mcp/python/tests/adapters/test_errors.py @@ -9,6 +9,34 @@ from apcore_mcp.adapters.errors import CIRCUIT_BREAKER_RECOVERY_GUIDANCE, ErrorMapper + +@pytest.mark.parametrize( + ("code", "message", "retryable"), + [("POLICY_DENIED", "Access denied", False), ("POLICY_EVALUATION_ERROR", "Policy evaluation failed", True)], +) +def test_policy_errors_use_public_diagnostics(code, message, retryable): + from apcore.errors import ModuleError + + error = ModuleError( + code=code, + message="private message", + details={"rule": "private rule"}, + ai_guidance="private guidance", + suggestion="private suggestion", + ) + expected = { + "isError": True, + "errorType": code, + "message": message, + "details": None, + "retryable": retryable, + "userFixable": not retryable, + } + if code == "POLICY_DENIED": + expected["aiGuidance"] = "Review the request against the host's policy before trying again." + assert ErrorMapper().to_mcp_error(error) == expected + + # Declarative user_fixable policy, mirroring apcore 0.24.0 _USER_FIXABLE_BY_CODE. _USER_FIXABLE_BY_CODE: dict[str, bool] = { "SCHEMA_VALIDATION_ERROR": True, diff --git a/mcp/rust/Cargo.lock b/mcp/rust/Cargo.lock index 504ba656..ee02401c 100644 --- a/mcp/rust/Cargo.lock +++ b/mcp/rust/Cargo.lock @@ -100,7 +100,7 @@ dependencies = [ name = "apcore" version = "1.0.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19dc73726e9aac784e05bb9e99ee3de032b720cde10e2fefa0b5b4a93017d96c" +checksum = "49109b2f64808f66f3663d5ac713ae4c3ed7008a812f302244042ab13125b494" dependencies = [ "async-stream", "async-trait", @@ -166,7 +166,7 @@ dependencies = [ name = "apcore-toolkit" version = "0.16.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59a229ba91ee7684424bd6b4e74c120b7ea427b17a4c20e3bbf5c56e46295fce" +checksum = "5c0b2b1f0ff80d81f70a7a21ea8c5a40631030677b70e5e0fedde0ec39384265" dependencies = [ "apcore", "async-trait", diff --git a/mcp/rust/src/adapters/errors.rs b/mcp/rust/src/adapters/errors.rs index 951387b0..ae411918 100644 --- a/mcp/rust/src/adapters/errors.rs +++ b/mcp/rust/src/adapters/errors.rs @@ -78,6 +78,30 @@ impl ErrorMapper { let code = error.code; let error_type = error_code_to_string(&code); + if matches!( + code, + ApcoreErrorCode::PolicyDenied | ApcoreErrorCode::PolicyEvaluationError + ) { + let denied = code == ApcoreErrorCode::PolicyDenied; + return McpErrorResponse { + is_error: true, + error_type, + message: if denied { + "Access denied" + } else { + "Policy evaluation failed" + } + .to_string(), + details: None, + retryable: Some(!denied), + ai_guidance: denied.then(|| { + "Review the request against the host's policy before trying again.".to_string() + }), + user_fixable: Some(denied), + suggestion: None, + }; + } + // Internal codes → generic message, no details if INTERNAL_ERROR_CODES.contains(&code) { return McpErrorResponse { @@ -437,6 +461,36 @@ mod tests { use super::*; use std::collections::HashMap; + #[test] + fn policy_errors_use_public_diagnostics() { + for (code, message, retryable) in [ + (ApcoreErrorCode::PolicyDenied, "Access denied", false), + ( + ApcoreErrorCode::PolicyEvaluationError, + "Policy evaluation failed", + true, + ), + ] { + let error = ModuleError::new(code, "private message") + .with_details(HashMap::from([("rule".to_string(), "private rule".into())])) + .with_ai_guidance("private guidance") + .with_suggestion("private suggestion"); + let response = ErrorMapper::to_mcp_error(&error); + + assert_eq!(response.error_type, error_code_to_string(&code)); + assert_eq!(response.message, message); + assert_eq!(response.details, None); + assert_eq!(response.retryable, Some(retryable)); + assert_eq!(response.user_fixable, Some(!retryable)); + assert_eq!(response.suggestion, None); + assert_eq!( + response.ai_guidance.as_deref(), + (!retryable) + .then_some("Review the request against the host's policy before trying again.") + ); + } + } + // -- wire envelope shape [A-D-EM-1] --------------------------------- /// `details` must always be present on the wire. Python emits diff --git a/mcp/rust/src/apcore_mcp.rs b/mcp/rust/src/apcore_mcp.rs index 31042e14..212e70d2 100644 --- a/mcp/rust/src/apcore_mcp.rs +++ b/mcp/rust/src/apcore_mcp.rs @@ -218,7 +218,7 @@ impl Default for APCoreMCPConfig { explorer_title: "APCore MCP Explorer".to_string(), explorer_project_name: Some("apcore-mcp".to_string()), explorer_project_url: Some( - "https://github.com/aiperceivable/apcore-mcp-rust".to_string(), + "https://github.com/aiperceivable/apcore-surfaces/tree/main/mcp/rust".to_string(), ), allow_execute: false, output_format: crate::server::router::OutputFormat::Json, @@ -3979,7 +3979,7 @@ mod tests { assert_eq!(cfg.explorer_project_name.as_deref(), Some("apcore-mcp")); assert_eq!( cfg.explorer_project_url.as_deref(), - Some("https://github.com/aiperceivable/apcore-mcp-rust") + Some("https://github.com/aiperceivable/apcore-surfaces/tree/main/mcp/rust") ); assert!(!cfg.allow_execute); } diff --git a/mcp/typescript/pnpm-lock.yaml b/mcp/typescript/pnpm-lock.yaml index 5fd939cd..06acf923 100644 --- a/mcp/typescript/pnpm-lock.yaml +++ b/mcp/typescript/pnpm-lock.yaml @@ -620,7 +620,7 @@ packages: engines: {node: '>=8'} apcore-js@1.0.0-beta.1: - resolution: {integrity: sha512-uRfWfWg/RvaGuj0QMb6LSSGEQiVJiD/tPPv+RTWuKZgBQwdta5UFLIlV/hdLe7Gfhlg+0KeywMIdtvvFtGNT0Q==} + resolution: {integrity: sha512-korVWIY+YubukyJKCpCE7/8lan0AqNjIz1v6GR0qkXqr2oydMdxvrforn05uP6zLyd3yTtc5jS9YPOMplshfAg==} engines: {node: '>=20.0.0'} peerDependencies: typescript: ^5.5.0 @@ -629,7 +629,7 @@ packages: optional: true apcore-toolkit@0.16.0-beta.1: - resolution: {integrity: sha512-aejP75mEwPcittHawzyJOhWupyFCy7wAxNwVA9teZ41XTPH0irUTiOLrIRxWoRPSCEgZEChOlbzHxkQyqnjhVA==} + resolution: {integrity: sha512-Zd1fnHCbX9fIBdUx/zAJl2WglG8o7/eUpg+ueDq7kNYwSse5VAuv5EUL/AcEDIdrfPw7ymDfZfG2CCCv2a2zwg==} engines: {node: '>=20.10.0'} peerDependencies: '@sinclair/typebox': '>=0.31.0' diff --git a/mcp/typescript/src/adapters/errors.ts b/mcp/typescript/src/adapters/errors.ts index 35542fe7..978d914a 100644 --- a/mcp/typescript/src/adapters/errors.ts +++ b/mcp/typescript/src/adapters/errors.ts @@ -119,6 +119,28 @@ export class ErrorMapper { const code = error.code; const details = error.details; + if (code === ErrorCodes.POLICY_DENIED) { + return { + isError: true, + errorType: code, + message: "Access denied", + details: null, + retryable: false, + userFixable: true, + aiGuidance: "Review the request against the host's policy before trying again.", + }; + } + if (code === ErrorCodes.POLICY_EVALUATION_ERROR) { + return { + isError: true, + errorType: code, + message: "Policy evaluation failed", + details: null, + retryable: true, + userFixable: false, + }; + } + // Internal error codes -> generic message if (INTERNAL_ERROR_CODES.has(code)) { return { diff --git a/mcp/typescript/src/artifacts.ts b/mcp/typescript/src/artifacts.ts index 0eff3b11..d1452de1 100644 --- a/mcp/typescript/src/artifacts.ts +++ b/mcp/typescript/src/artifacts.ts @@ -1,7 +1,7 @@ import { randomUUID } from "node:crypto"; import type { ResourceLink } from "@modelcontextprotocol/sdk/types.js"; import * as apcore from "apcore-js"; -import { jsonSchemaToTypeBox, SchemaValidator, type ArtifactRef, type Identity } from "apcore-js"; +import { jsonSchemaToTypeBox, SchemaValidator, type ArtifactContent, type ArtifactRef, type ArtifactStore, type Identity } from "apcore-js"; export const ARTIFACT_URI_PREFIX = "apcore-artifact://"; const artifactIdPattern = /^[a-f0-9]{32}$/; @@ -20,6 +20,7 @@ export interface ArtifactOutputDeclaration { } type ArtifactMetadata = { readonly name: string; readonly mimeType: string; readonly size: number }; +type ResourceContent = { blob: string; mimeType: string }; type StoredArtifact = ArtifactMetadata & { readonly content: Buffer; readonly authority: string; @@ -32,7 +33,7 @@ function authority(identity: Identity): string { } /** Bounded in-process media storage owned by the embedding MCP host. */ -export class MCPArtifactStore { +export class MCPArtifactStore implements ArtifactStore { private readonly maxBytes: number; private readonly maxEntries: number; private readonly ttlMilliseconds: number; @@ -90,8 +91,20 @@ export class MCPArtifactStore { }; } - read(uri: string, identity: Identity | null): { blob: string; mimeType: string } | null { - const artifact = this.find(uri, identity); + read(uri: string, identity: Identity | null): ResourceContent | null; + read(id: string, identity: Identity, maxBytes: number): Promise; + read(idOrUri: string, identity: Identity | null, maxBytes?: number): ResourceContent | null | Promise { + if (maxBytes !== undefined) { + const artifact = this.find(ARTIFACT_URI_PREFIX + idOrUri, identity); + if (artifact === null || !Number.isSafeInteger(maxBytes) || maxBytes < artifact.size) { + return Promise.resolve(null); + } + return Promise.resolve({ + ref: { id: idOrUri, media_type: artifact.mimeType, size_bytes: artifact.size }, + content: new Uint8Array(artifact.content), + }); + } + const artifact = this.find(idOrUri, identity); return artifact === null ? null : { blob: artifact.content.toString("base64"), mimeType: artifact.mimeType, }; @@ -143,9 +156,13 @@ export function projectArtifactLinks( !Object.keys(field).every((key) => key === "type" || key === "title" || key === "description" || key.startsWith("x-"))) { continue; } - const validationSchema = jsonSchemaToTypeBox({ type: "object", properties: { artifact: field }, required: ["artifact"] }); - if (!schemaValidator.validate({ artifact: value }, validationSchema).valid) continue; - reference = apcore.parseArtifactRef(value); + try { + const validationSchema = jsonSchemaToTypeBox({ type: "object", properties: { artifact: field }, required: ["artifact"] }); + if (!schemaValidator.validate({ artifact: value }, validationSchema).valid) continue; + reference = apcore.parseArtifactRef(value); + } catch { + continue; + } } else if (field.type !== "string") { continue; } diff --git a/mcp/typescript/src/index.ts b/mcp/typescript/src/index.ts index d5fae4e8..03322315 100644 --- a/mcp/typescript/src/index.ts +++ b/mcp/typescript/src/index.ts @@ -781,7 +781,7 @@ async function serveInternal( allowExecute = false, explorerTitle = "APCore MCP Explorer", explorerProjectName = "apcore-mcp", - explorerProjectUrl = "https://github.com/aiperceivable/apcore-mcp-typescript", + explorerProjectUrl = "https://github.com/aiperceivable/apcore-surfaces/tree/main/mcp/typescript", authenticator, requireAuth: optRequireAuth, exemptPaths, @@ -1140,7 +1140,7 @@ export async function asyncServe( allowExecute = false, explorerTitle = "APCore MCP Explorer", explorerProjectName = "apcore-mcp", - explorerProjectUrl = "https://github.com/aiperceivable/apcore-mcp-typescript", + explorerProjectUrl = "https://github.com/aiperceivable/apcore-surfaces/tree/main/mcp/typescript", authenticator, requireAuth: optRequireAuth, exemptPaths, diff --git a/mcp/typescript/src/types.ts b/mcp/typescript/src/types.ts index 40226c07..61e0856b 100644 --- a/mcp/typescript/src/types.ts +++ b/mcp/typescript/src/types.ts @@ -24,6 +24,8 @@ export const ErrorCodes = Object.freeze({ MODULE_DISABLED: "MODULE_DISABLED", SCHEMA_VALIDATION_ERROR: "SCHEMA_VALIDATION_ERROR", ACL_DENIED: "ACL_DENIED", + POLICY_DENIED: "POLICY_DENIED", + POLICY_EVALUATION_ERROR: "POLICY_EVALUATION_ERROR", CALL_DEPTH_EXCEEDED: "CALL_DEPTH_EXCEEDED", CIRCULAR_CALL: "CIRCULAR_CALL", CALL_FREQUENCY_EXCEEDED: "CALL_FREQUENCY_EXCEEDED", diff --git a/mcp/typescript/tests/adapters/errors.test.ts b/mcp/typescript/tests/adapters/errors.test.ts index 0de35c09..6a437a46 100644 --- a/mcp/typescript/tests/adapters/errors.test.ts +++ b/mcp/typescript/tests/adapters/errors.test.ts @@ -28,6 +28,20 @@ function createModuleError( } describe("ErrorMapper", () => { + it.each([ + ["POLICY_DENIED", "Access denied", false], + ["POLICY_EVALUATION_ERROR", "Policy evaluation failed", true], + ] as const)("uses public diagnostics for %s", (code, message, retryable) => { + const error = createModuleError(code, "private message", { rule: "private rule" }, { + aiGuidance: "private guidance", + suggestion: "private suggestion", + }); + expect(mapper.toMcpError(error)).toEqual({ + isError: true, errorType: code, message, details: null, retryable, userFixable: !retryable, + ...(retryable ? {} : { aiGuidance: "Review the request against the host's policy before trying again." }), + }); + }); + // TC-ERROR-001 [D10-001 / D10-002]: Unknown exception -> GENERAL_INTERNAL_ERROR (EM-6) it("maps unknown exceptions to canonical GENERAL_INTERNAL_ERROR envelope", () => { const result = mapper.toMcpError(new TypeError("something unexpected")); diff --git a/mcp/typescript/tests/server/artifact-wire.test.ts b/mcp/typescript/tests/server/artifact-wire.test.ts index d4a54c38..f1be0d48 100644 --- a/mcp/typescript/tests/server/artifact-wire.test.ts +++ b/mcp/typescript/tests/server/artifact-wire.test.ts @@ -3,9 +3,42 @@ import { createServer } from "node:http"; import type { AddressInfo } from "node:net"; import { Client } from "@modelcontextprotocol/sdk/client/index.js"; import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"; -import { ACL, createIdentity, Executor, Middleware, Registry } from "apcore-js"; +import { ACL, createIdentity, Executor, Middleware, readArtifact, Registry } from "apcore-js"; import { expect, it } from "vitest"; import { MCPArtifactStore, asyncServe } from "../../src/index.js"; +import { projectArtifactLinks } from "../../src/artifacts.js"; + +it("supports Core reads while preserving resource URI reads", async () => { + const owner = createIdentity("owner", "agent"); + const guest = createIdentity("guest", "agent"); + const store = new MCPArtifactStore(); + const content = new Uint8Array([1, 2, 3]); + const id = store.put(content, { name: "preview.png", mimeType: "image/png", owner }); + const ref = { id, media_type: "image/png", size_bytes: content.length }; + + expect(await readArtifact(store, ref, owner)).toEqual({ ref, content }); + expect(await store.read(id, owner, 2)).toBeNull(); + expect(await readArtifact(store, ref, guest)).toBeNull(); + expect(store.read("apcore-artifact://" + id, owner)).toEqual({ blob: "AQID", mimeType: "image/png" }); +}); + +it("keeps valid links when validation of another declaration throws", () => { + const owner = createIdentity("owner", "agent"); + const store = new MCPArtifactStore(); + const id = store.put(new Uint8Array([1]), { name: "preview.png", mimeType: "image/png", owner }); + const schema = { + type: "object", + properties: { + broken: { + type: "object", "x-mcp-artifact": true, "x-artifact-ref": true, + get "x-max-bytes"(): never { throw new Error("unreadable fixture declaration"); }, + }, + preview: { type: "string", "x-mcp-artifact": true }, + }, + }; + expect(projectArtifactLinks(store, { broken: {}, preview: id }, schema, owner, { schema, isCurrent: () => true })) + .toEqual([{ type: "resource_link", uri: "apcore-artifact://" + id, name: "preview.png", mimeType: "image/png", size: 1 }]); +}); it.each(["legacy", "canonical", "size-mismatch", "media-mismatch", "over-limit", "downgrade", "ambiguous", "stale", "duplicate"])( "only projects a valid guarded link over MCP (%s)", async (scenario) => { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index aa51d06c..a0c23724 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1379,7 +1379,7 @@ packages: resolution: {integrity: sha512-7UvmKalWRt1wgjL1RrGxoSJW/0QZFIegpeGvZG9kjp8vrRu55XTHbwnqq2GpXm9uLbcuhxm3IqX9OB4MZR1b2A==} apcore-js@1.0.0-beta.1: - resolution: {integrity: sha512-uRfWfWg/RvaGuj0QMb6LSSGEQiVJiD/tPPv+RTWuKZgBQwdta5UFLIlV/hdLe7Gfhlg+0KeywMIdtvvFtGNT0Q==} + resolution: {integrity: sha512-korVWIY+YubukyJKCpCE7/8lan0AqNjIz1v6GR0qkXqr2oydMdxvrforn05uP6zLyd3yTtc5jS9YPOMplshfAg==} engines: {node: '>=20.0.0'} peerDependencies: typescript: ^5.5.0 @@ -1388,7 +1388,7 @@ packages: optional: true apcore-toolkit@0.16.0-beta.1: - resolution: {integrity: sha512-aejP75mEwPcittHawzyJOhWupyFCy7wAxNwVA9teZ41XTPH0irUTiOLrIRxWoRPSCEgZEChOlbzHxkQyqnjhVA==} + resolution: {integrity: sha512-Zd1fnHCbX9fIBdUx/zAJl2WglG8o7/eUpg+ueDq7kNYwSse5VAuv5EUL/AcEDIdrfPw7ymDfZfG2CCCv2a2zwg==} engines: {node: '>=20.10.0'} peerDependencies: '@sinclair/typebox': '>=0.31.0' diff --git a/pyproject.toml b/pyproject.toml index 4146e203..b04735f9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,5 +13,5 @@ package = false members = ["toolkit/python", "mcp/python", "a2a/python", "cli/python"] [tool.uv.sources] -apcore = { git = "https://github.com/aiperceivable/apcore.git", rev = "403482c27d5f88d3f070a01ecd1cb103ebfc97f9", subdirectory = "python" } +apcore = { git = "https://github.com/aiperceivable/apcore.git", rev = "3f6c785fab4a4a7140637fbb21039f1d65d0274b", subdirectory = "python" } apcore-toolkit = { workspace = true } diff --git a/toolkit/rust/Cargo.lock b/toolkit/rust/Cargo.lock index e7de6d50..2d911a7e 100644 --- a/toolkit/rust/Cargo.lock +++ b/toolkit/rust/Cargo.lock @@ -50,7 +50,7 @@ checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" name = "apcore" version = "1.0.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19dc73726e9aac784e05bb9e99ee3de032b720cde10e2fefa0b5b4a93017d96c" +checksum = "49109b2f64808f66f3663d5ac713ae4c3ed7008a812f302244042ab13125b494" dependencies = [ "async-stream", "async-trait", diff --git a/toolkit/typescript/pnpm-lock.yaml b/toolkit/typescript/pnpm-lock.yaml index 0536815e..a4a98375 100644 --- a/toolkit/typescript/pnpm-lock.yaml +++ b/toolkit/typescript/pnpm-lock.yaml @@ -566,7 +566,7 @@ packages: engines: {node: '>=8'} apcore-js@1.0.0-beta.1: - resolution: {integrity: sha512-uRfWfWg/RvaGuj0QMb6LSSGEQiVJiD/tPPv+RTWuKZgBQwdta5UFLIlV/hdLe7Gfhlg+0KeywMIdtvvFtGNT0Q==} + resolution: {integrity: sha512-korVWIY+YubukyJKCpCE7/8lan0AqNjIz1v6GR0qkXqr2oydMdxvrforn05uP6zLyd3yTtc5jS9YPOMplshfAg==} engines: {node: '>=20.0.0'} peerDependencies: typescript: ^5.5.0 diff --git a/uv.lock b/uv.lock index 0b953e64..50f06af8 100644 --- a/uv.lock +++ b/uv.lock @@ -264,11 +264,12 @@ wheels = [ [[package]] name = "apcore" version = "1.0.0b1" -source = { git = "https://github.com/aiperceivable/apcore.git?subdirectory=python&rev=403482c27d5f88d3f070a01ecd1cb103ebfc97f9#403482c27d5f88d3f070a01ecd1cb103ebfc97f9" } +source = { git = "https://github.com/aiperceivable/apcore.git?subdirectory=python&rev=3f6c785fab4a4a7140637fbb21039f1d65d0274b#3f6c785fab4a4a7140637fbb21039f1d65d0274b" } dependencies = [ { name = "jsonschema" }, { name = "pydantic" }, { name = "referencing" }, + { name = "typing-extensions" }, ] [package.optional-dependencies] @@ -310,7 +311,7 @@ openapi = [ [package.metadata] requires-dist = [ { name = "a2a-sdk", extras = ["http-server"], specifier = ">=1.1.2" }, - { name = "apcore", extras = ["config", "discovery"], git = "https://github.com/aiperceivable/apcore.git?subdirectory=python&rev=403482c27d5f88d3f070a01ecd1cb103ebfc97f9" }, + { name = "apcore", extras = ["config", "discovery"], git = "https://github.com/aiperceivable/apcore.git?subdirectory=python&rev=3f6c785fab4a4a7140637fbb21039f1d65d0274b" }, { name = "apcore-toolkit", editable = "toolkit/python" }, { name = "apcore-toolkit", extras = ["http-proxy"], marker = "extra == 'openapi'", editable = "toolkit/python" }, { name = "apdev", extras = ["dev"], marker = "extra == 'dev'", specifier = ">=0.2.1" }, @@ -353,7 +354,7 @@ dev = [ [package.metadata] requires-dist = [ - { name = "apcore", extras = ["config", "discovery"], git = "https://github.com/aiperceivable/apcore.git?subdirectory=python&rev=403482c27d5f88d3f070a01ecd1cb103ebfc97f9" }, + { name = "apcore", extras = ["config", "discovery"], git = "https://github.com/aiperceivable/apcore.git?subdirectory=python&rev=3f6c785fab4a4a7140637fbb21039f1d65d0274b" }, { name = "apcore-toolkit", extras = ["http-proxy"], editable = "toolkit/python" }, { name = "apdev", extras = ["dev"], marker = "extra == 'dev'", specifier = ">=0.2.3" }, { name = "click", specifier = ">=8.1" }, @@ -402,7 +403,7 @@ openapi = [ [package.metadata] requires-dist = [ - { name = "apcore", extras = ["config", "discovery"], git = "https://github.com/aiperceivable/apcore.git?subdirectory=python&rev=403482c27d5f88d3f070a01ecd1cb103ebfc97f9" }, + { name = "apcore", extras = ["config", "discovery"], git = "https://github.com/aiperceivable/apcore.git?subdirectory=python&rev=3f6c785fab4a4a7140637fbb21039f1d65d0274b" }, { name = "apcore-toolkit", marker = "extra == 'markdown'", editable = "toolkit/python" }, { name = "apcore-toolkit", extras = ["http-proxy"], marker = "extra == 'dev'", editable = "toolkit/python" }, { name = "apcore-toolkit", extras = ["http-proxy"], marker = "extra == 'openapi'", editable = "toolkit/python" }, @@ -466,7 +467,7 @@ json-schema = [ [package.metadata] requires-dist = [ - { name = "apcore", git = "https://github.com/aiperceivable/apcore.git?subdirectory=python&rev=403482c27d5f88d3f070a01ecd1cb103ebfc97f9" }, + { name = "apcore", git = "https://github.com/aiperceivable/apcore.git?subdirectory=python&rev=3f6c785fab4a4a7140637fbb21039f1d65d0274b" }, { name = "apdev", extras = ["dev"], marker = "extra == 'dev'", specifier = ">=0.2.1" }, { name = "httpx", marker = "extra == 'auth'", specifier = ">=0.24" }, { name = "httpx", marker = "extra == 'dev'", specifier = ">=0.24" },