agent-envelope-mcp 1.1.0 → 1.1.1
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 +7 -1
- package/package.json +15 -13
- package/server.json +15 -8
- package/src/server.js +74 -30
- package/tests/server.test.js +61 -0
package/README.md
CHANGED
|
@@ -41,6 +41,10 @@ No API key is needed to start the server or to use sovereign signature/record
|
|
|
41
41
|
verification. Hosted-governance tools require `AE_API_KEY` or, in HTTP mode, an
|
|
42
42
|
`Authorization: Bearer <portal-api-key>` header.
|
|
43
43
|
|
|
44
|
+
For verification-only deployments, set `AE_TOOLS=readonly`. In that mode the
|
|
45
|
+
server does not register `ae_mint`, so MCP clients can only call sovereign
|
|
46
|
+
verification and hosted read/query tools.
|
|
47
|
+
|
|
44
48
|
## Tools
|
|
45
49
|
|
|
46
50
|
| Tool | Mode | Credential | Notes |
|
|
@@ -52,7 +56,7 @@ verification. Hosted-governance tools require `AE_API_KEY` or, in HTTP mode, an
|
|
|
52
56
|
| `ae_authorize_action` | Hosted governance | `AE_API_KEY` or bearer | Normalizes hosted verification into an `allowed`/`denied` decision |
|
|
53
57
|
| `ae_get_delegate` | Hosted governance | `AE_API_KEY` or bearer | Fetches one active hosted delegate |
|
|
54
58
|
| `ae_check_legitimacy` | Hosted governance | `AE_API_KEY` or bearer | Normalizes legitimacy state into a decision |
|
|
55
|
-
| `ae_mint` | Hosted governance | `AE_API_KEY` or bearer | Governed mint request; returns receipt, not private material |
|
|
59
|
+
| `ae_mint` | Hosted governance | `AE_API_KEY` or bearer | Governed mint request; returns receipt, not private material. Omitted when `AE_TOOLS=readonly` |
|
|
56
60
|
|
|
57
61
|
Most tools return both readable MCP `content` and machine-readable
|
|
58
62
|
`structuredContent`.
|
|
@@ -239,6 +243,8 @@ await startHttp({ port: 8787, host: "127.0.0.1", path: "/mcp" });
|
|
|
239
243
|
|---|---|---|
|
|
240
244
|
| `AE_API_KEY` | Hosted tools | Portal-issued API key for hosted governance |
|
|
241
245
|
| `AE_API_BASE_URL` | Hosted tools | Optional override for the AgentEnvelope hosted API |
|
|
246
|
+
| `AE_TOOLS` | Tool exposure | Set to `readonly` to omit `ae_mint` |
|
|
247
|
+
| `AE_MCP_SESSION_IDLE_MS` | HTTP mode | Optional idle timeout for Streamable HTTP sessions; defaults to 30 minutes |
|
|
242
248
|
| `PORT` | HTTP mode | Default HTTP port when `--port` is omitted |
|
|
243
249
|
| `HOST` | HTTP mode | Default HTTP bind host when `--host` is omitted |
|
|
244
250
|
| `MCP_PATH` | HTTP mode | Default MCP path when `--path` is omitted |
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-envelope-mcp",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"mcpName": "io.github.BlackBoxEngineering/agent-envelope-mcp",
|
|
5
|
-
"description": "MCP adapter for AgentEnvelope: sovereign verification, hosted decisions, delegates, legitimacy, and mint receipts.",
|
|
5
|
+
"description": "MCP adapter for AgentEnvelope: sovereign verification, hosted decisions, delegates, legitimacy, and mint receipts.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
8
8
|
"agent-envelope-mcp": "bin/agent-envelope-mcp.js"
|
|
@@ -10,26 +10,28 @@
|
|
|
10
10
|
"exports": {
|
|
11
11
|
".": "./src/server.js"
|
|
12
12
|
},
|
|
13
|
-
"files": [
|
|
14
|
-
"bin",
|
|
15
|
-
"src",
|
|
16
|
-
"
|
|
17
|
-
"
|
|
13
|
+
"files": [
|
|
14
|
+
"bin",
|
|
15
|
+
"src",
|
|
16
|
+
"tests",
|
|
17
|
+
"server.json",
|
|
18
|
+
"README.md",
|
|
18
19
|
"LICENSE",
|
|
19
20
|
"NOTICE"
|
|
20
21
|
],
|
|
21
22
|
"scripts": {
|
|
23
|
+
"test": "node --test tests/*.test.js",
|
|
22
24
|
"start": "node bin/agent-envelope-mcp.js",
|
|
23
25
|
"start:http": "node bin/agent-envelope-mcp.js --http --port 8787"
|
|
24
26
|
},
|
|
25
27
|
"engines": {
|
|
26
28
|
"node": ">=18"
|
|
27
|
-
},
|
|
28
|
-
"dependencies": {
|
|
29
|
-
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
30
|
-
"agent-envelope-sdk": "^1.4.
|
|
31
|
-
"zod": "^4.4.3"
|
|
32
|
-
},
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
32
|
+
"agent-envelope-sdk": "^1.4.5",
|
|
33
|
+
"zod": "^4.4.3"
|
|
34
|
+
},
|
|
33
35
|
"keywords": [
|
|
34
36
|
"mcp",
|
|
35
37
|
"model-context-protocol",
|
package/server.json
CHANGED
|
@@ -6,24 +6,31 @@
|
|
|
6
6
|
"url": "https://github.com/BlackBoxEngineering/agent-envelope-mcp",
|
|
7
7
|
"source": "github"
|
|
8
8
|
},
|
|
9
|
-
"version": "1.1.
|
|
9
|
+
"version": "1.1.1",
|
|
10
10
|
"packages": [
|
|
11
11
|
{
|
|
12
12
|
"registryType": "npm",
|
|
13
13
|
"identifier": "agent-envelope-mcp",
|
|
14
|
-
"version": "1.1.
|
|
14
|
+
"version": "1.1.1",
|
|
15
15
|
"transport": {
|
|
16
16
|
"type": "stdio"
|
|
17
17
|
},
|
|
18
18
|
"environmentVariables": [
|
|
19
|
-
{
|
|
19
|
+
{
|
|
20
20
|
"name": "AE_API_KEY",
|
|
21
21
|
"description": "Portal-issued API key. Required only for hosted-governance tools (ae_get_agent, ae_verify_action, ae_authorize_action, ae_get_delegate, ae_check_legitimacy, ae_mint). Sovereign signature and record verification need no key.",
|
|
22
|
-
"isRequired": false,
|
|
23
|
-
"isSecret": true,
|
|
24
|
-
"format": "string"
|
|
25
|
-
}
|
|
26
|
-
|
|
22
|
+
"isRequired": false,
|
|
23
|
+
"isSecret": true,
|
|
24
|
+
"format": "string"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"name": "AE_TOOLS",
|
|
28
|
+
"description": "Optional tool exposure mode. Set to readonly to omit ae_mint and expose only verification/query tools.",
|
|
29
|
+
"isRequired": false,
|
|
30
|
+
"isSecret": false,
|
|
31
|
+
"format": "string"
|
|
32
|
+
}
|
|
33
|
+
]
|
|
27
34
|
}
|
|
28
35
|
]
|
|
29
36
|
}
|
package/src/server.js
CHANGED
|
@@ -18,9 +18,14 @@ import { AgentEnvelopeClient } from 'agent-envelope-sdk/client';
|
|
|
18
18
|
import { verifyAction as verifyActionSovereign, verifyRecord as verifyRecordSovereign } from 'agent-envelope-sdk';
|
|
19
19
|
|
|
20
20
|
const HOSTED_BASE_URL = process.env.AE_API_BASE_URL?.trim() || 'https://jemdjwteae.execute-api.us-east-1.amazonaws.com/v1';
|
|
21
|
-
const SERVER_VERSION = '1.1.
|
|
21
|
+
const SERVER_VERSION = '1.1.1';
|
|
22
22
|
const NEEDS_KEY =
|
|
23
23
|
'AE_API_KEY is not set. This is a hosted-governance tool; set the portal-issued API key to use it. Sovereign signature and record verification need no key.';
|
|
24
|
+
const TOOLS_MODE = process.env.AE_TOOLS?.trim().toLowerCase() || 'all';
|
|
25
|
+
const MINT_ENABLED = TOOLS_MODE !== 'readonly' && TOOLS_MODE !== 'read-only';
|
|
26
|
+
const MAX_HOSTED_CLIENTS = 100;
|
|
27
|
+
const HTTP_SESSION_IDLE_MS = Number.parseInt(process.env.AE_MCP_SESSION_IDLE_MS || '', 10) || 30 * 60 * 1000;
|
|
28
|
+
const HTTP_SESSION_SWEEP_MS = Math.min(60 * 1000, Math.max(5 * 1000, Math.floor(HTTP_SESSION_IDLE_MS / 2)));
|
|
24
29
|
|
|
25
30
|
const encoder = new TextEncoder();
|
|
26
31
|
const MAX_SIGNED_MESSAGE_BYTES = 64 * 1024;
|
|
@@ -44,7 +49,17 @@ function getApiKey(extra) {
|
|
|
44
49
|
function governanceClient(extra) {
|
|
45
50
|
const apiKey = getApiKey(extra);
|
|
46
51
|
if (!apiKey) return null;
|
|
47
|
-
if (
|
|
52
|
+
if (hostedClients.has(apiKey)) {
|
|
53
|
+
const client = hostedClients.get(apiKey);
|
|
54
|
+
hostedClients.delete(apiKey);
|
|
55
|
+
hostedClients.set(apiKey, client);
|
|
56
|
+
return client;
|
|
57
|
+
}
|
|
58
|
+
hostedClients.set(apiKey, new AgentEnvelopeClient({ apiKey }));
|
|
59
|
+
if (hostedClients.size > MAX_HOSTED_CLIENTS) {
|
|
60
|
+
const oldestKey = hostedClients.keys().next().value;
|
|
61
|
+
if (oldestKey) hostedClients.delete(oldestKey);
|
|
62
|
+
}
|
|
48
63
|
return hostedClients.get(apiKey);
|
|
49
64
|
}
|
|
50
65
|
|
|
@@ -146,18 +161,20 @@ async function readJsonBody(req) {
|
|
|
146
161
|
return JSON.parse(text);
|
|
147
162
|
}
|
|
148
163
|
|
|
149
|
-
function decisionFromReport(report, input) {
|
|
164
|
+
export function decisionFromReport(report, input) {
|
|
150
165
|
const reportValid = Boolean(report?.valid);
|
|
151
|
-
const
|
|
152
|
-
const
|
|
166
|
+
const hasOperation = typeof report?.envelope?.operation === 'string';
|
|
167
|
+
const hasResources = Array.isArray(report?.envelope?.resources);
|
|
168
|
+
const operationMatches = !input.operation || (hasOperation && report.envelope.operation === input.operation);
|
|
169
|
+
const resourceMatches = !input.resource || (hasResources && resourceAllowed(report.envelope.resources, input.resource));
|
|
153
170
|
const valid = reportValid && operationMatches && resourceMatches;
|
|
154
171
|
const reason = valid
|
|
155
172
|
? 'verified'
|
|
156
173
|
: !reportValid
|
|
157
174
|
? (report?.reason || report?.legitimacyReason || 'verification_failed')
|
|
158
175
|
: !operationMatches
|
|
159
|
-
? 'operation_mismatch'
|
|
160
|
-
: 'resource_mismatch';
|
|
176
|
+
? (hasOperation ? 'operation_mismatch' : 'operation_missing')
|
|
177
|
+
: (hasResources ? 'resource_mismatch' : 'resources_missing');
|
|
161
178
|
return {
|
|
162
179
|
type: 'agentenvelope.authorizationDecision',
|
|
163
180
|
version: 1,
|
|
@@ -411,28 +428,30 @@ export function createServer() {
|
|
|
411
428
|
},
|
|
412
429
|
);
|
|
413
430
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
431
|
+
if (MINT_ENABLED) {
|
|
432
|
+
server.registerTool(
|
|
433
|
+
'ae_mint',
|
|
434
|
+
{
|
|
435
|
+
title: 'Verify mint request (hosted receipt)',
|
|
436
|
+
description:
|
|
437
|
+
'Verify a MintDelegate and signed MintRequest through hosted governance. Returns a mint receipt; it does not return private capability material. Requires a portal-issued API key. This is a governed action.',
|
|
438
|
+
annotations: governedHosted,
|
|
439
|
+
inputSchema: {
|
|
440
|
+
delegate: mintObjectSchema.describe('The signed MintDelegate'),
|
|
441
|
+
request: mintObjectSchema.describe('The bot-signed MintRequest'),
|
|
442
|
+
},
|
|
424
443
|
},
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
|
|
444
|
+
async ({ delegate, request }, extra) => {
|
|
445
|
+
const client = governanceClient(extra);
|
|
446
|
+
if (!client) return fail(NEEDS_KEY);
|
|
447
|
+
try {
|
|
448
|
+
return hostedResult(await client.mint({ delegate, request }), 'mint failed');
|
|
449
|
+
} catch (err) {
|
|
450
|
+
return fail(err instanceof Error ? err.message : 'mint failed', errorBody(err));
|
|
451
|
+
}
|
|
452
|
+
},
|
|
453
|
+
);
|
|
454
|
+
}
|
|
436
455
|
|
|
437
456
|
return server;
|
|
438
457
|
}
|
|
@@ -447,9 +466,27 @@ export async function start() {
|
|
|
447
466
|
/** Build the server and expose it over Streamable HTTP. */
|
|
448
467
|
export async function startHttp({ port = 8787, host = '127.0.0.1', path = '/mcp' } = {}) {
|
|
449
468
|
const transports = new Map();
|
|
469
|
+
const closeSession = (id, entry) => {
|
|
470
|
+
transports.delete(id);
|
|
471
|
+
try {
|
|
472
|
+
const closeResult = entry?.transport?.close?.();
|
|
473
|
+
if (closeResult && typeof closeResult.catch === 'function') closeResult.catch(() => {});
|
|
474
|
+
} catch {
|
|
475
|
+
// Session eviction should never crash the HTTP listener.
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
const sweepIdleSessions = () => {
|
|
479
|
+
const cutoff = Date.now() - HTTP_SESSION_IDLE_MS;
|
|
480
|
+
for (const [id, entry] of transports) {
|
|
481
|
+
if (entry.lastSeen <= cutoff) closeSession(id, entry);
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
const sweepTimer = setInterval(sweepIdleSessions, HTTP_SESSION_SWEEP_MS);
|
|
485
|
+
sweepTimer.unref?.();
|
|
450
486
|
|
|
451
487
|
const httpServer = createHttpServer(async (req, res) => {
|
|
452
488
|
try {
|
|
489
|
+
sweepIdleSessions();
|
|
453
490
|
const url = new URL(req.url || '/', `http://${req.headers.host || `${host}:${port}`}`);
|
|
454
491
|
|
|
455
492
|
if (url.pathname === '/health') {
|
|
@@ -468,7 +505,9 @@ export async function startHttp({ port = 8787, host = '127.0.0.1', path = '/mcp'
|
|
|
468
505
|
const rawSessionId = req.headers['mcp-session-id'];
|
|
469
506
|
const sessionId = Array.isArray(rawSessionId) ? rawSessionId[0] : rawSessionId;
|
|
470
507
|
const body = req.method === 'POST' ? await readJsonBody(req) : undefined;
|
|
471
|
-
|
|
508
|
+
const entry = sessionId ? transports.get(sessionId) : undefined;
|
|
509
|
+
let transport = entry?.transport;
|
|
510
|
+
if (entry) entry.lastSeen = Date.now();
|
|
472
511
|
|
|
473
512
|
if (!transport) {
|
|
474
513
|
if (req.method !== 'POST' || !isInitializeRequest(body)) {
|
|
@@ -483,7 +522,7 @@ export async function startHttp({ port = 8787, host = '127.0.0.1', path = '/mcp'
|
|
|
483
522
|
transport = new StreamableHTTPServerTransport({
|
|
484
523
|
sessionIdGenerator: () => randomUUID(),
|
|
485
524
|
enableJsonResponse: true,
|
|
486
|
-
onsessioninitialized: (id) => transports.set(id, transport),
|
|
525
|
+
onsessioninitialized: (id) => transports.set(id, { transport, lastSeen: Date.now() }),
|
|
487
526
|
});
|
|
488
527
|
|
|
489
528
|
transport.onclose = () => {
|
|
@@ -506,6 +545,11 @@ export async function startHttp({ port = 8787, host = '127.0.0.1', path = '/mcp'
|
|
|
506
545
|
}
|
|
507
546
|
});
|
|
508
547
|
|
|
548
|
+
httpServer.on('close', () => {
|
|
549
|
+
clearInterval(sweepTimer);
|
|
550
|
+
for (const [id, entry] of transports) closeSession(id, entry);
|
|
551
|
+
});
|
|
552
|
+
|
|
509
553
|
await new Promise((resolve, reject) => {
|
|
510
554
|
httpServer.once('error', reject);
|
|
511
555
|
httpServer.listen(port, host, resolve);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { execFileSync } from 'node:child_process';
|
|
3
|
+
import test from 'node:test';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { decisionFromReport } from '../src/server.js';
|
|
6
|
+
|
|
7
|
+
const projectRoot = fileURLToPath(new URL('..', import.meta.url));
|
|
8
|
+
|
|
9
|
+
function spawnedToolNames(env) {
|
|
10
|
+
return execFileSync(
|
|
11
|
+
process.execPath,
|
|
12
|
+
[
|
|
13
|
+
'-e',
|
|
14
|
+
"import('./src/server.js').then(({createServer})=>console.log(Object.keys(createServer()._registeredTools||{}).sort().join(',')))",
|
|
15
|
+
],
|
|
16
|
+
{
|
|
17
|
+
cwd: projectRoot,
|
|
18
|
+
env,
|
|
19
|
+
encoding: 'utf8',
|
|
20
|
+
},
|
|
21
|
+
).trim().split(',').filter(Boolean);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
test('registers mint tool by default', () => {
|
|
25
|
+
const { AE_TOOLS: _aeTools, ...env } = process.env;
|
|
26
|
+
assert.ok(spawnedToolNames(env).includes('ae_mint'));
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('AE_TOOLS=readonly omits mint tool', () => {
|
|
30
|
+
assert.equal(spawnedToolNames({ ...process.env, AE_TOOLS: 'readonly' }).includes('ae_mint'), false);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('decisionFromReport fails closed when operation is requested but absent from report envelope', () => {
|
|
34
|
+
const decision = decisionFromReport(
|
|
35
|
+
{ valid: true, envelope: { resources: ['refund:123'] } },
|
|
36
|
+
{ agentId: 'agent-1', actionIndex: 0, operation: 'refund', resource: 'refund:123' },
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
assert.equal(decision.allowed, false);
|
|
40
|
+
assert.equal(decision.reason, 'operation_missing');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('decisionFromReport fails closed when resource is requested but absent from report envelope', () => {
|
|
44
|
+
const decision = decisionFromReport(
|
|
45
|
+
{ valid: true, envelope: { operation: 'refund' } },
|
|
46
|
+
{ agentId: 'agent-1', actionIndex: 0, operation: 'refund', resource: 'refund:123' },
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
assert.equal(decision.allowed, false);
|
|
50
|
+
assert.equal(decision.reason, 'resources_missing');
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('decisionFromReport allows matching operation and resource', () => {
|
|
54
|
+
const decision = decisionFromReport(
|
|
55
|
+
{ valid: true, envelope: { operation: 'refund', resources: ['refund:*'] } },
|
|
56
|
+
{ agentId: 'agent-1', actionIndex: 0, operation: 'refund', resource: 'refund:123' },
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
assert.equal(decision.allowed, true);
|
|
60
|
+
assert.equal(decision.reason, 'verified');
|
|
61
|
+
});
|