@atlasauth/pca-mcp 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +58 -2
- package/dist/index.d.ts +54 -0
- package/dist/index.js +62 -0
- package/dist/index.js.map +1 -0
- package/package.json +61 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Atlas Authorization
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,59 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @atlasauth/pca-mcp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Model Context Protocol adapter for Proof-Carrying Authority (PCA). `withPCA` wraps an MCP tool handler so every call first builds a signed PCActn (failing fast if the agent's own grant does not permit it), hands you the proof to forward to the resource server, and then runs the original handler.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm i @atlasauth/pca-mcp @atlasauth/pca
|
|
9
|
+
npm i @modelcontextprotocol/sdk # optional peer dependency (^1)
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { agent, generateKeyPair } from '@atlasauth/pca';
|
|
16
|
+
import { withPCA } from '@atlasauth/pca-mcp';
|
|
17
|
+
|
|
18
|
+
const pcaAgent = agent({
|
|
19
|
+
principal: generateKeyPair(),
|
|
20
|
+
goal: 'process refunds',
|
|
21
|
+
permissions: { stripe: ['refund'] },
|
|
22
|
+
limits: { refund: '$500/day' },
|
|
23
|
+
aud: 'ins_acme',
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
server.tool(
|
|
27
|
+
'refund',
|
|
28
|
+
schema,
|
|
29
|
+
withPCA(
|
|
30
|
+
pcaAgent,
|
|
31
|
+
{
|
|
32
|
+
verb: 'stripe.refund',
|
|
33
|
+
resource: (args) => `ch_${args.chargeId}`,
|
|
34
|
+
onProof: (pca, args) => {
|
|
35
|
+
// forward pca.headers (PCA-Action) to the resource server with your request
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
async (args) => ({ content: [{ type: 'text', text: await doRefund(args) }] }),
|
|
39
|
+
),
|
|
40
|
+
);
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The wrapped handler keeps the MCP handler shape `(args, extra?) => result`. When the local dry-run denies the action it returns an MCP error result (`isError: true`) instead of throwing, so the model can see the refusal.
|
|
44
|
+
|
|
45
|
+
## API
|
|
46
|
+
|
|
47
|
+
- `withPCA(agent, spec, handler)` - spec is `{ verb, resource, aud?, failFast?, onProof? }`.
|
|
48
|
+
- `guardToolResult(pca, result)` - adds the encoded PCActn to a tool result's `_meta['x-pca-action']`, keeping existing content.
|
|
49
|
+
- Re-exports `bridgeToolCall`, `pcaHeaders`, and the `PcaCall` type from `@atlasauth/pca`.
|
|
50
|
+
|
|
51
|
+
To make the server that receives these calls an OAuth resource server, see `@atlasauth/pca-mcp-rs`.
|
|
52
|
+
|
|
53
|
+
## Status
|
|
54
|
+
|
|
55
|
+
This package does not authorize anything. It attaches a proof-carrying action; the resource server's verifier (see `@atlasauth/pca`) decides. The MCP SDK is matched structurally and never imported. PCA cryptography has not been independently audited.
|
|
56
|
+
|
|
57
|
+
## License
|
|
58
|
+
|
|
59
|
+
MIT - see LICENSE
|
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":[],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C,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAgB,eAAe,CAAC,GAAY,EAAE,MAAqB;IACjE,MAAM,QAAQ,GACZ,MAAM,CAAC,KAAK,IAAI,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAE,MAAM,CAAC,KAAiC,CAAC,CAAC,CAAC,EAAE,CAAC;IACpG,OAAO,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,EAAE,GAAG,QAAQ,EAAE,cAAc,EAAE,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC;AAC5E,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,64 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlasauth/pca-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.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
|
+
"keywords": [
|
|
6
|
+
"mcp",
|
|
7
|
+
"model context protocol",
|
|
8
|
+
"tool calling",
|
|
9
|
+
"agent authorization",
|
|
10
|
+
"proof-carrying authority",
|
|
11
|
+
"pca",
|
|
12
|
+
"ai agents"
|
|
13
|
+
],
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"homepage": "https://github.com/Atlas-Authorization/pca#readme",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/Atlas-Authorization/pca/issues"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/Atlas-Authorization/pca.git",
|
|
22
|
+
"directory": "packages/pca-mcp"
|
|
23
|
+
},
|
|
24
|
+
"main": "./dist/index.js",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"default": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./package.json": "./package.json"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@atlasauth/pca": "0.2.0"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@modelcontextprotocol/sdk": "^1"
|
|
38
|
+
},
|
|
39
|
+
"peerDependenciesMeta": {
|
|
40
|
+
"@modelcontextprotocol/sdk": {
|
|
41
|
+
"optional": true
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"typescript": "^5.6.3",
|
|
46
|
+
"vitest": "^2.1.4"
|
|
47
|
+
},
|
|
48
|
+
"files": [
|
|
49
|
+
"dist",
|
|
50
|
+
"README.md",
|
|
51
|
+
"LICENSE"
|
|
52
|
+
],
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": ">=20"
|
|
55
|
+
},
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"access": "public"
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "tsc -p tsconfig.build.json",
|
|
61
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
62
|
+
"test": "vitest run"
|
|
63
|
+
}
|
|
6
64
|
}
|