Toolring
# Toolring
[](https://github.com/sudoHackIn/toolring/actions/workflows/ci.yml)
**One ring to scope them all.** Choose which CLI commands and Node.js handlers your agent can call over MCP, and which commands it can compose in Bash pipelines.

```yaml
tools:
- name: probe
description: Probe a media file, return JSON metadata
command: ffprobe
args: ["-print_format", "json", "-show_format"]
params:
- name: input
positional: true
type: string
required: true
```
```bash
npx toolring-mcp serve ./ffmpeg.yaml
```
That's it — your agent now has a `ffmpeg_probe` tool it can call with a
typed, validated `input` parameter.
## Why
Agents are only as useful as the tools you give them. There are thousands of
battle-tested CLIs (`ffmpeg`, `kubectl`, `pdftk`, `imagemagick`, `git`) that
agents cannot reach, and wrapping each one by hand means writing a full MCP
server every time. **toolring makes the wrapper a config file instead of a
project.**
The YAML selects the tools clients can call through this MCP server.
The server sends the [agent instructions (RU)](AGENT-INSTRUCTIONS.ru.md) to MCP
clients during initialization, along with the active profile and external registry
paths when available. Clients with their own project-instructions mechanism can
also reference the copy shipped in the installed toolring-mcp package.
Toolring builds on [config2mcp](https://github.com/linwanwanwa/config2mcp), distributed under the [MIT license](LICENSE).
## Migrating from config2mcp
Change the executable to `toolring` and update explicit management tool names from `config2mcp_*` to `toolring_*` in client settings and tool approval rules. Your profile's tool names and YAML syntax stay the same. Toolring reads `TOOLRING_CONFIG` and still recognizes `CONFIG2MCP_CONFIG` and the old default filenames. The bundled PostgreSQL profiles now reference `TOOLRING_POSTGRES_*` environment variables.
## Install
Until the first Toolring npm release, build from the repository and link the CLI locally:
```bash
git clone https://github.com/sudoHackIn/toolring.git
cd toolring
pnpm install --frozen-lockfile
pnpm build
npm link
toolring --version
```
After publication, install the package from npm:
```bash
# Use directly (recommended)
npx toolring-mcp serve ./my-tools.yaml
# Or install globally
npm install -g toolring-mcp
```
Requires Node 18+.
Run `toolring --version` to print the installed version.
## Quick start
```bash
# 1. Describe your tool
cat > ./echo.yaml <<'EOF'
tools:
- name: shout
description: Print a message in upper case
command: tr
args: ["a-z", "A-Z"]
params:
- name: message
positional: true
type: string
required: true
EOF
# 2. Check what the agent will see
npx toolring-mcp inspect ./echo.yaml
# 3. Validate
npx toolring-mcp validate ./echo.yaml
```
### Reload tools while the server is running
After saving the YAML, call the built-in MCP tool `toolring_reload` with
no arguments. It reads the file that the current server instance started
with and updates the tool list, schemas, and handlers on the existing MCP
connection. The server reads the file at startup and on demand.
The server sends `notifications/tools/list_changed` after applying changes.
Clients can also request the updated list with `tools/list`. Calls in progress
finish with the configuration they started with.
If reload returns an error, fix the YAML and call the tool again. The last
valid configuration stays active. Changes to connection settings or the
module paths used by those connections require a restart.
`toolring_reload`, `toolring_catalog`, and `toolring_call` are reserved tool names.
### Call a tool from the terminal
Use `inspect` to find the published tool name (including its prefix) and its parameters.
Then run `call` with the same profile. From a built checkout:
```bash
node bin/toolring.js inspect examples/git.yaml
node bin/toolring.js call examples/git.yaml git_log repoPath=. count=3
node bin/toolring.js call examples/node.yaml status service=api details=true
```
Pass each parameter as `name=value`. Quote values with spaces. The CLI uses the
declared parameter types, accepts `true` and `false` for booleans, and applies
the tool's defaults to omitted optional parameters. You can also pass a single
JSON object with typed values:
```bash
node bin/toolring.js call examples/node.yaml status '{"service":"api","details":true}'
```
`call` runs one configured command, handler, module function, or sequence and exits.
It writes the result to stdout and diagnostics to stderr. A failed call exits
with a nonzero status. Use `--dry-run` to preview the call or `--registry <path>`
to load the same module registry used by `serve`.
### One-prompt install (let your AI set it up)
Copy the block below, paste it to Claude / Cursor / DSH / any MCP-capable
agent, and it will set everything up for you — package, config, and client
registration. Just tell it which CLI tools you want to expose.
```text
Install the MCP server "toolring" for me. Steps:
1. Create a tools config file at ~/.toolring/tools.yaml that exposes these CLI tools: <list your commands here, e.g. ffmpeg for media conversion, git for repo status>
2. For each tool write: name (snake_case), a one-line description, the command, its args, and typed params (flag / positional / boolean with trueFlag).
3. Config format reference: https://github.com/sudoHackIn/toolring#config-reference — only commands declared in the YAML are reachable (allow-list), keep it read-only if unsure.
4. Validate with: npx -y toolring-mcp validate ~/.toolring/tools.yaml
5. Register the server with your own MCP client config as:
npx -y toolring-mcp serve ~/.toolring/tools.yaml
6. Tell me which tools got registered and how to test one.
```
### Connect to Claude Desktop
Add to `claude_desktop_config.json`:
```json
{
"mcpServers": {
"my-cli-tools": {
"command": "npx",
"args": ["-y", "toolring-mcp", "serve", "/absolute/path/to/echo.yaml"]
}
}
}
```
Works the same with any MCP client (Claude Code, Cursor, Windsurf, ...).
## Node.js handlers
Use `handler` in place of `command` to publish a local `.mjs` module. See
[examples/node.yaml](examples/node.yaml) and its [status handler](examples/tools/status.mjs).
Run the example from a Toolring checkout:
```bash
pnpm install --frozen-lockfile
pnpm build
node dist/index.js serve examples/node.yaml
```
Call `status` from your MCP client with `{"service":"api","details":true}`.
The handler's first argument is an object with the declared, validated
parameters. Optional parameters use their YAML defaults when omitted. Extra
parameters are rejected. The returned string or JSON-serializable value is
sent as MCP text. Load errors and thrown errors return an MCP tool error.
Relative handler paths resolve from the YAML file's directory. Node loads the
module on the first valid call and caches it for the life of the server. Install
any npm dependencies where Node can resolve them from the handler module.
Handlers share the server's working directory and environment. Use the global
`console` or stderr for logs and reserve stdout for MCP traffic.
YAML `env` and the command execution options apply to spawned commands only.
### Stream tool output
Node.js operations can return an async iterable to stream bytes into a Bash pipeline such as `jenkins_logs_tail | grep ERROR`. Independent MCP servers and clients can implement the optional stdout v1 extension for direct calls. [Handler API and wire protocol](TOOL-STDOUT.md)
### Report progress
Node.js handlers and named module functions receive `reportProgress` in their
second argument. A function bound to a connection receives the client in
that same context. TypeScript modules can import `ToolContext`,
`ConnectionContext`, and `ToolProgress` as types from `toolring-mcp/module`.
Use the usual YAML tool definition. In the module, call `await reportProgress(...)`
at the points you want the caller to see, such as after each batch of records.
An ordinary `await` just waits for the underlying operation.
```js
import { setTimeout as wait } from "node:timers/promises";
export default async function ({ service }, { reportProgress }) {
await reportProgress({ progress: 0, total: 2, message: "Starting" });
await wait(250);
await reportProgress({ progress: 1, total: 2, message: "Check complete" });
await wait(250);
return `${service}: ready`;
}
```
Await each update and use increasing `progress` values across the whole tool
call, including across `steps`. `total` and `message` are optional.
The MCP client is the application that calls the tool on the agent's behalf.
It requests updates by including `_meta.progressToken` in its `tools/call`
request. Each `reportProgress` call then sends a standard `notifications/progress`
notification carrying that token, so the client can match updates to the right
call even when several tools run concurrently. If the client omits the token,
`reportProgress` resolves silently. In both cases, the handler's `return`
supplies the final tool result. [MCP progress](https://modelcontextprotocol.io/specification/2025-11-25/basic/utilities/progress)
The client decides how to display updates and whether they extend its timeout.
For example, with a connected TypeScript MCP SDK client, `onprogress` requests
updates and `resetTimeoutOnProgress` restarts the 60-second timer each time
one arrives. [MCP timeouts](https://modelcontextprotocol.io/specification/2025-11-25/basic/lifecycle#timeouts)
```ts
const result = await client.callTool(
{ name: "status", arguments: { service: "api" } },
undefined,
{
onprogress: ({ progress, message }) => console.error(progress, message),
timeout: 60_000,
resetTimeoutOnProgress: true,
},
);
```
## Reusable modules
[Как добавить, собрать и подключить корпоративный модуль (RU)](docs/modules.ru.md)
For an end-to-end package example, see [Author an internal npm module](#author-an-internal-npm-module).
For an installable TypeScript module with seven Postgres MCP Pro operations, see the
[PostgreSQL module](modules/postgres/README.md).
Declare a local `.mjs` module once under `modules`, then select a named export
with `call: alias.function`. Built-in modules are available directly by name.
```yaml
modules:
services: ./tools/status.mjs
tools:
- name: service_status
description: Read the status of a demo service
call: services.status
params:
- { name: service, enum: [api, worker], required: true }
- name: normalize_text
description: Trim and collapse whitespace in text
call: text.normalizeWhitespace
params:
- { name: text, required: true }
```
The module contract is a named JavaScript function export, such as
`export async function status({ service }) { /* … */ }`. Its first argument
contains the validated YAML parameters. It may return a string or a
JSON-serializable value, directly or through a promise. Module functions share
the handler execution behavior described above. Each `tools` entry supplies
its own MCP name, description, and params. The server publishes the functions
selected by those entries.
Local module paths resolve from the YAML file's directory. For unbound tools,
`validate` and `inspect` check aliases and reference syntax. Their first live
call checks that the referenced export exists and is callable. For tools with
a connection, the schema and export are also checked during validation.
A named operation can use a connection provided by another module. For
example, `call: reports.check_db` with `connection: pg_read` loads
`check_db` from `reports` and passes the client for `pg_read` as
`ctx.connection`. If `connections.pg_read.module` is `postgresql`, that
module validates the settings and provides the client. Calls using the same
connection alias share the client. The operation must accept that client's type.
| Built-in function | Parameters | Result |
|---|---|---|
| `text.normalizeWhitespace` | `text` (string) | Text with trimmed edges and collapsed whitespace |
| `json.format` | `text` (JSON string) | Indented JSON text |
The aliases `text` and `json` are reserved. See [examples/modules.yaml](examples/modules.yaml)
for a runnable configuration with a local module and both built-ins.
### Discover modules from an MCP client
Call `toolring_catalog` with `{}` to list the available aliases. This reads
the active registry and local YAML module names without running their loaders.
Call it again with an alias such as `{"module":"postgres"}` to inspect its
named function exports. This can import the chosen module and run its top-level
initialization. Discovery does not invoke its operations or call `connect`.
Each entry gives the YAML `call`, its directly published MCP names
(`publishedAs`), and any tools using it in a sequence (`usedInSteps`). The
response also lists configured connection names. To document an operation before
publication, export an optional `operationMetadata` object from the module entry
point. Key it by the exact function export name and give each entry a
`description`, optionally with YAML-style `params` and an `example` argument
object. TypeScript packages can generate this export during their own build using
[TSDoc and the catalog generator](packages/catalog-gen/README.md).
The catalog returns those fields alongside the operation. See the
[typed module example](docs/modules.ru.md). Use `tools/list` for the input
schema published by the active profile.
### Call a module function directly with `toolring_call`
Starting in **0.2.0**, an operator can enable direct calls to named function
exports from built-in modules, the shared registry and local YAML modules.
The default is off. Set the top-level YAML boolean `allow-unpublished-tools: true`
to register `toolring_call`, even when `tools: []`.
To try the Jenkins fixture from a built checkout, save this as
`examples/jenkins/discovery.yaml` and start
`node bin/toolring.js serve examples/jenkins/discovery.yaml` from your MCP client.
```yaml
allow-unpublished-tools: true
modules:
jenkins: ./jenkins.mjs
tools: []
```
Call `toolring_catalog` with `{"module":"jenkins"}` to find the export, then
send these parameters to MCP `tools/call`:
```json
{"name":"toolring_call","arguments":{"call":"jenkins.getJobInfo","args":{"job":"mobile/app"}}}
```
| Argument | Value |
|---|---|
| `call` | Required. Exact `module.function` from the catalog. |
| `args` | JSON object passed to the function. Defaults to `{}`. |
| `connection` | For a bound function, a connection alias listed for that module in the active profile. |
The server awaits the function and returns its result in `content[0].text`.
Objects and arrays are rendered as JSON. A failed operation sets `isError: true`.
In the fixture, `property[0].parameterDefinitions` gives the branch default
(`main`), target choices (`android` or `ios`, default `android`), and the
boolean `runTests` (default `true`).
The [build profile](examples/jenkins/tools.yaml) uses these definitions for
`build_app`. To switch to it in the same session, copy its contents into the
active `discovery.yaml`, run `node bin/toolring.js validate examples/jenkins/discovery.yaml`,
then call `toolring_reload` with `{}`. The build profile omits the flag, so
`tools/list` now includes `build_app` and the server rejects further calls to
`toolring_call`. An explicit `false` has the same effect.
By default, direct calls can invoke any named function export with their own
arguments. To limit them, add a top-level `call-policy` to the server profile.
For example, with the PostgreSQL registry and connections from the
[guarded profile](modules/postgres/guarded.yaml):
```yaml
allow-unpublished-tools: true
call-policy:
default: deny
rules:
- call: postgres.describeTable
connection: pg_read
action: allow
allowed-args: [table]
when: { table: orders }
- call: postgres.execute_update
connection: pg_update
action: confirm
allowed-args: [sql]
```
In this example, a direct call to `postgres.describeTable` must supply exactly
`{"table":"orders"}` on `pg_read`. A different table, an extra argument, DDL,
general SQL and SQL files all receive a policy error. For an UPDATE, the MCP
client prompts with the connection and the complete SQL batch on every invocation.
- A rule names an exact `module.export` or all callable exports of one module with `module.*`, including future exports. Omitting `connection` matches all bindings, including an unbound call.
- An exact name takes precedence over `module.*` regardless of rule order. If any rules name that export, only those rules are considered. If none of them match the connection and arguments, the policy uses `default`.
- `allowed-args` lists the only argument names a matching call may supply. An empty list requires zero arguments. Omit the field to allow any keys.
- `when` requires each named argument to be present with the specified JSON value. Types, nested values and array order participate in equality. These arguments can be absent from every published tool schema.
- Matching rules take precedence in the order `deny`, `confirm`, `allow`. Unmatched calls use `default`. An empty policy defaults to `deny`. Use `call-policy: {default: confirm}` to prompt for every call through `toolring_call`.
The default scope is `toolring_call`. Both `default` and `rules` apply only
to the generic caller. You can publish the same operation as a named tool
with a narrower input schema, even when direct calls to it are denied.
With explicit `scope: all`, the server checks direct calls, published module
tools (including CLI calls) and every step in a sequence. Published tools apply schema defaults
first. A sequence prompts once with its ordered calls and shared arguments.
Approval applies only to that invocation. Declining, cancelling, using the
one-shot CLI or using an MCP client without form elicitation blocks execution
when confirmation is required. Dry runs skip the prompt and honor denials.
Use a server build that supports `call-policy`. Older builds can ignore unknown
YAML keys. The profile, registry, module code and MCP client are trusted.
Keep them under operator control when the agent has filesystem tools. The policy
covers named module dispatch. Shell commands and local handlers have their own
permissions.
### Install a shared registry
A separate npm package can supply modules for several profiles. Install the
registry package alongside `toolring-mcp`, with the operation packages listed in
the registry package's `dependencies`. Include a file such as `registry.mjs`
in the registry package:
```js
export default {
jenkins: () => import("@company/jenkins-tools"),
postgres: () => import("@company/postgres-tools"),
};
```
Set `--registry` once in the MCP server's launch arguments:
```bash
npx toolring-mcp serve ./profile.yaml --registry ./node_modules/@company/mcp-modules/registry.mjs
```
The profile can use `call: jenkins.buildStatus` directly in a tool entry with
its name, description, and params. The registry's default export maps
snake_case aliases to loader functions that resolve to modules with named
exports. Node resolves package imports from the registry's own location.
Aliases must be unique across the built-in modules, the shared registry, and
the profile's `modules` map.
`serve`, `call`, `validate`, and `inspect` accept `--registry`. A relative registry
path resolves from the current working directory. The registry file is trusted
JavaScript evaluated at startup. Put imports inside the registered loader
functions. The server loads modules when it needs to validate their connection
schemas or invoke their functions. `tools` selects which functions are published
through MCP.
Try the shared registry from a built checkout with
`node dist/index.js serve examples/preloaded.yaml --registry examples/registry.mjs`.
### Configure a connection
An operation package can export a `connection` definition containing `schema`
and `connect(settings)`. The schema implements synchronous `safeParse`, as
Zod schemas do. It receives the settings under the connection alias, with
the `module` selector removed. `connect` receives the validated settings,
including any defaults applied by the schema. For TypeScript modules, import
`ConnectionDefinition<Settings, Client>` and `ConnectionContext<Client>` as
types from `toolring-mcp/module`.
```yaml
connections:
jenkins_read:
module: jenkins
url: https://jenkins.company.example
tokenEnv: JENKINS_READ_TOKEN
tools:
- name: build_status
description: Read the latest build status
call: jenkins.buildStatus
connection: jenkins_read
params:
- { name: job, enum: [billing, catalog], required: true }
```
Here the module's schema defines `url` and `tokenEnv`. The module can read the
named environment variable in `connect`. A bound function receives
`(params, { connection })`, where `connection` is the client returned by
`connect`. Only the declared `params` appear in the MCP input schema.
`validate`, `inspect`, and server startup load connection schemas and report
errors with paths such as `connections.jenkins_read.url`. Keep module imports
and schema validation free of service calls. The server creates a client on
the first live call that needs it and shares it across tools bound to the same
alias. If initialization fails, MCP reports the connection alias and a later
call can retry. Modules can write sanitized diagnostic details to stderr.
The [connection example](examples/connections.yaml) uses a [local fixture](examples/tools/demo-service.mjs).
Run it from a built checkout with
`TOOLRING_DEMO_TOKEN=demo node dist/index.js serve examples/connections.yaml`.
### Author an internal npm module
**1. Package the operations.** An operation module is an ordinary Node.js
package with an ES module entry point. Start with the runnable
[demo service module](examples/tools/demo-service.mjs) as `index.mjs`:
```json
{
"name": "@company/service-tools",
"version": "0.1.0",
"exports": "./index.mjs",
"files": ["index.mjs"],
"dependencies": { "zod": "^3.25.0" }
}
```
The example exports `status({ service }, { connection })` and a `connection`
definition. Its Zod schema declares a URL and the name of an environment
variable. In your package, put the real client setup in `connect(settings)`
and use that client inside each named operation. Zod's `.strict()` reports
unrecognized settings. A module that only
exports standalone operations can use `operation(params)` by itself.
For a TypeScript package, use `ConnectionDefinition` to check the schema and
factory together. Ship the compiled ES module as the package's export.
```ts
import type { ConnectionContext, ConnectionDefinition } from "toolring-mcp/module";
import type { z } from "zod";
// schema is your Zod schema. ServiceClient is the client your factory creates.
export const connection = {
schema,
connect: createServiceClient,
} satisfies ConnectionDefinition<z.infer<typeof schema>, ServiceClient>;
export function status({ service }: { service: string }, { connection }: ConnectionContext<ServiceClient>) {
return connection.status(service);
}
```
**2. Register the package once.** In your shared registry package, add
`@company/service-tools` to `dependencies`, include `registry.mjs` in `files`,
and add this alias to the file's default export:
```js
export default {
services: () => import("@company/service-tools"),
};
```
Run `npm pack --dry-run` in each package to check which files it ships. Install
the registry alongside a build of `toolring` that supports `--registry`.
**3. Write and validate a profile.** A profile using the shared registry can
declare the connection and tool directly:
```yaml
connections:
demo_read:
module: services
url: https://status.company.example
tokenEnv: TOOLRING_DEMO_TOKEN
tools:
- name: service_status
description: Read the status of a demo service
call: services.status
connection: demo_read
params:
- { name: service, enum: [api, worker], required: true }
```
```bash
toolring validate ./profile.yaml --registry ./node_modules/@company/mcp-modules/registry.mjs
toolring inspect ./profile.yaml --registry ./node_modules/@company/mcp-modules/registry.mjs
```
`validate` reports connection setting errors by YAML path. `inspect` shows
the published tools and their parameters. For a live test with the demo
module, set `TOOLRING_DEMO_TOKEN=demo`, run `serve` with the same profile and
registry, and call `service_status` with `{"service":"api"}` over MCP.
### Run a sequence of module calls
A `steps` list publishes an ordered sequence as one MCP tool.
```yaml
tools:
- name: refresh_status
description: Refresh and read the demo service status
params:
- { name: service, enum: [api, worker], required: true }
steps:
- call: services.refresh
- call: services.status
```
Each step takes a `call` and an optional `connection` for that module. The
server checks the tool's arguments once, passes the same input values to
each step, and awaits each call before starting the next. Only the last step's
result is sent to the agent. The server resolves all named exports before
running the first step. If a step throws or rejects, the tool error names the
step and the sequence stops. Completed steps retain their effects. `inspect`
and `--dry-run` show the configured order.
Try [the sequence example](examples/steps.yaml) from a built checkout with
`node dist/index.js serve examples/steps.yaml`.
### Pipe commands and tools with `run_bash`
The optional top-level `bash-policy` publishes the MCP tool `run_bash`.
Start the [local Jenkins fixture](examples/pipeline.yaml) with
`toolring serve examples/pipeline.yaml`. With Bash, printf and jq on the
server's PATH, send this MCP tool call:
```json
{"name":"run_bash","arguments":{"script":"printf '%s' '{\"name\":\"mobile/app\"}' | jq -r '.name' | jenkins_build --job @stdin"}}
```
The returned JSON is the fixture's build preview. Bash streams adjacent
external processes together with `pipefail`. A published tool name, including
its configured prefix, invokes its existing handler. A name from the management
interface cannot be invoked as a stage. The agent receives the last stage's result.
`grep` exit status 1 means no matches. The stage succeeds and forwards its stdout,
which is usually empty. Other command failures still fail the pipeline.
With `allow-unpublished-tools: true`, use the exact `module.function` name
from `toolring_catalog` as a stage. Both `bash-policy` (under that stage
name) and the direct `call-policy` apply. For example, a profile that allows
both Jenkins operations can run:
```bash
jenkins.getJobInfo --job mobile/app --field fullName | jenkins.buildJob --job @stdin
```
Named flags pass strings to the function. Use one quoted JSON object for
typed arguments, or pipe a JSON object into a stage with no argument flags.
Use `--connection ALIAS` for operations that need a configured connection.
```yaml
bash-policy:
default: deny
rules:
- { command: jq, argv: [-r, .name], action: allow }
- { command: jenkins_build, action: confirm }
```
Use `bash-policy.rules[].when` to test only the options or subcommand you care about. Combine `subcommand` and `option` predicates with `not`, `anyOf`, and `allOf`. An option lists its aliases and accepts either `equals` or `oneOf`. A malformed or ambiguous invocation is denied. See the [complete profile](examples/bash-when.yaml) and [condition reference](docs/bash-policy.ru.md#условия-when-для-внешних-команд).
External command argument slots can also use `{ startsWith: "prefix" }` (a nonempty literal prefix of one argument), `{ oneOf: [...] }` or `{ jsonPatch: { paths: [...] } }` to check a full JSON Patch argument. Use `match.positionals` and `match.flags` to allow a CLI invocation independently of flag order. Each flag lists its accepted names and value, for example `{ names: [-n, --namespace], required: true, value: mobile }`. Unknown and duplicate flags fail the match.
For CLIs with a subcommand, target and named `key=value` arguments, use `match.subcommand`, `match.target` and `match.assignments`. In this form, command-wide option guards apply to every operation and their aliases are recognized alongside the operation's own flags. See the [deployment image profile](examples/deployment-image.yaml).
The [scoped writes profile](examples/scoped-writes.yaml) restricts kubectl fields, PostgreSQL DML targets and Jenkins jobs. The [policy guide (RU)](docs/bash-policy.ru.md) covers the working configuration and proposed extensions.
An `argv` rule matches the command name and its **entire** argument vector
after unquoting. For tool stages the runner normalizes named flags to
`--name=value` in both the call and rule, preserving their order. Output
selectors are excluded from matching. Omitting both `argv` and `match` matches all arguments. `argv: []` matches
zero arguments. Matching decisions have precedence `deny`, `confirm`,
`allow`. An unmatched invocation uses `bash-policy.command-defaults[command]` when present, then the global `default` (initially `deny`). For example, combine `default: allow` and `command-defaults: { kubectl: deny }` with explicit `kubectl` allow rules. Setting `default: allow` grants execution of arbitrary executables
on the server's PATH. An allowed external program runs with the server's OS
permissions and interprets its own flags, stdin and any child commands.
These rules do not sandbox programs or inspect Kubernetes manifests.
The runner checks every stage before starting the pipeline. A command-wide
`deny` rule vetoes the entire `run_bash` request, including when a more
specific `allow` rule matches the same command and arguments. Put `default: deny`
in the policy to allow a command only for the argument vectors listed in its
`allow` rules.
Supply known variables in the optional `vars` object of the MCP request. For
example, the Jenkins profile accepts the following:
```json
{"name":"run_bash","arguments":{"script":"jenkins_info --job \"$JOB\" --field fullName","vars":{"JOB":"mobile/app"}}}
```
The runner resolves `$JOB` or `${JOB}` in argument positions before checking
the whole pipeline. It passes those same argv values to the executor. A
different job fails the example profile's exact-argv rule. Names must be
literal commands. Variable lookup uses only the supplied `vars` object.
Double quotes preserve a single argument, including an empty string or
spaces. Single quotes and an escaped dollar sign preserve the literal dollar.
Use a standalone, unquoted `@stdin` to take one argument from the previous
stage, for example `jq -r '.namespace' | kubectl get pods -n @stdin`.
The runner waits for the producer to succeed and accepts one nonempty UTF-8
line, with an optional final LF or CRLF. Spaces and shell punctuation stay in
that argument. Repeating the marker reuses the same line, up to 256 KiB of
resolved arguments per marked stage. Quote `'@stdin'`
to pass the literal text. A process using the marker receives empty stdin.
Other adjacent process stages continue to stream through ordinary pipes.
For a marked stage, the runner checks the command and known arguments before
starting the pipeline, then checks the exact resolved arguments before starting
that stage. A `confirm` decision shows the resolved invocation for approval.
Published tools also enforce their input schema, `command-policy` and applicable
`call-policy`. A value derived from stdin is validated when it arrives.
Earlier completed stages retain their effects if validation or execution
later fails. Pass `dryRun: true` alongside `script` in a `run_bash` call to preview each stage, its policy decision and the reason. The preview returns `structuredContent.stages` without executing or asking for approval. A downstream stage needing stdin is marked `pending` until an actual run supplies the value. Starting the server with `--dry-run` forces previews even if the caller passes `dryRun: false`.
#### Published tool input and output
The following pipeline uses the same Jenkins fixture. It reads a job, passes
its full name into the build tool and returns just the branch from the preview.
```bash
jenkins_info --job mobile/app --field fullName | jenkins_build --job @stdin --branch main --runTests --field /parameters/branch
```
| Input or output | Contract |
|---|---|
| Named arguments | Use `--job mobile/app` or `--job=mobile/app`. The published schema determines the type. A bare boolean flag means true. Use `--runTests=false` for false. Quote values containing spaces. |
| JSON arguments | A single quoted JSON object supplies all explicit arguments, including a parameter literally named `field`. Output flags may accompany it. |
| Tool stdin | Use `--name @stdin` to bind a line to a typed flag. Without a marker the tool consumes a JSON argument object, or one line for the configured string parameter if the profile supplies a `bash-policy.stdin` binding. Supplying the bound parameter twice or receiving multiple lines fails. Each stage invokes the tool once. |
| Tool stdout | The runner serializes `structuredContent` as JSON when present. Otherwise it forwards the single text block verbatim. Ambiguous or non-text content fails the pipeline. |
| Last stage | An external process returns stdout. A published tool returns its original MCP result unless an output selector requests a projected value. Tool errors stop the pipeline before the next stage. |
`--field` reads from structured output or from a text block containing JSON.
A top-level key (`--field fullName`) or slash path (`--field /items/0/name`)
selects one value. A string is passed as raw text. Numbers, booleans, null,
arrays and objects are emitted as JSON. In slash paths, `~1` denotes a
literal slash and `~0` denotes a literal tilde in a key.
To produce a JSON argument object, give each selection a distinct alias:
```bash
jenkins_info --job mobile/app --field job=/fullName --field branch=/property/0/parameterDefinitions/0/defaultParameterValue/value
```
The result is `{"job":"mobile/app","branch":"main"}`. It can feed a tool
configured to consume a JSON object. A missing path is an error, including
when the next tool would otherwise accept an empty value. External commands
receive their own flags verbatim.
Supported shell syntax includes literal words, single and double quotes,
backslash escapes, and up to 32 stages separated by unquoted pipes.
Command substitutions, redirects, shell lists and assignments are unsupported.
The runner supplies each validated word as a separate Bash argument.
Each group of external processes has a 30-second timeout and a combined
256 KiB limit on captured stdout and stderr. Intermediate process pipes stream;
published tool boundaries exchange UTF-8 text.
## Config reference
| Field | Type | Default | Description |
|---|---|---|---|
| `allow-unpublished-tools` | boolean | `false` | Expose `toolring_call` for direct calls to module exports |
| `call-policy` | object | omitted | Rules and default action for named module calls. An omitted policy permits calls reachable through the profile. |
| `bash-policy` | object | omitted | Publish `run_bash` with pipeline stage rules and optional tool stdin bindings. |
| `prefix` | string | — | Tool name prefix, e.g. `ffmpeg` → `ffmpeg_probe` |
| `env` | map | — | Extra env vars for every spawned command |
| `modules` | map | — | Snake_case aliases for reusable local `.mjs` modules |
| `connections` | map | — | Named settings validated by the selected module's schema |
| `tools` | array | *required* | The tools to expose |
### Tool fields
Choose exactly one of `command`, `handler`, `call`, and `steps` per tool.
| Field | Type | Default | Description |
|---|---|---|---|
| `name` | string | *required* | snake_case tool name |
| `description` | string | *required* | What the tool does — the agent reads this |
| `command` | string | — | Executable to run (resolved from PATH) |
| `handler` | string | — | Local `.mjs` file with a default function export |
| `call` | string | — | Named function export in a local, registered, or built-in module, in `alias.function` form |
| `connection` | string | — | For `call` tools, name of a configured connection whose client is passed to the function |
| `steps` | array | — | Ordered list of module calls, each with `call` and optional `connection` |
| `args` | array | `[]` | Command-only. Literal argv tokens before any params |
| `params` | array | `[]` | Typed parameters (below) |
| `cwd` | string | — | Command-only. Working directory |
| `timeoutMs` | number | `30000` | Command-only. Kill the process after this long (max 600000) |
| `jsonOutput` | boolean | `false` | Command-only. Parse stdout as JSON into structured content |
| `includeStderr` | boolean | `false` | Command-only. Also return stderr on success |
### Param fields
| Field | Type | Default | Description |
|---|---|---|---|
| `name` | string | *required* | lowerCamelCase parameter name |
| `description` | string | auto | Agent-facing description |
| `type` | `string\|number\|boolean` | `string` | Value type. Node tools also accept `"string[]"` for a nonempty array of strings. |
| `required` | boolean | `false` | Agent must provide it |
| `flag` | string | — | Command-only. CLI flag, e.g. `-i` or `--format` |
| `equalsForm` | boolean | `false` | Command-only. Emit `--flag=value` instead of `--flag value` |
| `trueFlag` | string | — | Command-only. Token emitted when a boolean is true |
| `positional` | boolean | `false` | Command-only. Pass value as positional arg (in declaration order) |
| `placement` | `global\|local` | `local` | Command-only. `global` puts the flag right after the executable (e.g. `git -C <path> log`) |
| `enum` | array of strings | — | Allowed values for a `string` parameter |
| `default` | `string\|number\|boolean` | — | Used when the agent omits an optional param. For `"string[]"`, supply a nonempty array of strings. |
For `call`, `handler`, and `steps` tools, the server rejects extra input fields. A
parameter default must match its type and any enum. The module's own schema
defines the shape of `connections` settings and can include nested objects
and arrays.
## Docker
```bash
docker build -t toolring .
# mount your own config over the bundled safe default
docker run -i --rm -v $PWD/tools.yaml:/config/tools.yaml:ro toolring
```
## Trying it safely
Want to see exactly what an agent could run before granting anything?
```bash
toolring serve ./ffmpeg.yaml --dry-run
```
Each call shows the exact argv for a command, the resolved path for a Node.js
handler, or the configured `alias.function` references in order. `--dry-run`,
`validate`, and `inspect` read the registry and any configured connection
schemas. They leave connection clients unopened. Unbound operation modules
are loaded on their first live call.
## Security model
For command tools:
- **Local execution.** The runner spawns the configured executable directly.
Each argument is a separate argv token. The executable determines how it
interprets those arguments, including any remote shell processing by SSH.
- **Configured invocations.** The YAML selects the commands and how the
declared parameters become argv tokens.
- **Bounded by design.** Every command has a timeout (default 30 s) and
captured output is capped at 256 KiB to protect the agent's context window.
- **Failures are data, not exceptions.** Non-zero exits and timeouts are
returned to the agent as readable results, so it can react.
You are still responsible for *which* commands you expose: an agent with
access to `rm` can remove files. Expose read-only subcommands (see
[examples/git.yaml](examples/git.yaml) for a deliberately read-only git set).
Node.js handlers, local modules, and their dependencies are trusted operator
code. Keep the YAML and code outside agent-writable locations. The function
enforces which resources and actions its inputs can select. It runs with the
full permissions of the process running the tool through MCP or the CLI.
### Project-scoped SSH commands
Keep the tool definitions in the project's YAML profile and start the project's
MCP server with that file. For example, `toolring serve examples/billing-ssh.yaml`
publishes `billing_restart_api` with zero parameters. Its SSH destination and
the full remote command `systemctl --user restart billing-api.service` are
fixed in YAML. The unit name selects the project service within the remote
user's systemd manager. The companion tool `billing_service_state` accepts a
unit from a two-value enum, so the same profile can grant read access to both
units while granting restart access only to the API.
Both tools invoke OpenSSH with the same project-specific control socket under
the local user's private `~/.ssh` directory. OpenSSH reuses the established
connection and keeps it for five minutes after the last channel closes.
Replace the example destination and units, use a distinct socket prefix for
each project, and provision the verified host key and noninteractive SSH
authentication for the account running the MCP server.
[OpenSSH connection sharing](https://man.openbsd.org/ssh_config#ControlMaster)
OpenSSH passes the remote command through the remote user's shell. Keep
command words and flags fixed, and use exact enums of shell-safe literals for
selectable arguments, as in the unit selector below.
[Billing project profile](examples/billing-ssh.yaml)
## Examples
- [examples/billing-ssh.yaml](examples/billing-ssh.yaml) — project-scoped SSH commands for systemd user services
- [examples/ffmpeg.yaml](examples/ffmpeg.yaml) — media probing & conversion
- [examples/git.yaml](examples/git.yaml) — a read-only git window
```bash
npx toolring-mcp inspect examples/ffmpeg.yaml
```
## Development
Use the pnpm version pinned in `package.json`. The workspace contains the CLI at
the root and independently packable operation packages under `modules/*`.
```bash
pnpm install --frozen-lockfile
pnpm build # compile the CLI and its module contract, then the operation packages
pnpm test # core unit tests
node scripts/e2e.mjs # full MCP protocol test over stdio
```
CI runs the unit suite on a 3-OS × 4-Node matrix and the E2E protocol test
on all three OSes.
### Publishing the CLI
Run **Actions → Release → Run workflow** on `main` to build and test the CLI.
Download the `npm-package` artifact and unzip it to get the tested tarball.
For the first release, sign in with `npm login` and publish that tarball
(for example, `npm publish ./toolring-mcp-0.7.0.tgz --access public`).
Then, in the npm settings for `toolring-mcp`, add a GitHub Actions trusted
publisher with owner `sudoHackIn`, repository `toolring`, workflow filename
`release.yml`, and permission to run `npm publish`. Leave the environment
field empty. Set this up when the next version is ready, as npm requires
the first successful trusted publish within two days of configuration.
[npm trusted publishing](https://docs.npmjs.com/trusted-publishers/)
For each subsequent release, commit a new version in the root `package.json`
and push its matching tag (for example, `git tag v0.7.1 && git push origin v0.7.1`).
The workflow publishes the tested tarball to npm using OIDC and attaches it to
a GitHub Release. Stable versions receive the `latest` dist-tag and prereleases
receive `next`.
## License
MIT
TDQS
Scored across 3 tools
Each tool has a clearly distinct role: files_list enumerates directory contents, toolring_catalog inspects module aliases/operations, and toolring_reload refreshes YAML-defined tools. toolring_catalog has multiple inspection modes, but it does not overlap with the other tools.
All names use snake_case with a namespace/resource + action pattern (files_list, toolring_catalog, toolring_reload). The files_ prefix differs from the toolring_ prefix and 'catalog' is a less common verb, but the convention remains predictable.
Three tools are proportionate: one filesystem discovery tool plus two management tools for catalog inspection and reload. Each has a clear place and the surface is not bloated.
The lifecycle covers discovering files, inspecting the catalog, and reloading YAML-defined tools. However, there is no tool to read, edit, validate, or create the YAML file itself, leaving a notable gap for agents that need to modify configurations.