From 8d9ee1c2d440e9dfda62f9be54feac5555b0ba8c Mon Sep 17 00:00:00 2001 From: Tristan Date: Mon, 23 Nov 2026 15:54:44 -0800 Subject: [PATCH 1/3] Document MCP server instructions and egress policy - Add "Set the server instructions" and "Restrict outbound requests" sections to the Configure page, plus a cross-link from the custom-tool fetch section to the egress allow-list. - List instructions, appendInstructions, and egress in the sdk-config reference. --- fern/products/mcp-generator/configure.mdx | 39 ++++++++++++++++++- .../sdks/reference/sdk-config-reference.mdx | 9 +++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/fern/products/mcp-generator/configure.mdx b/fern/products/mcp-generator/configure.mdx index 9c69fcc98..dd9ca98d9 100644 --- a/fern/products/mcp-generator/configure.mdx +++ b/fern/products/mcp-generator/configure.mdx @@ -1,6 +1,6 @@ --- title: Configure the server -description: Choose which API operations become MCP tools, group them into toolsets, merge and rename tools, add custom tools and hooks, and pass credentials. +description: Choose which API operations become MCP tools, group them into toolsets, merge and rename tools, add custom tools and hooks, set the server instructions, restrict outbound requests, and pass credentials. --- The MCP Generator turns each operation in your OpenAPI spec into one tool. Settings in the `generation` block of the `mcp` target in `sdk-config.yml` decide which tools the server exposes and how agents see them, and OpenAPI extensions on each operation set its tool's name and description. Run `fern generate` after a change to redeploy the server with the same URL. @@ -189,12 +189,31 @@ The module exports four functions, each wrapping a point in the request lifecycl `context.fetch` doesn't set a content type. A non-2xx response returns to your handler without calling `onError`. On a `POST`, `PUT`, or `PATCH` with a JSON body, set `content-type: application/json`, or the body goes out as `text/plain` and many APIs answer `415`. +A custom tool's handler can call any public host by default; an [egress allow-list](#restrict-outbound-requests) limits it to hosts you declare. + `fern generate` uploads the custom tool and hook modules to Fern's build service, which bundles them into the server for both hosted and downloaded servers. ## Name the server `serverName` and `serverDescription` set the server's name and description. Without them, the name comes from `sdkName` in `sdk-config.yml`, with `sdk` replaced by `mcp` (`acme-sdk` becomes `acme-mcp`), and the description from `info.description` in your spec. +## Set the server instructions + +The server returns a block of instructions on `initialize` that tells an agent how to use it. Fern generates this block from your spec: the server's name and description, the authentication scheme and header to send, and the `openapi://` resource and schema URIs an agent reads to browse docs and fetch full input schemas. `instructions` and `appendInstructions` set or extend that text. + +```yaml title="sdk-config.yml" +targets: + - language: mcp + generation: + appendInstructions: | + Confirm a pet is available with get_pet_by_id before calling adopt_pet. + Prefer place_order over cancelling and re-creating an order. +``` + +`appendInstructions` adds your text after the generated block, keeping the generated wiring in place. `instructions` replaces the generated block outright. Setting both replaces the block, then appends. With neither set, the server returns the generated instructions unchanged. + +Replacing the block drops the generated `openapi://` URIs and `_meta` keys an agent needs to browse docs and fetch schemas, so prefer `appendInstructions` unless you restate that wiring yourself. Both fields go to the MCP client verbatim on every conversation, where they count against the context window, so keep them short. + ## Pass credentials Credentials come from the security schemes in your spec. Agents send them as request headers on every call, and the server forwards them to your API: @@ -205,6 +224,24 @@ Credentials come from the security schemes in your spec. Agents send them as req Parameters that carry a credential aren't tool inputs. When a call is missing a credential, the error names the headers to send. The dashboard's **Connect** button builds each agent's command with the right headers. +## Restrict outbound requests + +A generated tool only ever calls your API, but a custom tool's handler can `fetch` any public host. `egress` restricts where the server sends outbound requests, including the calls custom tools make through `context.fetch`. + +```yaml title="sdk-config.yml" +targets: + - language: mcp + generation: + egress: + policy: allowlist + allowedUpstreams: + - api.stripe.com +``` + +Under `policy: allowlist`, the server allows a request only to your API's origin, an OAuth issuer, or a host listed in `allowedUpstreams`, and refuses any other host. Declaring `allowedUpstreams` turns on `allowlist` on its own, so set `policy` alone to lock the server to its API origin with no extra hosts. Omitting the `egress` block, or setting `policy: open`, leaves egress unrestricted. + +Entries in `allowedUpstreams` are bare hostnames, without a scheme, path, port, or wildcard. The allow-list checks the resolved host of every outbound request, and a redirect to a host that isn't allowed is refused too. Blocking of private and internal addresses, and sending your API's credentials only to its own origin, both apply whatever the policy. + ## Limits Every tool call times out after 30 seconds, and a response from your API can be at most 1 MiB. The server rejects path parameters of `.` or `..` and cookie values that contain semicolons or control characters. diff --git a/fern/products/sdks/reference/sdk-config-reference.mdx b/fern/products/sdks/reference/sdk-config-reference.mdx index 7151834cb..a60515aeb 100644 --- a/fern/products/sdks/reference/sdk-config-reference.mdx +++ b/fern/products/sdks/reference/sdk-config-reference.mdx @@ -687,6 +687,12 @@ A `mcp` target's `generation` block configures the generated MCP server. [Config The server's description. See [Name the server](/learn/mcp-generator/get-started/configure#name-the-server). + + Replaces the instructions the server returns on `initialize`. See [Set the server instructions](/learn/mcp-generator/get-started/configure#set-the-server-instructions). + + + Appends text after the instructions the server returns on `initialize`. See [Set the server instructions](/learn/mcp-generator/get-started/configure#set-the-server-instructions). + Availability statuses to drop, such as `[DEPRECATED]`. See [Choose which operations become tools](/learn/mcp-generator/get-started/configure#choose-which-operations-become-tools). @@ -705,3 +711,6 @@ A `mcp` target's `generation` block configures the generated MCP server. [Config A `path` to a TypeScript module whose functions wrap each request and result. See [Add custom tools and hooks](/learn/mcp-generator/get-started/configure#add-custom-tools-and-hooks). + + A `policy` (`open` or `allowlist`) and `allowedUpstreams` hosts that restrict where the server sends outbound requests. See [Restrict outbound requests](/learn/mcp-generator/get-started/configure#restrict-outbound-requests). + From 1fd899feb95578e8518562744588e021caddae7b Mon Sep 17 00:00:00 2001 From: Tristan De Clarin Date: Tue, 24 Nov 2026 11:35:54 -0800 Subject: [PATCH 2/3] Expand server instructions and egress sections - Server instructions: spec-generated block, append-vs-replace, per-conversation token cost. - Egress: open(default)/allowlist/empty-allowlist lockdown, host-exact matching, every-hop redirects, always-on SSRF + credential-origin-lock. --- fern/products/mcp-generator/configure.mdx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/fern/products/mcp-generator/configure.mdx b/fern/products/mcp-generator/configure.mdx index dd9ca98d9..a385e736b 100644 --- a/fern/products/mcp-generator/configure.mdx +++ b/fern/products/mcp-generator/configure.mdx @@ -199,7 +199,7 @@ A custom tool's handler can call any public host by default; an [egress allow-li ## Set the server instructions -The server returns a block of instructions on `initialize` that tells an agent how to use it. Fern generates this block from your spec: the server's name and description, the authentication scheme and header to send, and the `openapi://` resource and schema URIs an agent reads to browse docs and fetch full input schemas. `instructions` and `appendInstructions` set or extend that text. +On `initialize`, the server returns a block of **instructions** that tells an agent how to work with it. Fern generates this block from your spec, with no configuration: the server's name and description, the authentication scheme and the header to send, the `openapi://` resource and schema URIs an agent reads to browse docs and fetch full input schemas, and a note that arguments must match each tool's input schema. `appendInstructions` adds your own guidance after that block, and `instructions` replaces it. ```yaml title="sdk-config.yml" targets: @@ -210,9 +210,9 @@ targets: Prefer place_order over cancelling and re-creating an order. ``` -`appendInstructions` adds your text after the generated block, keeping the generated wiring in place. `instructions` replaces the generated block outright. Setting both replaces the block, then appends. With neither set, the server returns the generated instructions unchanged. +Prefer `appendInstructions`. It keeps the generated wiring, the `openapi://` URIs and `_meta` keys an agent needs to browse docs and fetch schemas, and adds your domain guidance on top. `instructions` replaces that wiring, so a bare replacement can break an agent's doc and schema browsing unless you restate what you still need. Setting both replaces the block first, then appends. With neither set, the server returns the generated instructions unchanged. -Replacing the block drops the generated `openapi://` URIs and `_meta` keys an agent needs to browse docs and fetch schemas, so prefer `appendInstructions` unless you restate that wiring yourself. Both fields go to the MCP client verbatim on every conversation, where they count against the context window, so keep them short. +Keep this text short. The MCP client sends the instructions to the model on every turn of every conversation, so they cost context tokens on each call. The generated block is budgeted to stay compact; your `appendInstructions` and `instructions` text is sent verbatim with no size cap, so long instructions add token cost to every request for as long as they're set. ## Pass credentials @@ -238,9 +238,14 @@ targets: - api.stripe.com ``` -Under `policy: allowlist`, the server allows a request only to your API's origin, an OAuth issuer, or a host listed in `allowedUpstreams`, and refuses any other host. Declaring `allowedUpstreams` turns on `allowlist` on its own, so set `policy` alone to lock the server to its API origin with no extra hosts. Omitting the `egress` block, or setting `policy: open`, leaves egress unrestricted. +`policy` is either `open` or `allowlist`: -Entries in `allowedUpstreams` are bare hostnames, without a scheme, path, port, or wildcard. The allow-list checks the resolved host of every outbound request, and a redirect to a host that isn't allowed is refused too. Blocking of private and internal addresses, and sending your API's credentials only to its own origin, both apply whatever the policy. +- **`open`** places no allow-list on destinations. It's the default, and leaving out the `egress` block entirely is the same as `open`, so existing servers keep reaching any public host until you opt in. +- **`allowlist`** refuses every outbound host except your API's origin, your OAuth issuer, and the hosts in `allowedUpstreams`. Declaring any `allowedUpstreams` turns on `allowlist` on its own, so write `policy: allowlist` by itself only to lock a server down to its API with no extra hosts (an empty allow-list). + +`allowedUpstreams` entries are bare hostnames, with no scheme, path, port, or wildcard, matched exactly: `api.stripe.com` does not cover `sub.api.stripe.com`. Under `allowlist` the check runs on every hop, so a redirect to a host that isn't allowed is refused too. + +The allow-list layers on protections that apply under every policy, including `open`: the server always blocks requests to private and internal addresses, and sends your API's credentials only to your API's origin. A private or internal address is refused even if you list it in `allowedUpstreams`. ## Limits From 0c0e4b6c5cc4fcc6b737555f664ee02916a054fa Mon Sep 17 00:00:00 2001 From: Tristan Date: Wed, 25 Nov 2026 10:53:47 -0800 Subject: [PATCH 3/3] Address PR review: accept style suggestions, pin CLI versions, clarify egress scope --- fern/products/mcp-generator/configure.mdx | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/fern/products/mcp-generator/configure.mdx b/fern/products/mcp-generator/configure.mdx index a385e736b..ad953b38d 100644 --- a/fern/products/mcp-generator/configure.mdx +++ b/fern/products/mcp-generator/configure.mdx @@ -189,7 +189,7 @@ The module exports four functions, each wrapping a point in the request lifecycl `context.fetch` doesn't set a content type. A non-2xx response returns to your handler without calling `onError`. On a `POST`, `PUT`, or `PATCH` with a JSON body, set `content-type: application/json`, or the body goes out as `text/plain` and many APIs answer `415`. -A custom tool's handler can call any public host by default; an [egress allow-list](#restrict-outbound-requests) limits it to hosts you declare. +A custom tool's handler can call any public host by default; an [egress allowlist](#restrict-outbound-requests) limits it to hosts you declare. `fern generate` uploads the custom tool and hook modules to Fern's build service, which bundles them into the server for both hosted and downloaded servers. @@ -199,7 +199,7 @@ A custom tool's handler can call any public host by default; an [egress allow-li ## Set the server instructions -On `initialize`, the server returns a block of **instructions** that tells an agent how to work with it. Fern generates this block from your spec, with no configuration: the server's name and description, the authentication scheme and the header to send, the `openapi://` resource and schema URIs an agent reads to browse docs and fetch full input schemas, and a note that arguments must match each tool's input schema. `appendInstructions` adds your own guidance after that block, and `instructions` replaces it. +On `initialize`, the server returns a block of **instructions** that tells an agent how to work with it. Fern generates this block from your spec, with no configuration: the server's name and description, the authentication scheme and the header to send, the `openapi://` resource and schema URIs an agent reads to browse docs and fetch full input schemas, and the rule that arguments must match each tool's input schema. `appendInstructions` adds your own guidance after that block, and `instructions` replaces it. Both require Fern CLI 5.225.0 or later. ```yaml title="sdk-config.yml" targets: @@ -210,9 +210,9 @@ targets: Prefer place_order over cancelling and re-creating an order. ``` -Prefer `appendInstructions`. It keeps the generated wiring, the `openapi://` URIs and `_meta` keys an agent needs to browse docs and fetch schemas, and adds your domain guidance on top. `instructions` replaces that wiring, so a bare replacement can break an agent's doc and schema browsing unless you restate what you still need. Setting both replaces the block first, then appends. With neither set, the server returns the generated instructions unchanged. +Prefer `appendInstructions`, which keeps the generated block. `instructions` replaces it, so restate the `openapi://` URIs if agents still need to browse docs and fetch schemas. Setting both replaces the block first, then appends. With neither set, the server returns the generated block unchanged. -Keep this text short. The MCP client sends the instructions to the model on every turn of every conversation, so they cost context tokens on each call. The generated block is budgeted to stay compact; your `appendInstructions` and `instructions` text is sent verbatim with no size cap, so long instructions add token cost to every request for as long as they're set. +Keep this text short. The MCP client sends the instructions to the model on every turn, and your text goes out verbatim with no size cap. ## Pass credentials @@ -226,7 +226,7 @@ Parameters that carry a credential aren't tool inputs. When a call is missing a ## Restrict outbound requests -A generated tool only ever calls your API, but a custom tool's handler can `fetch` any public host. `egress` restricts where the server sends outbound requests, including the calls custom tools make through `context.fetch`. +A generated tool calls only your API, but a custom tool's handler can `fetch` any public host. `egress` restricts where the server sends every outbound request, covering both `context.fetch` and the global `fetch` a handler can call. It requires Fern CLI 5.228.0 or later. ```yaml title="sdk-config.yml" targets: @@ -240,12 +240,12 @@ targets: `policy` is either `open` or `allowlist`: -- **`open`** places no allow-list on destinations. It's the default, and leaving out the `egress` block entirely is the same as `open`, so existing servers keep reaching any public host until you opt in. -- **`allowlist`** refuses every outbound host except your API's origin, your OAuth issuer, and the hosts in `allowedUpstreams`. Declaring any `allowedUpstreams` turns on `allowlist` on its own, so write `policy: allowlist` by itself only to lock a server down to its API with no extra hosts (an empty allow-list). +- **`open`** (the default, and the same as leaving out `egress`) places no limit on destinations, so existing servers keep reaching any public host until you opt in. +- **`allowlist`** refuses every outbound host except your API's origin, your OAuth issuer, and the hosts in `allowedUpstreams`. Listing any `allowedUpstreams` turns on `allowlist` without setting `policy`. Set `policy: allowlist` alone to limit the server to its API. -`allowedUpstreams` entries are bare hostnames, with no scheme, path, port, or wildcard, matched exactly: `api.stripe.com` does not cover `sub.api.stripe.com`. Under `allowlist` the check runs on every hop, so a redirect to a host that isn't allowed is refused too. +`allowedUpstreams` entries are bare hostnames, with no scheme, path, port, or wildcard, matched exactly: `api.stripe.com` doesn't cover `sub.api.stripe.com`. Under `allowlist` the check runs on every hop, so a redirect to a host that isn't allowed is refused too (the global `fetch` follows redirects; `context.fetch` doesn't). -The allow-list layers on protections that apply under every policy, including `open`: the server always blocks requests to private and internal addresses, and sends your API's credentials only to your API's origin. A private or internal address is refused even if you list it in `allowedUpstreams`. +The allowlist layers on protections that apply under every policy, including `open`: the server always blocks requests to private and internal addresses, and sends your API's credentials only to your API's origin. A private or internal address is refused even if you list it in `allowedUpstreams`. ## Limits