This guide wraps a local Filesystem MCP server with ToolFence. Codex launches ToolFence over stdio; ToolFence then launches the upstream server.
npm install -g toolfence-mcp
cd /absolute/path/project
toolfence policy init
toolfence policy check --policy ./toolfence.yamlReview the generated policy before connecting it to a host. It is conservative and will not overwrite an existing file.
Add the following to ~/.codex/config.toml, or to .codex/config.toml in a trusted project:
[mcp_servers.filesystem]
command = "toolfence"
args = [
"wrap",
"--policy", "/absolute/path/project/toolfence.yaml",
"--server", "filesystem",
"--workspace", "/absolute/path/project",
"--",
"npx", "-y", "@modelcontextprotocol/server-filesystem", "/absolute/path/project",
]
cwd = "/absolute/path/project"
required = trueCodex supports command, args, and cwd for stdio MCP servers. Project-scoped configuration is loaded only after the project is trusted. See the Codex configuration reference.
Use absolute paths. If Codex cannot find toolfence, replace the command with the absolute path printed by which toolfence.
ToolFence uses its local Broker for ask decisions:
toolfence brokerIn a second terminal:
toolfence approvalsRestart Codex after changing MCP configuration. Run toolfence doctor --policy /absolute/path/to/toolfence.yaml -- <the configured upstream command> to validate the Policy, Broker permissions, and upstream startup before reconnecting.
- An unavailable or disconnected Broker causes
askdecisions to fail closed. - ToolFence writes diagnostics to stderr and reserves stdout for MCP JSON-RPC.
- ToolFence policies supplement the host's own approvals; keep both layers enabled when you want defense in depth.
- ToolFence currently wraps local stdio servers. It does not wrap Codex HTTP MCP connections.