Skip to main content
Glama
README.md
<p align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="./assets/react-portal-lockup-on-dark.svg">
    <img src="./assets/react-portal-lockup.svg" alt="React Portal" height="56">
  </picture>
</p>

# rpf-mcp

rpf-mcp is the Forge MCP server: build React Portal portals and components from **Claude Code** or
**Claude Desktop**. React Portal is a ServiceNow application for building portals with React. The application is a
paid product, sold separately; the rpf tools that work with it are free and MIT-licensed.

The server is a local [MCP](https://modelcontextprotocol.io) server on stdio. Its tools call the instance's Forge API
(`/api/x_312987_portal/rp_forge`) **as your ServiceNow user**, so your React Portal Studio roles decide what it can do:
developer for component code; designer for portals, pages, placements, menus and themes. No AI runs on the instance
and no AI keys are stored there; your Claude does the thinking.

The server is built into the rpf CLI as `rpf mcp`: install `@quixomatic/rpf` to get it. rpf-mcp isn't published to
npm on its own; this repository is its source, and a checkout can also run it directly with Bun.

## Requirements

- A ServiceNow instance with React Portal installed and Forge enabled, and a user with a React Portal Studio role.
- With `rpf mcp` (recommended): Node 24 or newer.
- From a checkout: [Bun](https://bun.sh) 1.4 or newer (the source is TypeScript and runs with Bun directly).

## Install and run

### Recommended: `rpf mcp`

```sh
npm i -g @quixomatic/rpf
rpf auth add dev --instance acme-dev --kind oauth-code
rpf auth login dev

claude mcp add forge -- rpf mcp --profile dev
```

`rpf mcp` takes its settings from the profile (or `RP_*` environment variables with `--instance`), keeps secrets in
rpf's encrypted credential store, and has the same tools. For Claude Desktop, add it to `claude_desktop_config.json`
(Settings, Developer, Edit config) and restart Claude Desktop:

```json
{
    "mcpServers": {
        "forge": {
            "command": "rpf",
            "args": ["mcp", "--profile", "dev"]
        }
    }
}
```

### From a checkout (development)

```sh
git clone https://github.com/Quixomatic/rpf-mcp   # inside the workspace folder with its sibling repos (Contributing)

claude mcp add forge -e RP_INSTANCE=https://acme-dev.service-now.com -e FORGE_AUTH=oauth-code -- bun run /path/to/rpf-mcp/src/index.ts
bun run src/index.ts auth login       # oauth-code: browser sign-in with PKCE (--no-browser, --paste)
bun run src/index.ts auth status      # kind, cached token expiry, who Forge runs as
bun run src/index.ts auth logout      # revoke and forget the cached token
```

Settings come from the environment first, then an env file: `FORGE_ENV_FILE`, else `.forge-mcp.env` in the project
folder. The project folder is `RP_REPO`, else the current directory (Claude Code starts MCP servers in the project).
Keep the env file out of version control.

| Variable | Meaning |
|---|---|
| `RP_INSTANCE` | `https://<instance>.service-now.com` |
| `FORGE_AUTH` | Sign-in kind (see [Authentication](#authentication)). Unset: `RP_TOKEN` means `bearer`, `RP_COOKIE` means `session`, `RP_API_KEY` means `apikey`, else `basic` |
| `RP_USER`, `RP_PASSWORD` | Basic auth and the OAuth password grant |
| `FORGE_DRY_RUN` | `1` turns every write into a dry run |
| `FORGE_TIMEOUT_MS` | Per-request timeout (default 280000) |
| `FORGE_TOKEN_STORE` | Where OAuth tokens are cached (default `~/.forge-mcp/tokens.json`, owner-only) |
| `FORGE_WORKSPACE_ROOTS` | Extra folders (a path list) where the workspace tools look for local workspaces, besides `apps/` in the project folder |

## Safety

- **Your roles apply.** Every call runs as you, and the instance checks your Studio role per operation.
- **Writes follow the application scope.** Editing a record needs your current application (the application picker)
  to be the record's app; new portals, components and themes land in the current app, never Global; a portal's pages,
  placements and menus follow the portal's app. Otherwise the write answers `wrong_scope` with the owning app.
  `switch_app` changes the picker (optionally with an update set); every write also takes an optional `app`, and the
  instance refuses the write unless that app is current.
- **Dry run everywhere.** Every write tool accepts `dryRun: true`. The instance validates everything (roles,
  references, regions, option keys, and a full compile of component files) and returns exactly what would change. The
  real write runs the same prepared arguments, so the plan and the result can't drift.
- **No deletes.** Removing a page, side panel, page variant, placement or menu item deactivates it. `apply_spec` never
  removes anything and reports what the spec doesn't list in `plan.unlisted`.
- **New portals are drafts.** Forge can't publish: `create_portal` and `update_portal` refuse `active: true`.
  Publishing is a Studio action that needs the publisher role.
- **Kill switch.** Setting the system property `x_312987_portal.forge.mcp.enabled` to anything but `true` blocks the
  whole Forge API with a 403, and every tool then answers "Forge is disabled on this instance".

## Tools

Call `orientation` first: it returns the hard rules, the workspace, the instance (React Portal version, Forge API
level, features, your capabilities), the component anatomy, the examples and a reading list.

| Group | Tools |
|---|---|
| Context | `orientation`, `get_context`, `switch_app` |
| Reuse and lookups | `search_catalog`, `find_pattern`, `show_example`, `where_used`, `list_components`, `describe_component`, `read_component_source`, `search_docs`, `read_doc`, `lookup_api`, `search_icons`, `examples`, `scaffold_component` |
| Data (read-only, as you) | `data_find_tables`, `describe_table`, `data_relations`, `data_query` (flags terms on fields that don't exist, which the platform drops silently), `data_sample`, `data_stats`, `data_graphql` (queries only), `data_table_api` |
| Portals | `list_portals`, `get_portal`, `get_page`, `get_preview`, `create_portal`, `update_portal`, `create_page`, `update_page`, `place_component`, `update_placement`, `remove_placement`, `set_menu`, `create_panel`, `update_panel`, `create_variant`, `update_variant`, `set_criteria`, `apply_spec` (a declarative portal spec in one plan) |
| List cells | `list_cell_renderers`, `set_cell_renderer`, `remove_cell_renderer` |
| Components | `check_component`, `create_component`, `write_component_files`, `edit_component_file`, `get_execution_log` |
| Themes | `list_themes`, `get_theme`, `create_theme` (from a theme, a brand color with a contrast-safe palette made locally, or pasted shadcn CSS), `update_theme` |
| Local workspaces | `workspace_pull`, `workspace_status`, `workspace_diff`, `workspace_resolve`, `workspace_rename`, `workspace_check`, `workspace_push` |
| `rpf dev` preview | `dev_status`, `dev_stage`, `dev_open`, `dev_act`, `dev_screenshot`, `dev_inspect`, `dev_eval`, `dev_wait_idle`: drive the workspace's running `rpf dev` page like a user, in a read-only browser |
| References and plans | `ref_list`, `ref_read`, `ref_view`, `ref_add`, `ref_capture`, `ref_compare`, `ref_facts`, `compare_list`, `plan_check_file`, `plan_check`, `reuse_report`, `annotation_list`, `annotation_read` |

The prompt `design_theme` (arguments `brief` and an optional `base`) walks Claude through designing a contrast-safe
theme and creating it with `create_theme`, dry run first.

## Authentication

Every sign-in kind resolves to a real ServiceNow user, and Forge applies that user's Studio roles.

| `FORGE_AUTH` | Settings | Runs as | Instance setup |
|---|---|---|---|
| `basic` | `RP_USER`, `RP_PASSWORD` | that user | none |
| `oauth-password` | `RP_OAUTH_CLIENT_ID`, `RP_OAUTH_CLIENT_SECRET`, `RP_USER`, `RP_PASSWORD` | that user | Application Registry client |
| `oauth-client` | `RP_OAUTH_CLIENT_ID`, `RP_OAUTH_CLIENT_SECRET` | the client's OAuth Application User | client with that user + `glide.oauth.inbound.client.credential.grant_type.enabled=true` |
| `oauth-code` | none: `RP_OAUTH_CLIENT_ID` defaults to `react-portal-forge-mcp`, `RP_OAUTH_REDIRECT_URI` to `http://localhost:8765/callback` | whoever signs in in the browser | none: React Portal installs the public PKCE client **Forge MCP** |
| `bearer` | `RP_TOKEN` | the token's user | any OAuth client; not refreshed |
| `apikey` | `RP_API_KEY`, `RP_API_KEY_HEADER` (default `x-sn-apikey`) | the key's user | REST API Key + API key auth profile + an API access policy on `rp_forge` |
| `mtls` | `RP_CLIENT_CERT`, `RP_CLIENT_KEY` (PEM), `RP_CLIENT_KEY_PASSPHRASE`, `RP_CA_CERT` | the mapped user | CA Certificate Chain + User to Certificate Mapping |
| `session` | `RP_COOKIE`, `RP_USER_TOKEN` (the tab's `g_ck`) | the browser session's user | none |

`RP_CLIENT_CERT` / `RP_CLIENT_KEY` are presented under any kind, so a certificate can sit under OAuth or basic too.

The **Forge MCP** OAuth client that React Portal installs is public, with PKCE always on, so it covers `oauth-code`
only. `oauth-password` and `oauth-client` need a confidential client an admin creates; set its ID and secret in
`RP_OAUTH_CLIENT_ID` / `RP_OAUTH_CLIENT_SECRET`. OAuth tokens are refreshed a minute before expiry and once more after
a 401; they are never logged.

Errors name the kind: `unauthenticated` (401), `forbidden` (403: a user without a Studio role, or a token scope or
access policy), `oauth_token_failed` (a grant refused, with that grant's requirements), `login_required` (`oauth-code`
without a valid refresh token).

The full per-kind setup is in the React Portal docs on your instance (`rpf docs read studio/forge-mcp`).

## How it fits

| Repository | npm | What |
|---|---|---|
| [rpf-core](https://github.com/Quixomatic/rpf-core) | `@quixomatic/rpf-core` | The shared core, TypeScript source |
| [rpf-dev-host](https://github.com/Quixomatic/rpf-dev-host) | `@quixomatic/rpf-dev-host` | The browser host behind `rpf dev` |
| [rpf-mcp](https://github.com/Quixomatic/rpf-mcp) (this one) | bundled in `@quixomatic/rpf` (not on npm) | The Forge MCP server |
| [rpf-cli](https://github.com/Quixomatic/rpf-cli) | `@quixomatic/rpf` | The `rpf` command |
| [rpf-forge](https://github.com/Quixomatic/rpf-forge) | `@quixomatic/rpf-forge` | `rpf forge`, the local agent workspace (add-on) |
| [rpf-desktop](https://github.com/Quixomatic/rpf-desktop) | not on npm | React Portal Forge, the desktop app |

rpf-mcp depends on rpf-core. The CLI bundles rpf-core, rpf-mcp and the rpf-dev-host build, so `@quixomatic/rpf` is
the one package most people install. Forge is an add-on installed next to it. The desktop app bundles rpf and
rpf-forge. All public packages are released in lockstep with the same version (1.x).

## Contributing / development

The rpf repositories are developed side by side in one folder, linked by a pnpm workspace:

```yaml
# pnpm-workspace.yaml, in the folder that holds the checkouts
packages:
  - rpf-core
  - rpf-dev-host
  - rpf-mcp
  - rpf-cli
  - rpf-forge
  - rpf-desktop
nodeLinker: hoisted
```

`pnpm install` at the workspace root links them; dependencies between the packages are `workspace:*` (publishing
replaces them with the exact version). The package scripts run with Bun, so install Bun 1.4+ as well. For local runs,
copy `.env.example` to `.forge-mcp.env` and fill it in.

- **Imports.** This repository's own code is imported through the `#src/*` alias (package.json
  `"imports": { "#src/*": "./src/*" }` plus the matching tsconfig `paths`), never through `../` chains. Other packages
  are imported by name, e.g. `@quixomatic/rpf-core/client.ts`.
- **Style.** Prettier with the shared `.prettierrc.json`: semicolons, single quotes, 4 spaces, 120 columns. JSDoc on
  every function.
- **Changelog.** Every change gets a `CHANGELOG.md` entry.

Scripts:

| Script | What |
|---|---|
| `pnpm start` | Runs the server on stdio |
| `pnpm check` | Verifies the settings and that Forge is enabled; prints your capabilities |
| `pnpm auth login \| status \| logout` | The sign-in commands |
| `pnpm test` | Schema, smoke and auth tests (the auth tests run every kind against a mocked instance) |
| `pnpm typecheck` | `tsc --noEmit` |
| `pnpm test:acceptance` | Drives the server through a real MCP client against the configured instance: reads, dry runs, dry run then real writes, cleanup by deactivation. It creates the draft portal `forge-test` |
| `pnpm test:auth-live` | Read-only sign-in checks against the configured instance |
| `pnpm sync:check` | Checks that the synced files (`assets/`) are untouched |

## License

MIT © TurboForge LLC (see [LICENSE](./LICENSE)). React Portal itself, the ServiceNow application, is a separate
proprietary product.