|
| 1 | +# Options |
| 2 | + |
| 3 | +## Configuration Options |
| 4 | + |
| 5 | +| Option | Type | Default | Description | |
| 6 | +| --------------------------- | ---------------------------------------------------------------------------------------------------------- | ---------------------- | ----------------------------------------------------------------------------------- | |
| 7 | +| [`specSource`](#specsource) | `{ type: "object"; spec: OpenAPISpec } \| { type: "url"; spec: string } \| { type: "file"; spec: string }` | — | Provide your OpenAPI 3.x spec as an object, or point to it via URL or file path. | |
| 8 | +| [`server`](#server) | `{ name?: string; version?: string }` | see [below](#server) | MCP server metadata exposed during initialize. | |
| 9 | +| [`tools`](#tools) | `OpenAPIMcpToolsOptions` | see [below](#tools) | Control tool inclusion and naming. | |
| 10 | +| [`http`](#http) | `OpenAPIMcpHttpOptions` | see [below](#http) | Configure built-in MCP HTTP endpoint behavior. | |
| 11 | +| [`executor`](#executor) | `OpenAPIMcpExecutorOptions` | see [below](#executor) | Configure how generated tools execute target HTTP operations. | |
| 12 | +| `extendServer` | `(server: McpServer) => void \| Promise<void>` | — | Hook to register custom tools/resources/prompts or modify the generated MCP server. | |
| 13 | +| `debug` | `boolean` | `false` | Verbose logs for troubleshooting. | |
| 14 | + |
| 15 | +### `specSource` |
| 16 | + |
| 17 | +| Type | Type | Typical use | |
| 18 | +| ---------- | ------------- | ------------------------------------------------ | |
| 19 | +| `"object"` | `OpenAPISpec` | Static spec object. | |
| 20 | +| `"url"` | `string` | Link to a centralized or externally hosted spec. | |
| 21 | +| `"file"` | `string` | Local file path to a json/yaml file. | |
| 22 | + |
| 23 | +### `server` |
| 24 | + |
| 25 | +| Option | Type | Default | Description | |
| 26 | +| --------- | -------- | ---------------------------------- | ------------------------------------------ | |
| 27 | +| `name` | `string` | `spec.info.title` or `openapi-mcp` | MCP server display name during initialize. | |
| 28 | +| `version` | `string` | `spec.info.version` or `0.0.0` | MCP server version during initialize. | |
| 29 | + |
| 30 | +### `tools` |
| 31 | + |
| 32 | +| Option | Type | Default | Description | |
| 33 | +| ---------------- | --------- | ------- | ------------------------------------------------------------------- | |
| 34 | +| `defaultInclude` | `boolean` | `false` | Include operations as tools by default when `x-mcp` is not defined. | |
| 35 | +| `namePrefix` | `string` | — | Optional prefix for generated tool names (e.g. `api_`). | |
| 36 | + |
| 37 | +`x-mcp` precedence for operation inclusion is: |
| 38 | + |
| 39 | +1. operation-level `x-mcp` |
| 40 | +2. path-level `x-mcp` |
| 41 | +3. root-level `x-mcp` |
| 42 | +4. fallback to `tools.defaultInclude` |
| 43 | + |
| 44 | +### `http` |
| 45 | + |
| 46 | +| Option | Type | Default | Description | |
| 47 | +| ---------------- | --------------------------- | ------------- | ---------------------------------------------------------------------------- | |
| 48 | +| `enabled` | `boolean` | `true` | Enable built-in MCP HTTP endpoint/controller. | |
| 49 | +| `path` | `string` | `"/mcp"` | Endpoint path for streamable HTTP MCP transport. | |
| 50 | +| `sessionMode` | `"stateless" \| "stateful"` | `"stateless"` | Transport lifecycle mode for HTTP requests. | |
| 51 | +| `sessionTtlMs` | `number` | `3600000` | Session TTL in stateful mode. Expired sessions are cleaned up automatically. | |
| 52 | +| `allowedOrigins` | `string[]` | — | Optional origin allowlist check (returns `403` when denied). | |
| 53 | +| `allowedHosts` | `string[]` | — | Optional host allowlist check (returns `403` when denied). | |
| 54 | + |
| 55 | +### `executor` |
| 56 | + |
| 57 | +| Option | Type | Default | Description | |
| 58 | +| ---------------- | ---------- | ------------------- | ---------------------------------------------------------------------- | |
| 59 | +| `baseUrl` | `string` | — | Base URL for upstream HTTP execution. Required. | |
| 60 | +| `forwardHeaders` | `string[]` | `["authorization"]` | Request headers to forward from MCP request context to upstream calls. | |
| 61 | +| `timeoutMs` | `number` | `30000` | Upstream HTTP timeout per tool call. | |
| 62 | + |
| 63 | +## Async Configuration |
| 64 | + |
| 65 | +Use `forRootAsync()` for dependency injection: |
| 66 | + |
| 67 | +```ts |
| 68 | +OpenAPIMcpModule.forRootAsync({ |
| 69 | + imports: [ConfigModule], |
| 70 | + useFactory: (config: ConfigService) => ({ |
| 71 | + specSource: { type: "url", spec: config.getOrThrow("OPENAPI_SPEC_URL") }, |
| 72 | + http: { |
| 73 | + path: "/mcp", |
| 74 | + sessionMode: "stateless", |
| 75 | + }, |
| 76 | + executor: { |
| 77 | + baseUrl: config.getOrThrow("TARGET_API_BASE_URL"), |
| 78 | + forwardHeaders: ["authorization", "x-api-key"], |
| 79 | + timeoutMs: 15000, |
| 80 | + }, |
| 81 | + }), |
| 82 | + inject: [ConfigService], |
| 83 | +}); |
| 84 | +``` |
0 commit comments