Build a GitBook Integration
A skill for building integrations on GitBook's developer platform: apps that run inside GitBook itself. An integration can render custom blocks in the editor, show configuration UI, listen to events (content updated, Git sync completed, space viewed), authenticate against external services with OAuth, and talk to anything over HTTP.
This skill covers the integration lifecycle — scaffold, code, develop, publish. For creating or restructuring the docs
site an integration might be installed into, defer to
; for authoring page content, defer to
.
What an integration is (mental model)
An integration is a small TypeScript app executed by GitBook's runtime — not a script injected into pages, and not code running on the user's server. Three consequences shape everything else:
- Rendering happens on GitBook's backend. Your component's function runs server-side on every interaction and returns ContentKit markup (a JSX-like UI description). There is no client-side React tree you control, no DOM access, and UI updates flow through the action → new state → re-render loop.
- You cannot inject JavaScript into a site. The and scopes you'll see in GitBook-owned integrations are internal-only. If the user's plan amounts to "add a script tag to their docs", stop and say so early — the supported paths are custom blocks, webframes, and events.
- Local development is a proxy, not a server you visit. routes the installed integration's traffic to your machine. You never open the dev server's port in a browser; you interact with the integration inside app.gitbook.com.
The project
my-integration/
├── gitbook-manifest.yaml # identity, scopes, blocks, configuration schema
├── .gitbook-dev.yaml # local dev config (generated by `gitbook dev`)
├── package.json
└── src/
└── index.tsx # entry file — default-exports createIntegration()
The entry file (whatever
in the manifest points to) default-exports
createIntegration({ fetch, components, events })
:
tsx
import { createIntegration, createComponent } from '@gitbook/runtime';
const helloBlock = createComponent({
componentId: 'hello-world', // must match a block id in the manifest
initialState: { message: 'Say hello!' },
action: async (element, action, context) => {
switch (action.action) {
case 'say':
return { state: { message: 'Hello world' } };
default:
return {};
}
},
render: async (element, context) => (
<block>
<button label={element.state.message} onPress={{ action: 'say' }} />
</block>
),
});
export default createIntegration({
components: [helloBlock],
events: {
space_content_updated: async (event, context) => {
// react to content changes
},
},
});
A custom block only appears in the editor's insert palette (⌘ + /) if it is declared in
both places:
in the code
and a
entry in the manifest whose
matches the
. Forgetting one half is the most common "my block doesn't show up" cause.
The manifest, briefly
is the integration's identity and permission grant. Required:
(globally unique across all of GitBook — pick something namespaced like
, not
),
,
,
(org id or subdomain),
,
, and
. Request only the scopes the code actually uses — installers see them.
The manifest also declares
, installer-facing
(account-level and site-level property schemas rendered as a settings form), and
(e.g.
CLIENT_ID: ${{ env.CLIENT_ID }}
, loaded at publish time — use
so
sees your
).
Full field-by-field schema, scope list, and configuration property types:
. Read it whenever you're editing the manifest beyond the basics.
The development loop
The loop has a non-obvious order — publish comes before local development:
- Prerequisites. Node 18+, a personal access token from https://app.gitbook.com/account/developer, and the CLI:
npm install @gitbook/cli -g
, then (or gitbook auth --token=<token>
). If a token needs to be pasted into the conversation, export it to the environment and never echo it back or commit it.
- Scaffold. — prompts for name, title, organization, and scopes.
- Publish once. in the project root. This registers the integration (private by default) and prints an install link.
- Install it into at least one space or site via that link. Local dev doesn't work until it's installed somewhere.
- Develop. starts the proxy: all traffic for the installed integration is served from your local code instead of the published version. Interact with it in the GitBook editor, not at the server URL. UI changes need a browser refresh; disable browser caching for a smoother loop. Logs surface in the browser console or your terminal depending on where the code runs — check both before concluding logging is broken.
- Re-publish with whenever you want the hosted version updated. removes it.
CLI command reference (including
and
):
.
Runtime: fetch, events, environment, OAuth
Details and full tables live in
— read it when writing event handlers, OAuth flows, or anything touching
. The essentials:
- handles incoming HTTP requests to the integration's public endpoint using standard Fetch API / objects. Outgoing HTTP is plain too.
- maps event names (, , , , , , , ) to handlers. Some events require matching scopes.
- exposes , , installation info (space, status, per-installation values entered by the installer), , and public URLs (
environment.integration.urls.publicEndpoint
).
- OAuth against an external provider is a fixed pattern: a -type configuration property whose routes to a
createOAuthHandler({...})
in your fetch handler, with client id/secret coming from . Don't hand-roll the redirect/token exchange.
- Calling the GitBook API from inside the integration: use (an authenticated client) rather than constructing your own client from raw tokens.
ContentKit: building the UI
ContentKit is the component vocabulary
can return: layout (
,
,
,
), display (
,
,
,
,
), and interactive elements (
,
,
,
,
,
,
,
,
). Interactivity model in one line: inputs bind their value to a
key; buttons dispatch actions; your
reducer returns new state; GitBook re-renders.
Read
before writing any component beyond a trivial button — it has the full prop tables plus the patterns that are hard to guess: dynamic state binding for live previews, webframe
communication, modals with
, persisting props with
, link unfurling via
+
manifest patterns, and markdown code-block serialization of blocks.
Publishing and sharing
Visibility in the manifest controls reach:
- (default) — installable only by members of the owning org. Right for internal tools; stay here during development.
- — installable by any org, but only via the shared install link. Right for sharing with specific customers or beta testers.
- — installable by anyone; required before submitting to the integration marketplace (which is a separate review process — see GitBook's "submit your app for review" docs).
Re-run
after changing visibility. Before suggesting
, sanity-check the manifest is presentable:
,
(Markdown, ≤2048 chars),
(1600×800),
,
.
Working style
- Scaffold with the CLI rather than by hand when starting fresh — wires up the manifest, TypeScript config, and versions correctly.
- Trace a block's id chain (manifest ↔ ) whenever a component misbehaves.
- Keep secrets out of the manifest file itself — always the indirection, never literal values.
- When the user's goal is content or site automation from outside GitBook (scripts hitting the REST API, CI pipelines), an integration may be the wrong tool — the plain API with a personal token is simpler. Integrations earn their keep when code must run inside GitBook: blocks, config UI, event reactions, OAuth on behalf of installers.
References
- — every field, all scopes, configuration property types, secrets, CLI command reference, installation/configuration flow.
- — / / signatures, event catalog, shape, HTTP in and out.
- — full component reference with props, built-in actions, and interactivity recipes (dynamic binding, webframes, modals, unfurling, markdown serialization).