MCP server for your site
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 your readers can get instant answers about your product directly within their development environment.
This is the server your readers connect to, and it serves your content. To point your own agent at Fern’s product documentation while you build your site, or at your organization’s Fern data, use Fern’s MCP server. To give agents tools that call your API, generate one with the MCP Generator.
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.
How it works
The server exposes a single tool that answers questions about your documentation site using the same Retrieval Augmented Generation (RAG) pipeline as Ask Fern. Queries are semantic rather than keyword-based — the tool searches indexed content and synthesizes an answer, not a list of raw results.
Each message sent through the MCP server runs Ask Fern under the hood and consumes 2 AI credits, the same as an Ask Fern query.
Self-hosted containers
Self-hosted containers also serve /_mcp/server, without Ask Fern or AI credits. Instead of the RAG pipeline, the self-hosted server exposes two tools:
searchDocsruns keyword search against the container’s built-in search index and returns matching pages rather than a synthesized answer.fetchPagereturns a page’s Markdown.
Both tools enforce the same access control as a browser request. A result is only returned for a page the caller could open, based on their roles and credentials (including a FERN_TOKEN header). Setting mcp: false disables the server on self-hosted containers too.
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 addcommand 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:
Authenticated sites
On sites with authentication enabled, a client that isn’t signed in only gets publicly visible content (if any), plus instructions for signing in. A signed-in client gets the same pages its user could open in a browser, based on their roles.
Sign in from an MCP client
MCP clients that support OAuth sign-in can sign in through your site’s own login. Sign-in is available on:
- SSO sites, with no extra configuration.
- Password, JWT, and OAuth sites, after you set
mcp-authtotrueand publish with Fern CLI 5.221.0 or later:
To sign in, the user picks the client’s Sign in or Authenticate option for the server, or connects the client to your-documentation-site.com/_mcp/server?sign_in=true. The client opens the site’s login page in the browser and then refreshes its access automatically. A sign-in lasts up to 30 days, and never longer than the site’s own login session. Role changes take effect the next time the user signs in.
On OAuth sites, users only get roles if your provider’s access token includes them in a claim. See Add a custom claim.
Pass a token manually
Clients without OAuth sign-in, and scripts, can include a FERN_TOKEN header containing a valid JWT instead.
Get a token
Exchange your credentials for a JWT. The endpoint depends on how your site authenticates users.
API key (JWT / OAuth)
Password protection
Exchange a Fern API key for a JWT via the get-jwt endpoint:
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:
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. A manually passed token isn’t refreshed automatically.
Exclude test and eval traffic from analytics
By default, every request through the MCP server is recorded as a conversation in the Ask Fern analytics dashboard. Automated tests or evals that call the server are recorded alongside real user queries, which can skew the data.
To prevent a request from being recorded, include the header x-fern-skip-save-query: true (or x-fern-skip-save-query: 1) on the MCP HTTP request. The request is still answered normally and still consumes AI credits — only the analytics recording is skipped.
In Claude Code, pass the header with --header:
Disable the MCP server
To turn the server off entirely, set mcp to false in your page-actions configuration:
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.
The server answers through Ask Fern, so it’s also off on sites with Ask Fern disabled: the endpoint returns 404 and agents aren’t pointed to it. Self-hosted containers serve the server without Ask Fern and are unaffected.
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.