@atlasauth/pca-mcp 0.0.0-stage → 0.1.0
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.
- package/README.md +36 -2
- package/dist/index.d.ts +54 -0
- package/dist/index.js +62 -0
- package/dist/index.js.map +1 -0
- package/package.json +38 -3
package/README.md
CHANGED
|
@@ -1,3 +1,37 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @atlasauth/pca-mcp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Model Context Protocol adapter for Proof-Carrying Authority: wrap an MCP tool handler so every call emits a PCActn (and attaches the proof) before the handler runs.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm i @atlasauth/pca-mcp
|
|
9
|
+
# peer dependency, install alongside:
|
|
10
|
+
npm i @modelcontextprotocol/sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`@modelcontextprotocol/sdk` (^1) is an optional peer dependency.
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { withPCA } from '@atlasauth/pca-mcp';
|
|
19
|
+
|
|
20
|
+
server.tool(
|
|
21
|
+
'refund',
|
|
22
|
+
schema,
|
|
23
|
+
withPCA(
|
|
24
|
+
agent, // core @atlasauth/pca Agent
|
|
25
|
+
{
|
|
26
|
+
verb: 'stripe.refund',
|
|
27
|
+
resource: (args) => `ch_${args.chargeId}`,
|
|
28
|
+
onProof: (pca) => { /* forward pca.encoded to the resource server */ },
|
|
29
|
+
},
|
|
30
|
+
async (args) => ({ content: [{ type: 'text', text: await doRefund(args) }] }),
|
|
31
|
+
),
|
|
32
|
+
);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The wrapped handler keeps the MCP handler shape. On a local fast-fail it returns an MCP error result (`isError: true`) rather than throwing. It builds + attaches a PCActn; it does not authorize on its own — the resource server's verifier decides.
|
|
36
|
+
|
|
37
|
+
Part of Proof-Carrying Authority — see `@atlasauth/pca`.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model Context Protocol adapter for Proof-Carrying Authority.
|
|
3
|
+
*
|
|
4
|
+
* Wrap an MCP tool handler so every call first builds a PCActn (via the core `guard`) — fast-failing on
|
|
5
|
+
* the agent's local dry-run and handing the proof to your `onProof` so it can be forwarded to / attached
|
|
6
|
+
* for the resource server — then runs the original handler. Drop-in: the wrapped handler has the SAME
|
|
7
|
+
* shape as an MCP tool handler, so it slots straight into `server.tool(name, schema, withPCA(agent, {...},
|
|
8
|
+
* handler))` / `server.registerTool`.
|
|
9
|
+
*
|
|
10
|
+
* Structurally compatible with the `@modelcontextprotocol/sdk` package v1 (declared as an OPTIONAL peer
|
|
11
|
+
* dependency). We never import the SDK's runtime — the handler/result types below are a minimal
|
|
12
|
+
* structural shim, so this works across minor versions and even when the SDK is absent.
|
|
13
|
+
*
|
|
14
|
+
* HONEST: this does not authorize — it attaches a proof-carrying action; the resource server's verifier
|
|
15
|
+
* decides. A bypassed wrapper just means the action lacks a valid PCActn and fails server-side. The local
|
|
16
|
+
* dry-run is a convenience fast-fail, not a grant.
|
|
17
|
+
*/
|
|
18
|
+
import { type Agent, type PcaCall, bridgeToolCall, pcaHeaders } from '@atlasauth/pca';
|
|
19
|
+
/** Minimal structural shape of an MCP tool result (`server.tool` / `registerTool` handler return). */
|
|
20
|
+
export interface McpToolResult {
|
|
21
|
+
content: Array<{
|
|
22
|
+
type: string;
|
|
23
|
+
[k: string]: unknown;
|
|
24
|
+
}>;
|
|
25
|
+
isError?: boolean;
|
|
26
|
+
[k: string]: unknown;
|
|
27
|
+
}
|
|
28
|
+
/** An MCP tool handler: `(args, extra?) => result`, as registered via `server.tool` / `registerTool`. */
|
|
29
|
+
export type McpToolHandler<ARGS = Record<string, unknown>> = (args: ARGS, extra?: unknown) => Promise<McpToolResult> | McpToolResult;
|
|
30
|
+
export interface GuardToolSpec<ARGS> {
|
|
31
|
+
/** Catalog verb this tool maps to (e.g. `stripe.refund`). */
|
|
32
|
+
verb: string;
|
|
33
|
+
/** Resource for the call: fixed, or derived from the tool args. */
|
|
34
|
+
resource: string | ((args: ARGS) => string);
|
|
35
|
+
/** Audience (resource-server / instance id); falls back to the agent's default. */
|
|
36
|
+
aud?: string;
|
|
37
|
+
/** Fast-fail on the local dry-run before running the handler (default true). */
|
|
38
|
+
failFast?: boolean;
|
|
39
|
+
/** Receive the PCActn so the proof can be forwarded (e.g. as request headers) to the resource server. */
|
|
40
|
+
onProof?: (pca: PcaCall, args: ARGS) => void;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Wrap an MCP tool handler so each call emits + attaches a PCActn before the original handler runs.
|
|
44
|
+
*
|
|
45
|
+
* On a local fast-fail (`PcaDenied`), returns an MCP error result (`{ isError: true }`) rather than
|
|
46
|
+
* throwing — MCP handlers signal tool errors in-band via `isError` so the model can see them.
|
|
47
|
+
*/
|
|
48
|
+
export declare function withPCA<ARGS extends Record<string, unknown>>(agent: Agent, spec: GuardToolSpec<ARGS>, handler: McpToolHandler<ARGS>): McpToolHandler<ARGS>;
|
|
49
|
+
/**
|
|
50
|
+
* Attach the encoded PCActn into a result's `_meta` so a downstream (gateway / RS) can read the proof off
|
|
51
|
+
* the tool result. Additive and non-destructive: existing `content`, `isError` and `_meta` keys are kept.
|
|
52
|
+
*/
|
|
53
|
+
export declare function guardToolResult(pca: PcaCall, result: McpToolResult): McpToolResult;
|
|
54
|
+
export { bridgeToolCall, pcaHeaders, type PcaCall };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Model Context Protocol adapter for Proof-Carrying Authority.
|
|
4
|
+
*
|
|
5
|
+
* Wrap an MCP tool handler so every call first builds a PCActn (via the core `guard`) — fast-failing on
|
|
6
|
+
* the agent's local dry-run and handing the proof to your `onProof` so it can be forwarded to / attached
|
|
7
|
+
* for the resource server — then runs the original handler. Drop-in: the wrapped handler has the SAME
|
|
8
|
+
* shape as an MCP tool handler, so it slots straight into `server.tool(name, schema, withPCA(agent, {...},
|
|
9
|
+
* handler))` / `server.registerTool`.
|
|
10
|
+
*
|
|
11
|
+
* Structurally compatible with the `@modelcontextprotocol/sdk` package v1 (declared as an OPTIONAL peer
|
|
12
|
+
* dependency). We never import the SDK's runtime — the handler/result types below are a minimal
|
|
13
|
+
* structural shim, so this works across minor versions and even when the SDK is absent.
|
|
14
|
+
*
|
|
15
|
+
* HONEST: this does not authorize — it attaches a proof-carrying action; the resource server's verifier
|
|
16
|
+
* decides. A bypassed wrapper just means the action lacks a valid PCActn and fails server-side. The local
|
|
17
|
+
* dry-run is a convenience fast-fail, not a grant.
|
|
18
|
+
*/
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.pcaHeaders = exports.bridgeToolCall = void 0;
|
|
21
|
+
exports.withPCA = withPCA;
|
|
22
|
+
exports.guardToolResult = guardToolResult;
|
|
23
|
+
const pca_1 = require("@atlasauth/pca");
|
|
24
|
+
Object.defineProperty(exports, "bridgeToolCall", { enumerable: true, get: function () { return pca_1.bridgeToolCall; } });
|
|
25
|
+
Object.defineProperty(exports, "pcaHeaders", { enumerable: true, get: function () { return pca_1.pcaHeaders; } });
|
|
26
|
+
/**
|
|
27
|
+
* Wrap an MCP tool handler so each call emits + attaches a PCActn before the original handler runs.
|
|
28
|
+
*
|
|
29
|
+
* On a local fast-fail (`PcaDenied`), returns an MCP error result (`{ isError: true }`) rather than
|
|
30
|
+
* throwing — MCP handlers signal tool errors in-band via `isError` so the model can see them.
|
|
31
|
+
*/
|
|
32
|
+
function withPCA(agent, spec, handler) {
|
|
33
|
+
return async (args, extra) => {
|
|
34
|
+
const run = (0, pca_1.guard)(agent, {
|
|
35
|
+
verb: spec.verb,
|
|
36
|
+
resource: spec.resource,
|
|
37
|
+
...(spec.aud !== undefined ? { aud: spec.aud } : {}),
|
|
38
|
+
...(spec.failFast !== undefined ? { failFast: spec.failFast } : {}),
|
|
39
|
+
}, async (a, pca) => {
|
|
40
|
+
spec.onProof?.(pca, a);
|
|
41
|
+
return handler(a, extra);
|
|
42
|
+
});
|
|
43
|
+
try {
|
|
44
|
+
return await run(args);
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
if (err instanceof pca_1.PcaDenied) {
|
|
48
|
+
return { content: [{ type: 'text', text: err.message }], isError: true };
|
|
49
|
+
}
|
|
50
|
+
throw err;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Attach the encoded PCActn into a result's `_meta` so a downstream (gateway / RS) can read the proof off
|
|
56
|
+
* the tool result. Additive and non-destructive: existing `content`, `isError` and `_meta` keys are kept.
|
|
57
|
+
*/
|
|
58
|
+
function guardToolResult(pca, result) {
|
|
59
|
+
const prevMeta = result._meta && typeof result._meta === 'object' ? result._meta : {};
|
|
60
|
+
return { ...result, _meta: { ...prevMeta, 'x-pca-action': pca.encoded } };
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;AAoCH,0BA4BC;AAMD,0CAIC;AAxED,wCAAwG;AA0E/F,+FA1EqC,oBAAc,OA0ErC;AAAE,2FA1E4C,gBAAU,OA0E5C;AA9CnC;;;;;GAKG;AACH,SAAgB,OAAO,CACrB,KAAY,EACZ,IAAyB,EACzB,OAA6B;IAE7B,OAAO,KAAK,EAAE,IAAU,EAAE,KAAe,EAA0B,EAAE;QACnE,MAAM,GAAG,GAAG,IAAA,WAAK,EACf,KAAK,EACL;YACE,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,GAAG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1
|
{
|
|
2
2
|
"name": "@atlasauth/pca-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Model Context Protocol adapter for Proof-Carrying Authority: wrap an MCP tool handler so every call emits a PCActn (and attaches the proof) before the handler runs.",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./package.json": "./package.json"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@atlasauth/pca": "0.1.0"
|
|
16
|
+
},
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"@modelcontextprotocol/sdk": "^1"
|
|
19
|
+
},
|
|
20
|
+
"peerDependenciesMeta": {
|
|
21
|
+
"@modelcontextprotocol/sdk": {
|
|
22
|
+
"optional": true
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"typescript": "^5.6.3",
|
|
27
|
+
"vitest": "^2.1.4"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"README.md"
|
|
32
|
+
],
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc -p tsconfig.build.json",
|
|
38
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
39
|
+
"test": "vitest run"
|
|
40
|
+
}
|
|
6
41
|
}
|