@pixlcore/xycli 1.2.3 → 1.2.4
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/CHANGELOG.md +8 -0
- package/lib/mcp/server.js +6 -1
- package/lib/mcp/transports/http.js +27 -6
- package/lib/mcp/transports/stdio.js +5 -1
- package/package.json +1 -1
- package/test/mcp-http-unit.test.js +114 -1
- package/test/mcp-stdio-unit.test.js +20 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# xyCLI Changelog
|
|
2
2
|
|
|
3
|
+
## Version v1.2.3
|
|
4
|
+
|
|
5
|
+
> November 5, 2026
|
|
6
|
+
|
|
7
|
+
- [`e7da2e7`](https://github.com/pixlcore/xycli/commit/e7da2e7251d4a4834b569fe581cc4338ed9ecaf1): Version 1.2.3
|
|
8
|
+
- [`48c1fca`](https://github.com/pixlcore/xycli/commit/48c1fcac6e1128f132a571eb915da66df7c6705e): Fix: Prevent a theoretically compromised xyOps server client config from infecting CLI sync config.
|
|
9
|
+
- [`023129a`](https://github.com/pixlcore/xycli/commit/023129a91b7f2c64062bad3e5d4300d0f8c10d4b): Fix: Use secure JSON parsing at user trust boundaries.
|
|
10
|
+
|
|
3
11
|
## Version v1.2.2
|
|
4
12
|
|
|
5
13
|
> November 2, 2026
|
package/lib/mcp/server.js
CHANGED
|
@@ -9,7 +9,12 @@ module.exports = function serverFactory(tools, context) {
|
|
|
9
9
|
// STDIO uses the configured context. HTTP supplies a key for each
|
|
10
10
|
// exchange, shared by all API calls made by that exchange's tools.
|
|
11
11
|
const scoped = apiKey === undefined ? context : context.withApiKey(apiKey);
|
|
12
|
-
|
|
12
|
+
// Our catalog is fixed when this instance is built. Override the SDK's
|
|
13
|
+
// listChanged:true default so clients do not open unused subscriptions.
|
|
14
|
+
const server = new McpServer({ name: 'xyops', version: pkg.version }, {
|
|
15
|
+
capabilities: { tools: { listChanged: false } }
|
|
16
|
+
});
|
|
17
|
+
|
|
13
18
|
for (const tool of tools.values()) {
|
|
14
19
|
const { name, ...description } = tool.description;
|
|
15
20
|
if (scoped.readOnly && !description.annotations.readOnlyHint) continue;
|
|
@@ -2,10 +2,21 @@
|
|
|
2
2
|
const http = require('node:http');
|
|
3
3
|
const https = require('node:https');
|
|
4
4
|
const fs = require('node:fs');
|
|
5
|
+
const { AsyncLocalStorage } = require('node:async_hooks');
|
|
5
6
|
const { createMcpHandler } = require('@modelcontextprotocol/server');
|
|
6
7
|
const { toNodeHandler, hostHeaderValidation } = require('@modelcontextprotocol/node');
|
|
7
8
|
|
|
8
9
|
module.exports = async function startHTTP(factory, options) {
|
|
10
|
+
// SDK callbacks are shared by all requests. Keep diagnostic redaction in
|
|
11
|
+
// the caller's async scope rather than storing a mutable "current" key.
|
|
12
|
+
const requestKeys = new AsyncLocalStorage();
|
|
13
|
+
function logError(label, error) {
|
|
14
|
+
let message = String(error?.message || error);
|
|
15
|
+
const apiKey = requestKeys.getStore();
|
|
16
|
+
if (apiKey) message = message.split(apiKey).join('[redacted]');
|
|
17
|
+
options.log(label + ': ' + message);
|
|
18
|
+
}
|
|
19
|
+
|
|
9
20
|
// Check only the header shape here. xyOps validates the key and enforces
|
|
10
21
|
// privileges when the tool calls its API; there is no separate MCP secret.
|
|
11
22
|
function bearerKey(authorization) {
|
|
@@ -19,9 +30,18 @@ module.exports = async function startHTTP(factory, options) {
|
|
|
19
30
|
// Auto returns JSON for ordinary calls and preserves streamed messages
|
|
20
31
|
// if a future tool needs progress notifications during its response.
|
|
21
32
|
responseMode: 'auto', maxRequestBodySize: options.max_request_bytes,
|
|
22
|
-
maxSubscriptions: 0, onerror
|
|
33
|
+
maxSubscriptions: 0, onerror(error) {
|
|
34
|
+
// A client may subscribe even though our catalog is static. The SDK
|
|
35
|
+
// still returns its refusal, but our deliberate zero limit is quiet.
|
|
36
|
+
// Match only this exact SDK diagnostic; other protocol faults matter.
|
|
37
|
+
if (error?.message === 'subscriptions/listen refused: subscription limit reached (0)') return;
|
|
38
|
+
logError('MCP protocol error on HTTP request', error);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
const nodeHandler = toNodeHandler(handler, {
|
|
42
|
+
maxRequestBodySize: options.max_request_bytes,
|
|
43
|
+
onerror: error => logError('MCP HTTP adapter error', error)
|
|
23
44
|
});
|
|
24
|
-
const nodeHandler = toNodeHandler(handler, { maxRequestBodySize: options.max_request_bytes, onerror: () => options.log('MCP HTTP adapter error.') });
|
|
25
45
|
const validateHost = hostHeaderValidation(options.allowed_hosts);
|
|
26
46
|
|
|
27
47
|
function respond(response, status, text) {
|
|
@@ -35,16 +55,17 @@ module.exports = async function startHTTP(factory, options) {
|
|
|
35
55
|
if (!validateHost(request, response)) return;
|
|
36
56
|
const origin = request.headers.origin;
|
|
37
57
|
if (origin && !options.allowed_origins.includes(origin)) return respond(response, 403, 'Origin not allowed');
|
|
38
|
-
|
|
58
|
+
const apiKey = bearerKey(request.headers.authorization);
|
|
59
|
+
if (!apiKey) {
|
|
39
60
|
response.setHeader('WWW-Authenticate', 'Bearer');
|
|
40
61
|
return respond(response, 401, 'Supply a xyOps API key as a Bearer token');
|
|
41
62
|
}
|
|
42
63
|
response.setHeader('Cache-Control', 'no-store');
|
|
43
|
-
nodeHandler(request, response).catch(function() {
|
|
44
|
-
|
|
64
|
+
requestKeys.run(apiKey, () => nodeHandler(request, response).catch(function(error) {
|
|
65
|
+
logError('MCP HTTP request failed', error);
|
|
45
66
|
if (!response.headersSent) respond(response, 500, 'Internal server error');
|
|
46
67
|
else response.destroy();
|
|
47
|
-
});
|
|
68
|
+
}));
|
|
48
69
|
}
|
|
49
70
|
|
|
50
71
|
const server = options.tls_cert ? https.createServer({ cert: fs.readFileSync(options.tls_cert), key: fs.readFileSync(options.tls_key) }, request) : http.createServer(request);
|
|
@@ -3,5 +3,9 @@ const { serveStdio, StdioServerTransport } = require('@modelcontextprotocol/serv
|
|
|
3
3
|
|
|
4
4
|
module.exports = function startStdio(factory, options) {
|
|
5
5
|
const transport = new StdioServerTransport(process.stdin, process.stdout, { maxBufferSize: options.max_request_bytes });
|
|
6
|
-
return serveStdio(factory, {
|
|
6
|
+
return serveStdio(factory, {
|
|
7
|
+
transport, maxSubscriptions: 0,
|
|
8
|
+
// The context logger already redacts the configured STDIO API key.
|
|
9
|
+
onerror: error => options.log('MCP protocol error on stdin: ' + (error?.message || String(error)))
|
|
10
|
+
});
|
|
7
11
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixlcore/xycli",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.4",
|
|
4
4
|
"description": "A complete command-line interface for the xyOps workflow automation system.",
|
|
5
5
|
"author": "Joseph Huckaby <jhuckaby@pixlcore.com>",
|
|
6
6
|
"homepage": "https://github.com/pixlcore/xycli",
|
|
@@ -9,7 +9,120 @@ const { createContext } = require('../lib/mcp/context.js');
|
|
|
9
9
|
const factory = require('../lib/mcp/server.js');
|
|
10
10
|
const start = require('../lib/mcp/transports/http.js');
|
|
11
11
|
const tools = require('../lib/mcp/registry.js')();
|
|
12
|
-
const { httpRPC } = require('./helpers/mcp.js');
|
|
12
|
+
const { decode, httpRPC } = require('./helpers/mcp.js');
|
|
13
|
+
|
|
14
|
+
test('HTTP advertises a static tool catalog for modern and legacy clients', async t => {
|
|
15
|
+
// Both permission modes use the same static catalog capabilities. Check the
|
|
16
|
+
// wire responses so an SDK default cannot silently re-enable notifications.
|
|
17
|
+
for (const read_only of [false, true]) {
|
|
18
|
+
const service = await start(factory(tools, createContext({}, { read_only })), { ...configuration({}, {}), port: 0, log() {} });
|
|
19
|
+
t.after(() => service.close());
|
|
20
|
+
const url = 'http://127.0.0.1:' + service.address.port + '/mcp';
|
|
21
|
+
const headers = { Authorization: 'Bearer fixture-key' };
|
|
22
|
+
const modern = await httpRPC(url, 'server/discover', {}, { headers, modern: true });
|
|
23
|
+
const legacy = await httpRPC(url, 'initialize', {
|
|
24
|
+
protocolVersion: '2025-11-25', capabilities: {}, clientInfo: { name: 'xycli-test', version: '1' }
|
|
25
|
+
}, { headers });
|
|
26
|
+
for (const reply of [modern, legacy]) assert.deepEqual(reply.result.capabilities.tools, { listChanged: false });
|
|
27
|
+
const listing = await httpRPC(url, 'tools/list', {}, { headers, modern: true });
|
|
28
|
+
assert.equal(listing.result.tools.length, read_only ? 8 : tools.size);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('HTTP keeps intentional subscription refusals quiet and reports other protocol errors', async t => {
|
|
33
|
+
const logs = [];
|
|
34
|
+
const service = await start(factory(tools, createContext({})), { ...configuration({}, {}), port: 0, log: line => logs.push(line) });
|
|
35
|
+
t.after(() => service.close());
|
|
36
|
+
const url = 'http://127.0.0.1:' + service.address.port + '/mcp';
|
|
37
|
+
const headers = { Authorization: 'Bearer fixture-key' };
|
|
38
|
+
|
|
39
|
+
// Clients may subscribe despite listChanged:false. Keep the SDK's refusal
|
|
40
|
+
// on the wire, without treating our deliberate zero limit as a server fault.
|
|
41
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
42
|
+
const response = await fetch(url, {
|
|
43
|
+
method: 'POST', headers: {
|
|
44
|
+
...headers, 'Content-Type': 'application/json', Accept: 'application/json, text/event-stream',
|
|
45
|
+
'MCP-Protocol-Version': '2026-07-28', 'Mcp-Method': 'subscriptions/listen'
|
|
46
|
+
},
|
|
47
|
+
body: JSON.stringify({ jsonrpc: '2.0', id: attempt + 1, method: 'subscriptions/listen', params: {
|
|
48
|
+
notifications: { toolsListChanged: true },
|
|
49
|
+
_meta: { 'io.modelcontextprotocol/protocolVersion': '2026-07-28', 'io.modelcontextprotocol/clientCapabilities': {} }
|
|
50
|
+
} })
|
|
51
|
+
});
|
|
52
|
+
assert.equal(response.status, 200);
|
|
53
|
+
assert.deepEqual((await decode(response)).error, { code: -32603, message: 'Subscription limit reached' });
|
|
54
|
+
}
|
|
55
|
+
assert.deepEqual(logs, []);
|
|
56
|
+
|
|
57
|
+
// A mismatched routing header must still produce a useful diagnostic.
|
|
58
|
+
// Include the caller's key in that header to exercise diagnostic redaction.
|
|
59
|
+
const rejected = await httpRPC(url, 'tools/list', {}, {
|
|
60
|
+
modern: true, headers: { ...headers, 'Mcp-Method': 'fixture-key' }
|
|
61
|
+
});
|
|
62
|
+
assert.ok(rejected.error);
|
|
63
|
+
assert.equal(logs.length, 1);
|
|
64
|
+
assert.match(logs[0], /^MCP protocol error on HTTP request: .*Mcp-Method/i);
|
|
65
|
+
assert.doesNotMatch(logs[0], /fixture-key/);
|
|
66
|
+
assert.ok((await httpRPC(url, 'tools/list', {}, { headers, modern: true })).result.tools.length);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('HTTP protocol errors include the cause and redact each concurrent caller key', async t => {
|
|
70
|
+
const logs = [];
|
|
71
|
+
const service = await start(async ({ apiKey }) => {
|
|
72
|
+
// A failed factory reaches the SDK's protocol error callback. Vary the
|
|
73
|
+
// timing to verify request-scoped diagnostics across concurrent callers.
|
|
74
|
+
await new Promise(resolve => setTimeout(resolve, apiKey === 'slow-secret' ? 20 : 1));
|
|
75
|
+
throw new Error('Fixture setup failed for ' + apiKey);
|
|
76
|
+
}, { ...configuration({}, {}), port: 0, log: line => logs.push(line) });
|
|
77
|
+
t.after(() => service.close());
|
|
78
|
+
const url = 'http://127.0.0.1:' + service.address.port + '/mcp';
|
|
79
|
+
const replies = await Promise.all(['slow-secret', 'fast-secret'].map(key => httpRPC(url, 'server/discover', {}, {
|
|
80
|
+
modern: true, headers: { Authorization: 'Bearer ' + key }
|
|
81
|
+
})));
|
|
82
|
+
assert.ok(replies.every(reply => reply.error));
|
|
83
|
+
assert.deepEqual(logs, [
|
|
84
|
+
'MCP protocol error on HTTP request: Fixture setup failed for [redacted]',
|
|
85
|
+
'MCP protocol error on HTTP request: Fixture setup failed for [redacted]'
|
|
86
|
+
]);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('HTTP logs subscription faults other than the intentional zero limit', async t => {
|
|
90
|
+
const logs = [];
|
|
91
|
+
// Inject a nearby SDK diagnostic through its real error callback. A broad
|
|
92
|
+
// match for subscription errors would hide a future nonzero capacity fault.
|
|
93
|
+
const message = 'subscriptions/listen refused: subscription limit reached (1)';
|
|
94
|
+
const service = await start(() => { throw new Error(message); }, {
|
|
95
|
+
...configuration({}, {}), port: 0, log: line => logs.push(line)
|
|
96
|
+
});
|
|
97
|
+
t.after(() => service.close());
|
|
98
|
+
const reply = await httpRPC('http://127.0.0.1:' + service.address.port + '/mcp', 'server/discover', {}, {
|
|
99
|
+
modern: true, headers: { Authorization: 'Bearer fixture-key' }
|
|
100
|
+
});
|
|
101
|
+
assert.ok(reply.error);
|
|
102
|
+
assert.deepEqual(logs, ['MCP protocol error on HTTP request: ' + message]);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('HTTP adapter errors include their underlying cause', async t => {
|
|
106
|
+
const logs = [];
|
|
107
|
+
const service = await start(factory(tools, createContext({})), { ...configuration({}, {}), port: 0, log: line => logs.push(line) });
|
|
108
|
+
t.after(() => service.close());
|
|
109
|
+
// Node's web Request conversion rejects TRACE before MCP dispatch. Use a
|
|
110
|
+
// native request because fetch itself refuses to send this HTTP method.
|
|
111
|
+
const status = await new Promise((resolve, reject) => {
|
|
112
|
+
const request = http.request({
|
|
113
|
+
hostname: '127.0.0.1', port: service.address.port, path: '/mcp', method: 'TRACE',
|
|
114
|
+
headers: { Authorization: 'Bearer fixture-key' }
|
|
115
|
+
}, response => {
|
|
116
|
+
response.resume();
|
|
117
|
+
response.on('end', () => resolve(response.statusCode));
|
|
118
|
+
});
|
|
119
|
+
request.on('error', reject);
|
|
120
|
+
request.end();
|
|
121
|
+
});
|
|
122
|
+
assert.equal(status, 500);
|
|
123
|
+
assert.equal(logs.length, 1);
|
|
124
|
+
assert.match(logs[0], /^MCP HTTP adapter error: .*TRACE.*unsupported/i);
|
|
125
|
+
});
|
|
13
126
|
|
|
14
127
|
test('HTTP serves both protocol generations, validates calls and rejects unauthorized access', async t => {
|
|
15
128
|
let calls = 0;
|
|
@@ -2,8 +2,27 @@ const { test } = require('node:test');
|
|
|
2
2
|
const assert = require('node:assert/strict');
|
|
3
3
|
const http = require('node:http');
|
|
4
4
|
const { spawnSync } = require('node:child_process');
|
|
5
|
+
const { once } = require('node:events');
|
|
5
6
|
const { httpRPC, stdioClient } = require('./helpers/mcp.js');
|
|
6
7
|
|
|
8
|
+
test('modern STDIO advertises a static catalog and logs useful protocol errors', async t => {
|
|
9
|
+
const client = stdioClient(t, { XYOPS_BASE_URL: 'http://127.0.0.1:1', XYOPS_API_KEY: 'fixture-key' });
|
|
10
|
+
const _meta = { 'io.modelcontextprotocol/protocolVersion': '2026-07-28', 'io.modelcontextprotocol/clientCapabilities': {} };
|
|
11
|
+
assert.deepEqual((await client.request('server/discover', { _meta })).result.capabilities.tools, { listChanged: false });
|
|
12
|
+
assert.ok((await client.request('tools/list', { _meta })).result.tools.length);
|
|
13
|
+
|
|
14
|
+
// Once modern traffic pins the connection, legacy requests are rejected.
|
|
15
|
+
// Observe stderr before sending to avoid missing a fast child's diagnostic.
|
|
16
|
+
const diagnostic = once(client.child.stderr, 'data', { signal: AbortSignal.timeout(5000) });
|
|
17
|
+
assert.ok((await client.initialize()).error);
|
|
18
|
+
await diagnostic;
|
|
19
|
+
assert.match(client.stderr(), /MCP protocol error on stdin: Rejected 2025-era request/);
|
|
20
|
+
assert.doesNotMatch(client.stderr(), /fixture-key/);
|
|
21
|
+
assert.ok((await client.request('tools/list', { _meta })).result.tools.length);
|
|
22
|
+
client.child.stdin.end();
|
|
23
|
+
assert.equal((await client.exit)[0], 0);
|
|
24
|
+
});
|
|
25
|
+
|
|
7
26
|
test('STDIO uses the real CLI and SDK with protocol-only stdout and clean EOF', async t => {
|
|
8
27
|
let calls = 0;
|
|
9
28
|
const backend = http.createServer((request, response) => {
|
|
@@ -16,7 +35,7 @@ test('STDIO uses the real CLI and SDK with protocol-only stdout and clean EOF',
|
|
|
16
35
|
await new Promise(resolve => backend.listen(0, '127.0.0.1', resolve));
|
|
17
36
|
t.after(() => new Promise(resolve => { backend.close(resolve); backend.closeAllConnections(); }));
|
|
18
37
|
const client = stdioClient(t, { XYOPS_BASE_URL: 'http://127.0.0.1:' + backend.address().port, XYOPS_API_KEY: 'fixture-key', XYOPS_RETRIES: '4' }, ['mcp', 'stdio', '--verbose', '--debug', '--read-only']);
|
|
19
|
-
assert.
|
|
38
|
+
assert.deepEqual((await client.initialize()).result.capabilities.tools, { listChanged: false });
|
|
20
39
|
const listing = await client.request('tools/list');
|
|
21
40
|
assert.equal(listing.result.tools.length, 8);
|
|
22
41
|
assert.equal((await client.call('get_event', { id: 'fixture' })).result.structuredContent.event.revision, 2);
|