@sudohackin/toolring-mcp 0.0.0-stage → 0.10.0
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/AGENT-INSTRUCTIONS.ru.md +136 -0
- package/LICENSE +21 -0
- package/README.md +1144 -2
- package/RUN-BASH.ru.md +34 -0
- package/TOOL-STDOUT.md +50 -0
- package/bin/toolring.js +2 -0
- package/dist/argv-policy.d.ts +493 -0
- package/dist/argv-policy.js +211 -0
- package/dist/argv-policy.js.map +1 -0
- package/dist/bash-process.d.ts +3 -0
- package/dist/bash-process.js +98 -0
- package/dist/bash-process.js.map +1 -0
- package/dist/bash-when.d.ts +44 -0
- package/dist/bash-when.js +119 -0
- package/dist/bash-when.js.map +1 -0
- package/dist/call-policy.d.ts +20 -0
- package/dist/call-policy.js +74 -0
- package/dist/call-policy.js.map +1 -0
- package/dist/call.d.ts +107 -0
- package/dist/call.js +90 -0
- package/dist/call.js.map +1 -0
- package/dist/catalog.d.ts +30 -0
- package/dist/catalog.js +34 -0
- package/dist/catalog.js.map +1 -0
- package/dist/command-plan.d.ts +34 -0
- package/dist/command-plan.js +229 -0
- package/dist/command-plan.js.map +1 -0
- package/dist/config.d.ts +4559 -0
- package/dist/config.js +459 -0
- package/dist/config.js.map +1 -0
- package/dist/connections.d.ts +17 -0
- package/dist/connections.js +87 -0
- package/dist/connections.js.map +1 -0
- package/dist/default-tools.yaml +15 -0
- package/dist/executor.d.ts +39 -0
- package/dist/executor.js +166 -0
- package/dist/executor.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +288 -0
- package/dist/index.js.map +1 -0
- package/dist/module-contract.d.ts +98 -0
- package/dist/module-contract.js +4 -0
- package/dist/module-contract.js.map +1 -0
- package/dist/modules/json.d.ts +14 -0
- package/dist/modules/json.js +14 -0
- package/dist/modules/json.js.map +1 -0
- package/dist/modules/text.d.ts +14 -0
- package/dist/modules/text.js +14 -0
- package/dist/modules/text.js.map +1 -0
- package/dist/modules.d.ts +17 -0
- package/dist/modules.js +113 -0
- package/dist/modules.js.map +1 -0
- package/dist/pipeline-io.d.ts +15 -0
- package/dist/pipeline-io.js +112 -0
- package/dist/pipeline-io.js.map +1 -0
- package/dist/pipeline-parser.d.ts +8 -0
- package/dist/pipeline-parser.js +111 -0
- package/dist/pipeline-parser.js.map +1 -0
- package/dist/pipeline.d.ts +32 -0
- package/dist/pipeline.js +409 -0
- package/dist/pipeline.js.map +1 -0
- package/dist/schema.d.ts +38 -0
- package/dist/schema.js +113 -0
- package/dist/schema.js.map +1 -0
- package/dist/server.d.ts +38 -0
- package/dist/server.js +447 -0
- package/dist/server.js.map +1 -0
- package/dist/stdout-protocol.d.ts +4 -0
- package/dist/stdout-protocol.js +21 -0
- package/dist/stdout-protocol.js.map +1 -0
- package/dist/tool-stream.d.ts +6 -0
- package/dist/tool-stream.js +30 -0
- package/dist/tool-stream.js.map +1 -0
- package/docs/bash-policy.ru.md +211 -0
- package/package.json +68 -4
- package/skills/toolring/SKILL.md +22 -0
- package/skills/toolring-authoring/SKILL.md +63 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { CommandToolSpec } from "./config.js";
|
|
2
|
+
export interface ExecResult {
|
|
3
|
+
ok: boolean;
|
|
4
|
+
exitCode: number | null;
|
|
5
|
+
stdout: string;
|
|
6
|
+
stderr: string;
|
|
7
|
+
timedOut: boolean;
|
|
8
|
+
argv: string[];
|
|
9
|
+
durationMs: number;
|
|
10
|
+
/** True when the command was not actually executed (dry run). */
|
|
11
|
+
dryRun?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Build the final argv from a tool spec and validated parameter values.
|
|
15
|
+
* Pure function — trivially unit-testable, and the single place where
|
|
16
|
+
* agent-controlled data touches the command line.
|
|
17
|
+
*/
|
|
18
|
+
export declare function buildArgv(spec: CommandToolSpec, values: Record<string, unknown>): string[];
|
|
19
|
+
export interface RunOptions {
|
|
20
|
+
/** Extra env vars (config-level env block) merged over process.env. */
|
|
21
|
+
env?: Record<string, string>;
|
|
22
|
+
/** Override the cwd from the tool spec. */
|
|
23
|
+
cwd?: string;
|
|
24
|
+
/** Override timeoutMs from the tool spec. */
|
|
25
|
+
timeoutMs?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Print the argv that would run instead of executing it.
|
|
28
|
+
* The result is marked ok=false so the agent sees it is not real output.
|
|
29
|
+
*/
|
|
30
|
+
dryRun?: boolean;
|
|
31
|
+
confirmCommand?: (command: string, argv: readonly string[]) => Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Run a tool spec with the given values. Never throws for command failures —
|
|
35
|
+
* failures are data (non-zero exit, timeout) so the agent can see them.
|
|
36
|
+
*/
|
|
37
|
+
export declare function runTool(spec: CommandToolSpec, values: Record<string, unknown>, opts?: RunOptions): Promise<ExecResult>;
|
|
38
|
+
/** Execute the exact argument vector approved by the planner. */
|
|
39
|
+
export declare function executeCommand(spec: CommandToolSpec, argv: string[], opts: RunOptions): Promise<ExecResult>;
|
package/dist/executor.js
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* toolring — safe command execution engine.
|
|
3
|
+
*
|
|
4
|
+
* Commands are spawned directly (never through a shell), so shell injection
|
|
5
|
+
* is structurally impossible: every user value becomes exactly one argv
|
|
6
|
+
* token. Output size and runtime are both bounded.
|
|
7
|
+
*/
|
|
8
|
+
import { spawn } from "node:child_process";
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
import { commandAction } from "./call-policy.js";
|
|
11
|
+
import { buildZodShape } from "./schema.js";
|
|
12
|
+
/** Hard cap on captured output — protects the agent context window. */
|
|
13
|
+
const MAX_OUTPUT_BYTES = 256 * 1024;
|
|
14
|
+
/* ------------------------------------------------------------------ */
|
|
15
|
+
/* argv construction */
|
|
16
|
+
/* ------------------------------------------------------------------ */
|
|
17
|
+
/**
|
|
18
|
+
* Build the final argv from a tool spec and validated parameter values.
|
|
19
|
+
* Pure function — trivially unit-testable, and the single place where
|
|
20
|
+
* agent-controlled data touches the command line.
|
|
21
|
+
*/
|
|
22
|
+
export function buildArgv(spec, values) {
|
|
23
|
+
const globalTokens = [];
|
|
24
|
+
const localTokens = [];
|
|
25
|
+
const positional = [];
|
|
26
|
+
spec.params.forEach((p, idx) => {
|
|
27
|
+
let v = Object.hasOwn(values, p.name) ? values[p.name] : undefined;
|
|
28
|
+
if (v === undefined)
|
|
29
|
+
v = p.default;
|
|
30
|
+
if (v === undefined || v === null) {
|
|
31
|
+
return; // omitted optional param → nothing on the command line
|
|
32
|
+
}
|
|
33
|
+
const sink = p.placement === "global" ? globalTokens : localTokens;
|
|
34
|
+
if (p.type === "boolean") {
|
|
35
|
+
if (v === true) {
|
|
36
|
+
sink.push(p.trueFlag ?? p.flag ?? "");
|
|
37
|
+
}
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const s = String(v);
|
|
41
|
+
if (p.flag && !p.positional) {
|
|
42
|
+
if (p.equalsForm) {
|
|
43
|
+
sink.push(`${p.flag}=${s}`);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
sink.push(p.flag, s);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
positional.push({ value: s, order: idx });
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
positional.sort((a, b) => a.order - b.order);
|
|
54
|
+
return [...globalTokens, ...spec.args, ...localTokens, ...positional.map(x => x.value)];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Run a tool spec with the given values. Never throws for command failures —
|
|
58
|
+
* failures are data (non-zero exit, timeout) so the agent can see them.
|
|
59
|
+
*/
|
|
60
|
+
export async function runTool(spec, values, opts = {}) {
|
|
61
|
+
const policy = spec["command-policy"];
|
|
62
|
+
const input = policy ? z.object(buildZodShape(spec)).strict().parse(values) : values;
|
|
63
|
+
const argv = buildArgv(spec, input);
|
|
64
|
+
if (policy) {
|
|
65
|
+
const action = commandAction(policy, input);
|
|
66
|
+
if (action === "deny")
|
|
67
|
+
throw new Error(`Command policy denied "${spec.name}" with these arguments.`);
|
|
68
|
+
if (action === "confirm" && !opts.dryRun) {
|
|
69
|
+
if (!opts.confirmCommand)
|
|
70
|
+
throw new Error("Command policy requires user confirmation.");
|
|
71
|
+
await opts.confirmCommand(spec.command, argv);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return executeCommand(spec, argv, opts);
|
|
75
|
+
}
|
|
76
|
+
/** Execute the exact argument vector approved by the planner. */
|
|
77
|
+
export async function executeCommand(spec, argv, opts) {
|
|
78
|
+
if (opts.dryRun) {
|
|
79
|
+
return {
|
|
80
|
+
ok: true,
|
|
81
|
+
exitCode: null,
|
|
82
|
+
stdout: "",
|
|
83
|
+
stderr: "",
|
|
84
|
+
timedOut: false,
|
|
85
|
+
argv,
|
|
86
|
+
durationMs: 0,
|
|
87
|
+
dryRun: true,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
const cwd = opts.cwd ?? spec.cwd;
|
|
91
|
+
const timeoutMs = opts.timeoutMs ?? spec.timeoutMs;
|
|
92
|
+
const env = opts.env ? { ...process.env, ...opts.env } : { ...process.env };
|
|
93
|
+
const started = Date.now();
|
|
94
|
+
let stdout = "";
|
|
95
|
+
let stderr = "";
|
|
96
|
+
let stdoutCut = false;
|
|
97
|
+
let stderrCut = false;
|
|
98
|
+
let timedOut = false;
|
|
99
|
+
let spawnError = null;
|
|
100
|
+
let exitCode = null;
|
|
101
|
+
await new Promise(resolve => {
|
|
102
|
+
let child;
|
|
103
|
+
try {
|
|
104
|
+
child = spawn(spec.command, argv, {
|
|
105
|
+
cwd,
|
|
106
|
+
env,
|
|
107
|
+
shell: false, // security: never a shell
|
|
108
|
+
windowsHide: true,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
spawnError = err instanceof Error ? err.message : String(err);
|
|
113
|
+
resolve();
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const timer = setTimeout(() => {
|
|
117
|
+
timedOut = true;
|
|
118
|
+
child.kill("SIGKILL");
|
|
119
|
+
}, timeoutMs);
|
|
120
|
+
child.stdout?.on("data", (chunk) => {
|
|
121
|
+
if (stdout.length + chunk.length > MAX_OUTPUT_BYTES) {
|
|
122
|
+
stdoutCut = true;
|
|
123
|
+
stdout += chunk.subarray(0, Math.max(0, MAX_OUTPUT_BYTES - stdout.length)).toString("utf8");
|
|
124
|
+
child.kill("SIGKILL");
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
stdout += chunk.toString("utf8");
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
child.stderr?.on("data", (chunk) => {
|
|
131
|
+
if (stderr.length + chunk.length > MAX_OUTPUT_BYTES) {
|
|
132
|
+
stderrCut = true;
|
|
133
|
+
stderr += chunk.subarray(0, Math.max(0, MAX_OUTPUT_BYTES - stderr.length)).toString("utf8");
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
stderr += chunk.toString("utf8");
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
child.on("error", err => {
|
|
140
|
+
spawnError = err.message;
|
|
141
|
+
clearTimeout(timer);
|
|
142
|
+
resolve();
|
|
143
|
+
});
|
|
144
|
+
child.on("close", (code) => {
|
|
145
|
+
exitCode = code;
|
|
146
|
+
clearTimeout(timer);
|
|
147
|
+
resolve();
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
if (spawnError !== null) {
|
|
151
|
+
stderr += (stderr ? "\n" : "") + `[toolring] failed to run "${spec.command}": ${spawnError}`;
|
|
152
|
+
}
|
|
153
|
+
if (timedOut) {
|
|
154
|
+
stderr += (stderr ? "\n" : "") + `[toolring] timed out after ${timeoutMs} ms and was killed.`;
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
ok: spawnError === null && !timedOut && exitCode === 0,
|
|
158
|
+
exitCode,
|
|
159
|
+
stdout: stdoutCut ? stdout + "\n[toolring] output truncated at 256 KiB" : stdout,
|
|
160
|
+
stderr: stderrCut ? stderr + "\n[toolring] stderr truncated at 256 KiB" : stderr,
|
|
161
|
+
timedOut,
|
|
162
|
+
argv,
|
|
163
|
+
durationMs: Date.now() - started,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAe5C,uEAAuE;AACvE,MAAM,gBAAgB,GAAG,GAAG,GAAG,IAAI,CAAC;AAEpC,wEAAwE;AACxE,yEAAyE;AACzE,wEAAwE;AAExE;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,IAAqB,EAAE,MAA+B;IAC9E,MAAM,YAAY,GAAa,EAAE,CAAC;IAClC,MAAM,WAAW,GAAa,EAAE,CAAC;IACjC,MAAM,UAAU,GAAuC,EAAE,CAAC;IAE1D,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE;QAC7B,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACnE,IAAI,CAAC,KAAK,SAAS;YAAE,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC;QACnC,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;YAClC,OAAO,CAAC,u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,CAAC;QACZ,CAAC,CAAC,CAAC;QACH,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAmB,EAAE,EAAE;YACxC,QAAQ,GAAG,IAAI,CAAC;YAChB,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,OAAO,EAAE,CAAC;QACZ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;QACxB,MAAM,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,6BAA6B,IAAI,CAAC,OAAO,MAAM,UAAU,EAAE,CAAC;IAC/F,CAAC;IACD,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,8BAA8B,SAAS,qBAAqB,CAAC;IAChG,CAAC;IAED,OAAO;QACL,EAAE,EAAE,UAAU,KAAK,IAAI,IAAI,CAAC,QAAQ,IAAI,QAAQ,KAAK,CAAC;QACtD,QAAQ;QACR,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,MAAM,GAAG,0CAA0C,CAAC,CAAC,CAAC,MAAM;QAChF,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,MAAM,GAAG,0CAA0C,CAAC,CAAC,CAAC,MAAM;QAChF,QAAQ;QACR,IAAI;QACJ,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO;KACjC,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { lstatSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
3
|
+
import { Console } from "node:console";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import process from "node:process";
|
|
7
|
+
import { prefixedName, parseConfig, policyModuleWarnings, ConfigError } from "./config.js";
|
|
8
|
+
import { buildInputSchema } from "./schema.js";
|
|
9
|
+
import { packageVersion, runStdio } from "./server.js";
|
|
10
|
+
import { callConfiguredTool, streamToStdout } from "./call.js";
|
|
11
|
+
import { builtinModules, loadModuleRegistry } from "./modules.js";
|
|
12
|
+
import { preparePlanners } from "./command-plan.js";
|
|
13
|
+
import { prepareConnections } from "./connections.js";
|
|
14
|
+
function readConfig(path, registry) {
|
|
15
|
+
let raw;
|
|
16
|
+
try {
|
|
17
|
+
raw = readFileSync(path, "utf8");
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
21
|
+
console.error(`toolring: cannot read ${path}: ${msg}`);
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
return parseConfig(raw, registry);
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
if (e instanceof ConfigError) {
|
|
29
|
+
console.error(`toolring: invalid config in ${path}: ${e.message}`);
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
throw e;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function usage(error) {
|
|
36
|
+
if (error)
|
|
37
|
+
console.error(`toolring: ${error}`);
|
|
38
|
+
const stream = error ? process.stderr : process.stdout;
|
|
39
|
+
stream.write(`Usage:
|
|
40
|
+
toolring --version Print the installed package version
|
|
41
|
+
toolring skill [name] Print SKILL.md (default: toolring)
|
|
42
|
+
toolring skills [name] List project skills or print a named SKILL.md
|
|
43
|
+
toolring [-f <file>] serve [--dry-run] Start an MCP server on stdio
|
|
44
|
+
toolring [-f <file>] validate Validate a config file
|
|
45
|
+
toolring [-f <file>] inspect Show the tools that would be exposed
|
|
46
|
+
toolring [-f <file>] call <tool> [name=value ...] [--dry-run]
|
|
47
|
+
Run a published tool or an enabled module.function with allow-unpublished-tools: true.
|
|
48
|
+
Module commands and allowed external commands accept native arguments. Use -- to pass all following arguments verbatim.
|
|
49
|
+
Published tools accept --name value, declared short aliases, name=value, or one JSON object. Use --connection <alias> for a direct module call.
|
|
50
|
+
Example: toolring -f examples/node.yaml call status service=api details=true
|
|
51
|
+
-f <file> before the tool name, use this file instead of $TOOLRING_CONFIG or the nearest toolring.yaml
|
|
52
|
+
(search from the current directory up to the Git root, inclusive)
|
|
53
|
+
A positional config file immediately after the command is also supported.
|
|
54
|
+
--dry-run show what each tool call would run, never execute
|
|
55
|
+
--registry <path> load an external module registry for any of these commands
|
|
56
|
+
`);
|
|
57
|
+
process.exit(error ? 2 : 0);
|
|
58
|
+
}
|
|
59
|
+
function discoverConfig(bareServer) {
|
|
60
|
+
const env = process.env.TOOLRING_CONFIG || process.env.CONFIG2MCP_CONFIG;
|
|
61
|
+
if (env)
|
|
62
|
+
return env;
|
|
63
|
+
const cwd = process.cwd();
|
|
64
|
+
if (lstatSync("toolring.yaml", { throwIfNoEntry: false }))
|
|
65
|
+
return "toolring.yaml";
|
|
66
|
+
// A .git file marks a worktree or submodule just as a .git directory marks a checkout.
|
|
67
|
+
let root = cwd;
|
|
68
|
+
while (!lstatSync(path.join(root, ".git"), { throwIfNoEntry: false })) {
|
|
69
|
+
const parent = path.dirname(root);
|
|
70
|
+
if (parent === root) {
|
|
71
|
+
root = cwd; // Outside Git, only the invocation directory is in scope.
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
root = parent;
|
|
75
|
+
}
|
|
76
|
+
for (let dir = cwd; dir !== root;) {
|
|
77
|
+
dir = path.dirname(dir);
|
|
78
|
+
const candidate = path.join(dir, "toolring.yaml");
|
|
79
|
+
if (lstatSync(candidate, { throwIfNoEntry: false }))
|
|
80
|
+
return candidate;
|
|
81
|
+
}
|
|
82
|
+
if (bareServer) {
|
|
83
|
+
for (const name of ["tools.yaml", "tools.yml", "toolring.yml", "config2mcp.yaml", "config2mcp.yml"]) {
|
|
84
|
+
if (lstatSync(name, { throwIfNoEntry: false }))
|
|
85
|
+
return name;
|
|
86
|
+
}
|
|
87
|
+
return fileURLToPath(new URL("./default-tools.yaml", import.meta.url));
|
|
88
|
+
}
|
|
89
|
+
throw new Error("No toolring.yaml found. Pass -f <file> or set TOOLRING_CONFIG.");
|
|
90
|
+
}
|
|
91
|
+
function parseArguments(argv) {
|
|
92
|
+
let i = 0;
|
|
93
|
+
const positional = [];
|
|
94
|
+
let commandArgs = [];
|
|
95
|
+
let registryPath;
|
|
96
|
+
let connection;
|
|
97
|
+
let configPath;
|
|
98
|
+
let dryRun = false;
|
|
99
|
+
while (i < argv.length) {
|
|
100
|
+
const arg = argv[i++];
|
|
101
|
+
const afterTool = positional[0] === "call" && positional.length >= 2;
|
|
102
|
+
if (arg === "--") {
|
|
103
|
+
commandArgs = argv.slice(i);
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
else if (arg === "-f" && !afterTool) {
|
|
107
|
+
if (configPath !== undefined)
|
|
108
|
+
usage("-f can be specified only once.");
|
|
109
|
+
configPath = argv[i++];
|
|
110
|
+
if (!configPath || configPath.startsWith("-"))
|
|
111
|
+
usage("-f requires a file path.");
|
|
112
|
+
}
|
|
113
|
+
else if (arg === "--registry" || arg.startsWith("--registry=")) {
|
|
114
|
+
if (registryPath !== undefined)
|
|
115
|
+
usage("--registry can be specified only once.");
|
|
116
|
+
registryPath = arg === "--registry" ? argv[i++] : arg.slice("--registry=".length);
|
|
117
|
+
if (!registryPath || registryPath.startsWith("-"))
|
|
118
|
+
usage("--registry requires a file path.");
|
|
119
|
+
}
|
|
120
|
+
else if (arg === "--connection" || arg.startsWith("--connection=")) {
|
|
121
|
+
if (connection !== undefined)
|
|
122
|
+
usage("--connection can be specified only once.");
|
|
123
|
+
connection = arg === "--connection" ? argv[i++] : arg.slice("--connection=".length);
|
|
124
|
+
if (!connection || connection.startsWith("-"))
|
|
125
|
+
usage("--connection requires a connection alias.");
|
|
126
|
+
}
|
|
127
|
+
else if (arg === "--dry-run") {
|
|
128
|
+
dryRun = true;
|
|
129
|
+
}
|
|
130
|
+
else if (arg === "--help" || (arg === "-h" && !afterTool)) {
|
|
131
|
+
usage();
|
|
132
|
+
}
|
|
133
|
+
else if (arg.startsWith("-") && !afterTool) {
|
|
134
|
+
usage(`Unknown option "${arg}".`);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
positional.push(arg);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const [cmd, ...rest] = positional;
|
|
141
|
+
if (cmd && !["serve", "validate", "inspect", "call"].includes(cmd))
|
|
142
|
+
usage(`Unknown command "${cmd}".`);
|
|
143
|
+
// A bare argument after the tool may be a native subcommand, such as kubectl get.
|
|
144
|
+
const [first, second] = rest;
|
|
145
|
+
const positionalFile = cmd === "call"
|
|
146
|
+
? second !== undefined && !second.startsWith("-") && !second.includes("=") && !second.trimStart().startsWith("{")
|
|
147
|
+
&& (/[/\\]|\.(?:ya?ml|json)$/i.test(first) || (configPath === undefined && statSync(first, { throwIfNoEntry: false })?.isFile()))
|
|
148
|
+
: rest.length > 0;
|
|
149
|
+
if (positionalFile) {
|
|
150
|
+
if (configPath !== undefined)
|
|
151
|
+
usage("Specify the config file only once.");
|
|
152
|
+
configPath = rest.shift();
|
|
153
|
+
}
|
|
154
|
+
if (cmd === "call") {
|
|
155
|
+
if (!rest[0])
|
|
156
|
+
usage("call requires a tool name.");
|
|
157
|
+
}
|
|
158
|
+
else if (rest.length) {
|
|
159
|
+
usage(`${cmd} accepts at most one config file.`);
|
|
160
|
+
}
|
|
161
|
+
if (connection !== undefined && cmd !== "call")
|
|
162
|
+
usage("--connection is only available for call.");
|
|
163
|
+
if (commandArgs.length && cmd !== "call")
|
|
164
|
+
usage("Command arguments after -- require call.");
|
|
165
|
+
return { cmd, configPath, rest: [...rest, ...commandArgs], dryRun, registryPath, connection };
|
|
166
|
+
}
|
|
167
|
+
async function withConsoleOnStderr(run) {
|
|
168
|
+
// Keep module startup logs out of CLI output and MCP stdout.
|
|
169
|
+
const cliConsole = globalThis.console;
|
|
170
|
+
globalThis.console = new Console(process.stderr);
|
|
171
|
+
try {
|
|
172
|
+
return await run();
|
|
173
|
+
}
|
|
174
|
+
finally {
|
|
175
|
+
globalThis.console = cliConsole;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
async function readValidatedConfig(configPath, registry) {
|
|
179
|
+
const cfg = readConfig(configPath, registry);
|
|
180
|
+
const planners = await withConsoleOnStderr(async () => {
|
|
181
|
+
const connections = await prepareConnections(cfg, { configPath, registry });
|
|
182
|
+
return preparePlanners(cfg, { configPath, registry }, connections);
|
|
183
|
+
});
|
|
184
|
+
return { cfg, planners };
|
|
185
|
+
}
|
|
186
|
+
async function main() {
|
|
187
|
+
const argv = process.argv.slice(2);
|
|
188
|
+
if (argv.length === 1 && argv[0] === "--version") {
|
|
189
|
+
process.stdout.write(packageVersion + "\n");
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (argv[0] === "skill" || argv[0] === "skills") {
|
|
193
|
+
const [command, requestedName, ...extra] = argv;
|
|
194
|
+
const name = requestedName ?? (command === "skill" ? "toolring" : undefined);
|
|
195
|
+
if (name === "--help" || name === "-h")
|
|
196
|
+
usage();
|
|
197
|
+
if (extra.length)
|
|
198
|
+
usage(`${command} accepts at most one skill name.`);
|
|
199
|
+
const directory = new URL("../skills/", import.meta.url);
|
|
200
|
+
const names = readdirSync(directory, { withFileTypes: true })
|
|
201
|
+
.filter(entry => entry.isDirectory())
|
|
202
|
+
.map(entry => entry.name).sort();
|
|
203
|
+
if (name === undefined) {
|
|
204
|
+
for (const available of names)
|
|
205
|
+
console.log(available);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (!names.includes(name))
|
|
209
|
+
usage(`Unknown skill "${name}". Run toolring skills to list names.`);
|
|
210
|
+
process.stdout.write(readFileSync(new URL(`${name}/SKILL.md`, directory)));
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const { cmd, configPath: explicitPath, rest, dryRun, registryPath, connection } = parseArguments(argv);
|
|
214
|
+
const configPath = explicitPath ?? discoverConfig(!cmd);
|
|
215
|
+
const registry = registryPath ? await withConsoleOnStderr(() => loadModuleRegistry(registryPath)) : builtinModules;
|
|
216
|
+
// With no subcommand, start an MCP server on stdio.
|
|
217
|
+
switch (cmd ?? "serve") {
|
|
218
|
+
case "call": {
|
|
219
|
+
const cfg = readConfig(configPath, registry);
|
|
220
|
+
const [name, ...tokens] = rest;
|
|
221
|
+
globalThis.console = new Console(process.stderr);
|
|
222
|
+
const result = await callConfiguredTool(cfg, name, tokens, {
|
|
223
|
+
configPath, env: cfg.env, dryRun, registry, connection, stream: streamToStdout,
|
|
224
|
+
});
|
|
225
|
+
if (result.content.length) {
|
|
226
|
+
const output = result.content.flatMap(block => block.type === "text" ? [block.text] : []).join("\n");
|
|
227
|
+
const stream = result.isError ? process.stderr : process.stdout;
|
|
228
|
+
await new Promise(resolve => stream.write(output.endsWith("\n") ? output : output + "\n", () => resolve()));
|
|
229
|
+
}
|
|
230
|
+
// Stdout writes have completed. Flush module diagnostics before exiting even if a pool is still open.
|
|
231
|
+
await new Promise(resolve => process.stderr.write("", () => resolve()));
|
|
232
|
+
process.exit(result.isError ? 1 : 0);
|
|
233
|
+
}
|
|
234
|
+
case "serve": {
|
|
235
|
+
const cfg = readConfig(configPath, registry);
|
|
236
|
+
if (!cmd)
|
|
237
|
+
console.error(`toolring: serving from ${configPath}`);
|
|
238
|
+
if (dryRun) {
|
|
239
|
+
console.error("toolring: --dry-run enabled — tool calls will show what would run.");
|
|
240
|
+
}
|
|
241
|
+
await runStdio(cfg, { configPath, env: cfg.env, dryRun, registry, registryPath });
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
case "validate": {
|
|
245
|
+
const { cfg } = await readValidatedConfig(configPath, registry);
|
|
246
|
+
console.log(`✓ valid — ${cfg.tools.length} tool(s)`);
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
case "inspect": {
|
|
250
|
+
const { cfg, planners } = await readValidatedConfig(configPath, registry);
|
|
251
|
+
for (const warning of policyModuleWarnings(cfg, registry))
|
|
252
|
+
console.error(`toolring: warning: ${warning}`);
|
|
253
|
+
for (const t of cfg.tools) {
|
|
254
|
+
const name = prefixedName(cfg, t);
|
|
255
|
+
let target;
|
|
256
|
+
if (t.command !== undefined)
|
|
257
|
+
target = `${t.command} ${t.args.join(" ")}`;
|
|
258
|
+
else if (t.handler !== undefined)
|
|
259
|
+
target = `Node.js handler ${t.handler}`;
|
|
260
|
+
else if (t.steps !== undefined) {
|
|
261
|
+
target = ["Node.js sequence", ...t.steps.map(({ call, connection }, index) => ` ${index + 1}. ${call}${connection ? ` using connection ${connection}` : ""}`)].join("\n");
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
target = `Node.js module function ${t.call}${t.connection ? ` using connection ${t.connection}` : ""}`;
|
|
265
|
+
}
|
|
266
|
+
console.log(`${name} → ${target}`);
|
|
267
|
+
const schema = buildInputSchema(t);
|
|
268
|
+
for (const [pname, prop] of Object.entries(schema.properties)) {
|
|
269
|
+
const req = schema.required.includes(pname) ? "required" : "optional";
|
|
270
|
+
const type = prop.type === "array" ? "string[]" : prop.type;
|
|
271
|
+
const aliases = t.params.find(p => p.name === pname)?.aliases?.join(", ");
|
|
272
|
+
const en = prop.enum ? ` enum={${prop.enum.join(",")}}` : "";
|
|
273
|
+
console.log(` ${pname}: ${type} (${req})${en}${aliases ? ` aliases=${aliases}` : ""}`);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
for (const [command, owner] of planners.nativeCommands) {
|
|
277
|
+
const binding = owner.connection ? ` using ${owner.connection}` : "";
|
|
278
|
+
console.log(`${command} (native argv) → ${owner.module ?? "generic"} parser${binding}`);
|
|
279
|
+
}
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
main().catch(e => {
|
|
285
|
+
console.error("toolring:", e instanceof Error ? e.message : e);
|
|
286
|
+
process.exit(1);
|
|
287
|
+
});
|
|
288
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACzE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC3F,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAuB,MAAM,cAAc,CAAC;AACvF,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,SAAS,UAAU,CAAC,IAAY,EAAE,QAAwB;IACxD,IAAI,GAAW,CAAC;IAChB,IAAI,CAAC;QACH,GAAG,GAAG,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACnC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,GAAG,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QACvD,OAAO,CAAC,KAAK,CAAC,yBAAyB,IAAI,KAAK,GAAG,EAAE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,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/** A synchronous schema that reports errors with paths, such as a Zod schema. */
|
|
2
|
+
export interface ConnectionSettingsSchema<Settings> {
|
|
3
|
+
safeParse(value: unknown): {
|
|
4
|
+
success: true;
|
|
5
|
+
data: Settings;
|
|
6
|
+
} | {
|
|
7
|
+
success: false;
|
|
8
|
+
error: {
|
|
9
|
+
issues: readonly ConnectionSettingsIssue[];
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export interface ConnectionSettingsIssue {
|
|
14
|
+
path: readonly PropertyKey[];
|
|
15
|
+
message: string;
|
|
16
|
+
}
|
|
17
|
+
/** Export this definition as `connection` from a module with connection settings. */
|
|
18
|
+
export interface ConnectionDefinition<Settings, Client> {
|
|
19
|
+
schema: ConnectionSettingsSchema<Settings>;
|
|
20
|
+
/** Pin environment-derived connection defaults once for command planning and client creation. */
|
|
21
|
+
resolveSettings?(settings: Settings): Settings;
|
|
22
|
+
/** Aliases prepared together receive the same scope for sharing module resources. */
|
|
23
|
+
connect(settings: Settings, scope?: object): Client | Promise<Client>;
|
|
24
|
+
}
|
|
25
|
+
export interface ToolProgress {
|
|
26
|
+
progress: number;
|
|
27
|
+
total?: number;
|
|
28
|
+
message?: string;
|
|
29
|
+
}
|
|
30
|
+
/** Second argument of a Node.js handler or module operation. */
|
|
31
|
+
export interface ToolContext {
|
|
32
|
+
/** Aborted when the request is cancelled or the downstream reader closes. */
|
|
33
|
+
signal: AbortSignal;
|
|
34
|
+
/** Send an update when the MCP client requested progress for the active call. */
|
|
35
|
+
reportProgress(update: ToolProgress): Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
/** Context of a tool operation that declares a connection. */
|
|
38
|
+
export interface ConnectionContext<Client> extends ToolContext {
|
|
39
|
+
connection: Client;
|
|
40
|
+
}
|
|
41
|
+
/** Optional descriptions keyed by the exact names of exported operations. */
|
|
42
|
+
export type { OperationMetadata } from "./config.js";
|
|
43
|
+
/** Output bytes in order. String chunks are encoded as UTF-8. End the iterator to signal EOF. */
|
|
44
|
+
export type ToolOutputStream = AsyncIterable<string | Uint8Array>;
|
|
45
|
+
/** toolring's optional MCP stdout extension, protocol version 1. */
|
|
46
|
+
export declare const stdoutExtension = "io.github.config2mcp/stdout";
|
|
47
|
+
export declare const stdoutNotification = "notifications/io.github.config2mcp/stdout";
|
|
48
|
+
/** Implementations are trusted profile code. Parsing, binding and planning must be side-effect free. */
|
|
49
|
+
export interface CommandInput {
|
|
50
|
+
command: string;
|
|
51
|
+
argv: readonly string[];
|
|
52
|
+
}
|
|
53
|
+
export type CommandDestination = {
|
|
54
|
+
kind: "process";
|
|
55
|
+
argv: readonly string[];
|
|
56
|
+
} | {
|
|
57
|
+
kind: "module";
|
|
58
|
+
call: string;
|
|
59
|
+
args: Record<string, unknown>;
|
|
60
|
+
};
|
|
61
|
+
export interface ModuleCommandAdapter<Parsed, Bound = Parsed> {
|
|
62
|
+
requiresConnection?: boolean;
|
|
63
|
+
parse(input: CommandInput): Parsed;
|
|
64
|
+
/** Resolve defaults and reject explicit connection conflicts before any policy extension runs. */
|
|
65
|
+
bind(parsed: Parsed, settings: Readonly<Record<string, unknown>> | undefined): Bound;
|
|
66
|
+
/** Map a bound invocation to an operation exported by this module. */
|
|
67
|
+
operation(bound: Bound): {
|
|
68
|
+
call: string;
|
|
69
|
+
args: Record<string, unknown>;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/** Adapter contract for profiles with an explicit legacy command backend. */
|
|
73
|
+
export interface CommandAdapter<Parsed, Bound = Parsed> extends Omit<ModuleCommandAdapter<Parsed, Bound>, "operation"> {
|
|
74
|
+
transform(bound: Bound, backend: "process" | "module"): CommandDestination;
|
|
75
|
+
}
|
|
76
|
+
export interface CommandValidation<Bound = unknown> extends CommandInput {
|
|
77
|
+
parsed: Bound;
|
|
78
|
+
connection?: string;
|
|
79
|
+
}
|
|
80
|
+
export type CommandValidator<Bound = unknown> = (invocation: CommandValidation<Bound>) => {
|
|
81
|
+
action: "allow" | "deny" | "confirm";
|
|
82
|
+
reason?: string;
|
|
83
|
+
};
|
|
84
|
+
/** Receives the actual arguments of a named module operation after input defaults. */
|
|
85
|
+
export interface OperationValidation<Args = Record<string, unknown>> {
|
|
86
|
+
call: string;
|
|
87
|
+
connection?: string;
|
|
88
|
+
args: Args;
|
|
89
|
+
}
|
|
90
|
+
export interface OperationValidationContext<Client = unknown> {
|
|
91
|
+
/** Lazily obtain the client of this operation's bound connection. Throws for unbound operations. */
|
|
92
|
+
getClient(): Promise<Client>;
|
|
93
|
+
}
|
|
94
|
+
export type PolicyVerdict = {
|
|
95
|
+
action: "allow" | "deny" | "confirm";
|
|
96
|
+
reason?: string;
|
|
97
|
+
};
|
|
98
|
+
export type OperationValidator<Args = Record<string, unknown>, Client = unknown> = (operation: OperationValidation<Args>, context: OperationValidationContext<Client>) => PolicyVerdict | Promise<PolicyVerdict>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-contract.js","sourceRoot":"","sources":["../src/module-contract.ts"],"names":[],"mappings":"AA8CA,oEAAoE;AACpE,MAAM,CAAC,MAAM,eAAe,GAAG,6BAA6B,CAAC;AAC7D,MAAM,CAAC,MAAM,kBAAkB,GAAG,2CAA2C,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Pretty-print JSON supplied as text. */
|
|
2
|
+
export declare function format({ text }: Record<string, unknown>): string;
|
|
3
|
+
export declare const operationMetadata: {
|
|
4
|
+
format: {
|
|
5
|
+
description: string;
|
|
6
|
+
params: {
|
|
7
|
+
name: string;
|
|
8
|
+
required: true;
|
|
9
|
+
}[];
|
|
10
|
+
example: {
|
|
11
|
+
text: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
};
|