mirror of
https://github.com/samanhappy/mcphub.git
synced 2025-12-31 20:00:00 -05:00
Compare commits
4 Commits
copilot/im
...
copilot/fi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0ce649d2d4 | ||
|
|
834244dead | ||
|
|
fe7da99dfd | ||
|
|
ff6f8dc3ea |
@@ -19,6 +19,7 @@ MCPHub facilite la gestion et la mise à l'échelle de plusieurs serveurs MCP (M
|
|||||||
- **Configuration à chaud** : Ajoutez, supprimez ou mettez à jour les serveurs MCP à la volée, sans temps d'arrêt.
|
- **Configuration à chaud** : Ajoutez, supprimez ou mettez à jour les serveurs MCP à la volée, sans temps d'arrêt.
|
||||||
- **Contrôle d'accès basé sur les groupes** : Organisez les serveurs en groupes personnalisables pour une gestion simplifiée des autorisations.
|
- **Contrôle d'accès basé sur les groupes** : Organisez les serveurs en groupes personnalisables pour une gestion simplifiée des autorisations.
|
||||||
- **Authentification sécurisée** : Gestion des utilisateurs intégrée avec contrôle d'accès basé sur les rôles, optimisée par JWT et bcrypt.
|
- **Authentification sécurisée** : Gestion des utilisateurs intégrée avec contrôle d'accès basé sur les rôles, optimisée par JWT et bcrypt.
|
||||||
|
- **Support de proxy** : Configurez des proxys HTTP/HTTPS pour les serveurs MCP qui doivent accéder à des ressources externes. Voir le [Guide de support proxy](docs/configuration/proxy-support.mdx).
|
||||||
- **Prêt pour Docker** : Déployez instantanément avec notre configuration conteneurisée.
|
- **Prêt pour Docker** : Déployez instantanément avec notre configuration conteneurisée.
|
||||||
|
|
||||||
## 🔧 Démarrage rapide
|
## 🔧 Démarrage rapide
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ MCPHub makes it easy to manage and scale multiple MCP (Model Context Protocol) s
|
|||||||
- **Secure Authentication**: Built-in user management with role-based access powered by JWT and bcrypt.
|
- **Secure Authentication**: Built-in user management with role-based access powered by JWT and bcrypt.
|
||||||
- **OAuth 2.0 Support**: Full OAuth support for upstream MCP servers with proxy authorization capabilities.
|
- **OAuth 2.0 Support**: Full OAuth support for upstream MCP servers with proxy authorization capabilities.
|
||||||
- **Environment Variable Expansion**: Use environment variables anywhere in your configuration for secure credential management. See [Environment Variables Guide](docs/environment-variables.md).
|
- **Environment Variable Expansion**: Use environment variables anywhere in your configuration for secure credential management. See [Environment Variables Guide](docs/environment-variables.md).
|
||||||
|
- **Proxy Support**: Configure HTTP/HTTPS proxies for MCP servers that need to access external resources. See [Proxy Support Guide](docs/configuration/proxy-support.mdx).
|
||||||
- **Docker-Ready**: Deploy instantly with our containerized setup.
|
- **Docker-Ready**: Deploy instantly with our containerized setup.
|
||||||
|
|
||||||
## 🔧 Quick Start
|
## 🔧 Quick Start
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ MCPHub 通过将多个 MCP(Model Context Protocol)服务器组织为灵活
|
|||||||
- **热插拔式配置**:在运行时动态添加、移除或更新服务器配置,无需停机。
|
- **热插拔式配置**:在运行时动态添加、移除或更新服务器配置,无需停机。
|
||||||
- **基于分组的访问控制**:自定义分组并管理服务器访问权限。
|
- **基于分组的访问控制**:自定义分组并管理服务器访问权限。
|
||||||
- **安全认证机制**:内置用户管理,基于 JWT 和 bcrypt,实现角色权限控制。
|
- **安全认证机制**:内置用户管理,基于 JWT 和 bcrypt,实现角色权限控制。
|
||||||
|
- **代理支持**:为需要通过代理访问外部资源的 MCP 服务器配置 HTTP/HTTPS 代理。参见[代理支持指南](docs/configuration/proxy-support.mdx)。
|
||||||
- **Docker 就绪**:提供容器化镜像,快速部署。
|
- **Docker 就绪**:提供容器化镜像,快速部署。
|
||||||
|
|
||||||
## 🔧 快速开始
|
## 🔧 快速开始
|
||||||
|
|||||||
368
docs/configuration/proxy-support.mdx
Normal file
368
docs/configuration/proxy-support.mdx
Normal file
@@ -0,0 +1,368 @@
|
|||||||
|
# Proxy Support for MCP Servers
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
MCPHub supports configuring proxy servers for MCP servers that need to access external resources through a proxy. This is particularly useful when:
|
||||||
|
|
||||||
|
- Your MCP servers need to install packages from external repositories
|
||||||
|
- Your network environment requires proxy for internet access
|
||||||
|
- You need to route MCP server traffic through a specific proxy
|
||||||
|
|
||||||
|
## How It Works
|
||||||
|
|
||||||
|
For **stdio-based MCP servers** (servers that spawn child processes), MCPHub automatically passes environment variables to the spawned process. This includes standard proxy environment variables:
|
||||||
|
|
||||||
|
- `HTTP_PROXY` / `http_proxy` - Proxy server for HTTP connections
|
||||||
|
- `HTTPS_PROXY` / `https_proxy` - Proxy server for HTTPS connections
|
||||||
|
- `NO_PROXY` / `no_proxy` - Comma-separated list of hosts that should bypass the proxy
|
||||||
|
|
||||||
|
## Configuration Methods
|
||||||
|
|
||||||
|
### Method 1: System-wide Environment Variables
|
||||||
|
|
||||||
|
Set proxy environment variables before starting MCPHub. These will be inherited by all MCP servers:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Linux/macOS
|
||||||
|
export HTTP_PROXY="http://proxy.example.com:8080"
|
||||||
|
export HTTPS_PROXY="http://proxy.example.com:8080"
|
||||||
|
export NO_PROXY="localhost,127.0.0.1,.local"
|
||||||
|
|
||||||
|
# Start MCPHub
|
||||||
|
npm start
|
||||||
|
```
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# Windows PowerShell
|
||||||
|
$env:HTTP_PROXY="http://proxy.example.com:8080"
|
||||||
|
$env:HTTPS_PROXY="http://proxy.example.com:8080"
|
||||||
|
$env:NO_PROXY="localhost,127.0.0.1,.local"
|
||||||
|
|
||||||
|
# Start MCPHub
|
||||||
|
npm start
|
||||||
|
```
|
||||||
|
|
||||||
|
### Method 2: Per-Server Configuration
|
||||||
|
|
||||||
|
Configure proxy settings for specific MCP servers in `mcp_settings.json`:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"mcpServers": {
|
||||||
|
"my-server": {
|
||||||
|
"type": "stdio",
|
||||||
|
"command": "npx",
|
||||||
|
"args": ["-y", "@modelcontextprotocol/server-example"],
|
||||||
|
"env": {
|
||||||
|
"HTTP_PROXY": "http://proxy.example.com:8080",
|
||||||
|
"HTTPS_PROXY": "http://proxy.example.com:8080",
|
||||||
|
"NO_PROXY": "localhost,127.0.0.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Method 3: Using Environment Variable References
|
||||||
|
|
||||||
|
Combine per-server configuration with environment variable references for flexibility:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"mcpServers": {
|
||||||
|
"my-server": {
|
||||||
|
"type": "stdio",
|
||||||
|
"command": "uvx",
|
||||||
|
"args": ["mcp-server-fetch"],
|
||||||
|
"env": {
|
||||||
|
"HTTP_PROXY": "${COMPANY_HTTP_PROXY}",
|
||||||
|
"HTTPS_PROXY": "${COMPANY_HTTPS_PROXY}",
|
||||||
|
"NO_PROXY": "${COMPANY_NO_PROXY}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Then set the environment variables:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export COMPANY_HTTP_PROXY="http://proxy.example.com:8080"
|
||||||
|
export COMPANY_HTTPS_PROXY="http://proxy.example.com:8080"
|
||||||
|
export COMPANY_NO_PROXY="localhost,127.0.0.1,.local"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Docker Usage
|
||||||
|
|
||||||
|
### Method 1: Docker Environment Variables
|
||||||
|
|
||||||
|
Pass proxy settings when running MCPHub container:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run \
|
||||||
|
-e HTTP_PROXY="http://proxy.example.com:8080" \
|
||||||
|
-e HTTPS_PROXY="http://proxy.example.com:8080" \
|
||||||
|
-e NO_PROXY="localhost,127.0.0.1" \
|
||||||
|
-v $(pwd)/mcp_settings.json:/app/mcp_settings.json \
|
||||||
|
samanhappy/mcphub:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
### Method 2: Docker Compose
|
||||||
|
|
||||||
|
Configure proxy in `docker-compose.yml`:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
version: '3.8'
|
||||||
|
services:
|
||||||
|
mcphub:
|
||||||
|
image: samanhappy/mcphub:latest
|
||||||
|
environment:
|
||||||
|
- HTTP_PROXY=http://proxy.example.com:8080
|
||||||
|
- HTTPS_PROXY=http://proxy.example.com:8080
|
||||||
|
- NO_PROXY=localhost,127.0.0.1,.local
|
||||||
|
volumes:
|
||||||
|
- ./mcp_settings.json:/app/mcp_settings.json
|
||||||
|
```
|
||||||
|
|
||||||
|
### Method 3: Docker Environment File
|
||||||
|
|
||||||
|
Create a `.env` file:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# .env
|
||||||
|
HTTP_PROXY=http://proxy.example.com:8080
|
||||||
|
HTTPS_PROXY=http://proxy.example.com:8080
|
||||||
|
NO_PROXY=localhost,127.0.0.1,.local
|
||||||
|
```
|
||||||
|
|
||||||
|
Use it with Docker:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run --env-file .env -v $(pwd)/mcp_settings.json:/app/mcp_settings.json samanhappy/mcphub:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
Or with docker-compose.yml:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
version: '3.8'
|
||||||
|
services:
|
||||||
|
mcphub:
|
||||||
|
image: samanhappy/mcphub:latest
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
|
volumes:
|
||||||
|
- ./mcp_settings.json:/app/mcp_settings.json
|
||||||
|
```
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
### Example 1: NPM Packages with Proxy
|
||||||
|
|
||||||
|
Configure an MCP server that uses NPM packages through a proxy:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"mcpServers": {
|
||||||
|
"playwright-server": {
|
||||||
|
"type": "stdio",
|
||||||
|
"command": "npx",
|
||||||
|
"args": ["@playwright/mcp@latest", "--headless"],
|
||||||
|
"env": {
|
||||||
|
"HTTP_PROXY": "http://proxy.company.com:8080",
|
||||||
|
"HTTPS_PROXY": "http://proxy.company.com:8080",
|
||||||
|
"NO_PROXY": "localhost,127.0.0.1,.company.com"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Example 2: Python UVX with Proxy
|
||||||
|
|
||||||
|
Configure a Python-based MCP server that needs proxy for package installation:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"mcpServers": {
|
||||||
|
"fetch-server": {
|
||||||
|
"type": "stdio",
|
||||||
|
"command": "uvx",
|
||||||
|
"args": ["mcp-server-fetch"],
|
||||||
|
"env": {
|
||||||
|
"HTTP_PROXY": "http://proxy.company.com:8080",
|
||||||
|
"HTTPS_PROXY": "http://proxy.company.com:8080",
|
||||||
|
"NO_PROXY": "localhost,127.0.0.1,*.internal"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Example 3: Mixed Configuration
|
||||||
|
|
||||||
|
Some servers use proxy, others don't:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"mcpServers": {
|
||||||
|
"external-api": {
|
||||||
|
"type": "stdio",
|
||||||
|
"command": "npx",
|
||||||
|
"args": ["-y", "@external/mcp-server"],
|
||||||
|
"env": {
|
||||||
|
"HTTP_PROXY": "${EXTERNAL_PROXY}",
|
||||||
|
"HTTPS_PROXY": "${EXTERNAL_PROXY}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"internal-service": {
|
||||||
|
"type": "stdio",
|
||||||
|
"command": "npx",
|
||||||
|
"args": ["-y", "@internal/mcp-server"],
|
||||||
|
"env": {
|
||||||
|
"NO_PROXY": "*"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Proxy Authentication
|
||||||
|
|
||||||
|
If your proxy requires authentication, include credentials in the proxy URL:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"mcpServers": {
|
||||||
|
"my-server": {
|
||||||
|
"type": "stdio",
|
||||||
|
"command": "npx",
|
||||||
|
"args": ["-y", "my-mcp-server"],
|
||||||
|
"env": {
|
||||||
|
"HTTP_PROXY": "http://username:password@proxy.example.com:8080",
|
||||||
|
"HTTPS_PROXY": "http://username:password@proxy.example.com:8080"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Security Note**: For better security, use environment variable references to avoid storing credentials in configuration files:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"mcpServers": {
|
||||||
|
"my-server": {
|
||||||
|
"type": "stdio",
|
||||||
|
"command": "npx",
|
||||||
|
"args": ["-y", "my-mcp-server"],
|
||||||
|
"env": {
|
||||||
|
"HTTP_PROXY": "${PROXY_URL_WITH_CREDENTIALS}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Then set the environment variable:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export PROXY_URL_WITH_CREDENTIALS="http://username:password@proxy.example.com:8080"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
### Proxy Not Working
|
||||||
|
|
||||||
|
1. **Verify proxy configuration**:
|
||||||
|
```bash
|
||||||
|
echo $HTTP_PROXY
|
||||||
|
echo $HTTPS_PROXY
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Check proxy connectivity**:
|
||||||
|
```bash
|
||||||
|
curl -x http://proxy.example.com:8080 https://www.google.com
|
||||||
|
```
|
||||||
|
|
||||||
|
3. **Test with a simple command**:
|
||||||
|
```bash
|
||||||
|
HTTP_PROXY=http://proxy.example.com:8080 curl https://api.github.com
|
||||||
|
```
|
||||||
|
|
||||||
|
4. **Check MCP server logs**:
|
||||||
|
- Look for connection errors in MCPHub console output
|
||||||
|
- Check if the MCP server reports proxy-related errors
|
||||||
|
|
||||||
|
### Certificate Issues
|
||||||
|
|
||||||
|
If using HTTPS proxy with self-signed certificates:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"mcpServers": {
|
||||||
|
"my-server": {
|
||||||
|
"type": "stdio",
|
||||||
|
"command": "npx",
|
||||||
|
"args": ["-y", "my-mcp-server"],
|
||||||
|
"env": {
|
||||||
|
"HTTPS_PROXY": "http://proxy.example.com:8080",
|
||||||
|
"NODE_TLS_REJECT_UNAUTHORIZED": "0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Warning**: Disabling certificate validation (`NODE_TLS_REJECT_UNAUTHORIZED=0`) should only be used in development or trusted networks.
|
||||||
|
|
||||||
|
### Proxy for Package Installation Only
|
||||||
|
|
||||||
|
If you only need proxy for package installation (not runtime):
|
||||||
|
|
||||||
|
For NPM:
|
||||||
|
```bash
|
||||||
|
npm config set proxy http://proxy.example.com:8080
|
||||||
|
npm config set https-proxy http://proxy.example.com:8080
|
||||||
|
```
|
||||||
|
|
||||||
|
For Python/UV:
|
||||||
|
```bash
|
||||||
|
export UV_HTTP_PROXY=http://proxy.example.com:8080
|
||||||
|
```
|
||||||
|
|
||||||
|
## Limitations
|
||||||
|
|
||||||
|
### SSE and HTTP-based MCP Servers
|
||||||
|
|
||||||
|
The proxy configuration described here applies to **stdio-based MCP servers** (servers that spawn child processes).
|
||||||
|
|
||||||
|
For **SSE** or **HTTP-based** MCP servers, MCPHub itself acts as the HTTP client. In these cases:
|
||||||
|
|
||||||
|
1. Set proxy environment variables for the MCPHub process (not in `mcp_settings.json`)
|
||||||
|
2. The Node.js HTTP client will automatically use these proxy settings
|
||||||
|
|
||||||
|
Example for SSE servers:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Set proxy for MCPHub process
|
||||||
|
export HTTP_PROXY="http://proxy.example.com:8080"
|
||||||
|
export HTTPS_PROXY="http://proxy.example.com:8080"
|
||||||
|
|
||||||
|
# Start MCPHub - it will use these settings for SSE/HTTP connections
|
||||||
|
npm start
|
||||||
|
```
|
||||||
|
|
||||||
|
## Best Practices
|
||||||
|
|
||||||
|
1. **Use environment variables** for proxy credentials to avoid storing them in configuration files
|
||||||
|
2. **Configure NO_PROXY** to exclude internal services and localhost
|
||||||
|
3. **Test proxy configuration** before deploying to production
|
||||||
|
4. **Document proxy requirements** for your deployment environment
|
||||||
|
5. **Use separate proxy configurations** for different MCP servers when needed
|
||||||
|
6. **Monitor proxy logs** for connection issues and performance
|
||||||
|
|
||||||
|
## Related Documentation
|
||||||
|
|
||||||
|
- [Environment Variables](../environment-variables.md) - Learn about environment variable expansion
|
||||||
|
- [Docker Setup](./docker-setup.mdx) - Docker-specific configuration
|
||||||
|
- [MCP Settings](./mcp-settings.mdx) - Complete configuration reference
|
||||||
@@ -31,6 +31,31 @@
|
|||||||
"DATABASE_URL": "${DATABASE_URL}"
|
"DATABASE_URL": "${DATABASE_URL}"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"example-stdio-server-with-proxy": {
|
||||||
|
"type": "stdio",
|
||||||
|
"command": "npx",
|
||||||
|
"args": [
|
||||||
|
"-y",
|
||||||
|
"@modelcontextprotocol/server-example"
|
||||||
|
],
|
||||||
|
"env": {
|
||||||
|
"HTTP_PROXY": "${HTTP_PROXY}",
|
||||||
|
"HTTPS_PROXY": "${HTTPS_PROXY}",
|
||||||
|
"NO_PROXY": "${NO_PROXY}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"example-python-server-with-proxy": {
|
||||||
|
"type": "stdio",
|
||||||
|
"command": "uvx",
|
||||||
|
"args": [
|
||||||
|
"mcp-server-fetch"
|
||||||
|
],
|
||||||
|
"env": {
|
||||||
|
"HTTP_PROXY": "http://proxy.example.com:8080",
|
||||||
|
"HTTPS_PROXY": "http://proxy.example.com:8080",
|
||||||
|
"NO_PROXY": "localhost,127.0.0.1,.local"
|
||||||
|
}
|
||||||
|
},
|
||||||
"example-openapi-server": {
|
"example-openapi-server": {
|
||||||
"type": "openapi",
|
"type": "openapi",
|
||||||
"openapi": {
|
"openapi": {
|
||||||
|
|||||||
142
examples/proxy-configuration-examples.json
Normal file
142
examples/proxy-configuration-examples.json
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
{
|
||||||
|
"_note": "This file demonstrates various proxy configuration patterns for MCPHub",
|
||||||
|
"_documentation": "For complete documentation, see docs/configuration/proxy-support.mdx",
|
||||||
|
|
||||||
|
"mcpServers": {
|
||||||
|
"_example1": "Basic proxy configuration with static values",
|
||||||
|
"npm-server-with-proxy": {
|
||||||
|
"type": "stdio",
|
||||||
|
"command": "npx",
|
||||||
|
"args": ["-y", "@playwright/mcp@latest", "--headless"],
|
||||||
|
"env": {
|
||||||
|
"HTTP_PROXY": "http://proxy.example.com:8080",
|
||||||
|
"HTTPS_PROXY": "http://proxy.example.com:8080",
|
||||||
|
"NO_PROXY": "localhost,127.0.0.1,.local"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"_example2": "Proxy configuration using environment variables",
|
||||||
|
"python-server-with-proxy": {
|
||||||
|
"type": "stdio",
|
||||||
|
"command": "uvx",
|
||||||
|
"args": ["mcp-server-fetch"],
|
||||||
|
"env": {
|
||||||
|
"HTTP_PROXY": "${COMPANY_HTTP_PROXY}",
|
||||||
|
"HTTPS_PROXY": "${COMPANY_HTTPS_PROXY}",
|
||||||
|
"NO_PROXY": "${COMPANY_NO_PROXY}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"_example3": "Proxy with authentication",
|
||||||
|
"authenticated-proxy-server": {
|
||||||
|
"type": "stdio",
|
||||||
|
"command": "npx",
|
||||||
|
"args": ["-y", "@modelcontextprotocol/server-slack"],
|
||||||
|
"env": {
|
||||||
|
"HTTP_PROXY": "http://username:password@proxy.example.com:8080",
|
||||||
|
"HTTPS_PROXY": "http://username:password@proxy.example.com:8080",
|
||||||
|
"SLACK_BOT_TOKEN": "${SLACK_BOT_TOKEN}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"_example4": "Proxy credentials from environment variables (more secure)",
|
||||||
|
"secure-proxy-server": {
|
||||||
|
"type": "stdio",
|
||||||
|
"command": "npx",
|
||||||
|
"args": ["-y", "my-mcp-server"],
|
||||||
|
"env": {
|
||||||
|
"HTTP_PROXY": "${AUTHENTICATED_PROXY_URL}",
|
||||||
|
"HTTPS_PROXY": "${AUTHENTICATED_PROXY_URL}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"_example5": "Different proxy for different servers",
|
||||||
|
"external-api-server": {
|
||||||
|
"type": "stdio",
|
||||||
|
"command": "npx",
|
||||||
|
"args": ["-y", "@external/api-server"],
|
||||||
|
"env": {
|
||||||
|
"HTTP_PROXY": "http://external-proxy.example.com:8080",
|
||||||
|
"HTTPS_PROXY": "http://external-proxy.example.com:8080"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"_example6": "No proxy for internal servers",
|
||||||
|
"internal-server": {
|
||||||
|
"type": "stdio",
|
||||||
|
"command": "npx",
|
||||||
|
"args": ["-y", "@internal/mcp-server"],
|
||||||
|
"env": {
|
||||||
|
"NO_PROXY": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"_example7": "Corporate proxy with comprehensive NO_PROXY list",
|
||||||
|
"corporate-server": {
|
||||||
|
"type": "stdio",
|
||||||
|
"command": "npx",
|
||||||
|
"args": ["-y", "@company/mcp-server"],
|
||||||
|
"env": {
|
||||||
|
"HTTP_PROXY": "http://proxy.corp.com:8080",
|
||||||
|
"HTTPS_PROXY": "http://proxy.corp.com:8080",
|
||||||
|
"NO_PROXY": "localhost,127.0.0.1,*.corp.com,.internal,10.0.0.0/8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"_example8": "Mixed proxy and API key configuration",
|
||||||
|
"api-server-with-proxy": {
|
||||||
|
"type": "stdio",
|
||||||
|
"command": "uvx",
|
||||||
|
"args": ["mcp-server-example", "--api-key", "${API_KEY}"],
|
||||||
|
"env": {
|
||||||
|
"HTTP_PROXY": "${PROXY_URL}",
|
||||||
|
"HTTPS_PROXY": "${PROXY_URL}",
|
||||||
|
"NO_PROXY": "localhost,127.0.0.1",
|
||||||
|
"API_KEY": "${MY_API_KEY}",
|
||||||
|
"DEBUG": "false"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"_example9": "Proxy for package installation only (NPM)",
|
||||||
|
"npm-custom-registry": {
|
||||||
|
"type": "stdio",
|
||||||
|
"command": "npx",
|
||||||
|
"args": ["-y", "my-package"],
|
||||||
|
"env": {
|
||||||
|
"HTTP_PROXY": "http://proxy.example.com:8080",
|
||||||
|
"HTTPS_PROXY": "http://proxy.example.com:8080"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"_example10": "Proxy for Python package installation",
|
||||||
|
"python-custom-index": {
|
||||||
|
"type": "stdio",
|
||||||
|
"command": "uvx",
|
||||||
|
"args": ["mcp-server-fetch"],
|
||||||
|
"env": {
|
||||||
|
"HTTP_PROXY": "http://proxy.example.com:8080",
|
||||||
|
"HTTPS_PROXY": "http://proxy.example.com:8080"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"_important": "Remember to set the following environment variables before starting MCPHub",
|
||||||
|
"_required_env_vars": [
|
||||||
|
"COMPANY_HTTP_PROXY=http://proxy.company.com:8080",
|
||||||
|
"COMPANY_HTTPS_PROXY=http://proxy.company.com:8080",
|
||||||
|
"COMPANY_NO_PROXY=localhost,127.0.0.1,*.company.com,.internal",
|
||||||
|
"AUTHENTICATED_PROXY_URL=http://user:pass@secure-proxy.com:3128",
|
||||||
|
"PROXY_URL=http://proxy.example.com:8080",
|
||||||
|
"MY_API_KEY=your-api-key-here",
|
||||||
|
"SLACK_BOT_TOKEN=your-slack-bot-token",
|
||||||
|
"API_KEY=your-api-key"
|
||||||
|
],
|
||||||
|
|
||||||
|
"users": [
|
||||||
|
{
|
||||||
|
"username": "admin",
|
||||||
|
"password": "$2b$10$Vt7krIvjNgyN67LXqly0uOcTpN0LI55cYRbcKC71pUDAP0nJ7RPa.",
|
||||||
|
"isAdmin": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
447
tests/services/mcpService-proxy.test.ts
Normal file
447
tests/services/mcpService-proxy.test.ts
Normal file
@@ -0,0 +1,447 @@
|
|||||||
|
import { replaceEnvVars } from '../../src/config/index.js';
|
||||||
|
import { ServerConfig } from '../../src/types/index.js';
|
||||||
|
|
||||||
|
describe('MCP Service - Proxy Support', () => {
|
||||||
|
const originalEnv = process.env;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.resetModules();
|
||||||
|
process.env = { ...originalEnv };
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
process.env = originalEnv;
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Proxy environment variables in server configuration', () => {
|
||||||
|
it('should expand HTTP_PROXY in env configuration', () => {
|
||||||
|
process.env.HTTP_PROXY = 'http://proxy.example.com:8080';
|
||||||
|
|
||||||
|
const config: ServerConfig = {
|
||||||
|
type: 'stdio',
|
||||||
|
command: 'npx',
|
||||||
|
args: ['-y', '@modelcontextprotocol/server-example'],
|
||||||
|
env: {
|
||||||
|
HTTP_PROXY: '${HTTP_PROXY}',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = replaceEnvVars(config) as ServerConfig;
|
||||||
|
|
||||||
|
expect(result.env?.HTTP_PROXY).toBe('http://proxy.example.com:8080');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should expand HTTPS_PROXY in env configuration', () => {
|
||||||
|
process.env.HTTPS_PROXY = 'http://proxy.example.com:8080';
|
||||||
|
|
||||||
|
const config: ServerConfig = {
|
||||||
|
type: 'stdio',
|
||||||
|
command: 'uvx',
|
||||||
|
args: ['mcp-server-fetch'],
|
||||||
|
env: {
|
||||||
|
HTTPS_PROXY: '${HTTPS_PROXY}',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = replaceEnvVars(config) as ServerConfig;
|
||||||
|
|
||||||
|
expect(result.env?.HTTPS_PROXY).toBe('http://proxy.example.com:8080');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should expand NO_PROXY in env configuration', () => {
|
||||||
|
process.env.NO_PROXY = 'localhost,127.0.0.1,.local';
|
||||||
|
|
||||||
|
const config: ServerConfig = {
|
||||||
|
type: 'stdio',
|
||||||
|
command: 'node',
|
||||||
|
args: ['server.js'],
|
||||||
|
env: {
|
||||||
|
NO_PROXY: '${NO_PROXY}',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = replaceEnvVars(config) as ServerConfig;
|
||||||
|
|
||||||
|
expect(result.env?.NO_PROXY).toBe('localhost,127.0.0.1,.local');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should expand all proxy environment variables together', () => {
|
||||||
|
process.env.HTTP_PROXY = 'http://proxy.example.com:8080';
|
||||||
|
process.env.HTTPS_PROXY = 'http://proxy.example.com:8080';
|
||||||
|
process.env.NO_PROXY = 'localhost,127.0.0.1';
|
||||||
|
|
||||||
|
const config: ServerConfig = {
|
||||||
|
type: 'stdio',
|
||||||
|
command: 'npx',
|
||||||
|
args: ['my-server'],
|
||||||
|
env: {
|
||||||
|
HTTP_PROXY: '${HTTP_PROXY}',
|
||||||
|
HTTPS_PROXY: '${HTTPS_PROXY}',
|
||||||
|
NO_PROXY: '${NO_PROXY}',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = replaceEnvVars(config) as ServerConfig;
|
||||||
|
|
||||||
|
expect(result.env?.HTTP_PROXY).toBe('http://proxy.example.com:8080');
|
||||||
|
expect(result.env?.HTTPS_PROXY).toBe('http://proxy.example.com:8080');
|
||||||
|
expect(result.env?.NO_PROXY).toBe('localhost,127.0.0.1');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Static proxy configuration in server config', () => {
|
||||||
|
it('should preserve static proxy values from server config', () => {
|
||||||
|
const config: ServerConfig = {
|
||||||
|
type: 'stdio',
|
||||||
|
command: 'npx',
|
||||||
|
args: ['-y', 'my-server'],
|
||||||
|
env: {
|
||||||
|
HTTP_PROXY: 'http://custom-proxy.example.com:3128',
|
||||||
|
HTTPS_PROXY: 'http://custom-proxy.example.com:3128',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = replaceEnvVars(config) as ServerConfig;
|
||||||
|
|
||||||
|
expect(result.env?.HTTP_PROXY).toBe('http://custom-proxy.example.com:3128');
|
||||||
|
expect(result.env?.HTTPS_PROXY).toBe('http://custom-proxy.example.com:3128');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should expand environment variable references in proxy configuration', () => {
|
||||||
|
process.env.PROXY_HOST = 'proxy.example.com';
|
||||||
|
process.env.PROXY_PORT = '8080';
|
||||||
|
|
||||||
|
const config: ServerConfig = {
|
||||||
|
type: 'stdio',
|
||||||
|
command: 'npx',
|
||||||
|
args: ['-y', 'my-server'],
|
||||||
|
env: {
|
||||||
|
HTTP_PROXY: 'http://${PROXY_HOST}:${PROXY_PORT}',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = replaceEnvVars(config) as ServerConfig;
|
||||||
|
|
||||||
|
expect(result.env?.HTTP_PROXY).toBe('http://proxy.example.com:8080');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should expand proxy URL from single environment variable', () => {
|
||||||
|
process.env.COMPANY_PROXY = 'http://proxy.company.com:3128';
|
||||||
|
|
||||||
|
const config: ServerConfig = {
|
||||||
|
type: 'stdio',
|
||||||
|
command: 'npx',
|
||||||
|
args: ['-y', 'my-server'],
|
||||||
|
env: {
|
||||||
|
HTTP_PROXY: '${COMPANY_PROXY}',
|
||||||
|
HTTPS_PROXY: '${COMPANY_PROXY}',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = replaceEnvVars(config) as ServerConfig;
|
||||||
|
|
||||||
|
expect(result.env?.HTTP_PROXY).toBe('http://proxy.company.com:3128');
|
||||||
|
expect(result.env?.HTTPS_PROXY).toBe('http://proxy.company.com:3128');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Proxy authentication', () => {
|
||||||
|
it('should preserve proxy authentication in URL', () => {
|
||||||
|
const config: ServerConfig = {
|
||||||
|
type: 'stdio',
|
||||||
|
command: 'npx',
|
||||||
|
args: ['-y', 'my-server'],
|
||||||
|
env: {
|
||||||
|
HTTP_PROXY: 'http://user:pass@proxy.example.com:8080',
|
||||||
|
HTTPS_PROXY: 'http://user:pass@proxy.example.com:8080',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = replaceEnvVars(config) as ServerConfig;
|
||||||
|
|
||||||
|
expect(result.env?.HTTP_PROXY).toBe('http://user:pass@proxy.example.com:8080');
|
||||||
|
expect(result.env?.HTTPS_PROXY).toBe('http://user:pass@proxy.example.com:8080');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should expand proxy credentials from environment variables', () => {
|
||||||
|
process.env.PROXY_USERNAME = 'user';
|
||||||
|
process.env.PROXY_PASSWORD = 'secret';
|
||||||
|
process.env.PROXY_HOST = 'proxy.example.com';
|
||||||
|
|
||||||
|
const config: ServerConfig = {
|
||||||
|
type: 'stdio',
|
||||||
|
command: 'npx',
|
||||||
|
args: ['-y', 'my-server'],
|
||||||
|
env: {
|
||||||
|
HTTP_PROXY: 'http://${PROXY_USERNAME}:${PROXY_PASSWORD}@${PROXY_HOST}:8080',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = replaceEnvVars(config) as ServerConfig;
|
||||||
|
|
||||||
|
expect(result.env?.HTTP_PROXY).toBe('http://user:secret@proxy.example.com:8080');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should expand complete proxy URL with credentials from environment variable', () => {
|
||||||
|
process.env.AUTHENTICATED_PROXY = 'http://admin:password123@secure-proxy.local:3128';
|
||||||
|
|
||||||
|
const config: ServerConfig = {
|
||||||
|
type: 'stdio',
|
||||||
|
command: 'npx',
|
||||||
|
args: ['-y', 'my-server'],
|
||||||
|
env: {
|
||||||
|
HTTP_PROXY: '${AUTHENTICATED_PROXY}',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = replaceEnvVars(config) as ServerConfig;
|
||||||
|
|
||||||
|
expect(result.env?.HTTP_PROXY).toBe('http://admin:password123@secure-proxy.local:3128');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('NO_PROXY configuration', () => {
|
||||||
|
it('should preserve NO_PROXY for excluding hosts', () => {
|
||||||
|
const config: ServerConfig = {
|
||||||
|
type: 'stdio',
|
||||||
|
command: 'npx',
|
||||||
|
args: ['-y', 'my-server'],
|
||||||
|
env: {
|
||||||
|
HTTP_PROXY: 'http://proxy.example.com:8080',
|
||||||
|
NO_PROXY: 'localhost,127.0.0.1,*.internal,.local',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = replaceEnvVars(config) as ServerConfig;
|
||||||
|
|
||||||
|
expect(result.env?.NO_PROXY).toBe('localhost,127.0.0.1,*.internal,.local');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should preserve NO_PROXY=* to disable proxy for all hosts', () => {
|
||||||
|
const config: ServerConfig = {
|
||||||
|
type: 'stdio',
|
||||||
|
command: 'npx',
|
||||||
|
args: ['-y', 'my-server'],
|
||||||
|
env: {
|
||||||
|
HTTP_PROXY: 'http://proxy.example.com:8080',
|
||||||
|
NO_PROXY: '*',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = replaceEnvVars(config) as ServerConfig;
|
||||||
|
|
||||||
|
expect(result.env?.NO_PROXY).toBe('*');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should expand NO_PROXY from environment variable', () => {
|
||||||
|
process.env.COMPANY_NO_PROXY = 'localhost,127.0.0.1,*.company.com,.internal';
|
||||||
|
|
||||||
|
const config: ServerConfig = {
|
||||||
|
type: 'stdio',
|
||||||
|
command: 'npx',
|
||||||
|
args: ['-y', 'my-server'],
|
||||||
|
env: {
|
||||||
|
HTTP_PROXY: 'http://proxy.company.com:8080',
|
||||||
|
NO_PROXY: '${COMPANY_NO_PROXY}',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = replaceEnvVars(config) as ServerConfig;
|
||||||
|
|
||||||
|
expect(result.env?.NO_PROXY).toBe('localhost,127.0.0.1,*.company.com,.internal');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Mixed proxy configurations', () => {
|
||||||
|
it('should support different proxies for different servers', () => {
|
||||||
|
const config1: ServerConfig = {
|
||||||
|
type: 'stdio',
|
||||||
|
command: 'npx',
|
||||||
|
args: ['-y', 'server1'],
|
||||||
|
env: {
|
||||||
|
HTTP_PROXY: 'http://proxy1.example.com:8080',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const config2: ServerConfig = {
|
||||||
|
type: 'stdio',
|
||||||
|
command: 'npx',
|
||||||
|
args: ['-y', 'server2'],
|
||||||
|
env: {
|
||||||
|
HTTP_PROXY: 'http://proxy2.example.com:3128',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const result1 = replaceEnvVars(config1) as ServerConfig;
|
||||||
|
const result2 = replaceEnvVars(config2) as ServerConfig;
|
||||||
|
|
||||||
|
expect(result1.env?.HTTP_PROXY).toBe('http://proxy1.example.com:8080');
|
||||||
|
expect(result2.env?.HTTP_PROXY).toBe('http://proxy2.example.com:3128');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should support proxy for some servers and not others', () => {
|
||||||
|
const configWithProxy: ServerConfig = {
|
||||||
|
type: 'stdio',
|
||||||
|
command: 'npx',
|
||||||
|
args: ['-y', 'external-server'],
|
||||||
|
env: {
|
||||||
|
HTTP_PROXY: 'http://proxy.example.com:8080',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const configWithoutProxy: ServerConfig = {
|
||||||
|
type: 'stdio',
|
||||||
|
command: 'npx',
|
||||||
|
args: ['-y', 'internal-server'],
|
||||||
|
env: {
|
||||||
|
NO_PROXY: '*',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const result1 = replaceEnvVars(configWithProxy) as ServerConfig;
|
||||||
|
const result2 = replaceEnvVars(configWithoutProxy) as ServerConfig;
|
||||||
|
|
||||||
|
expect(result1.env?.HTTP_PROXY).toBe('http://proxy.example.com:8080');
|
||||||
|
expect(result2.env?.NO_PROXY).toBe('*');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should support mixing environment variable references and static values', () => {
|
||||||
|
process.env.PRIMARY_PROXY = 'http://proxy1.company.com:8080';
|
||||||
|
|
||||||
|
const config1: ServerConfig = {
|
||||||
|
type: 'stdio',
|
||||||
|
command: 'npx',
|
||||||
|
args: ['-y', 'server1'],
|
||||||
|
env: {
|
||||||
|
HTTP_PROXY: '${PRIMARY_PROXY}',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const config2: ServerConfig = {
|
||||||
|
type: 'stdio',
|
||||||
|
command: 'npx',
|
||||||
|
args: ['-y', 'server2'],
|
||||||
|
env: {
|
||||||
|
HTTP_PROXY: 'http://proxy2.company.com:3128',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const result1 = replaceEnvVars(config1) as ServerConfig;
|
||||||
|
const result2 = replaceEnvVars(config2) as ServerConfig;
|
||||||
|
|
||||||
|
expect(result1.env?.HTTP_PROXY).toBe('http://proxy1.company.com:8080');
|
||||||
|
expect(result2.env?.HTTP_PROXY).toBe('http://proxy2.company.com:3128');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Proxy with other environment variables', () => {
|
||||||
|
it('should support proxy alongside API keys and other env vars', () => {
|
||||||
|
const config: ServerConfig = {
|
||||||
|
type: 'stdio',
|
||||||
|
command: 'npx',
|
||||||
|
args: ['-y', 'my-server'],
|
||||||
|
env: {
|
||||||
|
HTTP_PROXY: 'http://proxy.example.com:8080',
|
||||||
|
HTTPS_PROXY: 'http://proxy.example.com:8080',
|
||||||
|
API_KEY: 'secret-key-123',
|
||||||
|
DEBUG: 'true',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = replaceEnvVars(config) as ServerConfig;
|
||||||
|
|
||||||
|
expect(result.env?.HTTP_PROXY).toBe('http://proxy.example.com:8080');
|
||||||
|
expect(result.env?.HTTPS_PROXY).toBe('http://proxy.example.com:8080');
|
||||||
|
expect(result.env?.API_KEY).toBe('secret-key-123');
|
||||||
|
expect(result.env?.DEBUG).toBe('true');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should expand mix of proxy and other environment variables', () => {
|
||||||
|
process.env.PROXY_URL = 'http://proxy.company.com:8080';
|
||||||
|
process.env.MY_API_KEY = 'api-key-xyz';
|
||||||
|
process.env.DATABASE_URL = 'postgresql://localhost/mydb';
|
||||||
|
|
||||||
|
const config: ServerConfig = {
|
||||||
|
type: 'stdio',
|
||||||
|
command: 'uvx',
|
||||||
|
args: ['mcp-server-example'],
|
||||||
|
env: {
|
||||||
|
HTTP_PROXY: '${PROXY_URL}',
|
||||||
|
HTTPS_PROXY: '${PROXY_URL}',
|
||||||
|
API_KEY: '${MY_API_KEY}',
|
||||||
|
DATABASE_URL: '${DATABASE_URL}',
|
||||||
|
DEBUG: 'true',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = replaceEnvVars(config) as ServerConfig;
|
||||||
|
|
||||||
|
expect(result.env?.HTTP_PROXY).toBe('http://proxy.company.com:8080');
|
||||||
|
expect(result.env?.HTTPS_PROXY).toBe('http://proxy.company.com:8080');
|
||||||
|
expect(result.env?.API_KEY).toBe('api-key-xyz');
|
||||||
|
expect(result.env?.DATABASE_URL).toBe('postgresql://localhost/mydb');
|
||||||
|
expect(result.env?.DEBUG).toBe('true');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Real-world proxy scenarios', () => {
|
||||||
|
it('should handle corporate proxy configuration', () => {
|
||||||
|
process.env.CORPORATE_PROXY = 'http://proxy.corp.com:8080';
|
||||||
|
process.env.CORPORATE_NO_PROXY = 'localhost,127.0.0.1,*.corp.com,.internal';
|
||||||
|
|
||||||
|
const config: ServerConfig = {
|
||||||
|
type: 'stdio',
|
||||||
|
command: 'npx',
|
||||||
|
args: ['-y', '@modelcontextprotocol/server-example'],
|
||||||
|
env: {
|
||||||
|
HTTP_PROXY: '${CORPORATE_PROXY}',
|
||||||
|
HTTPS_PROXY: '${CORPORATE_PROXY}',
|
||||||
|
NO_PROXY: '${CORPORATE_NO_PROXY}',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = replaceEnvVars(config) as ServerConfig;
|
||||||
|
|
||||||
|
expect(result.env?.HTTP_PROXY).toBe('http://proxy.corp.com:8080');
|
||||||
|
expect(result.env?.HTTPS_PROXY).toBe('http://proxy.corp.com:8080');
|
||||||
|
expect(result.env?.NO_PROXY).toBe('localhost,127.0.0.1,*.corp.com,.internal');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle Python package installation with proxy', () => {
|
||||||
|
const config: ServerConfig = {
|
||||||
|
type: 'stdio',
|
||||||
|
command: 'uvx',
|
||||||
|
args: ['mcp-server-fetch'],
|
||||||
|
env: {
|
||||||
|
HTTP_PROXY: 'http://proxy.example.com:8080',
|
||||||
|
HTTPS_PROXY: 'http://proxy.example.com:8080',
|
||||||
|
NO_PROXY: 'localhost,127.0.0.1',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = replaceEnvVars(config) as ServerConfig;
|
||||||
|
|
||||||
|
expect(result.env?.HTTP_PROXY).toBe('http://proxy.example.com:8080');
|
||||||
|
expect(result.env?.HTTPS_PROXY).toBe('http://proxy.example.com:8080');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle NPM package installation with proxy', () => {
|
||||||
|
const config: ServerConfig = {
|
||||||
|
type: 'stdio',
|
||||||
|
command: 'npx',
|
||||||
|
args: ['@playwright/mcp@latest', '--headless'],
|
||||||
|
env: {
|
||||||
|
HTTP_PROXY: 'http://proxy.company.com:8080',
|
||||||
|
HTTPS_PROXY: 'http://proxy.company.com:8080',
|
||||||
|
NO_PROXY: 'localhost,127.0.0.1,.company.com',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = replaceEnvVars(config) as ServerConfig;
|
||||||
|
|
||||||
|
expect(result.env?.HTTP_PROXY).toBe('http://proxy.company.com:8080');
|
||||||
|
expect(result.env?.HTTPS_PROXY).toBe('http://proxy.company.com:8080');
|
||||||
|
expect(result.env?.NO_PROXY).toBe('localhost,127.0.0.1,.company.com');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user