feat: 新增HTML转URL工具服务,优化API转换器配置

- 新增lzwcai_mcpskills_visual2url项目,提供本地HTML文件、HTML代码转可访问URL的MCP工具
- 重构lzwcai_mcp_api_converter配置加载逻辑,取消内存缓存复用,强制拉取最新配置并新增缓存降级容错机制
- 升级lzwcai_mcp_api_converter至0.2.5、项目模板至0.1.3
- 更新各示例项目的环境配置参数与模板工具配置
This commit is contained in:
2026-05-25 11:48:12 +08:00
parent 992d97c0a4
commit fb61ae27cf
28 changed files with 1024 additions and 182 deletions

View File

@@ -0,0 +1,37 @@
# lzwcai_mcpskills_visual2url
基于 FastMCP 的 MCP Server 项目。主要提供 HTML 转换为浏览器可访问 URL 的工具。
## 功能
提供以下两个工具Tools
- `html_file_to_url`: 传入本地 HTML 文件路径,转换成 `file://` 协议的 URL方便浏览器直接打开预览。
- `html_code_to_url`: 传入 HTML 代码片段,将其保存为临时文件并返回可访问的 `file://` URL。
## 安装
```bash
pip install lzwcai_mcpskills_visual2url
```
## 使用
```bash
# 直接运行服务端
lzwcai_mcpskills_visual2url
```
## 项目结构
```
lzwcai_mcpskills_visual2url/
├── main.py # 入口文件
├── pyproject.toml # 项目配置
├── README.md # 说明文档
└── lzwcai_mcpskills_visual2url/ # 核心代码
└── main.py # FastMCP Server 主逻辑
```
## License
MIT

View File

@@ -0,0 +1,72 @@
from mcp.server.fastmcp import FastMCP
import os
import requests
# 创建 FastMCP 实例
mcp = FastMCP("Visual2URL")
UPLOAD_URL = "http://192.168.2.236:5002/api/html/upload"
AUTHORIZATION = "Bearer eyJhbGciOiJIUzUxMiJ9.eyJ0b2tlbl90eXBlIjoiTE9HSU4iLCJsb2dpbl91c2VyX2tleSI6IjM3OTAzNGIwLTg3OTQtNGU2OS05MzRiLTJkNTA3ZWIzODQyOCJ9.X5O0zez0_zm4Ejc9wTyj04Sf3GLT2L9ilIE6W0qbSgggdTvKcaboVm-A64U3SPxC8rpB1Gxc5p-XK7FXqAjgEg"
@mcp.tool()
def html_file_to_url(file_path: str) -> str:
"""
将本地 HTML 文件上传至服务器并转换成可在浏览器中打开的 URL。
Args:
file_path: 本地 HTML 文件的绝对路径
"""
if not os.path.exists(file_path):
return f"Error: 文件不存在: {file_path}"
headers = {
'Authorization': AUTHORIZATION,
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
}
try:
with open(file_path, 'rb') as f:
files = {
'file': (os.path.basename(file_path), f, 'text/html')
}
response = requests.post(UPLOAD_URL, headers=headers, files=files)
response.raise_for_status()
data = response.json()
if data.get('code') == 200 and 'data' in data and 'fileUrl' in data['data']:
return data['data']['fileUrl']
else:
return f"上传失败: {data.get('msg', '未知错误')}"
except Exception as e:
return f"请求发生异常: {str(e)}"
@mcp.tool()
def html_code_to_url(html_code: str) -> str:
"""
将 HTML 代码片段上传至服务器并转换成可在浏览器中打开的 URL。
Args:
html_code: HTML 代码字符串
"""
headers = {
'Authorization': AUTHORIZATION,
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
'Content-Type': 'text/html'
}
try:
response = requests.post(UPLOAD_URL, headers=headers, data=html_code.encode('utf-8'))
response.raise_for_status()
data = response.json()
if data.get('code') == 200 and 'data' in data and 'fileUrl' in data['data']:
return data['data']['fileUrl']
else:
return f"上传失败: {data.get('msg', '未知错误')}"
except Exception as e:
return f"请求发生异常: {str(e)}"
def main():
# 运行 MCP Server
mcp.run()
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,9 @@
"""
Entry point for lzwcai_mcpskills_visual2url
MCP Server 项目入口
"""
if __name__ == "__main__":
# Import and run the actual MCP server
from lzwcai_mcpskills_visual2url.main import main
main()

View File

@@ -0,0 +1,31 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "lzwcai_mcpskills_visual2url"
version = "0.1.1"
description = "MCP Server 模板项目 - 用于快速创建新的 MCP 服务"
readme = "README.md"
requires-python = ">=3.10"
license = {text = "MIT"}
authors = [
{name = "lzwcai", email = "your-email@example.com"},
]
keywords = ["mcp", "template", "server"]
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
]
dependencies = [
"mcp>=1.0.0",
"requests>=2.31.0",
]
[project.scripts]
lzwcai_mcpskills_visual2url = "lzwcai_mcpskills_visual2url.main:main"
[tool.hatch.build.targets.wheel]
packages = ["lzwcai_mcpskills_visual2url"]