MCP server

View as Markdown

Fern automatically generates and hosts a production-ready Model Context Protocol (MCP) server for every documentation site with Ask Fern enabled. The server connects AI clients like Claude Code, Cursor, and Windsurf to your documentation as an external data source, so developers can get instant answers about your product directly within their development environment.

Your MCP server is available at your-documentation-site.com/_mcp/server. For example, the MCP server for this site is at https://buildwithfern.com/learn/_mcp/server.

Connect to your MCP server

For Claude Code and Cursor, page action buttons let users connect in one click:

  • Connect to Claude Code copies a claude mcp add command to the clipboard to register the server.
  • Connect to Cursor opens Cursor with the server URL pre-filled for one-click install.

Both buttons are enabled by default on sites with Ask Fern.

All other clients (including Claude Desktop, Windsurf, and VS Code) connect using the server URL directly. Add your-documentation-site.com/_mcp/server to your MCP configuration. For CLI clients, that looks like:

$claude mcp add --transport http \
> fern_mcp_docs.example.com https://docs.example.com/_mcp/server

Authenticated sites

On sites with authentication enabled, MCP clients must include a FERN_TOKEN header containing a valid JWT. Without it, the server only returns publicly visible content (if any).

1

Get a token

Exchange your credentials for a JWT. The endpoint depends on how your site authenticates users.

Exchange a Fern API key for a JWT via the get-jwt endpoint:

$curl https://docs.example.com/api/fern-docs/get-jwt \
> -H "FERN_API_KEY: $FERN_TOKEN"
$# → { "fern_token": "eyJ...", "roles": [] }
2

Configure your MCP client

Register the server manually, as the page action buttons can’t carry credentials. Then, add the JWT as a FERN_TOKEN header. In Claude Code:

$claude mcp add --transport http \
> --header "FERN_TOKEN: <jwt>" \
> fern_mcp_docs.example.com https://docs.example.com/_mcp/server

For Cursor, VS Code, and other clients, add FERN_TOKEN: <jwt> to the headers field in your MCP server configuration if the client supports custom headers.

JWTs expire. Re-run the token exchange when the token lapses. There is no automatic refresh mechanism in the MCP transport.

Disable the server

To turn the server off entirely, set mcp to false in your page-actions configuration:

docs.yml
1page-actions:
2 options:
3 mcp: false

This is especially useful on authenticated sites because unauthenticated agents can discover the MCP endpoint but can’t read its content. Disabling the server returns 404 from the endpoint, hides the connection buttons, and stops agents from discovering it through llms.txt or agent prompts.

Other ways agents can access your docs

Agents can also fetch documentation directly over HTTP. Fern serves clean Markdown via per-page URLs and llms.txt — including on authenticated sites.