---
title: Environment Variables
description: Configuration via environment variables
sidebar:
  order: 7
---

import { Aside } from '@astrojs/starlight/components';

mcserial reads configuration from environment variables at startup. These variables set server-wide defaults that apply to all connections unless overridden by tool parameters.

---

## Server Configuration

### MCSERIAL_DEFAULT_BAUDRATE

Default baud rate used when `open_serial_port` is called without a `baudrate` parameter and auto-detection either fails or is not applicable (e.g., URL-based connections).

| | |
|---|---|
| **Default** | `9600` |
| **Type** | Integer |
| **Example** | `MCSERIAL_DEFAULT_BAUDRATE=115200` |

```bash
# Set a higher default for modern devices
export MCSERIAL_DEFAULT_BAUDRATE=115200
```

### MCSERIAL_DEFAULT_TIMEOUT

Default read timeout in seconds for new connections. Applied as the `timeout` parameter when `open_serial_port` is called without an explicit timeout.

| | |
|---|---|
| **Default** | `1.0` |
| **Type** | Float (seconds) |
| **Example** | `MCSERIAL_DEFAULT_TIMEOUT=2.0` |

```bash
# Longer timeout for slow devices
export MCSERIAL_DEFAULT_TIMEOUT=5.0
```

### MCSERIAL_MAX_CONNECTIONS

Maximum number of simultaneously open serial port connections. Attempts to open more ports than this limit return an error.

| | |
|---|---|
| **Default** | `10` |
| **Type** | Integer |
| **Example** | `MCSERIAL_MAX_CONNECTIONS=20` |

```bash
# Allow more concurrent connections
export MCSERIAL_MAX_CONNECTIONS=20
```

<Aside type="note">
Each open connection holds a file descriptor and kernel buffer memory. The default of 10 is sufficient for most use cases. Increase it only if you genuinely need many simultaneous connections.
</Aside>

---

## Setting Environment Variables

<Aside type="tip">
When using mcserial with Claude Code, set environment variables before adding the server:

```bash
# Option 1: Inline with the command
claude mcp add mcserial "env MCSERIAL_DEFAULT_BAUDRATE=115200 uvx mcserial"

# Option 2: Export in your shell profile
export MCSERIAL_DEFAULT_BAUDRATE=115200
claude mcp add mcserial "uvx mcserial"
```
</Aside>

For other MCP clients, consult their documentation for how to pass environment variables to server processes.

---

## Installation Extras

mcserial supports optional dependency groups for specialized hardware.

### mcserial[cp2110]

Adds the `hidapi` package for Silicon Labs CP2110 HID-to-UART bridge support. Required to use the `cp2110://` URL scheme with `open_serial_port`.

```bash
# Install with CP2110 support
uv pip install mcserial[cp2110]

# Or with uvx
uvx --with hidapi mcserial
```

Without this extra installed, attempting to open a `cp2110://` URL returns an error:

```
cp2110:// requires the hidapi package. Install with: pip install mcserial[cp2110]
```

<Aside type="note">
The `hidapi` package has system-level dependencies on some platforms. On Linux, you may need `libhidapi-dev` or equivalent. On macOS, it installs cleanly via pip. On Windows, no additional system packages are needed.
</Aside>
