> For a complete index of all SignalWire documentation pages, fetch https://signalwire.com/docs/llms.txt

# MCPGateway

> The main HTTP gateway service bridging MCP servers with SignalWire SWAIG functions.

[mcpmanager]: /docs/server-sdks/reference/python/agents/mcp-gateway/mcp-manager

[sessionmanager]: /docs/server-sdks/reference/python/agents/mcp-gateway/session-manager

[securityconfig]: /docs/server-sdks/reference/python/agents/configuration/security-config

[mcp-gateway-cli-command]: /docs/server-sdks/reference/python/agents/cli/mcp-gateway

[run]: /docs/server-sdks/reference/python/agents/mcp-gateway/mcp-gateway/run

[shutdown]: /docs/server-sdks/reference/python/agents/mcp-gateway/mcp-gateway/shutdown

MCPGateway is the main service class for the MCP-SWAIG gateway. It loads
configuration from a JSON file, initializes an
[`MCPManager`][mcpmanager] and
[`SessionManager`][sessionmanager],
sets up authenticated HTTP routes, and runs a Flask server that translates
between MCP tool calls and SignalWire SWAIG requests.

The gateway supports Basic auth and Bearer token authentication, rate limiting,
SSL/TLS, and automatic session cleanup.

## **Properties**

The underlying Flask application instance.

The loaded and environment-variable-substituted configuration dictionary.

The [`MCPManager`][mcpmanager] instance
that manages MCP service definitions and client lifecycles.

The [`SessionManager`][sessionmanager] instance
that tracks active MCP sessions.

The [`SecurityConfig`][securityconfig] instance
for authentication and security headers.

## **HTTP Endpoints**

The gateway exposes the following REST endpoints. All endpoints except `/health`
require authentication.

| Endpoint                 | Method | Description                      |
| ------------------------ | ------ | -------------------------------- |
| `/health`                | GET    | Health check (no auth required)  |
| `/services`              | GET    | List available MCP services      |
| `/services/<name>/tools` | GET    | Get tools for a specific service |
| `/services/<name>/call`  | POST   | Call a tool on a service         |
| `/sessions`              | GET    | List active sessions             |
| `/sessions/<id>`         | DELETE | Close a specific session         |

## **`main` Function**

```python
from signalwire.mcp_gateway import main
```

**main**() -> `None`

CLI entry point that parses command-line arguments and starts the gateway. Accepts
a `-c` / `--config` flag to specify the configuration file path (defaults to
`config.json`).

Use the [`mcp-gateway` CLI command][mcp-gateway-cli-command]
to run the gateway from the command line without writing any Python code.

## **Methods**

#### [run](/docs/server-sdks/reference/python/agents/mcp-gateway/mcp-gateway/run)

Start the gateway HTTP server, blocking until shutdown.

#### [shutdown](/docs/server-sdks/reference/python/agents/mcp-gateway/mcp-gateway/shutdown)

Gracefully shut down the gateway and all active sessions.