GitHub 0
Skip to content

Definitions

Write MCP servers once and get each agent's own config entry, and check hook files against the format each agent reads.

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 or your program does.

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

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

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

{
  "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}" }
    }
  }
}
mcp.json

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.

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
mcp.json: server "linear" header "Authorization" is a literal; headers may carry secrets, so write the value with a ${VAR} reference
text

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.

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

AgentConfigLocal serverRemote serverReference
claude-code~/.claude.jsontype: "stdio", command, args, envtype, url, headers${NAME}
codex~/.codex/config.tomlcommand, args, env, env_vars, cwdurl, bearer_token_env_var, env_http_headersnone
cursor~/.cursor/mcp.jsontype: "stdio", command, args, envurl, headers${env:NAME}
gemini-cli~/.gemini/settings.jsoncommand, args, env, cwdhttpUrl or url, headers$NAME
github-copilot~/.copilot/mcp-config.jsontype: "local", …, tools: ["*"]type, url, headers, tools${NAME}
grok~/.grok/config.tomlcommand, args, env, cwdurl, type: "sse", headers${NAME}
opencodeopencode.json under mcptype: "local", command: [command, ...args], environmenttype: "remote", url, headers{env:NAME}

The github server above becomes, for Codex:

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

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.
codex: server "api" has a variable in its url, and Codex reads variables only as whole values; skipped
text

mcpEntries returns plain objects. For Codex and Grok, write them as TOML tables with setTomlTable.

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.

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

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

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:

import { parseHookFile } from "skillrc/definitions";

const events = parseHookFile("claude-code", text, "hooks.json");
ts
hooks.json has event "PreTooluse", which claude-code doesn't fire
text

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

{
  "hooks": {
    "PostToolUse": [
      { "matcher": "Edit|Write", "hooks": [{ "type": "command", "command": "fmt", "timeout": 30 }] }
    ]
  }
}
hooks.json
AgentHandler typestimeoutNotes
claude-codecommand, http, mcp_tool, prompt, agentseconds
codexcommand, mcp_toolwhole seconds
grokcommand, httpseconds, 0 allowedmatcher may be a list
gemini-clicommandmillisecondsgroups take sequential
cursorcommand, promptsecondsno 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.

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

AgentWritten to
claude-codeA 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>
grokOne file per definition, ~/.grok/hooks/<program>-<name>.json
gemini-cliMarked groups under hooks in ~/.gemini/settings.json
cursorMarked 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.

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

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" },
  },
};
ts

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.