javascript-solid-server 0.0.200 → 0.0.202
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/MAINTAINERS.md +29 -0
- package/README.md +4 -0
- package/bin/jss.js +8 -2
- package/docs/mcp.md +110 -3
- package/package.json +1 -1
- package/src/mcp/index.js +81 -2
- package/src/mcp/tools.js +386 -1
- package/src/server.js +7 -4
- package/src/tunnel/index.js +8 -0
- package/test/mcp.test.js +291 -0
- package/test/nostr-cid-vm.test.js +6 -3
- package/.claude/scheduled_tasks.lock +0 -1
- package/.claude/settings.local.json +0 -420
package/test/mcp.test.js
CHANGED
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
getBaseUrl,
|
|
20
20
|
getPodToken
|
|
21
21
|
} from './helpers.js';
|
|
22
|
+
import { emitChange } from '../src/notifications/events.js';
|
|
22
23
|
|
|
23
24
|
let token;
|
|
24
25
|
|
|
@@ -237,6 +238,296 @@ describe('MCP server (--mcp enabled)', () => {
|
|
|
237
238
|
assert.strictEqual(body.error?.code, -32601);
|
|
238
239
|
});
|
|
239
240
|
|
|
241
|
+
// --- read_acl / write_acl (#496) ---
|
|
242
|
+
|
|
243
|
+
it('read_acl returns existing authorizations for /mcptest/public/', async () => {
|
|
244
|
+
const { body } = await rpc({
|
|
245
|
+
jsonrpc: '2.0', id: 200, method: 'tools/call',
|
|
246
|
+
params: { name: 'read_acl', arguments: { path: '/mcptest/public/' } }
|
|
247
|
+
}, { token });
|
|
248
|
+
assert.strictEqual(body.result.isError, false, body.result.content?.[0]?.text);
|
|
249
|
+
const payload = JSON.parse(body.result.content[0].text);
|
|
250
|
+
assert.strictEqual(payload.exists, true);
|
|
251
|
+
assert.ok(Array.isArray(payload.authorizations));
|
|
252
|
+
assert.ok(payload.authorizations.length > 0, 'should have at least owner auth');
|
|
253
|
+
// Owner auth should include Read, Write, Control
|
|
254
|
+
const ownerAuth = payload.authorizations.find(a => a.modes.includes('Control'));
|
|
255
|
+
assert.ok(ownerAuth, 'owner auth with Control should exist');
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it('write_acl + read_acl round-trip', async () => {
|
|
259
|
+
const auths = [
|
|
260
|
+
{
|
|
261
|
+
agents: ['/mcptest/profile/card.jsonld#me'],
|
|
262
|
+
modes: ['Read', 'Write', 'Control'],
|
|
263
|
+
isDefault: true
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
agentClasses: ['acl:AuthenticatedAgent'],
|
|
267
|
+
modes: ['Read', 'Append'],
|
|
268
|
+
isDefault: true
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
agentClasses: ['foaf:Agent'],
|
|
272
|
+
modes: ['Read'],
|
|
273
|
+
isDefault: true
|
|
274
|
+
}
|
|
275
|
+
];
|
|
276
|
+
const wr = await rpc({
|
|
277
|
+
jsonrpc: '2.0', id: 201, method: 'tools/call',
|
|
278
|
+
params: { name: 'write_acl', arguments: { path: '/mcptest/public/', authorizations: auths } }
|
|
279
|
+
}, { token });
|
|
280
|
+
assert.strictEqual(wr.body.result.isError, false, wr.body.result.content?.[0]?.text);
|
|
281
|
+
|
|
282
|
+
const rd = await rpc({
|
|
283
|
+
jsonrpc: '2.0', id: 202, method: 'tools/call',
|
|
284
|
+
params: { name: 'read_acl', arguments: { path: '/mcptest/public/' } }
|
|
285
|
+
}, { token });
|
|
286
|
+
const payload = JSON.parse(rd.body.result.content[0].text);
|
|
287
|
+
assert.strictEqual(payload.authorizations.length, 3);
|
|
288
|
+
const classes = payload.authorizations.flatMap(a => a.agentClasses || []);
|
|
289
|
+
assert.ok(classes.includes('acl:AuthenticatedAgent'));
|
|
290
|
+
assert.ok(classes.includes('foaf:Agent'));
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it('write_acl refuses to lock caller out (safety)', async () => {
|
|
294
|
+
// Try to write an ACL that grants Control only to a foreign WebID
|
|
295
|
+
// — would lock the caller (mcptest owner) out. Safety should refuse.
|
|
296
|
+
const { body } = await rpc({
|
|
297
|
+
jsonrpc: '2.0', id: 204, method: 'tools/call',
|
|
298
|
+
params: { name: 'write_acl', arguments: {
|
|
299
|
+
path: '/mcptest/public/',
|
|
300
|
+
authorizations: [
|
|
301
|
+
{
|
|
302
|
+
agents: ['https://stranger.example/profile#me'],
|
|
303
|
+
modes: ['Read', 'Write', 'Control'],
|
|
304
|
+
isDefault: true
|
|
305
|
+
}
|
|
306
|
+
]
|
|
307
|
+
} }
|
|
308
|
+
}, { token });
|
|
309
|
+
assert.ok(body.result.isError);
|
|
310
|
+
assert.match(body.result.content[0].text, /lock the caller out|would not grant Control/i);
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
it('write_acl denied without Control', async () => {
|
|
314
|
+
const { body } = await rpc({
|
|
315
|
+
jsonrpc: '2.0', id: 203, method: 'tools/call',
|
|
316
|
+
params: { name: 'write_acl', arguments: {
|
|
317
|
+
path: '/mcptest/public/',
|
|
318
|
+
authorizations: [{ agentClasses: ['foaf:Agent'], modes: ['Read'] }]
|
|
319
|
+
} }
|
|
320
|
+
}); // no token
|
|
321
|
+
assert.ok(body.result.isError);
|
|
322
|
+
assert.match(body.result.content[0].text, /control/i);
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
// --- call_remote_pod (#495) ---
|
|
326
|
+
|
|
327
|
+
it('call_remote_pod denied without federation gate access', async () => {
|
|
328
|
+
const { body } = await rpc({
|
|
329
|
+
jsonrpc: '2.0', id: 210, method: 'tools/call',
|
|
330
|
+
params: {
|
|
331
|
+
name: 'call_remote_pod',
|
|
332
|
+
arguments: {
|
|
333
|
+
pod_url: 'http://example.invalid',
|
|
334
|
+
tool: 'pod_info',
|
|
335
|
+
arguments: {}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}); // no token
|
|
339
|
+
assert.ok(body.result.isError);
|
|
340
|
+
// Anonymous → "local WebID identity" error; authenticated-but-not-gated → "federation gate"
|
|
341
|
+
assert.match(body.result.content[0].text, /federation/i);
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
it('call_remote_pod hits its own /mcp when gated open', async () => {
|
|
345
|
+
// Federation gate lives at <agent-pod>/private/federation/. For the
|
|
346
|
+
// mcptest pod owner that's /mcptest/private/federation/. Create the
|
|
347
|
+
// container, then grant AuthenticatedAgent Write there.
|
|
348
|
+
await rpc({
|
|
349
|
+
jsonrpc: '2.0', id: 220, method: 'tools/call',
|
|
350
|
+
params: {
|
|
351
|
+
name: 'create_resource',
|
|
352
|
+
arguments: { container: '/mcptest/private/', slug: 'federation', isContainer: true }
|
|
353
|
+
}
|
|
354
|
+
}, { token });
|
|
355
|
+
await rpc({
|
|
356
|
+
jsonrpc: '2.0', id: 221, method: 'tools/call',
|
|
357
|
+
params: {
|
|
358
|
+
name: 'write_acl',
|
|
359
|
+
arguments: {
|
|
360
|
+
path: '/mcptest/private/federation/',
|
|
361
|
+
authorizations: [
|
|
362
|
+
{
|
|
363
|
+
agents: ['/mcptest/profile/card.jsonld#me'],
|
|
364
|
+
modes: ['Read', 'Write', 'Control'],
|
|
365
|
+
isDefault: true
|
|
366
|
+
}
|
|
367
|
+
]
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}, { token });
|
|
371
|
+
|
|
372
|
+
// Now call our own MCP back at /mcp invoking pod_info
|
|
373
|
+
const base = getBaseUrl();
|
|
374
|
+
const { body } = await rpc({
|
|
375
|
+
jsonrpc: '2.0', id: 222, method: 'tools/call',
|
|
376
|
+
params: {
|
|
377
|
+
name: 'call_remote_pod',
|
|
378
|
+
arguments: {
|
|
379
|
+
pod_url: base,
|
|
380
|
+
tool: 'pod_info',
|
|
381
|
+
arguments: {}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}, { token });
|
|
385
|
+
assert.strictEqual(body.result.isError, false, body.result.content?.[0]?.text);
|
|
386
|
+
const payload = JSON.parse(body.result.content[0].text);
|
|
387
|
+
assert.strictEqual(payload.depth, 1);
|
|
388
|
+
assert.ok(payload.remote_result);
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
it('call_remote_pod enforces depth cap', async () => {
|
|
392
|
+
// Force an inbound MCP-Federation-Depth header so the next hop trips MAX
|
|
393
|
+
const res = await request('/mcp', {
|
|
394
|
+
method: 'POST',
|
|
395
|
+
headers: {
|
|
396
|
+
'Content-Type': 'application/json',
|
|
397
|
+
'Authorization': `Bearer ${token}`,
|
|
398
|
+
'MCP-Federation-Depth': '3' // already at max → next hop would be 4
|
|
399
|
+
},
|
|
400
|
+
body: JSON.stringify({
|
|
401
|
+
jsonrpc: '2.0', id: 230, method: 'tools/call',
|
|
402
|
+
params: {
|
|
403
|
+
name: 'call_remote_pod',
|
|
404
|
+
arguments: {
|
|
405
|
+
pod_url: getBaseUrl(),
|
|
406
|
+
tool: 'pod_info',
|
|
407
|
+
arguments: {}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
})
|
|
411
|
+
});
|
|
412
|
+
const data = await res.json();
|
|
413
|
+
assert.ok(data.result.isError);
|
|
414
|
+
assert.match(data.result.content[0].text, /depth exceeded/);
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
// --- subscribe (#494) ---
|
|
418
|
+
|
|
419
|
+
it('subscribe streams SSE events on resourceEvents change', async () => {
|
|
420
|
+
// Open the SSE stream
|
|
421
|
+
const res = await fetch(`${getBaseUrl()}/mcp`, {
|
|
422
|
+
method: 'POST',
|
|
423
|
+
headers: {
|
|
424
|
+
'Content-Type': 'application/json',
|
|
425
|
+
'Authorization': `Bearer ${token}`
|
|
426
|
+
},
|
|
427
|
+
body: JSON.stringify({
|
|
428
|
+
jsonrpc: '2.0', id: 300, method: 'tools/call',
|
|
429
|
+
params: { name: 'subscribe', arguments: { path: '/mcptest/public/' } }
|
|
430
|
+
})
|
|
431
|
+
});
|
|
432
|
+
assert.strictEqual(res.status, 200);
|
|
433
|
+
assert.match(res.headers.get('content-type') || '', /text\/event-stream/);
|
|
434
|
+
|
|
435
|
+
// Read the initial "subscribed" event then trigger a change
|
|
436
|
+
const reader = res.body.getReader();
|
|
437
|
+
const decoder = new TextDecoder();
|
|
438
|
+
let buffer = '';
|
|
439
|
+
let events = [];
|
|
440
|
+
|
|
441
|
+
async function readUntil(predicate, timeoutMs = 3000) {
|
|
442
|
+
const deadline = Date.now() + timeoutMs;
|
|
443
|
+
while (Date.now() < deadline) {
|
|
444
|
+
const { value, done } = await Promise.race([
|
|
445
|
+
reader.read(),
|
|
446
|
+
new Promise(r => setTimeout(() => r({ value: null, done: false }), 200))
|
|
447
|
+
]);
|
|
448
|
+
if (done) break;
|
|
449
|
+
if (value) {
|
|
450
|
+
buffer += decoder.decode(value, { stream: true });
|
|
451
|
+
// Parse complete SSE events (terminated by \n\n)
|
|
452
|
+
let idx;
|
|
453
|
+
while ((idx = buffer.indexOf('\n\n')) !== -1) {
|
|
454
|
+
const chunk = buffer.slice(0, idx);
|
|
455
|
+
buffer = buffer.slice(idx + 2);
|
|
456
|
+
const dataLine = chunk.split('\n').find(l => l.startsWith('data: '));
|
|
457
|
+
if (dataLine) {
|
|
458
|
+
events.push(JSON.parse(dataLine.slice(6)));
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
if (predicate(events)) return;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
await readUntil(e => e.length >= 1); // wait for "subscribed" event
|
|
467
|
+
assert.ok(events.length >= 1);
|
|
468
|
+
assert.strictEqual(events[0].method, 'notifications/tool_event');
|
|
469
|
+
assert.strictEqual(events[0].params.event.type, 'subscribed');
|
|
470
|
+
|
|
471
|
+
// Trigger a change inside scope
|
|
472
|
+
emitChange(`${getBaseUrl()}/mcptest/public/triggered.txt`);
|
|
473
|
+
|
|
474
|
+
await readUntil(e => e.some(ev => ev.params?.event?.type === 'resource_changed'), 3000);
|
|
475
|
+
const change = events.find(ev => ev.params?.event?.type === 'resource_changed');
|
|
476
|
+
assert.ok(change, `expected resource_changed event; got ${JSON.stringify(events)}`);
|
|
477
|
+
assert.strictEqual(change.params.event.path, '/mcptest/public/triggered.txt');
|
|
478
|
+
|
|
479
|
+
// Clean up: cancel stream
|
|
480
|
+
await reader.cancel();
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
it('subscribe filters by scope', async () => {
|
|
484
|
+
const res = await fetch(`${getBaseUrl()}/mcp`, {
|
|
485
|
+
method: 'POST',
|
|
486
|
+
headers: {
|
|
487
|
+
'Content-Type': 'application/json',
|
|
488
|
+
'Authorization': `Bearer ${token}`
|
|
489
|
+
},
|
|
490
|
+
body: JSON.stringify({
|
|
491
|
+
jsonrpc: '2.0', id: 301, method: 'tools/call',
|
|
492
|
+
params: { name: 'subscribe', arguments: { path: '/mcptest/public/' } }
|
|
493
|
+
})
|
|
494
|
+
});
|
|
495
|
+
const reader = res.body.getReader();
|
|
496
|
+
const decoder = new TextDecoder();
|
|
497
|
+
let buffer = '';
|
|
498
|
+
let events = [];
|
|
499
|
+
|
|
500
|
+
async function read(ms = 800) {
|
|
501
|
+
const deadline = Date.now() + ms;
|
|
502
|
+
while (Date.now() < deadline) {
|
|
503
|
+
const { value, done } = await Promise.race([
|
|
504
|
+
reader.read(),
|
|
505
|
+
new Promise(r => setTimeout(() => r({ value: null, done: false }), 100))
|
|
506
|
+
]);
|
|
507
|
+
if (done) break;
|
|
508
|
+
if (value) {
|
|
509
|
+
buffer += decoder.decode(value, { stream: true });
|
|
510
|
+
let idx;
|
|
511
|
+
while ((idx = buffer.indexOf('\n\n')) !== -1) {
|
|
512
|
+
const chunk = buffer.slice(0, idx);
|
|
513
|
+
buffer = buffer.slice(idx + 2);
|
|
514
|
+
const dataLine = chunk.split('\n').find(l => l.startsWith('data: '));
|
|
515
|
+
if (dataLine) events.push(JSON.parse(dataLine.slice(6)));
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
await read(500); // pick up "subscribed"
|
|
522
|
+
// Out-of-scope change — should NOT trigger an event
|
|
523
|
+
emitChange(`${getBaseUrl()}/mcptest/private/notes/x.txt`);
|
|
524
|
+
await read(500);
|
|
525
|
+
const changes = events.filter(e => e.params?.event?.type === 'resource_changed');
|
|
526
|
+
assert.strictEqual(changes.length, 0, 'out-of-scope change should not emit');
|
|
527
|
+
|
|
528
|
+
await reader.cancel();
|
|
529
|
+
});
|
|
530
|
+
|
|
240
531
|
it('rejects unknown tool', async () => {
|
|
241
532
|
const { body } = await rpc({
|
|
242
533
|
jsonrpc: '2.0', id: 100, method: 'tools/call',
|
|
@@ -210,9 +210,12 @@ describe('NIP-98 + CID verificationMethod lookup (#399)', () => {
|
|
|
210
210
|
|
|
211
211
|
it('rejects a JWK with the right x but wrong y (curve-point integrity)', async () => {
|
|
212
212
|
const goodJwk = evenYJwk(pk);
|
|
213
|
-
//
|
|
214
|
-
//
|
|
215
|
-
|
|
213
|
+
// Force y = 0 (43 'A's = 32 zero bytes). (x, 0) is on secp256k1
|
|
214
|
+
// iff x³ ≡ -7 mod p, which has exactly 3 solutions in ~2²⁵⁶ — so
|
|
215
|
+
// for any practical x this is provably off-curve. Avoids the flake
|
|
216
|
+
// where a single-char flip in y was either a base64url padding-bit
|
|
217
|
+
// no-op or, far more rarely, landed on the negation -y mod p.
|
|
218
|
+
const badJwk = { ...goodJwk, y: 'A'.repeat(43) };
|
|
216
219
|
nextProfile = buildProfile({ pubkey: pk, jwk: badJwk });
|
|
217
220
|
const url = `https://${POD_HOST}/private/data.ttl`;
|
|
218
221
|
const { authHeader } = nip98Authorization({ method: 'GET', url, secretKey: sk });
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"sessionId":"a05da419-92b7-4056-93b8-e97b2035d4ae","pid":3932382,"procStart":"114094236","acquiredAt":1778317500161}
|