diff --git a/fern/products/mcp-generator/configure.mdx b/fern/products/mcp-generator/configure.mdx index 9c69fcc98..ad953b38d 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 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. ## 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 + +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: + - 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. +``` + +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, and your text goes out verbatim with no size cap. + ## 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,29 @@ 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 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: + - language: mcp + generation: + egress: + policy: allowlist + allowedUpstreams: + - api.stripe.com +``` + +`policy` is either `open` or `allowlist`: + +- **`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` 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 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 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). +