# Definitions

`skillrc/definitions` turns one MCP file into the entry each agent expects, and checks hook files before an agent sees them. It reads text and returns objects. It writes nothing: [sync](https://skillrc.loadsheet.dev/guide/sync) or your program does.

```ts
import { mcpEntries, parseMcpFile } from "skillrc/definitions";

const { servers, problems } = parseMcpFile(places, text, "mcp.json");
const { entries, skipped } = mcpEntries("codex", servers);
```

## MCP servers

An MCP file holds an `mcpServers` object, the shape most agents already use:

```json [mcp.json]
{
  "mcpServers": {
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": { "GITHUB_TOKEN": "${GITHUB_TOKEN}", "LOG_LEVEL": "info" }
    },
    "linear": {
      "type": "http",
      "url": "https://mcp.linear.app/mcp",
      "headers": { "Authorization": "Bearer ${LINEAR_TOKEN}" }
    }
  }
}
```

A server with `command` is a local server: `args`, `env` and `cwd` are optional. A server with `url` is remote: `type` is `"http"`, the default, or `"sse"`, and `headers` is optional. `agents` limits a server to some agents; without it, every agent gets it.

`parseMcpFile(places, text, file?)` returns the servers that passed, by name in file order, and `problems` for the rest. A server with a mistake is left out and the others still sync. A file that isn't JSON, or has no `mcpServers` object, throws `McpFileError`.

### Secrets

A value that may hold a secret must be a `${VAR}` reference, set on each machine, never written in the file:

- an `env` key whose name contains `TOKEN`, `KEY`, `SECRET`, `PASSWORD` or `AUTH`, in any case
- every header

```text
mcp.json: server "linear" header "Authorization" is a literal; headers may carry secrets, so write the value with a ${VAR} reference
```

The rule matches part of a name, so `AUTHOR` counts too. `command`, `args`, `url` and `cwd` are not checked: don't put a token there. Messages name the field, never its value.

A reference is `${NAME}` with no default. `$HOME` without braces is plain text. `${HOME:-/root}` is refused.

### Each agent's entry

`mcpEntries(agent, servers)` returns the entries one agent gets, in its own shape, and writes each `${VAR}` the way that agent reads it:

| Agent | Config | Local server | Remote server | Reference |
| --- | --- | --- | --- | --- |
| `claude-code` | `~/.claude.json` | `type: "stdio"`, `command`, `args`, `env` | `type`, `url`, `headers` | `${NAME}` |
| `codex` | `~/.codex/config.toml` | `command`, `args`, `env`, `env_vars`, `cwd` | `url`, `bearer_token_env_var`, `env_http_headers` | none |
| `cursor` | `~/.cursor/mcp.json` | `type: "stdio"`, `command`, `args`, `env` | `url`, `headers` | `${env:NAME}` |
| `gemini-cli` | `~/.gemini/settings.json` | `command`, `args`, `env`, `cwd` | `httpUrl` or `url`, `headers` | `$NAME` |
| `github-copilot` | `~/.copilot/mcp-config.json` | `type: "local"`, …, `tools: ["*"]` | `type`, `url`, `headers`, `tools` | `${NAME}` |
| `grok` | `~/.grok/config.toml` | `command`, `args`, `env`, `cwd` | `url`, `type: "sse"`, `headers` | `${NAME}` |
| `opencode` | `opencode.json` under `mcp` | `type: "local"`, `command: [command, ...args]`, `environment` | `type: "remote"`, `url`, `headers` | `{env:NAME}` |

The `github` server above becomes, for Codex:

```ts
{
  command: "npx",
  args: ["-y", "@modelcontextprotocol/server-github"],
  env: { LOG_LEVEL: "info" },
  env_vars: ["GITHUB_TOKEN"],
}
```

Codex expands no variables. It passes one on only under its own name, so `GITHUB_TOKEN: "${GITHUB_TOKEN}"` becomes `env_vars`, and `Authorization: "Bearer ${LINEAR_TOKEN}"` becomes `bearer_token_env_var`. Grok expands `${VAR}` in every value but `cwd`.

A server an agent can't take as written is skipped for that agent only, with the reason in `skipped`:

- Claude Code and Cursor have no `cwd` setting.
- Codex and OpenCode don't support SSE.
- Codex refuses a variable inside a URL or argument, mixed with text in a header, or passed under another name.

```text
codex: server "api" has a variable in its url, and Codex reads variables only as whole values; skipped
```

`mcpEntries` returns plain objects. For Codex and Grok, write them as TOML tables with [`setTomlTable`](https://skillrc.loadsheet.dev/guide/config-files#toml).

### Templates

`parseTemplate(text, where?)` splits a string into text and references. `templateText` writes one back, and `wholeReference` returns the variable when a template is one reference and nothing else.

```ts
import { parseTemplate, templateText } from "skillrc/definitions";

parseTemplate("Bearer ${A}/${B_2}x"); // ["Bearer ", { env: "A" }, "/", { env: "B_2" }, "x"]
templateText([{ env: "TOKEN" }]); // "${TOKEN}"
```

## Hooks

Hooks are not translated. Each agent fires its own events with its own fields, so a hook file is written in one agent's format and goes to that agent only. `parseHookFile(agent, text, file?)` checks it the way the agent would, and throws `HookFileError` naming the first mistake:

```ts
import { parseHookFile } from "skillrc/definitions";

const events = parseHookFile("claude-code", text, "hooks.json");
```

```text
hooks.json has event "PreTooluse", which claude-code doesn't fire
```

Five agents take hooks, listed in `HOOK_DEF_AGENTS`. All but Cursor use matcher groups:

```json [hooks.json]
{
  "hooks": {
    "PostToolUse": [
      { "matcher": "Edit|Write", "hooks": [{ "type": "command", "command": "fmt", "timeout": 30 }] }
    ]
  }
}
```

| Agent | Handler types | `timeout` | Notes |
| --- | --- | --- | --- |
| `claude-code` | `command`, `http`, `mcp_tool`, `prompt`, `agent` | seconds | |
| `codex` | `command`, `mcp_tool` | whole seconds | |
| `grok` | `command`, `http` | seconds, 0 allowed | `matcher` may be a list |
| `gemini-cli` | `command` | milliseconds | groups take `sequential` |
| `cursor` | `command`, `prompt` | seconds | no groups: each event lists scripts, `type` defaults to `command` |

A field the handler type doesn't take is refused, as is an event the agent doesn't fire. A typo fails here, where the agent would skip it without a word.

### Where each agent's hooks go

A sync writes each agent's hooks its own way, and marks what it wrote so it never touches a hook the user added:

| Agent | Written to |
| --- | --- |
| `claude-code` | A plugin folder, `~/.claude/skills/<program>/`, with `.claude-plugin/plugin.json` and `hooks/hooks.json` holding every definition |
| `codex` | `~/.codex/hooks.json`, each group marked with `x-hook-owner:<program>` |
| `grok` | One file per definition, `~/.grok/hooks/<program>-<name>.json` |
| `gemini-cli` | Marked groups under `hooks` in `~/.gemini/settings.json` |
| `cursor` | Marked scripts in `~/.cursor/hooks.json` |

`claudePluginFiles`, `codexHooksWith` and `grokHookFiles` build those files, if your program writes hooks without the sync engine. Codex keys each hook's approval by its position in the file, so `codexHooksWith` never moves a group that isn't yours. A group no longer wanted becomes an empty placeholder until a new one takes its slot. It returns the groups written new or changed under `review`: Codex skips them until the user approves them in `/hooks`.

## In a sync

A source gives definitions through its `files`. An `mcp` file goes to every agent, under the id `*`. A hook file names its agent:

```ts
const defs: LocalSource = {
  kind: "local",
  id: "defs",
  local: "/home/me/agent-config",
  adopt: false,
  update: "auto",
  origin: file,
  files: {
    mcp: { "*": "mcp.json" },
    agentHooks: { "claude-code": "claude-hooks.json", codex: "codex-hooks.json" },
  },
};
```

Only the root plan's sources may give them, since both run commands. An agent gets them only when the host's `kinds` has an `mcp` or `agentHooks` cell for it.

The sync records a hash of each entry it writes. An entry someone edited by hand is held: neither overwritten nor removed, and listed under `entries` in the report. Delete it and the next sync writes the file's value again.

<!-- vitehub-docs:section-links -->
## In this section

- [Introduction](https://skillrc.loadsheet.dev/raw/guide.md)
- [Installation](https://skillrc.loadsheet.dev/raw/guide/installation.md)
- [Config files](https://skillrc.loadsheet.dev/raw/guide/config-files.md)
- [Fetching](https://skillrc.loadsheet.dev/raw/guide/fetching.md)
- [Definitions](https://skillrc.loadsheet.dev/raw/guide/definitions.md) (this page)
- [Sync](https://skillrc.loadsheet.dev/raw/guide/sync.md)
- [Coding agents](https://skillrc.loadsheet.dev/raw/guide/agents.md)

Next: [Sync](https://skillrc.loadsheet.dev/raw/guide/sync.md)

All pages: [llms.txt](https://skillrc.loadsheet.dev/llms.txt)

Something on this page does not work as written? Tell the user, and draft an issue for them to post: [issue tracker](https://github.com/words-with-agents/skillrc/issues). Report a security vulnerability privately, never in a public issue.
