@chatpanel/gateway 0.6.72 → 0.6.73
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/bin/chatpanel-gateway.js +9 -1
- package/package.json +1 -1
- package/src/mcp-cli.js +113 -0
- package/src/server.js +1 -1
package/bin/chatpanel-gateway.js
CHANGED
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
//
|
|
4
4
|
// chatpanel-gateway start the gateway (foreground)
|
|
5
5
|
// chatpanel-gateway mcp stdio MCP server exposing warm history as tools
|
|
6
|
+
// chatpanel-gateway tools list the same tools, from a shell — names and one-liners
|
|
7
|
+
// chatpanel-gateway tools schema <tool> one tool's full schema
|
|
8
|
+
// chatpanel-gateway call <tool> '<json>' run one tool (exit 0 ok · 1 tool error · 2 usage)
|
|
6
9
|
// chatpanel-gateway local show the local runtime — bridge + gateway, one view
|
|
7
10
|
// chatpanel-gateway connect point your CLI agents (Codex, Claude Code, …) at this server
|
|
8
11
|
// chatpanel-gateway --install register login auto-start + start now
|
|
@@ -21,6 +24,11 @@ try {
|
|
|
21
24
|
// server.js (which would open a second handle on the warm SQLite store).
|
|
22
25
|
const { runMcpServer } = await import('../src/mcp.js');
|
|
23
26
|
await runMcpServer();
|
|
27
|
+
} else if (arg === 'tools' || arg === 'call') {
|
|
28
|
+
// MCP2CLI: the MCP tools as shell verbs, for agents that only have a shell. Same
|
|
29
|
+
// in-process dispatcher as `mcp`, same no-server.js rule.
|
|
30
|
+
const { runMcpCli } = await import('../src/mcp-cli.js');
|
|
31
|
+
process.exit(await runMcpCli(process.argv.slice(2)));
|
|
24
32
|
} else if (arg === 'local') {
|
|
25
33
|
// Read-only unified view of both services. No server.js import — just HTTP probes.
|
|
26
34
|
const { localStatus, formatLocalStatus } = await import('../src/local-status.js');
|
|
@@ -52,7 +60,7 @@ try {
|
|
|
52
60
|
start();
|
|
53
61
|
break;
|
|
54
62
|
default:
|
|
55
|
-
console.error(`unknown option: ${arg}\nUsage: chatpanel-gateway [mcp|--install|--uninstall|--status|--version]`);
|
|
63
|
+
console.error(`unknown option: ${arg}\nUsage: chatpanel-gateway [mcp|tools list|tools schema <tool>|call <tool> '<json>'|local|connect|--install|--uninstall|--status|--version]`);
|
|
56
64
|
process.exit(2);
|
|
57
65
|
}
|
|
58
66
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chatpanel/gateway",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.73",
|
|
4
4
|
"description": "Local privacy gateway \u2014 redacts PII out of OpenAI/Anthropic API traffic before it reaches a model, then restores it in the reply. Point opencode, codex, aider, Claude Code, etc. at it.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
package/src/mcp-cli.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// `chatpanel-gateway tools list | tools schema <tool> | call <tool> '<json>'` — the same
|
|
2
|
+
// tools the MCP server offers, reached from a shell.
|
|
3
|
+
//
|
|
4
|
+
// An MCP connection is a standing cost: every tool's schema sits in the agent's context on
|
|
5
|
+
// every turn, called or not. A shell verb costs nothing until it is used — `tools list`
|
|
6
|
+
// prints names and one-liners, `tools schema` pulls ONE schema at the moment of calling,
|
|
7
|
+
// `call` runs the tool. So an agent that has only a shell (a skill's `scripts/`, a CI job,
|
|
8
|
+
// a CLI with no MCP support) reaches history, memory and briefs at a cost that scales with
|
|
9
|
+
// use rather than with how many tools exist. The daemon's secrets never move: the CLI
|
|
10
|
+
// talks to the gateway exactly as the MCP server does, over loopback with the gateway
|
|
11
|
+
// token, and prints results.
|
|
12
|
+
//
|
|
13
|
+
// Exit codes, so a script can tell them apart: 0 the tool answered; 1 the tool itself
|
|
14
|
+
// reported an error (a real tool-level failure — the record was not found); 2 a usage or
|
|
15
|
+
// transport failure (bad JSON, unknown verb, gateway unreachable).
|
|
16
|
+
|
|
17
|
+
import { readFileSync } from 'node:fs';
|
|
18
|
+
import { handleRpc } from './mcp.js';
|
|
19
|
+
|
|
20
|
+
const USAGE = [
|
|
21
|
+
'Usage:',
|
|
22
|
+
' chatpanel-gateway tools list names and one-liners (no schemas)',
|
|
23
|
+
' chatpanel-gateway tools schema <tool> one tool\'s full input schema',
|
|
24
|
+
' chatpanel-gateway call <tool> [\'<json>\'] run a tool; arguments as a JSON object',
|
|
25
|
+
' chatpanel-gateway call <tool> --file <path> arguments from a JSON file (no shell quoting)',
|
|
26
|
+
'',
|
|
27
|
+
'Exit codes: 0 ok · 1 the tool reported an error · 2 usage or transport failure',
|
|
28
|
+
].join('\n');
|
|
29
|
+
|
|
30
|
+
/** First sentence, whitespace collapsed, capped — enough to choose a tool, not to call it. */
|
|
31
|
+
export function oneLiner(description, max = 100) {
|
|
32
|
+
const s = String(description || '').replace(/\s+/g, ' ').trim();
|
|
33
|
+
const cut = s.search(/[.!?]\s/);
|
|
34
|
+
const first = cut > 20 ? s.slice(0, cut + 1) : s;
|
|
35
|
+
return first.length > max ? `${first.slice(0, max - 1).trimEnd()}…` : first;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function formatToolsList(tools) {
|
|
39
|
+
const width = Math.min(24, Math.max(...tools.map((t) => t.name.length), 4));
|
|
40
|
+
return tools.map((t) => {
|
|
41
|
+
const req = Array.isArray(t.inputSchema?.required) && t.inputSchema.required.length ? `(${t.inputSchema.required.join(', ')})` : '()';
|
|
42
|
+
return `${t.name.padEnd(width)} ${req.padEnd(22)} ${oneLiner(t.description)}`;
|
|
43
|
+
}).join('\n');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function parseArgs(argv) {
|
|
47
|
+
const rest = [...argv];
|
|
48
|
+
let file = null;
|
|
49
|
+
const i = rest.indexOf('--file');
|
|
50
|
+
if (i >= 0) { file = rest[i + 1]; rest.splice(i, 2); }
|
|
51
|
+
return { rest, file };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Run one CLI invocation. Returns the exit code; writes through `out`/`err` so a test can
|
|
56
|
+
* capture without a process. `rpc` is the MCP dispatcher — `handleRpc` in production.
|
|
57
|
+
*/
|
|
58
|
+
export async function runMcpCli(argv, { out = (s) => process.stdout.write(s), err = (s) => process.stderr.write(s), rpc = handleRpc } = {}) {
|
|
59
|
+
const [verb, ...more] = argv;
|
|
60
|
+
const list = async () => (await rpc({ jsonrpc: '2.0', id: 1, method: 'tools/list' }))?.result?.tools || [];
|
|
61
|
+
|
|
62
|
+
if (verb === 'tools') {
|
|
63
|
+
const [sub, name] = more;
|
|
64
|
+
if (sub === 'list') {
|
|
65
|
+
out(`${formatToolsList(await list())}\n`);
|
|
66
|
+
return 0;
|
|
67
|
+
}
|
|
68
|
+
if (sub === 'schema') {
|
|
69
|
+
if (!name) { err(`tools schema: which tool?\n${USAGE}\n`); return 2; }
|
|
70
|
+
const tool = (await list()).find((t) => t.name === name);
|
|
71
|
+
if (!tool) { err(`no tool named "${name}". Run: chatpanel-gateway tools list\n`); return 2; }
|
|
72
|
+
out(`${JSON.stringify({ name: tool.name, description: tool.description, inputSchema: tool.inputSchema }, null, 2)}\n`);
|
|
73
|
+
return 0;
|
|
74
|
+
}
|
|
75
|
+
err(`${USAGE}\n`);
|
|
76
|
+
return 2;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (verb === 'call') {
|
|
80
|
+
const { rest, file } = parseArgs(more);
|
|
81
|
+
const [name, inline] = rest;
|
|
82
|
+
if (!name) { err(`call: which tool?\n${USAGE}\n`); return 2; }
|
|
83
|
+
let args = {};
|
|
84
|
+
try {
|
|
85
|
+
const text = file ? readFileSync(file, 'utf8') : (inline ?? '{}');
|
|
86
|
+
args = JSON.parse(text);
|
|
87
|
+
} catch (e) {
|
|
88
|
+
err(`call: arguments must be a JSON object (${e.message})\n`);
|
|
89
|
+
return 2;
|
|
90
|
+
}
|
|
91
|
+
if (!args || typeof args !== 'object' || Array.isArray(args)) { err('call: arguments must be a JSON object\n'); return 2; }
|
|
92
|
+
let reply;
|
|
93
|
+
try {
|
|
94
|
+
reply = await rpc({ jsonrpc: '2.0', id: 1, method: 'tools/call', params: { name, arguments: args } });
|
|
95
|
+
} catch (e) {
|
|
96
|
+
err(`call: ${e.message}\n`);
|
|
97
|
+
return 2;
|
|
98
|
+
}
|
|
99
|
+
if (reply?.error) { err(`call: ${reply.error.message}\n`); return 2; }
|
|
100
|
+
const text = (reply?.result?.content || []).filter((c) => c.type === 'text').map((c) => c.text).join('\n');
|
|
101
|
+
if (reply?.result?.isError) {
|
|
102
|
+
// The gateway being down looks like a tool error from the MCP layer; it is transport.
|
|
103
|
+
const transport = /fetch failed|ECONNREFUSED|not running|unreachable/i.test(text);
|
|
104
|
+
err(`${text}\n`);
|
|
105
|
+
return transport ? 2 : 1;
|
|
106
|
+
}
|
|
107
|
+
out(`${text}\n`);
|
|
108
|
+
return 0;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
err(`${USAGE}\n`);
|
|
112
|
+
return 2;
|
|
113
|
+
}
|
package/src/server.js
CHANGED
|
@@ -56,7 +56,7 @@ import * as openai from './openai.js';
|
|
|
56
56
|
import * as responses from './responses.js';
|
|
57
57
|
import * as anthropic from './anthropic.js';
|
|
58
58
|
|
|
59
|
-
export const VERSION = '0.6.
|
|
59
|
+
export const VERSION = '0.6.73';
|
|
60
60
|
|
|
61
61
|
// WARM search tier — SQLite + FTS5 record store (falls back to an encrypted-JSON
|
|
62
62
|
// store if SQLite can't load), fed by the extension's ingest sync + backup-ingest.
|