Skip to main content
On this page

Install

Append this block to ~/.codex/config.toml. Both the CLI and the desktop app read from the same config.

~/.codex/config.toml
[mcp_servers.preset]
url = "https://mcp.presetai.dev/mcp"

Authorize

OAuth happens automatically on the first tool call. CLI and desktop both read this same config. Tokens refresh automatically.

You're set

OpenAI Codex now calls validate_code, resolve_value, and get_active_constraints as it writes UI code. See the section below to tell OpenAI Codex when to use preset AI.

Using preset AI with OpenAI Codex

Codex generates and edits code. preset AI makes that code design-system-aware.

OpenAI Codex is a coding agent available as a CLI binary, a desktop app, and an IDE extension — all sharing the same configuration. On its own, Codex’s agent reads your repo and writes code, but it has no vocabulary for your design system: it sees bg-[#0a0a0a] and might propose semantic-looking alternatives that don’t actually exist in your token catalog. Connect preset AI’s MCP server and Codex now validates against your tokens, cites your rules by name, and proposes fixes from your canonical preset library.

Codex’s agent does not automatically prefer MCP tools when your repo already has design-system documentation in AGENTS.md or CLAUDE.md. To make sure the agent calls preset AI on UI work, append this block to your project’s AGENTS.md (or create one if it doesn’t exist):

## preset AI MCP — design system enforcement

When working on UI components, Tailwind classes, CSS, or design tokens:

1. Before writing or suggesting UI code, call `validate_code` from the preset AI
   MCP server to check it against the active design system. Cite the returned
   `ruleId` and `fix` fields verbatim in your response.
2. When the user shares a hex color, px value, or arbitrary Tailwind value
   (e.g. `bg-[#0a0a0a]`, `p-[17px]`), call `resolve_value` to get the
   canonical token name or closest alternatives.
3. When generating new components or files, call
   `get_active_constraints(filePath)` first to learn path-scoped rules.
4. Before introducing a new utility or class, check `get_forbidden_primitives()`.

Always cite preset AI rule names (e.g. `no-uppercase`, `no-inline-hex-color`,
`ai-slop-arbitrary-spacing`) when explaining design system violations.

This pattern was validated on Cursor (using .cursor/rules/preset.mdc) and is the recommended Codex equivalent. It auto-attaches when Codex reads AGENTS.md at the start of a session.

What Codex + preset AI catches

Tested end-to-end. Sample violations and the agent’s response when validate_code fires:

Violationpreset AI MCP returnsCodex agent renders
<div className="bg-[#0a0a0a]">no-inline-hex-color, severity: warning, fix: “Use CSS variable""Hit on #0a0a0a — use var(--color-surface)
<span className="uppercase tracking-widest">BETA</span>no-uppercase, hits on uppercase and tracking-widest (normalized to tracking-wide rule family)“Use sentence case + size/weight hierarchy: text-xs font-medium text-[var(--color-text-secondary)]
<div className="p-[17px]">ai-slop-arbitrary-spacing, forbidden_primitive”Off-grid spacing — use p-4 from the spacing scale”
style={{ backgroundColor: '#00aaff' }}no-inline-hex-color”Saturated cyan #00aaff is specifically out of system”

The agent renders structured violations from preset AI (rule, found, fix, severity, line, ruleId) inline and typically follows up with a token-compliant rewrite.

How it works

OAuth vs API key

The MCP server supports both authentication methods:

OAuth (recommended) — Each Codex user authenticates individually against preset AI. Tokens refresh automatically. Codex implements OAuth metadata discovery, so the bare url = "..." config is enough — no client registration step required. Best for individuals and teams.

API key (Bearer) — Generate a pk_live_* key at preset.dev/api, set it as an environment variable, then reference it in config.toml:

[mcp_servers.preset]
url = "https://mcp.presetai.dev/mcp"
bearer_token_env_var = "PRESET_API_KEY"

Best for shared-account or CI setups where browser-based OAuth isn’t viable.

Tool scoping

Codex’s agent has access to all of preset AI’s MCP tools by default and chooses which to call based on the task. Like Cursor, Codex is IDE-class — it benefits from the full tool surface (generation + validation + lookup), not the narrowed 7-tool review profile that PR-review clients (e.g. CodeRabbit) use.

If you want a narrower surface, Codex supports native per-tool toggling via the enabled_tools and disabled_tools arrays in the server config:

[mcp_servers.preset]
url = "https://mcp.presetai.dev/mcp"
enabled_tools = ["validate_code", "quick_check_violations", "get_forbidden_primitives", "get_active_constraints", "resolve_value", "suggest_preset", "get_component_api"]

This scopes preset AI to the 7-tool review profile — useful if you’re using Codex primarily for review-style tasks and want to suppress generation tools.

Data flow

When Codex’s agent calls a preset AI tool, it sends the file path, code snippet, and any inferred intent. preset AI resolves the active design system’s rules — forbidden primitives, context rules, tokens, presets, scoped by layer if configured — and returns structured results. Codex renders these inline in the agent panel and applies suggested fixes if you accept them.

No code is stored on preset AI’s side. Queries are processed in real time and logged to the design system’s audit trail, not Codex’s.

FAQ

Which Codex plan or surface do I need?

Any Codex surface that supports MCP works: CLI, desktop app, and the IDE extension all read ~/.codex/config.toml. preset AI is plan-agnostic on the Codex side — your preset AI connection authenticates against your preset AI account, not your OpenAI subscription tier.

Does this work in Codex Cloud (chatgpt.com/codex)?

As of 2026-04-18, OpenAI’s documentation does not address whether the cloud-hosted Codex agent supports custom MCP servers. The CLI / desktop / IDE-extension paths are the confirmed surfaces. If you need preset AI enforcement in cloud Codex specifically, watch developers.openai.com/codex for updates and file an issue.

How do I revoke Codex’s access?

Two paths. From Codex: open the desktop app → Plugins → Manage → MCPs, find preset AI, toggle off. From preset AI: Connect → Active integrations, find the Codex MCP Client entry, revoke. Either revokes the refresh token on preset AI’s side immediately.

Why does the agent sometimes ignore preset AI and read local docs instead?

Codex’s agent picks the cheapest path to an answer. If your repo already has AGENTS.md, CLAUDE.md, tokens.css, or design-system docs that cover the same ground, it may read those instead of calling preset AI. The recommended AGENTS.md snippet above tells the agent when preset AI is the authoritative source.

My project already has an AGENTS.md — will adding a preset AI section break anything?

No. AGENTS.md is additive and section-based. Append the preset AI block as a new ## preset AI MCP — design system enforcement section; existing sections (project layout, conventions, build commands, etc.) keep working. Codex reads the whole file.

What’s the difference between Plugins and MCPs in the Codex desktop app?

Plugins are OpenAI’s curated catalog (one-click install from the marketplace, examples: GitHub, Slack, Linear-as-plugin). MCPs are servers you’ve added to config.toml directly. Both surface in the same Manage view but live in different config sections ([plugins.*] vs [mcp_servers.*]).

What gets logged?

Every MCP call from Codex is logged to preset AI’s audit trail with client ID, tool name, and timestamp — queryable from the preset AI dashboard. OAuth events (token issuance, refresh, revocation) are captured in the oauth_events telemetry table.