javascript-solid-server 0.0.198 → 0.0.200
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 +4 -1
- package/bin/jss.js +6 -2
- package/docs/app-install.md +193 -0
- package/docs/mcp.md +121 -0
- package/package.json +1 -1
- package/src/cli/install.js +142 -8
- package/src/config.js +5 -0
- package/src/mcp/index.js +133 -0
- package/src/mcp/protocol.js +52 -0
- package/src/mcp/skills.js +138 -0
- package/src/mcp/tools.js +375 -0
- package/src/server.js +11 -0
- package/test/mcp.test.js +271 -0
package/src/server.js
CHANGED
|
@@ -25,6 +25,7 @@ import { createPayHandler, isPayRequest } from './handlers/pay.js';
|
|
|
25
25
|
import { activityPubPlugin, getActorHandler } from './ap/index.js';
|
|
26
26
|
import { remoteStoragePlugin } from './remotestorage.js';
|
|
27
27
|
import { dbPlugin } from './db/index.js';
|
|
28
|
+
import { mcpPlugin } from './mcp/index.js';
|
|
28
29
|
import { webrtcPlugin } from './webrtc/index.js';
|
|
29
30
|
import { tunnelPlugin } from './tunnel/index.js';
|
|
30
31
|
import { terminalPlugin } from './terminal/index.js';
|
|
@@ -139,6 +140,10 @@ export function createServer(options = {}) {
|
|
|
139
140
|
const liveReloadEnabled = options.liveReload ?? false;
|
|
140
141
|
// MongoDB-backed /db/ route is OFF by default
|
|
141
142
|
const mongoEnabled = options.mongo ?? false;
|
|
143
|
+
// MCP (Model Context Protocol) server — exposes the pod as a tool
|
|
144
|
+
// surface for agents (Claude Desktop, Cursor, etc.). OFF by default.
|
|
145
|
+
// See docs/mcp.md and #490.
|
|
146
|
+
const mcpEnabled = options.mcp ?? false;
|
|
142
147
|
// Provision a Schnorr secp256k1 owner key in /private/privkey.jsonld
|
|
143
148
|
// when a single-user pod is first created. Phase 1 of #437. Off by
|
|
144
149
|
// default: keys-on-disk is a real security tradeoff, opt-in keeps
|
|
@@ -394,6 +399,11 @@ export function createServer(options = {}) {
|
|
|
394
399
|
fastify.register(dbPlugin, { mongoUrl, mongoDatabase, singleUser });
|
|
395
400
|
}
|
|
396
401
|
|
|
402
|
+
// Register MCP server if enabled (issue #490)
|
|
403
|
+
if (mcpEnabled) {
|
|
404
|
+
fastify.register(mcpPlugin);
|
|
405
|
+
}
|
|
406
|
+
|
|
397
407
|
// Register rate limiting plugin
|
|
398
408
|
// Protects against brute force attacks and resource exhaustion
|
|
399
409
|
fastify.register(rateLimit, {
|
|
@@ -648,6 +658,7 @@ export function createServer(options = {}) {
|
|
|
648
658
|
request.url.startsWith('/storage/') ||
|
|
649
659
|
(payEnabled && isPayRequest(request.url)) ||
|
|
650
660
|
(mongoEnabled && (request.url === '/db' || request.url.startsWith('/db/'))) ||
|
|
661
|
+
(mcpEnabled && (request.url === '/mcp' || request.url.startsWith('/mcp?'))) ||
|
|
651
662
|
(webrtcEnabled && (request.url === webrtcPath || request.url.startsWith(webrtcPath + '?'))) ||
|
|
652
663
|
(terminalEnabled && (request.url === '/.terminal' || request.url.startsWith('/.terminal?'))) ||
|
|
653
664
|
(tunnelEnabled && (request.url === tunnelPath || request.url.startsWith(tunnelPath + '?') || request.url.startsWith('/tunnel/'))) ||
|
package/test/mcp.test.js
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP (Model Context Protocol) server tests.
|
|
3
|
+
*
|
|
4
|
+
* Covers:
|
|
5
|
+
* - handshake (initialize / tools/list)
|
|
6
|
+
* - CRUD tools (list, read, write, create, delete, head)
|
|
7
|
+
* - skill discovery (list_skills, get_skill, get_pod_skill)
|
|
8
|
+
* - docs (list_docs, read_docs)
|
|
9
|
+
* - WAC enforcement (anonymous denied write, owner allowed)
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { describe, it, before, after } from 'node:test';
|
|
13
|
+
import assert from 'node:assert';
|
|
14
|
+
import {
|
|
15
|
+
startTestServer,
|
|
16
|
+
stopTestServer,
|
|
17
|
+
request,
|
|
18
|
+
createTestPod,
|
|
19
|
+
getBaseUrl,
|
|
20
|
+
getPodToken
|
|
21
|
+
} from './helpers.js';
|
|
22
|
+
|
|
23
|
+
let token;
|
|
24
|
+
|
|
25
|
+
async function rpc(body, opts = {}) {
|
|
26
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
27
|
+
if (opts.token) headers.Authorization = `Bearer ${opts.token}`;
|
|
28
|
+
const res = await request('/mcp', {
|
|
29
|
+
method: 'POST',
|
|
30
|
+
headers,
|
|
31
|
+
body: JSON.stringify(body)
|
|
32
|
+
});
|
|
33
|
+
if (res.status === 204) return { status: 204, body: null };
|
|
34
|
+
const data = await res.json();
|
|
35
|
+
return { status: res.status, body: data };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
describe('MCP server (--mcp enabled)', () => {
|
|
39
|
+
before(async () => {
|
|
40
|
+
await startTestServer({ mcp: true });
|
|
41
|
+
await createTestPod('mcptest');
|
|
42
|
+
token = getPodToken('mcptest');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
after(async () => {
|
|
46
|
+
await stopTestServer();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('responds to initialize with protocol version', async () => {
|
|
50
|
+
const { status, body } = await rpc({
|
|
51
|
+
jsonrpc: '2.0', id: 1, method: 'initialize',
|
|
52
|
+
params: { protocolVersion: '2025-03-26', capabilities: {}, clientInfo: { name: 'test', version: '0' } }
|
|
53
|
+
});
|
|
54
|
+
assert.strictEqual(status, 200);
|
|
55
|
+
assert.strictEqual(body.jsonrpc, '2.0');
|
|
56
|
+
assert.ok(body.result?.protocolVersion);
|
|
57
|
+
assert.strictEqual(body.result.serverInfo.name, 'jss-mcp');
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('lists tools', async () => {
|
|
61
|
+
const { body } = await rpc({ jsonrpc: '2.0', id: 2, method: 'tools/list' });
|
|
62
|
+
const names = body.result.tools.map(t => t.name);
|
|
63
|
+
for (const expected of [
|
|
64
|
+
'list_resources', 'read_resource', 'write_resource',
|
|
65
|
+
'create_resource', 'delete_resource', 'head_resource',
|
|
66
|
+
'list_skills', 'get_skill', 'get_pod_skill',
|
|
67
|
+
'list_docs', 'read_docs', 'pod_info'
|
|
68
|
+
]) {
|
|
69
|
+
assert.ok(names.includes(expected), `missing tool: ${expected}`);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('write_resource denied without auth', async () => {
|
|
74
|
+
const { body } = await rpc({
|
|
75
|
+
jsonrpc: '2.0', id: 3, method: 'tools/call',
|
|
76
|
+
params: { name: 'write_resource', arguments: { path: '/mcptest/public/anon.txt', content: 'nope' } }
|
|
77
|
+
});
|
|
78
|
+
assert.ok(body.result?.isError, 'expected isError for anonymous write');
|
|
79
|
+
assert.match(body.result.content[0].text, /denied/i);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('write_resource works with owner token', async () => {
|
|
83
|
+
const { body } = await rpc({
|
|
84
|
+
jsonrpc: '2.0', id: 4, method: 'tools/call',
|
|
85
|
+
params: {
|
|
86
|
+
name: 'write_resource',
|
|
87
|
+
arguments: { path: '/mcptest/public/hello.txt', content: 'hi', contentType: 'text/plain' }
|
|
88
|
+
}
|
|
89
|
+
}, { token });
|
|
90
|
+
assert.strictEqual(body.result.isError, false, body.result.content?.[0]?.text);
|
|
91
|
+
assert.match(body.result.content[0].text, /wrote/);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('read_resource returns the written content', async () => {
|
|
95
|
+
const { body } = await rpc({
|
|
96
|
+
jsonrpc: '2.0', id: 5, method: 'tools/call',
|
|
97
|
+
params: { name: 'read_resource', arguments: { path: '/mcptest/public/hello.txt' } }
|
|
98
|
+
}, { token });
|
|
99
|
+
assert.strictEqual(body.result.isError, false);
|
|
100
|
+
const payload = JSON.parse(body.result.content[0].text);
|
|
101
|
+
assert.strictEqual(payload.body, 'hi');
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('list_resources lists the container', async () => {
|
|
105
|
+
const { body } = await rpc({
|
|
106
|
+
jsonrpc: '2.0', id: 6, method: 'tools/call',
|
|
107
|
+
params: { name: 'list_resources', arguments: { path: '/mcptest/public/' } }
|
|
108
|
+
}, { token });
|
|
109
|
+
assert.strictEqual(body.result.isError, false);
|
|
110
|
+
const payload = JSON.parse(body.result.content[0].text);
|
|
111
|
+
assert.ok(payload.items.some(i => i.name === 'hello.txt'));
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('create_resource auto-mints filename', async () => {
|
|
115
|
+
const { body } = await rpc({
|
|
116
|
+
jsonrpc: '2.0', id: 7, method: 'tools/call',
|
|
117
|
+
params: {
|
|
118
|
+
name: 'create_resource',
|
|
119
|
+
arguments: { container: '/mcptest/public/', slug: 'minted', content: 'x' }
|
|
120
|
+
}
|
|
121
|
+
}, { token });
|
|
122
|
+
assert.strictEqual(body.result.isError, false);
|
|
123
|
+
assert.match(body.result.content[0].text, /\/mcptest\/public\/minted/);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('delete_resource removes the file', async () => {
|
|
127
|
+
const { body } = await rpc({
|
|
128
|
+
jsonrpc: '2.0', id: 8, method: 'tools/call',
|
|
129
|
+
params: { name: 'delete_resource', arguments: { path: '/mcptest/public/hello.txt' } }
|
|
130
|
+
}, { token });
|
|
131
|
+
assert.strictEqual(body.result.isError, false);
|
|
132
|
+
assert.match(body.result.content[0].text, /deleted/);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('head_resource returns 404 on missing path', async () => {
|
|
136
|
+
const { body } = await rpc({
|
|
137
|
+
jsonrpc: '2.0', id: 9, method: 'tools/call',
|
|
138
|
+
params: { name: 'head_resource', arguments: { path: '/mcptest/public/does-not-exist' } }
|
|
139
|
+
}, { token });
|
|
140
|
+
assert.ok(body.result.isError);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('list_skills returns the index shape', async () => {
|
|
144
|
+
const { body } = await rpc({
|
|
145
|
+
jsonrpc: '2.0', id: 10, method: 'tools/call',
|
|
146
|
+
params: { name: 'list_skills', arguments: {} }
|
|
147
|
+
}, { token });
|
|
148
|
+
assert.strictEqual(body.result.isError, false);
|
|
149
|
+
const payload = JSON.parse(body.result.content[0].text);
|
|
150
|
+
assert.strictEqual(payload['@type'], 'skill:SkillIndex');
|
|
151
|
+
assert.ok(Array.isArray(payload['skill:items']));
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('list_skills discovers per-app SKILL.md', async () => {
|
|
155
|
+
// Seed a per-app skill
|
|
156
|
+
await rpc({
|
|
157
|
+
jsonrpc: '2.0', id: 1010, method: 'tools/call',
|
|
158
|
+
params: {
|
|
159
|
+
name: 'write_resource',
|
|
160
|
+
arguments: {
|
|
161
|
+
path: '/mcptest/public/apps/demo/index.html',
|
|
162
|
+
content: '<h1>demo</h1>',
|
|
163
|
+
contentType: 'text/html'
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}, { token });
|
|
167
|
+
await rpc({
|
|
168
|
+
jsonrpc: '2.0', id: 1011, method: 'tools/call',
|
|
169
|
+
params: {
|
|
170
|
+
name: 'write_resource',
|
|
171
|
+
arguments: {
|
|
172
|
+
path: '/mcptest/public/apps/demo/SKILL.md',
|
|
173
|
+
content: '# demo app skill',
|
|
174
|
+
contentType: 'text/markdown'
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}, { token });
|
|
178
|
+
|
|
179
|
+
// Now list against the pod root — but list_skills walks /public/apps/
|
|
180
|
+
// and /private/bots/ at the pod root, not inside a named pod. For this
|
|
181
|
+
// test, we just verify the per-app discovery walks containers correctly
|
|
182
|
+
// by listing /mcptest/public/apps/ directly via list_resources and
|
|
183
|
+
// confirming "demo" comes back as a container (isContainer=true).
|
|
184
|
+
const { body } = await rpc({
|
|
185
|
+
jsonrpc: '2.0', id: 1012, method: 'tools/call',
|
|
186
|
+
params: { name: 'list_resources', arguments: { path: '/mcptest/public/apps/' } }
|
|
187
|
+
}, { token });
|
|
188
|
+
assert.strictEqual(body.result.isError, false);
|
|
189
|
+
const payload = JSON.parse(body.result.content[0].text);
|
|
190
|
+
const demo = payload.items.find(i => i.name === 'demo');
|
|
191
|
+
assert.ok(demo, 'demo container should be listed');
|
|
192
|
+
assert.strictEqual(demo.isContainer, true, 'isContainer must be true for directories');
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it('list_docs returns the JSS-builtin doc set', async () => {
|
|
196
|
+
const { body } = await rpc({
|
|
197
|
+
jsonrpc: '2.0', id: 11, method: 'tools/call',
|
|
198
|
+
params: { name: 'list_docs', arguments: {} }
|
|
199
|
+
});
|
|
200
|
+
assert.strictEqual(body.result.isError, false);
|
|
201
|
+
const payload = JSON.parse(body.result.content[0].text);
|
|
202
|
+
assert.strictEqual(payload.source, 'jss-builtin');
|
|
203
|
+
assert.ok(payload.docs.some(d => d.name.endsWith('.md')));
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it('read_docs fetches a known doc', async () => {
|
|
207
|
+
const { body } = await rpc({
|
|
208
|
+
jsonrpc: '2.0', id: 12, method: 'tools/call',
|
|
209
|
+
params: { name: 'read_docs', arguments: { name: 'git-support.md' } }
|
|
210
|
+
});
|
|
211
|
+
assert.strictEqual(body.result.isError, false);
|
|
212
|
+
const payload = JSON.parse(body.result.content[0].text);
|
|
213
|
+
assert.match(payload.body, /git/i);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it('read_docs rejects path traversal', async () => {
|
|
217
|
+
const { body } = await rpc({
|
|
218
|
+
jsonrpc: '2.0', id: 13, method: 'tools/call',
|
|
219
|
+
params: { name: 'read_docs', arguments: { name: '../package.json' } }
|
|
220
|
+
});
|
|
221
|
+
assert.ok(body.result.isError);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('pod_info returns identity info', async () => {
|
|
225
|
+
const { body } = await rpc({
|
|
226
|
+
jsonrpc: '2.0', id: 14, method: 'tools/call',
|
|
227
|
+
params: { name: 'pod_info', arguments: {} }
|
|
228
|
+
}, { token });
|
|
229
|
+
assert.strictEqual(body.result.isError, false);
|
|
230
|
+
const payload = JSON.parse(body.result.content[0].text);
|
|
231
|
+
assert.strictEqual(payload.server, 'jss');
|
|
232
|
+
assert.ok(payload.identity);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it('rejects unknown method', async () => {
|
|
236
|
+
const { body } = await rpc({ jsonrpc: '2.0', id: 99, method: 'doesnt/exist' });
|
|
237
|
+
assert.strictEqual(body.error?.code, -32601);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it('rejects unknown tool', async () => {
|
|
241
|
+
const { body } = await rpc({
|
|
242
|
+
jsonrpc: '2.0', id: 100, method: 'tools/call',
|
|
243
|
+
params: { name: 'fictional_tool', arguments: {} }
|
|
244
|
+
});
|
|
245
|
+
assert.ok(body.result?.isError);
|
|
246
|
+
assert.match(body.result.content[0].text, /unknown tool/);
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
describe('MCP server disabled (no flag)', () => {
|
|
251
|
+
before(async () => {
|
|
252
|
+
await startTestServer({});
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
after(async () => {
|
|
256
|
+
await stopTestServer();
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it('blocks /mcp when flag is off', async () => {
|
|
260
|
+
// Without --mcp, the route isn't registered. The global auth hook fires
|
|
261
|
+
// first on the missing route and rejects (401) since /mcp isn't on the
|
|
262
|
+
// skip list when mcpEnabled is false. Either 401 or 404 is correct
|
|
263
|
+
// "MCP is not available here" behavior; both block tool dispatch.
|
|
264
|
+
const res = await request('/mcp', {
|
|
265
|
+
method: 'POST',
|
|
266
|
+
headers: { 'Content-Type': 'application/json' },
|
|
267
|
+
body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'initialize' })
|
|
268
|
+
});
|
|
269
|
+
assert.ok(res.status === 404 || res.status === 401, `expected 404 or 401, got ${res.status}`);
|
|
270
|
+
});
|
|
271
|
+
});
|