# ChatGPT and Codex apps

Build MCP servers and interactive MCP Apps widgets for ChatGPT and Codex on Ferrite with the gpt-plugins source package, including OAuth challenges, checkout specs, and submission linting.

The `gpt-plugins` source package builds an MCP server tailored for ChatGPT and Codex inside a single constrained Ferrite application. From one Rust declaration, it serves MCP `2026-07-28` and legacy handshake revisions (`2025-11-25`, `2025-06-18`, `2025-03-26`), sandboxed MCP Apps widgets with OpenAI's host extensions, OAuth 2.1 protected resource metadata and linking challenges, skills, tasks, file transfers, checkout and company knowledge conventions, and the packaged archive required for submission.

## Add the package and declare a plugin

Install `gpt-plugins` (and its `sha256-hmac` dependency) with one command:

```bash
ferrite add gpt-plugins
```

Read `src/gpt_plugins/SETUP.md` after installing to copy the required `forward_headers` entry into `ferrite.json` (`accept`, `authorization`, `content-type`, `origin`, `mcp-protocol-version`, `mcp-method`, `mcp-name`). Without those forwarded headers, callers appear anonymous and MCP `2026-07-28` requests are refused.

Declare your tools, UI resources, and OAuth protected resource metadata in Rust and implement the `Host` trait:

```rust filename="src/plugin.rs"
use crate::gpt_plugins::auth::{self, ProtectedResource};
use crate::gpt_plugins::resource::UiResource;
use crate::gpt_plugins::result::{Content, ToolResult};
use crate::gpt_plugins::server::{CallContext, Host, Plugin};
use crate::gpt_plugins::tool::{Hints, Tool};
use ferrite_app::serde_json::{json, Value};

fn build_plugin() -> Plugin {
    let read = Hints { read_only: true, destructive: false, open_world: false };
    let board = UiResource::new("ui://notes/board-v1.html", "board")
        .domain("https://notes-widgets.example.com");

    Plugin::new("notes", "1.0.0")
        .instructions("Call list_notes before creating a new note to avoid duplicates.")
        .tool(
            Tool::new(
                "list_notes",
                "Find or review the user's saved notes.",
                json!({ "type": "object", "properties": { "query": { "type": "string" } } }),
                read,
            )
            .title("List notes")
            .security_schemes(vec![auth::security_scheme_oauth2(&["notes.read"])]),
        )
        .tool(
            Tool::new("show_board", "Show the interactive notes board.", json!({ "type": "object" }), read)
                .title("Show board")
                .ui(board.uri())
                .allow_anonymous(),
        )
        .ui_resource_with_schemes(&board, BOARD_HTML, vec![auth::security_scheme_noauth()])
        .protected_resource(
            ProtectedResource::new("https://notes.example.com/mcp")
                .authorization_server("https://auth.example.com")
                .scopes(&["notes.read"]),
        )
}
```

Dispatch requests through `gpt_plugins::server::handle(&plugin, &app, &request).await` ahead of your catch-all router. If your application also uses `agent-ready` for `llms.txt`, Markdown twins, and OpenAPI, run `gpt_plugins::server::handle` first so `/mcp` routes to `gpt-plugins`, and project your existing operations with `Tool::from_operation`.

## Build sandboxed widgets with `bridge::Widget`

`bridge::Widget` produces a self-contained HTML document with the `FerriteGpt` browser bridge inlined for sandboxed iframe rendering:

```rust filename="src/ui.rs"
let html = crate::gpt_plugins::bridge::Widget::new("Notes board")
    .body_html("<main id=\"root\"></main>")
    .script(include_str!("board.js"))
    .to_html();
```

In `board.js`, call `FerriteGpt.connect({ allowedOrigins: ["https://chatgpt.com"] })` with the exact host origins permitted to embed the frame. `FerriteGpt.connect()` fails closed with `no-origin` if `allowedOrigins` is omitted or contains wildcards, and never posts messages to `"*"`. Once connected, `FerriteGpt` exposes standard MCP Apps methods (`tools/call`, `ui/message`, `ui/update-model-context`, display modes), OpenAI extension methods under `FerriteGpt.ext`, and feature-detected wrappers around `window.openai` under `FerriteGpt.chatgpt`. Use `resource::versioned_uri` to bust widget caches when HTML changes.

## Capabilities included in `gpt-plugins`

| Area | Modules | What it provides |
| --- | --- | --- |
| Core MCP and auth | `server`, `tool`, `auth`, `result` | Dual-era MCP endpoint, RFC 9728 metadata, `AuthRefusal::ByClient` (HTTP 401/403 + `_meta["mcp/www_authenticate"]` for ChatGPT account linking) |
| Interactive widgets | `resource`, `bridge` | `ui://` resources, CSP and domain declarations, inlined `FerriteGpt` bridge, `window.openai` wrappers |
| Tasks, files, forms | `forms`, `files`, `server` | Durable `Plugin::serve_tasks`, inline and out-of-band `Plugin::serve_files`, sealed multi-round-trip forms |
| Skills and events | `skills`, `events`, `webhooks` | `skills/list` and `skills/get` with `directoryRead`, atomic `EventBackend`, signed Standard Webhooks |
| Commerce and knowledge | `checkout`, `conversion`, `knowledge`, `deeplink` | Checkout session builders, product/reservation/local-service conversion specs, company knowledge `search`/`fetch`, deep links |
| Packaging and review | `package`, `zip`, `review`, `checklist` | `plugin.json`, `mcp.json`, marketplace entry, ZIP packager, automated `plugin.lint(Stage::Upload)`, human review checklist |

## Security rules and submission checks

- **Explicit anonymous opt-in.** Whenever a plugin declares a protected resource or `oauth2` scheme, every tool, UI resource, skill, and extension method requires a signed-in caller by default. Declare public items explicitly with `Tool::allow_anonymous()` or `auth::security_scheme_noauth()`.
- **Strict audience verification.** `auth::principal_from_claims` rejects tokens whose `aud` claim names another server even if `resource` matches. Verify JWT signatures in `Host::authenticate` with the Ferrite SDK's `Jwks` verifier, per-app [Poppy OAuth](/developers/poppy-oauth/), or RFC 7662 introspection over a declared egress handle.
- **Run the linter in `ferrite test`.** Catch broken schemas, missing anonymous declarations, and packaging errors locally before uploading:

```rust filename="src/plugin.rs"
#[test]
fn plugin_passes_upload_lint() {
    use crate::gpt_plugins::{json::has_errors, package::Stage, review};
    let issues = build_plugin().lint(Stage::Upload);
    assert!(!has_errors(&issues), "{}", review::report(&issues));
}
```

## Platform boundaries

- **No `POST` SSE streaming or CORS preflight on `/mcp`.** The gateway answers `OPTIONS` with `405` and returns JSON replies on `POST`. ChatGPT, Codex, and MCP Inspector call `/mcp` server-to-server, and user confirmations run through multi-round-trip requests on MCP `2026-07-28`.
- **Static egress for webhooks.** MCP Events webhook deliveries can only target origins declared at deploy time in `ferrite.json`.
- **Surface-specific host limits.** File entrypoints, local file opening, and composer at-mentions are desktop-only; Android omits deep links; iOS and Android omit OpenAI form elicitation. Feature-detect capabilities and provide fallback tool flows.
- **No client-certificate mTLS.** Ferrite terminates TLS at the platform edge, so constrained applications cannot inspect OpenAI-managed mTLS client certificates.

## Next steps

- Learn the shared `ui://` protocol in [MCP Apps](/developers/mcp-apps/).
- Run your own isolated per-app OAuth 2.1 issuer with [Per-app OAuth (Poppy)](/developers/poppy-oauth/).
- Build customer-facing and internal Claude apps in [Build Claude-enabled apps](/developers/claude-apps/).
