@mcp-i/core 1.1.0 → 1.1.3
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 +79 -151
- package/dist/auth/handshake.d.ts +4 -19
- package/dist/auth/handshake.d.ts.map +1 -1
- package/dist/auth/handshake.js +15 -52
- package/dist/auth/handshake.js.map +1 -1
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js.map +1 -1
- package/dist/delegation/did-key-resolver.d.ts.map +1 -1
- package/dist/delegation/did-key-resolver.js +6 -9
- package/dist/delegation/did-key-resolver.js.map +1 -1
- package/dist/delegation/outbound-headers.d.ts +4 -2
- package/dist/delegation/outbound-headers.d.ts.map +1 -1
- package/dist/delegation/outbound-headers.js +3 -2
- package/dist/delegation/outbound-headers.js.map +1 -1
- package/dist/delegation/statuslist-manager.d.ts.map +1 -1
- package/dist/delegation/statuslist-manager.js +1 -1
- package/dist/delegation/statuslist-manager.js.map +1 -1
- package/dist/delegation/vc-verifier.d.ts.map +1 -1
- package/dist/delegation/vc-verifier.js +2 -2
- package/dist/delegation/vc-verifier.js.map +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/dist/middleware/index.d.ts +0 -1
- package/dist/middleware/index.d.ts.map +1 -1
- package/dist/middleware/index.js +0 -1
- package/dist/middleware/index.js.map +1 -1
- package/dist/middleware/with-mcpi-server.d.ts +9 -25
- package/dist/middleware/with-mcpi-server.d.ts.map +1 -1
- package/dist/middleware/with-mcpi-server.js +47 -62
- package/dist/middleware/with-mcpi-server.js.map +1 -1
- package/dist/middleware/with-mcpi.d.ts +5 -26
- package/dist/middleware/with-mcpi.d.ts.map +1 -1
- package/dist/middleware/with-mcpi.js +10 -108
- package/dist/middleware/with-mcpi.js.map +1 -1
- package/dist/providers/memory.js +2 -2
- package/dist/providers/memory.js.map +1 -1
- package/dist/session/manager.d.ts +1 -7
- package/dist/session/manager.d.ts.map +1 -1
- package/dist/session/manager.js +4 -20
- package/dist/session/manager.js.map +1 -1
- package/dist/utils/crypto-service.d.ts.map +1 -1
- package/dist/utils/crypto-service.js +10 -11
- package/dist/utils/crypto-service.js.map +1 -1
- package/dist/utils/did-helpers.d.ts +0 -12
- package/dist/utils/did-helpers.d.ts.map +1 -1
- package/dist/utils/did-helpers.js +0 -18
- package/dist/utils/did-helpers.js.map +1 -1
- package/package.json +2 -1
- package/src/middleware/with-mcpi-server.ts +1 -5
- package/dist/errors.d.ts +0 -42
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js +0 -45
- package/dist/errors.js.map +0 -1
- package/dist/middleware/mcpi-transport.d.ts +0 -39
- package/dist/middleware/mcpi-transport.d.ts.map +0 -1
- package/dist/middleware/mcpi-transport.js +0 -121
- package/dist/middleware/mcpi-transport.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,203 +1,131 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
MCP-I
|
|
6
|
-
|
|
7
|
-
>
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://modelcontextprotocol-identity.io">
|
|
3
|
+
<picture>
|
|
4
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://modelcontextprotocol-identity.io/images/logo-mark_white.svg">
|
|
5
|
+
<img alt="MCP-I" src="https://modelcontextprotocol-identity.io/images/logo-mark_black.svg" width="64">
|
|
6
|
+
</picture>
|
|
7
|
+
</a>
|
|
8
|
+
</p>
|
|
9
|
+
|
|
10
|
+
<p align="center">
|
|
11
|
+
<strong>Identity, delegation, and proof for the Model Context Protocol.</strong>
|
|
12
|
+
</p>
|
|
13
|
+
|
|
14
|
+
<p align="center">
|
|
15
|
+
<a href="https://www.npmjs.com/package/@mcp-i/core"><img src="https://img.shields.io/npm/v/@mcp-i/core" alt="npm"></a>
|
|
16
|
+
<a href="https://modelcontextprotocol-identity.io"><img src="https://img.shields.io/badge/spec-modelcontextprotocol--identity.io-blue" alt="spec"></a>
|
|
17
|
+
<a href="https://identity.foundation/working-groups/agent-and-authorization.html"><img src="https://img.shields.io/badge/DIF-TAAWG-purple" alt="DIF TAAWG"></a>
|
|
18
|
+
<a href="./LICENSE"><img src="https://img.shields.io/github/license/modelcontextprotocol-identity/mcp-i-core" alt="license"></a>
|
|
19
|
+
</p>
|
|
8
20
|
|
|
9
21
|
---
|
|
10
22
|
|
|
11
|
-
|
|
23
|
+
AI agents call tools on your behalf. But today, there's no way to know *who* called, *whether they were allowed to*, or *what actually happened*. MCP-I fixes that.
|
|
12
24
|
|
|
13
|
-
|
|
25
|
+
- **Every server gets a cryptographic identity** (DID) — no accounts, no API keys, no central registry
|
|
26
|
+
- **Every tool call gets a signed proof** — a tamper-evident receipt the agent can't forge or deny
|
|
27
|
+
- **Protected tools require human consent** — per-tool authorization via W3C Delegation Credentials
|
|
28
|
+
- **The AI never knows** — identity, proofs, and consent happen transparently in the protocol layer
|
|
14
29
|
|
|
15
|
-
```bash
|
|
16
|
-
git clone https://github.com/modelcontextprotocol-identity/mcp-i-core.git
|
|
17
|
-
cd mcp-i-core
|
|
18
|
-
pnpm install
|
|
19
|
-
npx tsx examples/consent-basic/src/server.ts
|
|
20
30
|
```
|
|
21
|
-
|
|
22
|
-
Then connect with [MCP Inspector](https://github.com/modelcontextprotocol/inspector):
|
|
23
|
-
|
|
24
|
-
```bash
|
|
25
|
-
npx @modelcontextprotocol/inspector
|
|
26
|
-
# → Connect to http://localhost:3002/sse
|
|
31
|
+
npm install @mcp-i/core
|
|
27
32
|
```
|
|
28
33
|
|
|
29
|
-
Call `checkout` — you'll get a consent link. Open it, approve, then retry the tool. [Full walkthrough →](./examples/consent-basic/README.md)
|
|
30
|
-
|
|
31
34
|
---
|
|
32
35
|
|
|
33
|
-
##
|
|
36
|
+
## Migrate Any MCP Server in 2 Lines
|
|
34
37
|
|
|
35
|
-
|
|
38
|
+
**Before** — a standard MCP server with no identity or proofs:
|
|
36
39
|
|
|
37
40
|
```typescript
|
|
38
41
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
39
|
-
import { withMCPI, NodeCryptoProvider } from '@mcp-i/core';
|
|
40
42
|
|
|
41
43
|
const server = new McpServer({ name: 'my-server', version: '1.0.0' });
|
|
42
|
-
await withMCPI(server, { crypto: new NodeCryptoProvider() });
|
|
43
|
-
|
|
44
|
-
// Register tools normally — proofs are attached automatically
|
|
45
|
-
```
|
|
46
44
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
If your runtime has a native connection/auth handshake hook, disable tool exposure and call middleware directly:
|
|
52
|
-
|
|
53
|
-
```typescript
|
|
54
|
-
const mcpi = await withMCPI(server, {
|
|
55
|
-
crypto: new NodeCryptoProvider(),
|
|
56
|
-
handshakeExposure: 'none',
|
|
57
|
-
autoSession: false,
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
// In your runtime's connection handshake hook:
|
|
61
|
-
await mcpi.handleMCPI({
|
|
62
|
-
action: 'handshake',
|
|
63
|
-
nonce: 'client-generated-nonce',
|
|
64
|
-
audience: mcpi.identity.did,
|
|
65
|
-
timestamp: Math.floor(Date.now() / 1000),
|
|
66
|
-
agentDid: 'did:key:...optional...',
|
|
67
|
-
});
|
|
45
|
+
server.registerTool('greet', { description: 'Say hello' }, async (args) => ({
|
|
46
|
+
content: [{ type: 'text', text: `Hello, ${args.name}!` }],
|
|
47
|
+
}));
|
|
68
48
|
```
|
|
69
49
|
|
|
70
|
-
|
|
50
|
+
**After** — every tool response now carries a signed cryptographic proof:
|
|
71
51
|
|
|
72
52
|
```typescript
|
|
73
|
-
import {
|
|
53
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
54
|
+
import { withMCPI, NodeCryptoProvider } from '@mcp-i/core'; // +1 line
|
|
74
55
|
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
const mcpi = createMCPIMiddleware({ identity, session: { sessionTtlMinutes: 60 } }, crypto);
|
|
56
|
+
const server = new McpServer({ name: 'my-server', version: '1.0.0' });
|
|
57
|
+
await withMCPI(server, { crypto: new NodeCryptoProvider() }); // +1 line
|
|
78
58
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
content: [{ type: 'text', text: `Results for: ${args['query']}` }],
|
|
59
|
+
server.registerTool('greet', { description: 'Say hello' }, async (args) => ({
|
|
60
|
+
content: [{ type: 'text', text: `Hello, ${args.name}!` }],
|
|
82
61
|
}));
|
|
83
|
-
|
|
84
|
-
// Protected tool — requires delegation with scope 'orders:write'
|
|
85
|
-
const placeOrder = mcpi.wrapWithDelegation(
|
|
86
|
-
'place_order',
|
|
87
|
-
{ scopeId: 'orders:write', consentUrl: 'https://example.com/consent' },
|
|
88
|
-
mcpi.wrapWithProof('place_order', async (args) => ({
|
|
89
|
-
content: [{ type: 'text', text: `Order placed: ${args['item']}` }],
|
|
90
|
-
})),
|
|
91
|
-
);
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
---
|
|
95
|
-
|
|
96
|
-
## Install
|
|
97
|
-
|
|
98
|
-
```bash
|
|
99
|
-
npm install @mcp-i/core
|
|
100
62
|
```
|
|
101
63
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
---
|
|
105
|
-
|
|
106
|
-
## Architecture
|
|
64
|
+
That's it. `withMCPI` auto-generates an Ed25519 identity, registers the `_mcpi` protocol tool, and wraps the transport so every tool response includes a detached JWS proof in `_meta` — invisible to the LLM, verifiable by anyone.
|
|
107
65
|
|
|
108
|
-
|
|
109
|
-
┌─────────────┐ ┌──────────────┐ ┌─────────────┐
|
|
110
|
-
│ Agent │────▶│ MCP Server │────▶│ Downstream │
|
|
111
|
-
│ (did:key) │ │ + MCP-I │ │ Services │
|
|
112
|
-
└─────────────┘ └──────────────┘ └─────────────┘
|
|
113
|
-
│ │ │
|
|
114
|
-
│ handshake │ verify delegation │ outbound headers
|
|
115
|
-
│ (nonce+DID) │ attach proof │ (X-Agent-DID,
|
|
116
|
-
│ │ check scopes │ X-Delegation-Chain)
|
|
117
|
-
▼ ▼ ▼
|
|
118
|
-
Session established Tool executes Context forwarded
|
|
119
|
-
with replay with signed to downstream
|
|
120
|
-
prevention receipt with delegation
|
|
121
|
-
```
|
|
66
|
+
> See the full working example: [examples/context7-with-mcpi](./examples/context7-with-mcpi/) — a real MCP server (Context7) migrated with exactly 2 lines of code.
|
|
122
67
|
|
|
123
68
|
---
|
|
124
69
|
|
|
125
|
-
##
|
|
70
|
+
## Protect Tools with Human Consent
|
|
126
71
|
|
|
127
|
-
|
|
128
|
-
|--------|-------------|
|
|
129
|
-
| **middleware** | `withMCPI(server)` — one-call integration. `createMCPIMiddleware` for low-level control. |
|
|
130
|
-
| **delegation** | Issue and verify W3C VCs. DID:key and DID:web resolution. StatusList2021 revocation. Cascading revocation. |
|
|
131
|
-
| **proof** | Generate and verify detached JWS proofs with canonical hashing (JCS + SHA-256). |
|
|
132
|
-
| **session** | Nonce-based handshake. Replay prevention. Session TTL management. |
|
|
133
|
-
| **providers** | Abstract `CryptoProvider`, `IdentityProvider`, `StorageProvider`. Plug in your own KMS, HSM, or vault. |
|
|
134
|
-
| **types** | Pure TypeScript interfaces. Zero runtime dependencies. |
|
|
72
|
+
Some tools shouldn't run without a human saying "yes." MCP-I adds per-tool authorization using W3C Verifiable Credentials:
|
|
135
73
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
74
|
+
```typescript
|
|
75
|
+
const checkout = mcpi.wrapWithDelegation(
|
|
76
|
+
'checkout',
|
|
77
|
+
{ scopeId: 'cart:write', consentUrl: 'https://example.com/consent' },
|
|
78
|
+
mcpi.wrapWithProof('checkout', async (args) => ({
|
|
79
|
+
content: [{ type: 'text', text: `Order placed: ${args.item}` }],
|
|
80
|
+
})),
|
|
81
|
+
);
|
|
82
|
+
```
|
|
139
83
|
|
|
140
|
-
|
|
84
|
+
When an agent calls `checkout` without a delegation credential, it gets back a `needs_authorization` response with a consent URL. The human approves, a scoped credential is issued, and the agent retries — now authorized.
|
|
141
85
|
|
|
142
|
-
|
|
143
|
-
|---------|--------------|
|
|
144
|
-
| [**consent-basic**](./examples/consent-basic/) | Human-in-the-loop consent flow: `needs_authorization` → consent page → delegation VC → tool execution. SSE + Streamable HTTP transports. |
|
|
145
|
-
| [**consent-full**](./examples/consent-full/) | Same consent flow as consent-basic, powered by [`@kya-os/consent`](https://www.npmjs.com/package/@kya-os/consent) — multi-mode auth, configurable branding, and production-grade consent UI. |
|
|
146
|
-
| [**node-server**](./examples/node-server/) | Low-level Server API with handshake, proof, and restricted tools. |
|
|
147
|
-
| [**brave-search-mcp-server**](./examples/brave-search-mcp-server/) | Real-world MCP server wrapping Brave Search with MCP-I identity and proofs. |
|
|
148
|
-
| [**outbound-delegation**](./examples/outbound-delegation/) | Forwarding delegation context to downstream services (§7 gateway pattern). |
|
|
149
|
-
| [**verify-proof**](./examples/verify-proof/) | Standalone proof verification with DID:key resolution. |
|
|
150
|
-
| [**context7-with-mcpi**](./examples/context7-with-mcpi/) | Adding MCP-I to an existing MCP server with `withMCPI`. |
|
|
86
|
+
> Try it yourself: [examples/consent-basic](./examples/consent-basic/) walks through the full consent flow end-to-end.
|
|
151
87
|
|
|
152
88
|
---
|
|
153
89
|
|
|
154
|
-
##
|
|
90
|
+
## See It in Action
|
|
155
91
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
class KMSCryptoProvider extends CryptoProvider {
|
|
161
|
-
async sign(data: Uint8Array, keyArn: string) {
|
|
162
|
-
return kmsClient.sign({ KeyId: keyArn, Message: data });
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// Use Redis instead of in-memory nonce cache
|
|
167
|
-
class RedisNonceCacheProvider extends NonceCacheProvider {
|
|
168
|
-
async hasNonce(nonce: string) { return redis.exists(`nonce:${nonce}`); }
|
|
169
|
-
async addNonce(nonce: string, ttl: number) { redis.setex(`nonce:${nonce}`, ttl, '1'); }
|
|
170
|
-
}
|
|
92
|
+
```bash
|
|
93
|
+
git clone https://github.com/modelcontextprotocol-identity/mcp-i-core.git
|
|
94
|
+
cd mcp-i-core && npm install
|
|
95
|
+
bash scripts/demo.sh
|
|
171
96
|
```
|
|
172
97
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
---
|
|
176
|
-
|
|
177
|
-
## Conformance
|
|
98
|
+
This starts all example servers and opens [MCP Inspector](https://github.com/modelcontextprotocol/inspector). Connect to any server, call a tool, and inspect the proof in `_meta`:
|
|
178
99
|
|
|
179
|
-
|
|
100
|
+
| Port | Example | What it demonstrates |
|
|
101
|
+
|------|---------|---------------------|
|
|
102
|
+
| 3001 | [node-server](./examples/node-server/) | Proofs + restricted tools (low-level API) |
|
|
103
|
+
| 3002 | [consent-basic](./examples/consent-basic/) | Human consent flow with built-in UI |
|
|
104
|
+
| 3003 | [consent-full](./examples/consent-full/) | Production consent UI ([@kya-os/consent](https://www.npmjs.com/package/@kya-os/consent)) |
|
|
105
|
+
| 3004 | [context7-with-mcpi](./examples/context7-with-mcpi/) | 2-line migration of a real MCP server |
|
|
180
106
|
|
|
181
|
-
|
|
182
|
-
|-------|-------------|
|
|
183
|
-
| **Level 1** — Core Crypto | Ed25519 signatures, DID:key resolution, JCS canonicalization |
|
|
184
|
-
| **Level 2** — Full Session | Nonce-based handshake, session management, replay prevention |
|
|
185
|
-
| **Level 3** — Full Delegation | W3C VC issuance/verification, scope attenuation, StatusList2021, cascading revocation |
|
|
107
|
+
Also available: [outbound-delegation](./examples/outbound-delegation/) (gateway pattern), [verify-proof](./examples/verify-proof/) (standalone verification), [statuslist](./examples/statuslist/) (revocation lifecycle).
|
|
186
108
|
|
|
187
109
|
---
|
|
188
110
|
|
|
189
|
-
##
|
|
190
|
-
|
|
191
|
-
See [CONTRIBUTING.md](./CONTRIBUTING.md). DCO sign-off required. All PRs must pass CI (type check, lint, test across Node 20/22 on Linux/macOS/Windows).
|
|
111
|
+
## What's Under the Hood
|
|
192
112
|
|
|
193
|
-
|
|
113
|
+
| Capability | How it works |
|
|
114
|
+
|-----------|-------------|
|
|
115
|
+
| **Cryptographic identity** | Ed25519 key pairs, `did:key` and `did:web` resolution |
|
|
116
|
+
| **Signed proofs** | Detached JWS over JCS-canonicalized request/response hashes |
|
|
117
|
+
| **Delegation credentials** | W3C Verifiable Credentials with scope constraints |
|
|
118
|
+
| **Revocation** | StatusList2021 bitstring with cascading revocation |
|
|
119
|
+
| **Replay prevention** | Nonce-based handshake with timestamp skew validation |
|
|
120
|
+
| **Extensible** | Bring your own KMS, HSM, nonce cache (Redis, DynamoDB, KV), or DID method |
|
|
194
121
|
|
|
195
|
-
|
|
122
|
+
---
|
|
196
123
|
|
|
197
|
-
##
|
|
124
|
+
## Links
|
|
198
125
|
|
|
199
|
-
|
|
126
|
+
- [Spec](https://modelcontextprotocol-identity.io) | [DIF TAAWG](https://identity.foundation/working-groups/agent-and-authorization.html) | [npm](https://www.npmjs.com/package/@mcp-i/core)
|
|
127
|
+
- [CONTRIBUTING.md](./CONTRIBUTING.md) | [CONFORMANCE.md](./CONFORMANCE.md) | [SECURITY.md](./SECURITY.md) | [GOVERNANCE.md](./GOVERNANCE.md)
|
|
200
128
|
|
|
201
129
|
## License
|
|
202
130
|
|
|
203
|
-
MIT
|
|
131
|
+
MIT
|
package/dist/auth/handshake.d.ts
CHANGED
|
@@ -15,20 +15,12 @@ import type { DelegationVerifier, VerifyDelegationResult } from './types.js';
|
|
|
15
15
|
export type { DelegationVerifier, VerifyDelegationResult };
|
|
16
16
|
export interface AgentReputation {
|
|
17
17
|
agentDid: string;
|
|
18
|
-
score: number
|
|
18
|
+
score: number;
|
|
19
19
|
totalInteractions: number;
|
|
20
20
|
successRate: number;
|
|
21
21
|
riskLevel: 'low' | 'medium' | 'high' | 'unknown';
|
|
22
22
|
updatedAt: number;
|
|
23
23
|
}
|
|
24
|
-
/**
|
|
25
|
-
* Policy for handling agents with no reputation history.
|
|
26
|
-
*
|
|
27
|
-
* - 'deny' — reject unknown agents outright (strict environments)
|
|
28
|
-
* - 'require-consent' — route to the consent/authorization flow (default)
|
|
29
|
-
* - 'allow' — let unknown agents through (reputation is advisory only)
|
|
30
|
-
*/
|
|
31
|
-
export type UnknownAgentPolicy = 'deny' | 'require-consent' | 'allow';
|
|
32
24
|
export interface AuthHandshakeConfig {
|
|
33
25
|
delegationVerifier: DelegationVerifier;
|
|
34
26
|
resumeTokenStore: ResumeTokenStore;
|
|
@@ -40,15 +32,7 @@ export interface AuthHandshakeConfig {
|
|
|
40
32
|
authorization: {
|
|
41
33
|
authorizationUrl: string;
|
|
42
34
|
resumeTokenTtl?: number;
|
|
43
|
-
|
|
44
|
-
* How to handle agents with no reputation history (404 from reputation
|
|
45
|
-
* service, network error, or first-time agent).
|
|
46
|
-
*
|
|
47
|
-
* - 'deny' — reject outright
|
|
48
|
-
* - 'require-consent' — route to consent flow (default)
|
|
49
|
-
* - 'allow' — skip reputation gate for unknowns
|
|
50
|
-
*/
|
|
51
|
-
unknownAgentPolicy?: UnknownAgentPolicy;
|
|
35
|
+
requireAuthForUnknown?: boolean;
|
|
52
36
|
minReputationScore?: number;
|
|
53
37
|
};
|
|
54
38
|
debug?: boolean;
|
|
@@ -112,8 +96,9 @@ export declare class MemoryResumeTokenStore implements ResumeTokenStore {
|
|
|
112
96
|
* @param agentDid - The agent's DID to verify
|
|
113
97
|
* @param scopes - Required scopes for the operation
|
|
114
98
|
* @param config - Authorization configuration including verifier, token store, etc.
|
|
99
|
+
* @param _resumeToken - Optional resume token from previous authorization attempt
|
|
115
100
|
* @returns Result indicating authorization status, delegation, or auth hints
|
|
116
101
|
*/
|
|
117
|
-
export declare function verifyOrHints(agentDid: string, scopes: string[], config: AuthHandshakeConfig): Promise<VerifyOrHintsResult>;
|
|
102
|
+
export declare function verifyOrHints(agentDid: string, scopes: string[], config: AuthHandshakeConfig, _resumeToken?: string): Promise<VerifyOrHintsResult>;
|
|
118
103
|
export declare function hasSensitiveScopes(scopes: string[]): boolean;
|
|
119
104
|
//# sourceMappingURL=handshake.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handshake.d.ts","sourceRoot":"","sources":["../../src/auth/handshake.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EACV,uBAAuB,EAExB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAE7E,YAAY,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,CAAC;AAE3D,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"handshake.d.ts","sourceRoot":"","sources":["../../src/auth/handshake.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EACV,uBAAuB,EAExB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAE7E,YAAY,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,CAAC;AAE3D,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,iBAAiB,EAAE,MAAM,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAC;IACjD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,mBAAmB;IAClC,kBAAkB,EAAE,kBAAkB,CAAC;IACvC,gBAAgB,EAAE,gBAAgB,CAAC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,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,mBAAmB,CAAC,CA8F9B;AA8GD,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAc5D"}
|
package/dist/auth/handshake.js
CHANGED
|
@@ -18,10 +18,7 @@ export class MemoryResumeTokenStore {
|
|
|
18
18
|
this.ttl = ttlMs;
|
|
19
19
|
}
|
|
20
20
|
async create(agentDid, scopes, metadata) {
|
|
21
|
-
const
|
|
22
|
-
globalThis.crypto.getRandomValues(bytes);
|
|
23
|
-
const hex = Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join('');
|
|
24
|
-
const token = `rt_${hex}`;
|
|
21
|
+
const token = `rt_${Date.now()}_${Math.random().toString(36).substring(2, 18)}`;
|
|
25
22
|
const now = Date.now();
|
|
26
23
|
this.tokens.set(token, {
|
|
27
24
|
agentDid,
|
|
@@ -72,70 +69,36 @@ export class MemoryResumeTokenStore {
|
|
|
72
69
|
* @param agentDid - The agent's DID to verify
|
|
73
70
|
* @param scopes - Required scopes for the operation
|
|
74
71
|
* @param config - Authorization configuration including verifier, token store, etc.
|
|
72
|
+
* @param _resumeToken - Optional resume token from previous authorization attempt
|
|
75
73
|
* @returns Result indicating authorization status, delegation, or auth hints
|
|
76
74
|
*/
|
|
77
|
-
export async function verifyOrHints(agentDid, scopes, config) {
|
|
75
|
+
export async function verifyOrHints(agentDid, scopes, config, _resumeToken) {
|
|
78
76
|
const startTime = Date.now();
|
|
79
77
|
if (config.debug) {
|
|
80
78
|
logger.debug(`[AuthHandshake] Verifying ${agentDid} for scopes: ${scopes.join(', ')}`);
|
|
81
79
|
}
|
|
82
80
|
let reputation;
|
|
83
81
|
if (config.reputationService && config.authorization.minReputationScore !== undefined) {
|
|
84
|
-
const unknownPolicy = config.authorization.unknownAgentPolicy ?? 'require-consent';
|
|
85
82
|
try {
|
|
86
83
|
reputation = await fetchAgentReputation(agentDid, config.reputationService);
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
logger.error('[AuthHandshake] Reputation service unreachable, treating agent as unknown:', error);
|
|
90
|
-
reputation = {
|
|
91
|
-
agentDid,
|
|
92
|
-
score: null,
|
|
93
|
-
totalInteractions: 0,
|
|
94
|
-
successRate: 0,
|
|
95
|
-
riskLevel: 'unknown',
|
|
96
|
-
updatedAt: Date.now(),
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
if (config.debug) {
|
|
100
|
-
logger.debug(`[AuthHandshake] Reputation score: ${reputation.score}`);
|
|
101
|
-
}
|
|
102
|
-
// Unknown agent (no reputation data)
|
|
103
|
-
if (reputation.score === null) {
|
|
104
|
-
if (unknownPolicy === 'deny') {
|
|
105
|
-
const authError = await buildNeedsAuthorizationError(agentDid, scopes, config, 'Unknown agent denied by policy');
|
|
106
|
-
return {
|
|
107
|
-
authorized: false,
|
|
108
|
-
authError,
|
|
109
|
-
reputation,
|
|
110
|
-
reason: 'Unknown agent — policy: deny',
|
|
111
|
-
};
|
|
84
|
+
if (config.debug) {
|
|
85
|
+
logger.debug(`[AuthHandshake] Reputation score: ${reputation.score}`);
|
|
112
86
|
}
|
|
113
|
-
if (
|
|
114
|
-
|
|
87
|
+
if (reputation.score < config.authorization.minReputationScore) {
|
|
88
|
+
if (config.debug) {
|
|
89
|
+
logger.debug(`[AuthHandshake] Reputation ${reputation.score} < ${config.authorization.minReputationScore}, requiring authorization`);
|
|
90
|
+
}
|
|
91
|
+
const authError = await buildNeedsAuthorizationError(agentDid, scopes, config, 'Agent reputation score below threshold');
|
|
115
92
|
return {
|
|
116
93
|
authorized: false,
|
|
117
94
|
authError,
|
|
118
95
|
reputation,
|
|
119
|
-
reason: '
|
|
96
|
+
reason: 'Low reputation score',
|
|
120
97
|
};
|
|
121
98
|
}
|
|
122
|
-
// unknownPolicy === 'allow' — skip reputation gate, continue to delegation check
|
|
123
|
-
if (config.debug) {
|
|
124
|
-
logger.debug('[AuthHandshake] Unknown agent allowed by policy, skipping reputation gate');
|
|
125
|
-
}
|
|
126
99
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
if (config.debug) {
|
|
130
|
-
logger.debug(`[AuthHandshake] Reputation ${reputation.score} < ${config.authorization.minReputationScore}, requiring authorization`);
|
|
131
|
-
}
|
|
132
|
-
const authError = await buildNeedsAuthorizationError(agentDid, scopes, config, 'Agent reputation score below threshold');
|
|
133
|
-
return {
|
|
134
|
-
authorized: false,
|
|
135
|
-
authError,
|
|
136
|
-
reputation,
|
|
137
|
-
reason: 'Low reputation score',
|
|
138
|
-
};
|
|
100
|
+
catch (error) {
|
|
101
|
+
logger.warn('[AuthHandshake] Failed to check reputation:', error);
|
|
139
102
|
}
|
|
140
103
|
}
|
|
141
104
|
let delegationResult;
|
|
@@ -199,7 +162,7 @@ async function fetchAgentReputation(agentDid, reputationConfig) {
|
|
|
199
162
|
if (response.status === 404) {
|
|
200
163
|
return {
|
|
201
164
|
agentDid,
|
|
202
|
-
score:
|
|
165
|
+
score: 50,
|
|
203
166
|
totalInteractions: 0,
|
|
204
167
|
successRate: 0,
|
|
205
168
|
riskLevel: 'unknown',
|
|
@@ -209,7 +172,7 @@ async function fetchAgentReputation(agentDid, reputationConfig) {
|
|
|
209
172
|
throw new Error(`Reputation API error: ${response.status} ${response.statusText}`);
|
|
210
173
|
}
|
|
211
174
|
const data = (await response.json());
|
|
212
|
-
const score = data['score'] ??
|
|
175
|
+
const score = data['score'] ?? 50;
|
|
213
176
|
const levelRaw = (data['level'] ??
|
|
214
177
|
data['riskLevel'] ??
|
|
215
178
|
'unknown').toLowerCase();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handshake.js","sourceRoot":"","sources":["../../src/auth/handshake.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAMH,OAAO,EAAE,6BAA6B,EAAE,MAAM,sBAAsB,CAAC;AAErE,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"handshake.js","sourceRoot":"","s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AAE,CAAC,MAAM,EAAE,IAAI,CAAC;QACpB,iBAAiB,EAAE,QAAQ;QAC3B,KAAK,EAAE,oDAAoD,kBAAkB,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,EAAE;KACpG,CAAC;IAEF,OAAO,6BAA6B,CAAC;QACnC,OAAO;QACP,gBAAgB,EAAE,OAAO,CAAC,QAAQ,EAAE;QACpC,WAAW;QACX,SAAS;QACT,MAAM;QACN,OAAO;KACR,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,MAAgB;IACjD,MAAM,iBAAiB,GAAG;QACxB,OAAO;QACP,QAAQ;QACR,OAAO;QACP,SAAS;QACT,UAAU;QACV,SAAS;QACT,QAAQ;KACT,CAAC;IAEF,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAC3B,iBAAiB,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAC3E,CAAC;AACJ,CAAC"}
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { verifyOrHints, hasSensitiveScopes, MemoryResumeTokenStore, type AuthHandshakeConfig, type VerifyOrHintsResult, type AgentReputation, type ResumeTokenStore,
|
|
1
|
+
export { verifyOrHints, hasSensitiveScopes, MemoryResumeTokenStore, type AuthHandshakeConfig, type VerifyOrHintsResult, type AgentReputation, type ResumeTokenStore, } from './handshake.js';
|
|
2
2
|
export type { DelegationVerifier, VerifyDelegationResult } from './types.js';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/auth/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,sBAAsB,EACtB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,KAAK,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,sBAAsB,EACtB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,KAAK,gBAAgB,GACtB,MAAM,gBAAgB,CAAC;AAExB,YAAY,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/auth/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,sBAAsB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,sBAAsB,GAKvB,MAAM,gBAAgB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"did-key-resolver.d.ts","sourceRoot":"","sources":["../../src/delegation/did-key-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;
|
|
1
|
+
{"version":3,"file":"did-key-resolver.d.ts","sourceRoot":"","sources":["../../src/delegation/did-key-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAsB,MAAM,kBAAkB,CAAC;AASrF;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,CA8BzE;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,cAAc,EAAE,UAAU,GAAG;IAC1D,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,CAAC,EAAE,MAAM,CAAC;CACX,CAMA;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,IAAI,WAAW,CAsClD;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CA2BjE"}
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
* @see https://w3c-ccg.github.io/did-method-key/
|
|
15
15
|
*/
|
|
16
16
|
import { base58Decode } from '../utils/base58.js';
|
|
17
|
-
import { didKeyFragment } from '../utils/did-helpers.js';
|
|
18
17
|
import { base64urlEncodeFromBytes } from '../utils/base64.js';
|
|
19
18
|
import { logger } from '../logging/index.js';
|
|
20
19
|
/** Ed25519 multicodec prefix (0xed 0x01) */
|
|
@@ -103,9 +102,8 @@ export function createDidKeyResolver() {
|
|
|
103
102
|
// Get the multibase-encoded key for publicKeyMultibase
|
|
104
103
|
const multibaseKey = did.replace('did:key:', '');
|
|
105
104
|
// Construct the verification method
|
|
106
|
-
const fragment = didKeyFragment(did);
|
|
107
105
|
const verificationMethod = {
|
|
108
|
-
id: `${did}
|
|
106
|
+
id: `${did}#keys-1`,
|
|
109
107
|
type: 'Ed25519VerificationKey2020',
|
|
110
108
|
controller: did,
|
|
111
109
|
publicKeyJwk,
|
|
@@ -115,8 +113,8 @@ export function createDidKeyResolver() {
|
|
|
115
113
|
return {
|
|
116
114
|
id: did,
|
|
117
115
|
verificationMethod: [verificationMethod],
|
|
118
|
-
authentication: [`${did}
|
|
119
|
-
assertionMethod: [`${did}
|
|
116
|
+
authentication: [`${did}#keys-1`],
|
|
117
|
+
assertionMethod: [`${did}#keys-1`],
|
|
120
118
|
};
|
|
121
119
|
},
|
|
122
120
|
};
|
|
@@ -139,9 +137,8 @@ export function resolveDidKeySync(did) {
|
|
|
139
137
|
}
|
|
140
138
|
const publicKeyJwk = publicKeyToJwk(publicKeyBytes);
|
|
141
139
|
const multibaseKey = did.replace('did:key:', '');
|
|
142
|
-
const fragment = didKeyFragment(did);
|
|
143
140
|
const verificationMethod = {
|
|
144
|
-
id: `${did}
|
|
141
|
+
id: `${did}#keys-1`,
|
|
145
142
|
type: 'Ed25519VerificationKey2020',
|
|
146
143
|
controller: did,
|
|
147
144
|
publicKeyJwk,
|
|
@@ -150,8 +147,8 @@ export function resolveDidKeySync(did) {
|
|
|
150
147
|
return {
|
|
151
148
|
id: did,
|
|
152
149
|
verificationMethod: [verificationMethod],
|
|
153
|
-
authentication: [`${did}
|
|
154
|
-
assertionMethod: [`${did}
|
|
150
|
+
authentication: [`${did}#keys-1`],
|
|
151
|
+
assertionMethod: [`${did}#keys-1`],
|
|
155
152
|
};
|
|
156
153
|
}
|
|
157
154
|
//# sourceMappingURL=did-key-resolver.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"did-key-resolver.js","sourceRoot":"","sources":["../../src/delegation/did-key-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"did-key-resolver.js","sourceRoot":"","sources":["../../src/delegation/did-key-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAE9D,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,4CAA4C;AAC5C,MAAM,yBAAyB,GAAG,IAAI,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAE/D,gCAAgC;AAChC,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAErC;;;;;;;;;GASG;AACH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G,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAEjD,MAAM,kBAAkB,GAAuB;QAC7C,EAAE,EAAE,GAAG,GAAG,SAAS;QACnB,IAAI,EAAE,4BAA4B;QAClC,UAAU,EAAE,GAAG;QACf,YAAY;QACZ,kBAAkB,EAAE,YAAY;KACjC,CAAC;IAEF,OAAO;QACL,EAAE,EAAE,GAAG;QACP,kBAAkB,EAAE,CAAC,kBAAkB,CAAC;QACxC,cAAc,EAAE,CAAC,GAAG,GAAG,SAAS,CAAC;QACjC,eAAe,EAAE,CAAC,GAAG,GAAG,SAAS,CAAC;KACnC,CAAC;AACJ,CAAC"}
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* Related Spec: MCP-I §7 — Outbound Delegation Propagation
|
|
14
14
|
*/
|
|
15
15
|
import type { SessionContext, DelegationRecord } from '../types/protocol.js';
|
|
16
|
+
import type { CryptoProvider } from '../providers/base.js';
|
|
16
17
|
/**
|
|
17
18
|
* Header names for outbound delegation propagation
|
|
18
19
|
*/
|
|
@@ -56,6 +57,7 @@ export interface OutboundDelegationHeaders {
|
|
|
56
57
|
* downstream service can independently verify the delegation chain.
|
|
57
58
|
*
|
|
58
59
|
* @param context - The delegation context including session, delegation, and server identity
|
|
60
|
+
* @param _cryptoProvider - CryptoProvider (reserved for future use)
|
|
59
61
|
* @returns Headers object to attach to the outbound request
|
|
60
62
|
*
|
|
61
63
|
* @throws {Error} If session is missing agentDid or sessionId
|
|
@@ -69,11 +71,11 @@ export interface OutboundDelegationHeaders {
|
|
|
69
71
|
* delegation,
|
|
70
72
|
* serverIdentity: { did: serverDid, kid: serverKid, privateKey },
|
|
71
73
|
* targetUrl: 'https://downstream-api.example.com/resource',
|
|
72
|
-
* });
|
|
74
|
+
* }, cryptoProvider);
|
|
73
75
|
*
|
|
74
76
|
* // Attach headers to your HTTP request
|
|
75
77
|
* fetch(targetUrl, { headers });
|
|
76
78
|
* ```
|
|
77
79
|
*/
|
|
78
|
-
export declare function buildOutboundDelegationHeaders(context: OutboundDelegationContext): Promise<OutboundDelegationHeaders>;
|
|
80
|
+
export declare function buildOutboundDelegationHeaders(context: OutboundDelegationContext, _cryptoProvider: CryptoProvider): Promise<OutboundDelegationHeaders>;
|
|
79
81
|
//# sourceMappingURL=outbound-headers.d.ts.map
|