# How to Configure the Server Port and Environment Variables in castrozan/tcc

> Learn to configure server port and environment variables in castrozan/tcc using the loadConfig function. Command-line args override env vars, defaulting to port 3000.

- Repository: [Lucas Zanoni⠀⠀⠀⠀⠀ ⠀╱|、 ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ (˚ˎ 。7 ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ |、˜〵 ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ じしˍ,)ノ/tcc](https://github.com/castrozan/tcc)
- Tags: how-to-guide
- Published: 2026-02-27

---

**The MCP OpenAPI Server in the `castrozan/tcc` repository configures the server port and environment variables through the `loadConfig()` function in [`mcp-openapi-server/src/config.ts`](https://github.com/castrozan/tcc/blob/main/mcp-openapi-server/src/config.ts), where command-line arguments take precedence over environment variables, defaulting to port 3000 for HTTP transport.**

The `castrozan/tcc` repository provides an MCP (Model Context Protocol) OpenAPI Server that bridges REST APIs with MCP-compatible clients. Configuring the server port and environment variables correctly is essential for production deployments and local development. This guide explains how the configuration system works based on the actual implementation in [`mcp-openapi-server/src/config.ts`](https://github.com/castrozan/tcc/blob/main/mcp-openapi-server/src/config.ts) and [`mcp-openapi-server/src/index.ts`](https://github.com/castrozan/tcc/blob/main/mcp-openapi-server/src/index.ts).

## Configuration Architecture and Priority

The configuration system uses a layered approach defined in [`mcp-openapi-server/src/config.ts`](https://github.com/castrozan/tcc/blob/main/mcp-openapi-server/src/config.ts). The `loadConfig()` function parses inputs using **yargs** and resolves final values based on strict precedence rules.

**Priority order (highest to lowest):**

1. Command-line arguments
2. Environment variables
3. Default values

This means a `--port` flag overrides the `HTTP_PORT` environment variable, which in turn overrides the default value of `3000`.

## Configuring the Server Port and Host

When using HTTP transport, three key parameters control network binding: **port**, **host**, and **endpoint path**. These are resolved in `loadConfig()` at lines 143-145 of [`mcp-openapi-server/src/config.ts`](https://github.com/castrozan/tcc/blob/main/mcp-openapi-server/src/config.ts).

### Using Command-Line Arguments

Pass flags directly when starting the server:

```bash
npx ts-node ./mcp-openapi-server/src/index.ts \
  --transport http \
  --port 8080 \
  --host 0.0.0.0 \
  --path /api/v1/mcp

```

### Using Environment Variables

Set variables in your shell or `.env` file:

```bash
export TRANSPORT_TYPE=http
export HTTP_PORT=8080
export HTTP_HOST=0.0.0.0
export ENDPOINT_PATH=/mcp

```

## Required and Optional Environment Variables

The following table lists all configuration options recognized by the server:

| Variable | CLI Equivalent | Required | Default | Description |
|----------|---------------|----------|---------|-------------|
| `API_BASE_URL` | `--api-base-url` / `-u` | Yes | — | Base URL of the target REST API |
| `OPENAPI_SPEC_PATH` | `--openapi-spec` / `-s` | Yes | — | Path or URL to the OpenAPI specification |
| `TRANSPORT_TYPE` | `--transport` / `-t` | No | `stdio` | Transport protocol (`stdio` or `http`) |
| `HTTP_PORT` | `--port` / `-p` | No | `3000` | HTTP server port |
| `HTTP_HOST` | `--host` | No | `127.0.0.1` | HTTP server host |
| `ENDPOINT_PATH` | `--path` | No | `/mcp` | HTTP endpoint path |
| `API_HEADERS` | `--headers` / `-H` | No | — | Comma-separated `key:value` headers for API requests |
| `SERVER_NAME` | — | No | `mcp-openapi-server` | Server identifier |
| `SERVER_VERSION` | — | No | `1.0.0` | Server version |
| `TOOLS_MODE` | — | No | `all` | Tool loading mode (`all` or `dynamic`) |
| `DISABLE_ABBREVIATION` | — | No | — | Set to `true` to disable name optimization |

## Practical Configuration Examples

### Running with a Custom Port via CLI

To start the server on port 8085 accessible from any network interface:

```bash
npx ts-node ./mcp-openapi-server/src/index.ts \
  --transport http \
  --port 8085 \
  --host 0.0.0.0 \
  --path /my-mcp \
  --api-base-url https://api.example.com \
  --openapi-spec ./spec.yaml

```

The server will listen at `http://0.0.0.0:8085/my-mcp`.

### Using a .env File for Production

Create a `.env` file in the repository root:

```dotenv
TRANSPORT_TYPE=http
HTTP_PORT=8080
HTTP_HOST=0.0.0.0
ENDPOINT_PATH=/mcp
API_BASE_URL=https://api.example.com
OPENAPI_SPEC_PATH=./openapi.json
API_HEADERS=Authorization:Bearer abc123,X-API-Key:mykey

```

Then start the server:

```bash
npm run start:mcp

```

The `loadConfig()` function automatically reads these values when the environment variables are present in the shell environment.

### Mixing CLI Arguments and Environment Variables

CLI arguments override environment variables. In this example, the port comes from the flag while the host comes from the environment:

```bash
export HTTP_HOST=0.0.0.0
export API_BASE_URL=https://staging.api.com

npx ts-node ./mcp-openapi-server/src/index.ts \
  --transport http \
  --port 9000

```

The server binds to `0.0.0.0:9000` and uses the staging API base URL.

## Summary

- The **MCP OpenAPI Server** in `castrozan/tcc` uses a hierarchical configuration system where **CLI arguments take precedence** over environment variables.
- The `loadConfig()` function in [`mcp-openapi-server/src/config.ts`](https://github.com/castrozan/tcc/blob/main/mcp-openapi-server/src/config.ts) handles all parsing logic, defaulting to port **3000**, host **127.0.0.1**, and path **/mcp** for HTTP transport.
- Required variables include `API_BASE_URL` and `OPENAPI_SPEC_PATH` (or their CLI equivalents `--api-base-url` and `--openapi-spec`).
- You can configure the server port and environment variables using `.env` files, shell exports, or command-line flags depending on your deployment needs.

## Frequently Asked Questions

### What is the default server port?

The default server port is **3000** when using HTTP transport. This is defined in [`mcp-openapi-server/src/config.ts`](https://github.com/castrozan/tcc/blob/main/mcp-openapi-server/src/config.ts) where the `httpPort` variable falls back to `3000` if neither the `--port` CLI argument nor the `HTTP_PORT` environment variable is set.

### Do CLI arguments override environment variables?

Yes. The configuration system in `castrozan/tcc` follows a strict precedence order: **CLI arguments take priority** over environment variables, which in turn take priority over default values. For example, passing `--port 8080` overrides the `HTTP_PORT` environment variable.

### How do I configure the server to listen on all network interfaces?

Set the host to `0.0.0.0` using either the `--host` CLI flag or the `HTTP_HOST` environment variable. The default host is `127.0.0.1` (localhost only), so you must explicitly change it to accept external connections.

### What happens if required environment variables are missing?

The `loadConfig()` function in [`mcp-openapi-server/src/config.ts`](https://github.com/castrozan/tcc/blob/main/mcp-openapi-server/src/config.ts) throws an informative error during startup if required values like `API_BASE_URL` or `OPENAPI_SPEC_PATH` are missing. The server will not start until these are provided via CLI arguments or environment variables.