Skip to main content
Glama
Nginx Proxy Manager MCP Server

Nginx Proxy Manager MCP Server

by nice-winter

Nginx Proxy Manager MCP Server

一个用于管理 Nginx Proxy Manager 的 Model Context Protocol (MCP) 服务器。

✨ 特性

  • 🔐 自动 JWT 刷新:在 token 即将过期时自动刷新,避免多轮对话中认证失败

  • 🛠️ 完整的 API 覆盖:支持 Proxy Hosts、Redirection Hosts、Dead Hosts、Streams 等所有资源

  • 📝 支持 advanced_config:创建/更新记录时完全支持 advanced_config 和 locations[].advanced_config

  • 🔄 自动重试:收到 401 错误时自动重新登录并重试请求

  • 🌐 多种传输模式:支持 stdio 和 Streamable HTTP 两种模式

  • 🔧 灵活配置:支持命令行参数、环境变量、HTTP Headers 多种配置方式

Related MCP server: npm-mcp

📋 支持的 Tools

类别

Tools

Proxy Hosts

npm_list_proxy_hosts, npm_get_proxy_host, npm_create_proxy_host, npm_update_proxy_host, npm_delete_proxy_host, npm_enable_proxy_host, npm_disable_proxy_host

Redirection Hosts

npm_list_redirection_hosts, npm_get_redirection_host, npm_create_redirection_host, npm_update_redirection_host, npm_delete_redirection_host, npm_enable_redirection_host, npm_disable_redirection_host

Dead Hosts

npm_list_dead_hosts, npm_get_dead_host, npm_create_dead_host, npm_update_dead_host, npm_delete_dead_host, npm_enable_dead_host, npm_disable_dead_host

Streams

npm_list_streams, npm_get_stream, npm_create_stream, npm_update_stream, npm_delete_stream, npm_enable_stream, npm_disable_stream

Access Lists

npm_list_access_lists, npm_get_access_list, npm_create_access_list, npm_update_access_list, npm_delete_access_list

Certificates

npm_list_certificates, npm_get_certificate, npm_create_certificate, npm_delete_certificate, npm_renew_certificate, npm_list_dns_providers, npm_test_http_challenge

Users

npm_list_users, npm_get_user, npm_create_user, npm_update_user, npm_delete_user, npm_get_user_permissions, npm_set_user_permissions

Settings

npm_list_settings, npm_get_setting, npm_update_setting, npm_list_audit_log, npm_get_report

⚠️ 已知问题

以下工具在 NPM API 层面存在问题,并非本 MCP Server 的 bug:

工具

错误

说明

npm_get_report

Not Found - /reports

NPM API 端点 /reports 不存在,可能需要更新 NPM 版本

npm_create_user

Internal Error

NPM API 返回 500,疑似 NPM 后端 bug,与传参无关

npm_get_user_permissions

Not Found - /users/{id}/permissions

权限查询端点不存在,NPM 可能已变更该 API 路径

npm_set_user_permissions

同上

依赖同一端点,同样不可用

以上问题需在 Nginx Proxy Manager 侧修复后才能正常工作。

🚀 快速开始

1. 安装依赖

pnpm install

2. 配置环境变量(可选)

对于 stdio 模式,需要配置 NPM 连接信息。对于 Streamable HTTP 模式,可以通过 HTTP Headers 提供配置。

复制 .env.example 到 .env:

cp .env.example .env

.env 文件内容:

# Nginx Proxy Manager Configuration
NPM_BASE_URL=http://your-npm-server:81
NPM_USERNAME=admin@example.com
NPM_PASSWORD=your_password

# Optional: Token refresh margin in seconds (default: 300 = 5 minutes)
NPM_TOKEN_REFRESH_MARGIN=300

# MCP Transport Configuration
# Options: stdio (default), streamable-http
MCP_TRANSPORT=stdio

# Streamable HTTP Configuration (only used when MCP_TRANSPORT=streamable-http)
MCP_HTTP_HOST=0.0.0.0
MCP_HTTP_PORT=1234
# Optional: Auth token for HTTP mode (clients must send Authorization: Bearer <token>)
MCP_HTTP_AUTH_TOKEN=

3. 编译

pnpm run build

4. 运行

stdio 模式(默认,适合 Claude Desktop):

pnpm run start

Streamable HTTP 模式(适合远程访问):

pnpm run start:http

🔧 配置方式

配置优先级(从高到低):

  1. 命令行参数 - --base-url, --username, --password

  2. 环境变量 / .env 文件 - NPM_BASE_URL, NPM_USERNAME, NPM_PASSWORD

  3. HTTP Headers - NPM-Base-Url, NPM-Username, NPM-Password(仅 Streamable HTTP 模式)

命令行参数

# stdio 模式
node dist/index.js --base-url http://10.0.1.199:81 --username admin@example.com --password mypassword

# Streamable HTTP 模式
node dist/index.js --transport streamable-http --host 0.0.0.0 --port 1234 --base-url http://10.0.1.199:81 --username admin@example.com --password mypassword

支持的参数:

  • --base-url - NPM 服务器地址

  • --username - NPM 用户名

  • --password - NPM 密码

  • --transport - 传输模式 (stdio 或 streamable-http)

  • --host - HTTP 监听地址 (默认 0.0.0.0)

  • --port - HTTP 端口

  • --auth-token - MCP 认证 token

HTTP Headers(Streamable HTTP 模式)

当环境变量未配置时,客户端可以通过 HTTP Headers 提供 NPM 配置:

{
  "mcpServers": {
    "nginx-proxy-manager": {
      "type": "streamable-http",
      "url": "http://localhost:1234/mcp",
      "headers": {
        "NPM-Base-Url": "http://10.0.1.199:81",
        "NPM-Username": "admin@example.com",
        "NPM-Password": "password123"
      }
    }
  }
}

优势:

  • 无需在服务器端配置 .env

  • 不同客户端可以连接不同的 NPM 服务器

  • 适合多租户场景

环境变量(stdio 模式)

对于 stdio 模式,MCP 客户端通常通过 env 字段传递配置:

{
  "mcpServers": {
    "nginx-proxy-manager": {
      "command": "node",
      "args": ["dist/index.js"],
      "env": {
        "NPM_BASE_URL": "http://10.0.1.199:81",
        "NPM_USERNAME": "admin@example.com",
        "NPM_PASSWORD": "password123"
      }
    }
  }
}

🌐 Streamable HTTP 模式

Streamable HTTP 模式允许通过 HTTP 访问 MCP Server,适合远程访问和团队共享。

启动

# 使用 .env 配置
pnpm run start:http

# 使用命令行参数
node dist/index.js --transport streamable-http --host 0.0.0.0 --port 1234

API 端点

  • URL: http://<MCP_HTTP_HOST>:<MCP_HTTP_PORT>/mcp

  • Methods: POST, GET, DELETE

  • Content-Type: application/json

  • Accept: application/json, text/event-stream

认证

可选的 MCP 认证 token 保护:

# 通过环境变量
MCP_HTTP_AUTH_TOKEN=your-secret-token pnpm run start:http

# 通过命令行参数
node dist/index.js --transport streamable-http --auth-token your-secret-token

客户端配置:

{
  "mcpServers": {
    "nginx-proxy-manager": {
      "type": "streamable-http",
      "url": "http://localhost:1234/mcp",
      "headers": {
        "Authorization": "Bearer your-secret-token",
        "NPM-Base-Url": "http://10.0.1.199:81",
        "NPM-Username": "admin@example.com",
        "NPM-Password": "password123"
      }
    }
  }
}

🔐 JWT 自动刷新机制

为了解决 Agent 多轮调用中 JWT 过期的问题,本 MCP Server 实现了以下机制:

  1. 提前刷新:在 token 即将过期前 5 分钟(可配置)自动刷新

  2. 自动重试:收到 401 错误时自动重新登录并重试请求

  3. 并发安全:多个请求同时触发刷新时,只会执行一次刷新

配置刷新间隔

在 .env 中设置 NPM_TOKEN_REFRESH_MARGIN(单位:秒):

# 在 token 过期前 5 分钟刷新(默认值)
NPM_TOKEN_REFRESH_MARGIN=300

# 在 token 过期前 10 分钟刷新
NPM_TOKEN_REFRESH_MARGIN=600

📝 使用示例

创建带 advanced_config 的 Proxy Host

{
  "name": "npm_create_proxy_host",
  "arguments": {
    "domain_names": ["app.example.com"],
    "forward_scheme": "http",
    "forward_host": "127.0.0.1",
    "forward_port": 8080,
    "advanced_config": "proxy_set_header Host $host;\nproxy_set_header X-Real-IP $remote_addr;",
    "locations": [
      {
        "path": "/api",
        "forward_scheme": "http",
        "forward_host": "backend.local",
        "forward_port": 3000,
        "advanced_config": "proxy_set_header X-API-Key secret;"
      }
    ]
  }
}

更新 Proxy Host 的 advanced_config

{
  "name": "npm_update_proxy_host",
  "arguments": {
    "host_id": 1,
    "advanced_config": "# Updated config\nproxy_buffering off;",
    "locations": [
      {
        "path": "/",
        "forward_scheme": "http",
        "forward_host": "10.0.1.101",
        "forward_port": 3000,
        "advanced_config": "proxy_set_header Host $host:60443;"
      }
    ]
  }
}

🚀 systemd 服务(开机启动)

Streamable HTTP 模式下,可以配置为 systemd 服务实现开机自动启动。

安装服务

# 编译项目
pnpm run build

# 安装 systemd 服务
pnpm run service:install

管理服务

# 启动/停止/重启
sudo systemctl start npm-mcp
sudo systemctl stop npm-mcp
sudo systemctl restart npm-mcp

# 查看状态
sudo systemctl status npm-mcp

# 查看日志(实时)
journalctl -u npm-mcp -f

开机启动控制

# 启用开机启动
sudo systemctl enable npm-mcp

# 禁用开机启动
sudo systemctl disable npm-mcp

卸载服务

pnpm run service:uninstall

🔧 开发

开发模式运行

# stdio 模式
pnpm run dev

# Streamable HTTP 模式
pnpm run dev:http

项目结构

mcp/
├── src/
│   ├── index.ts              # MCP Server 主入口
│   ├── npm-client.ts         # NPM API 客户端(含 JWT 自动刷新)
│   ├── types.ts              # TypeScript 类型定义
│   └── tools/
│       ├── proxy-hosts.ts    # Proxy Hosts tools
│       ├── redirection-hosts.ts  # Redirection Hosts tools
│       ├── dead-hosts.ts     # Dead Hosts tools
│       ├── streams.ts        # Streams tools
│       ├── access-lists.ts   # Access Lists tools
│       ├── certificates.ts   # Certificates tools
│       ├── users.ts          # Users tools
│       └── settings.ts       # Settings tools
├── scripts/
│   └── setup-systemd.sh      # systemd 服务安装脚本
├── docs/                     # API 文档
├── package.json
├── tsconfig.json
└── .env                      # 环境变量配置(可选)

📚 API 文档

详细的 API 文档请参考 docs/ 目录:

📄 License

MIT

Available Tools

52 tools
npm_create_access_listC

Create a new access list with HTTP Basic Auth and/or IP restrictions

Inputs: name (required), items, clients, pass_auth, +1 more.

npm_create_certificateB

Request a new Let's Encrypt SSL certificate

Inputs: provider (required), domain_names (required), key_type, nice_name, +4 more.

npm_create_dead_hostC

Create a new 404 dead host. Supports advanced_config for custom nginx configuration.

Inputs: domain_names (required), ssl_forced, hsts_enabled, http2_support, +3 more.

npm_create_proxy_hostC

Create a new proxy host in Nginx Proxy Manager. Supports advanced_config for custom nginx configuration and locations with per-location advanced_config.

Inputs: domain_names (required), forward_host (required), forward_port (required), forward_scheme (required), +13 more.

npm_create_redirection_hostC

Create a new redirection host. Supports advanced_config for custom nginx configuration.

Inputs: domain_names (required), forward_scheme (required), forward_http_code (required), forward_domain_name (required), +8 more.

npm_create_streamC

Create a new TCP/UDP stream proxy

Inputs: incoming_port (required), forwarding_host (required), forwarding_port (required), domain_names, +3 more.

npm_create_userC

Create a new Nginx Proxy Manager user

Inputs: name (required), email (required), nickname (required), roles, +2 more.

npm_delete_access_listC

Delete an access list by ID

Inputs: list_id (required).

npm_delete_certificateC

Delete an SSL certificate by ID

Inputs: certificate_id (required).

npm_delete_dead_hostC

Delete a dead host by ID

Inputs: host_id (required).

npm_delete_proxy_hostB

Delete a proxy host by ID

Inputs: host_id (required).

npm_delete_redirection_hostC

Delete a redirection host by ID

Inputs: host_id (required).

npm_delete_streamC

Delete a stream by ID

Inputs: stream_id (required).

npm_delete_userC

Delete a user by ID

Inputs: user_id (required).

npm_disable_dead_hostC

Disable a dead host

Inputs: host_id (required).

npm_disable_proxy_hostC

Disable a proxy host

Inputs: host_id (required).

npm_disable_redirection_hostC

Disable a redirection host

Inputs: host_id (required).

npm_disable_streamC

Disable a stream

Inputs: stream_id (required).

npm_enable_dead_hostC

Enable a dead host

Inputs: host_id (required).

npm_enable_proxy_hostC

Enable a proxy host

Inputs: host_id (required).

npm_enable_redirection_hostC

Enable a redirection host

Inputs: host_id (required).

npm_enable_streamC

Enable a stream

Inputs: stream_id (required).

npm_get_access_listC

Get details of a specific access list by ID

Inputs: list_id (required), expand.

npm_get_certificateB

Get details of a specific SSL certificate by ID

Inputs: certificate_id (required), expand.

npm_get_dead_hostC

Get details of a specific dead host by ID

Inputs: host_id (required), expand.

npm_get_proxy_hostC

Get details of a specific proxy host by ID

Inputs: host_id (required), expand.

npm_get_redirection_hostB

Get details of a specific redirection host by ID

Inputs: host_id (required), expand.

npm_get_reportB

Get host count report (proxy, redirection, stream, dead)

Inputs: no named parameters.

npm_get_settingC

Get a specific setting by ID

Inputs: setting_id (required).

npm_get_streamB

Get details of a specific stream by ID

Inputs: stream_id (required), expand.

npm_get_userB

Get details of a specific user by ID (use "me" for current user)

Inputs: user_id (required), expand.

npm_get_user_permissionsC

Get permissions for a specific user

Inputs: user_id (required).

npm_list_access_listsC

List all access lists (basic auth, IP restrictions)

Inputs: query, expand.

npm_list_audit_logB

List recent audit log entries

Inputs: no named parameters.

npm_list_certificatesC

List all SSL certificates in Nginx Proxy Manager

Inputs: query, expand.

npm_list_dead_hostsB

List all 404 dead hosts configured in Nginx Proxy Manager

Inputs: query, expand.

npm_list_dns_providersB

List supported DNS providers for DNS challenge certificates

Inputs: no named parameters.

npm_list_proxy_hostsB

List all proxy hosts configured in Nginx Proxy Manager

Inputs: query, expand.

npm_list_redirection_hostsB

List all redirection hosts configured in Nginx Proxy Manager

Inputs: query, expand.

npm_list_settingsB

List all Nginx Proxy Manager settings

Inputs: no named parameters.

npm_list_streamsB

List all TCP/UDP stream proxies configured in Nginx Proxy Manager

Inputs: query, expand.

npm_list_usersB

List all Nginx Proxy Manager users

Inputs: query, expand.

npm_renew_certificateB

Renew a Let's Encrypt SSL certificate

Inputs: certificate_id (required).

npm_set_user_permissionsC

Set permissions for a specific user

Inputs: streams (required), user_id (required), dead_hosts (required), visibility (required), +4 more.

npm_test_http_challengeC

Test if domains are reachable for HTTP-01 ACME challenge

Inputs: domains (required).

npm_update_access_listC

Update an existing access list

Inputs: list_id (required), name, items, clients, +2 more.

npm_update_dead_hostC

Update an existing dead host. Supports advanced_config for custom nginx configuration.

Inputs: host_id (required), ssl_forced, domain_names, hsts_enabled, +4 more.

npm_update_proxy_hostC

Update an existing proxy host. Supports advanced_config for custom nginx configuration and locations with per-location advanced_config.

Inputs: host_id (required), enabled, locations, ssl_forced, +14 more.

npm_update_redirection_hostC

Update an existing redirection host. Supports advanced_config for custom nginx configuration.

Inputs: host_id (required), ssl_forced, domain_names, hsts_enabled, +9 more.

npm_update_settingC

Update a setting (e.g., default site behavior)

Inputs: value (required), setting_id (required), html, redirect.

npm_update_streamC

Update an existing stream

Inputs: stream_id (required), domain_names, incoming_port, certificate_id, +4 more.

npm_update_userC

Update an existing user

Inputs: user_id (required), name, email, roles, +2 more.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3/5.0

    Scored across 52 tools

    Disambiguation4/5

    Each tool pairs a distinct action with a distinct resource (proxy_host, redirection_host, dead_host, stream, access_list, certificate, user, setting), so boundaries are generally clear. The parallel operation sets across the four host types are well-differentiated by resource name, though the near-identical list/get/create/update/delete/enable/disable patterns raise mild misselection risk.

    Naming Consistency5/5

    Tool names follow a highly predictable npm_<verb>_<resource> snake_case pattern throughout (list/get/create/update/delete/enable/disable), with consistent plural-for-list and singular-for-single conventions. No mixed conventions or vague verbs.

    Tool Count3/5

    52 tools is heavy, well above the typical 3-15 range. It is largely justified by the broad domain (four host types, access lists, certificates, users, settings) each needing full CRUD plus enable/disable, but the volume makes the surface intimidating and some operations could be consolidated.

    Completeness5/5

    The surface covers full lifecycle CRUD for every host type, access lists, certificates (including renew and challenge testing), users (with permissions), settings, audit logs, and reports. No obvious domain operations are missing.

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      D
      maintenance
      Enables management of Nginx Proxy Manager instances for configuring proxy hosts, requesting Let's Encrypt SSL certificates, and managing access lists. It allows users to control their web proxy infrastructure through natural language commands in MCP-compatible environments.
      50
      3
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI assistants to manage Nginx Proxy Manager instances through natural language, covering 28 tools for proxy hosts, certificates, streams, and more.
      MIT