本地HTTP网桥MCP服务器
一个生产就绪的模型上下文协议(MCP)服务器,将来自Claude的HTTP请求桥接到您的专用网络资源。
  
这是什么?
当Claude在容器或远程环境中运行时,它无法访问您的专用网络资源,例如:
- 内部API(
api.company.internal) - 开发服务器(
*.hvs,*.local) - 中的自定义DNS条目
/etc/hosts - 本地主机应用程序(
localhost:8080) - 自签名证书服务
这个MCP服务器解决了这个问题。 它在您的主机上运行,充当安全的HTTP网桥,允许Claude通过受控的、分配的接口向这些私有资源发出请求。
快速开始
5分钟后开始跑步:
# 1. Install dependencies
pip install mcp httpx pydantic
# 2. Configure your domains
# Edit local_http_bridge_mcp.py, add your domains to ALLOWED_DOMAINS
# 3. Add to Claude Desktop config
{
"mcpServers": {
"local-http-bridge": {
"command": "python",
"args": ["/absolute/path/to/local_http_bridge_mcp.py"]
}
}
}
# 4. Restart Claude Desktop and test!完整指南:参见 QUICKSTART.md
特性
安全第一
- ✅ 域分配列表(仅可访问预先批准的域)
- ✅ SSL验证控制
- ✅ 请求大小和超时限制
- ✅ 输入验证(Pydantic模型)
- ✅ 标题编辑(Cookie等)
完全HTTP支持
- ✅ 所有方法:GET、POST、PUT、PATCH、DELETE、HEAD、OPTIONS
- ✅ 用于身份验证的自定义标头
- ✅ JSON自动检测
- ✅ 二进制内容处理
- ✅ 重定向以下内容
生产准备就绪
- ✅ 具有故障排除步骤的全面错误处理
- ✅ 结构化日志记录
- ✅ 测试套件(覆盖率95%以上)
- ✅ Docker部署支持
- ✅ 全程键入提示
用法示例
基本GET请求
Claude, check https://apex-demo.hvs/api/health使用JSON进行POST
Claude, POST this to https://apex-demo.hvs/api/users:
{
"name": "John Doe",
"email": "john@example.com"
}验证的请求
Claude, fetch https://api.hvs/data with Authorization header: Bearer abc123自签名证书
Claude, get https://dev.local/ without SSL verification配置
域允许列表
编辑 local_http_bridge_mcp.py:
ALLOWED_DOMAINS = [
"apex-demo.hvs", # Exact match
"*.hvs", # Wildcard for all .hvs subdomains
"localhost", # Localhost
"127.0.0.1", # IP address
"*.local", # Development domains
]资源限制
DEFAULT_TIMEOUT = 30.0 # Request timeout (seconds)
MAX_RESPONSE_SIZE = 10 * 1024 * 1024 # Max response size (10MB)
MAX_REDIRECTS = 5 # Max redirect follows高级配置
看 advanced_config.example.py 用于:
- 每个域身份验证
- 自定义超时
- 响应消毒
- 域特定的SSL设置
- 请求/响应日志记录
API 参考
这 fetch 工具
fetch(
url: str,
method: str = "GET",
headers: Optional[Dict[str, str]] = None,
body: Optional[str] = None,
verify_ssl: bool = True,
timeout: float = 30.0,
follow_redirects: bool = True,
) -> Dict[str, Any]参数:
url:目标URL(必须在列表中)method:HTTP方法(GET、POST、PUT、PATCH、DELETE、HEAD、OPTIONS)headers:自定义标题(例如。,{"Authorization": "Bearer token"})body:请求POST/PUT/PATCH的正文verify_ssl:是否验证SSL证书timeout:请求超时(秒)(最大300)follow_redirects:是否遵循HTTP重定向
退货:
{
"success": True,
"status_code": 200,
"headers": {...},
"body": {...}, # Parsed as JSON if possible
"content_type": "json",
"url": "https://...", # Final URL after redirects
"elapsed_ms": 123.45
}错误响应:
{
"success": False,
"error": "Error message",
"troubleshooting": [
"Step 1 to fix",
"Step 2 to fix"
]
}建筑
┌─────────────────┐ ┌──────────────────────┐ ┌─────────────────────┐
│ Claude Desktop │◄──MCP──►│ Local HTTP Bridge │◄──HTTP──►│ Private Network │
│ (Container) │ │ (Host Machine) │ │ Resources │
└─────────────────┘ └──────────────────────┘ └─────────────────────┘
│ │
│ ├─ apex-demo.hvs
└─ Reads /etc/hosts ├─ localhost:8080
└─ Resolves local DNS └─ *.local domains安装
来源
git clone https://github.com/yourusername/local-http-bridge-mcp.git
cd local-http-bridge-mcp
pip install -e .通过pip(如果已发布)
pip install local-http-bridge-mcp码头工人
docker build -t local-http-bridge-mcp .
docker run -d --name mcp-bridge \
-v /etc/hosts:/etc/hosts:ro \
local-http-bridge-mcpDocker Compose
docker-compose up -d测试
# Install dev dependencies
pip install -e ".[dev]"
# Run tests with coverage
pytest test_server.py -v --cov=local_http_bridge_mcp
# Run specific test
pytest test_server.py::TestDomainAllowlist -v
# Type checking
mypy local_http_bridge_mcp.py
# Linting
ruff check .
# Formatting
black .部署
systemd服务
创建 /etc/systemd/system/local-http-bridge.service:
[Unit]
Description=Local HTTP Bridge MCP Server
After=network.target
[Service]
Type=simple
User=youruser
WorkingDirectory=/path/to/local-http-mcp
ExecStart=/usr/bin/python3 /path/to/local_http_bridge_mcp.py
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target然后:
sudo systemctl enable local-http-bridge
sudo systemctl start local-http-bridge
sudo systemctl status local-http-bridge监控
检查日志:
# systemd
sudo journalctl -u local-http-bridge -f
# Docker
docker logs -f mcp-bridge
# Direct run
# Logs go to stderr故障排除
“域名不在allowlist中”
解决方案:将域添加到 ALLOWED_DOMAINS 在 local_http_bridge_mcp.py 并重新启动服务器。
“无法连接到服务器”
检查:
- 服务器正在运行:
curl https://apex-demo.hvs/ /etc/hosts具有域条目- 防火墙允许连接
- DNS解析正确
“请求超时”
解决方案:增加超时时间:
Claude, fetch https://slow-api.hvs/data with a 60 second timeout“SSL证书验证失败”
解决方案:禁用自签名证书的SSL验证:
Claude, get https://dev.local/ without SSL verification“找不到MCP服务器”
检查:
- 配置中的绝对路径正确
- Python在你的路径中:
python --version - 尝试
python3而不是python在配置中 - 重新启动克劳德桌面
“找不到模块:mcp”
解决方案:安装依赖项:
pip install mcp httpx pydantic安全
威胁模型
此服务器可防止:
- ✅ 未经授权的访问(域允许列表)
- ✅ 信息披露(标题编辑)
- ✅ 拒绝服务(大小/超时限制)
- ✅ 注入攻击(输入验证)
最佳实践
- 尽量减少冲突:只添加您需要的域
- 使用特定通配符:
*.hvs不*或*.com - 启用SSL验证:仅对已知的自签名证书禁用
- 不要硬编码令牌:使用环境变量或Vault
- 监控日志:注意可疑模式
- 保持依赖关系更新:运行
pip install --upgrade定期
局限性
此服务器无法防止:
- 来自已分配域的恶意内容
- 分配服务中的SSRF漏洞
- 本地网络基础设施受损
文档
- QUICKSTART.md -5分钟设置指南
- 项目\_ SUMMARY.md -完整的架构和使用
- advanced_config.example.py -高级定制
项目结构
local-http-mcp/
├── local_http_bridge_mcp.py # Main MCP server (300 lines)
├── test_server.py # Test suite (400+ lines)
├── pyproject.toml # Python project config
├── README.md # This file
├── PROJECT_SUMMARY.md # Detailed architecture
├── QUICKSTART.md # Quick setup guide
├── advanced_config_example.py # Advanced examples
├── Dockerfile # Container deployment
├── docker-compose.yml # Docker Compose config
├── .env.example # Environment template
└── .gitignore # Git ignore rules贡献
欢迎投稿!拜托:
- 分叉存储库
- 创建要素分支
- 添加新功能的测试
- 确保所有测试通过:
pytest -v - 运行类型检查:
mypy . - 格式代码:
black . - 提交拉取请求
路线图
- \[\]请求/响应缓存
- \[\]每个域的速率限制
- \[\]普罗米修斯指标
- \[\]WebSocket支持
- \[\]请求重试逻辑
- \[\]自定义DNS解析器
- \[\]mTLS支持
许可证
MIT许可证-有关详细信息,请参阅许可证文件。
鸣谢
内置:
支持
- 问题:
- MCP文件: https://modelcontextprotocol.io/
- 讨论:
______________________________________________________________________
采用MCP最佳实践构建,供生产使用。
如果这对你有帮助,考虑给它一个⭐ 在GitHub上!
