Skip to content
This repository was archived by the owner on Jul 14, 2025. It is now read-only.

Commit fb17dbf

Browse files
committed
Add mcp-gateway.md
1 parent ec43db2 commit fb17dbf

File tree

2 files changed

+187
-4
lines changed

2 files changed

+187
-4
lines changed

docs/configuration/mcp-gateway.md

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,97 @@
11
# mcp-gateway.yaml
22

3-
**很用力的补充中...**
3+
配置文件支持使用 `${VAR:default}` 语法进行环境变量注入。如果环境变量未设置,将使用默认值。
4+
5+
常见的做法是通过不同的`.env`, `.env.development`, `.env.prod`进行注入,当然也可以直接修改配置写死一个值
6+
7+
## 基础配置
8+
9+
```yaml
10+
port: ${MCP_GATEWAY_PORT:5235} # 服务监听端口
11+
pid: "${MCP_GATEWAY_PID:/var/run/mcp-gateway.pid}" # PID文件路径
12+
```
13+
14+
> 这里的PID和下面涉及的PID保持一致
15+
16+
## 存储配置
17+
18+
存储配置模块主要用于存储网关的代理配置信息。目前支持两种存储方式:
19+
- disk: 配置会以文件的形式存放在磁盘里,每个配置单独一个文件,可以理解跟nginx的vhost一个道理,比如 `svc-a.yaml`, `svc-b.yaml`
20+
- db: 存到数据库,每个配置是一条记录。目前支持三种数据库:
21+
- SQLite3
22+
- PostgreSQL
23+
- MySQL
24+
25+
```yaml
26+
storage:
27+
type: "${GATEWAY_STORAGE_TYPE:db}" # 存储类型:db, disk
28+
29+
# 数据库配置(当 type 为 'db' 时使用)
30+
database:
31+
type: "${GATEWAY_DB_TYPE:sqlite}" # 数据库类型(sqlite,postgres, myslq)
32+
host: "${GATEWAY_DB_HOST:localhost}" # 数据库主机地址
33+
port: ${GATEWAY_DB_PORT:5432} # 数据库端口
34+
user: "${GATEWAY_DB_USER:postgres}" # 数据库用户名
35+
password: "${GATEWAY_DB_PASSWORD:example}" # 数据库密码
36+
dbname: "${GATEWAY_DB_NAME:./data/mcp-gateway.db}" # 数据库名称或文件路径
37+
sslmode: "${GATEWAY_DB_SSL_MODE:disable}" # 数据库连接的 SSL 模式
38+
39+
# 磁盘配置(当 type 为 'disk' 时使用)
40+
disk:
41+
path: "${GATEWAY_STORAGE_DISK_PATH:}" # 数据文件存储路径
42+
```
43+
44+
## 通知配置
45+
46+
通知配置模块主要是用来当配置更新的时候如何让`mcp-gateway`感知到更新并进行热重载而无需重启服务。
47+
48+
目前支持4种通知方式:
49+
- signal: 通过发送操作系统信号量来通知,类似`kill -SIGHUP <pid>`或者`nginx -s reload`这种方式,可通过`mcp-gateway reload`命令调用,适合单机部署时使用
50+
- api: 通过调用一个api的方式通知,`mcp-gateway`会监听一个独立的端口,当收到请求时会进行热重载,可通过`curl http://localhost:5235/_reload`直接调用,适合单机和集群部署时使用
51+
- redis: 通过redis的发布/订阅功能通知,适合单机或集群部署时使用
52+
- composite: 组合通知,通过多种方式组合,默认`signal`和`api`一定会开启,可以在配合其他方式。适合单机和集群部署时使用,也是推荐的默认的方式
53+
54+
通知区分角色:
55+
- sender: 发送者,负责发送通知,`apiserver`只能走这个模式
56+
- receiver: 接收者,负责接收通知,单机的`mcp-gateway`建议只走这个模式
57+
- both: 既是发送者又是接收者,集群部署的`mcp-gateway`可以走这个方式
58+
59+
```yaml
60+
notifier:
61+
role: "${NOTIFIER_ROLE:receiver}" # 角色:'sender'(发送者)或 'receiver'(接收者)
62+
type: "${NOTIFIER_TYPE:signal}" # 类型:'signal'(信号)、'api'、'redis' 或 'composite'(组合)
63+
64+
# 信号配置(当 type 为 'signal' 时使用)
65+
signal:
66+
signal: "${NOTIFIER_SIGNAL:SIGHUP}" # 要发送的信号
67+
pid: "${NOTIFIER_SIGNAL_PID:/var/run/mcp-gateway.pid}" # PID 文件路径
68+
69+
# API 配置(当 type 为 'api' 时使用)
70+
api:
71+
port: ${NOTIFIER_API_PORT:5235} # API 端口
72+
target_url: "${NOTIFIER_API_TARGET_URL:http://localhost:5235/_reload}" # 重载端点
73+
74+
# Redis 配置(当 type 为 'redis' 时使用)
75+
redis:
76+
addr: "${NOTIFIER_REDIS_ADDR:localhost:6379}" # Redis 地址
77+
password: "${NOTIFIER_REDIS_PASSWORD:UseStrongPasswordIsAGoodPractice}" # Redis 密码
78+
db: ${NOTIFIER_REDIS_DB:0} # Redis 数据库编号
79+
topic: "${NOTIFIER_REDIS_TOPIC:mcp-gateway:reload}" # Redis 发布/订阅主题
80+
```
81+
82+
## 会话存储配置
83+
84+
会话存储配置用于存储MCP中的会话信息。目前支持两种存储方式:
85+
- memory: 内存存储,适合单机部署(需注意,重启会失去会话信息)
86+
- redis: Redis存储,适合单机或集群部署
87+
88+
```yaml
89+
session:
90+
type: "${SESSION_STORAGE_TYPE:memory}" # 存储类型:memory, redis
91+
redis:
92+
addr: "${SESSION_REDIS_ADDR:localhost:6379}" # Redis 地址
93+
password: "${SESSION_REDIS_PASSWORD:}" # Redis 密码
94+
db: ${SESSION_REDIS_DB:0} # Redis 数据库编号
95+
topic: "${SESSION_REDIS_TOPIC:mcp-gateway:session}" # Redis 发布/订阅主题
96+
```
497

5-
👇👇👇👇👇👇 如果你想帮忙完善可以点这里,十分感谢❤️
Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,96 @@
11
# mcp-gateway.yaml
22

3-
**Work in progress — fueled by caffeine and optimism...**
3+
Configuration files support environment variable injection using the `${VAR:default}` syntax. If the environment variable is not set, the default value will be used.
44

5-
👇👇👇👇👇👇 If you would like to help improve this documentation, feel free to contribute. Thank you so much ❤️
5+
Common practice is to inject through different `.env`, `.env.development`, `.env.prod` files, or you can directly modify the configuration with a fixed value.
6+
7+
## Basic Configuration
8+
9+
```yaml
10+
port: ${MCP_GATEWAY_PORT:5235} # Service listening port
11+
pid: "${MCP_GATEWAY_PID:/var/run/mcp-gateway.pid}" # PID file path
12+
```
13+
14+
> The PID here should be consistent with the PID mentioned below
15+
16+
## Storage Configuration
17+
18+
The storage configuration module is mainly used to store gateway proxy configuration information. Currently supports two storage methods:
19+
- disk: Configurations are stored as files on disk, with each configuration in a separate file, similar to nginx's vhost concept, e.g., `svc-a.yaml`, `svc-b.yaml`
20+
- db: Store in database, with each configuration as a record. Currently supports three databases:
21+
- SQLite3
22+
- PostgreSQL
23+
- MySQL
24+
25+
```yaml
26+
storage:
27+
type: "${GATEWAY_STORAGE_TYPE:db}" # Storage type: db, disk
28+
29+
# Database configuration (used when type is 'db')
30+
database:
31+
type: "${GATEWAY_DB_TYPE:sqlite}" # Database type (sqlite, postgres, mysql)
32+
host: "${GATEWAY_DB_HOST:localhost}" # Database host address
33+
port: ${GATEWAY_DB_PORT:5432} # Database port
34+
user: "${GATEWAY_DB_USER:postgres}" # Database username
35+
password: "${GATEWAY_DB_PASSWORD:example}" # Database password
36+
dbname: "${GATEWAY_DB_NAME:./data/mcp-gateway.db}" # Database name or file path
37+
sslmode: "${GATEWAY_DB_SSL_MODE:disable}" # Database SSL mode
38+
39+
# Disk configuration (used when type is 'disk')
40+
disk:
41+
path: "${GATEWAY_STORAGE_DISK_PATH:}" # Data file storage path
42+
```
43+
44+
## Notifier Configuration
45+
46+
The notifier configuration module is used to notify `mcp-gateway` of configuration updates and trigger hot reload without restarting the service.
47+
48+
Currently supports four notification methods:
49+
- signal: Notify through operating system signals, similar to `kill -SIGHUP <pid>` or `nginx -s reload`, can be called via `mcp-gateway reload` command, suitable for single-machine deployment
50+
- api: Notify through API calls, `mcp-gateway` listens on a separate port and performs hot reload when receiving requests, can be called directly via `curl http://localhost:5235/_reload`, suitable for both single-machine and cluster deployment
51+
- redis: Notify through Redis pub/sub functionality, suitable for both single-machine and cluster deployment
52+
- composite: Combined notification, using multiple methods, with `signal` and `api` enabled by default, can be combined with other methods. Suitable for both single-machine and cluster deployment, recommended as the default method
53+
54+
Notification roles:
55+
- sender: Sender, responsible for sending notifications, `apiserver` can only use this mode
56+
- receiver: Receiver, responsible for receiving notifications, single-machine `mcp-gateway` is recommended to use only this mode
57+
- both: Both sender and receiver, cluster-deployed `mcp-gateway` can use this mode
58+
59+
```yaml
60+
notifier:
61+
role: "${NOTIFIER_ROLE:receiver}" # Role: 'sender' or 'receiver'
62+
type: "${NOTIFIER_TYPE:signal}" # Type: 'signal', 'api', 'redis', or 'composite'
63+
64+
# Signal configuration (used when type is 'signal')
65+
signal:
66+
signal: "${NOTIFIER_SIGNAL:SIGHUP}" # Signal to send
67+
pid: "${NOTIFIER_SIGNAL_PID:/var/run/mcp-gateway.pid}" # PID file path
68+
69+
# API configuration (used when type is 'api')
70+
api:
71+
port: ${NOTIFIER_API_PORT:5235} # API port
72+
target_url: "${NOTIFIER_API_TARGET_URL:http://localhost:5235/_reload}" # Reload endpoint
73+
74+
# Redis configuration (used when type is 'redis')
75+
redis:
76+
addr: "${NOTIFIER_REDIS_ADDR:localhost:6379}" # Redis address
77+
password: "${NOTIFIER_REDIS_PASSWORD:UseStrongPasswordIsAGoodPractice}" # Redis password
78+
db: ${NOTIFIER_REDIS_DB:0} # Redis database number
79+
topic: "${NOTIFIER_REDIS_TOPIC:mcp-gateway:reload}" # Redis pub/sub topic
80+
```
81+
82+
## Session Storage Configuration
83+
84+
Session storage configuration is used to store MCP session information. Currently supports two storage methods:
85+
- memory: In-memory storage, suitable for single-machine deployment (note: session information will be lost on restart)
86+
- redis: Redis storage, suitable for both single-machine and cluster deployment
87+
88+
```yaml
89+
session:
90+
type: "${SESSION_STORAGE_TYPE:memory}" # Storage type: memory, redis
91+
redis:
92+
addr: "${SESSION_REDIS_ADDR:localhost:6379}" # Redis address
93+
password: "${SESSION_REDIS_PASSWORD:}" # Redis password
94+
db: ${SESSION_REDIS_DB:0} # Redis database number
95+
topic: "${SESSION_REDIS_TOPIC:mcp-gateway:session}" # Redis pub/sub topic
96+
```

0 commit comments

Comments
 (0)