Skip to main content

MCP 服务器 - 提供 HTML 文件创建和文件上传功能

Project description

HTML 文件创建和上传 MCP 服务器

这是一个基于 Model Context Protocol (MCP) 的 Python 服务器,提供三个核心功能:

  1. 创建 HTML 文件
  2. 上传文件到服务器
  3. 创建 HTML 文件并立即上传(组合工具)

功能说明

1. create_html - 创建 HTML 内容

根据提供的内容生成格式良好的 HTML 代码并返回(不保存文件)。

参数:

  • content (必需): HTML 文件的主体内容,可以是完整的 HTML 代码或仅内容片段

说明:

  • 直接返回完整的 HTML 代码
  • 不保存到本地文件系统(避免权限问题)
  • 标题默认为"文档"
  • 适用于任何沙箱环境

示例:

{
  "content": "<h1>欢迎</h1><p>这是我的第一个页面</p>"
}

返回示例:

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>文档</title>
</head>
<body>
<h1>欢迎</h1><p>这是我的第一个页面</p>
</body>
</html>

2. upload_file - 上传文件

上传文件到指定的服务器 API 接口,返回文件 URL。

参数:

  • file_path (必需): 要上传的文件路径(相对或绝对路径)
  • token (必需): API 认证 Token

说明:

  • 使用 form-data 格式,字段名固定为 file
  • Token 设置在请求头中
  • 返回服务器响应中 body.fileUrl 的值

示例:

{
  "file_path": "./page_20260112_143000.html",
  "token": "your-api-token-here"
}

返回示例:

https://example.com/uploads/your-file.html

上传接口:https://v5.kaleido.guru/api/proxyStorage/NoAuth/upload_file

3. create_and_upload_html - 创建并上传 HTML 文件

创建 HTML 内容并立即上传到服务器,一步完成两个操作,返回文件 URL。

参数:

  • content (必需): HTML 文件的主体内容,可以是完整的 HTML 代码或仅内容片段
  • token (必需): API 认证 Token

说明:

  • 文件名自动生成格式:page_YYYYMMDD_HHMMSS.html
  • 内存操作,不保存本地文件(避免文件系统权限问题)
  • 使用 form-data 格式,字段名固定为 file
  • Token 设置在请求头中
  • 返回服务器响应中 body.fileUrl 的值
  • 适用于任何沙箱环境(如 Claude Desktop)

示例:

{
  "content": "<h1>欢迎</h1><p>这是我的第一个页面</p>",
  "token": "your-api-token-here"
}

返回示例:

https://example.com/uploads/page_20260112_143000.html

安装

  1. 确保已安装 Python 3.10 或更高版本

  2. 安装依赖:

pip install -r requirements.txt

配置 MCP 客户端

Claude Desktop 配置

编辑 Claude Desktop 配置文件:

MacOS: ~/Library/Application Support/Claude/claude_desktop_config.json Windows: %APPDATA%\Claude\claude_desktop_config.json

添加以下配置:

{
  "mcpServers": {
    "html-file-server": {
      "command": "python3",
      "args": [
        "/Users/liujingjing/ljj/work/mcp-creat-upload-html/server.py"
      ]
    }
  }
}

注意:将路径替换为你的实际项目路径。

运行

MCP 服务器通过标准输入/输出 (stdio) 与客户端通信,通常由 MCP 客户端(如 Claude Desktop)自动启动。

你也可以手动测试服务器:

python3 server.py

使用示例

创建 HTML 内容

生成 HTML 代码:

请使用 create_html 工具创建 HTML 内容,内容是"<h1>你好世界</h1>"

这会返回完整的 HTML 代码,不会保存到本地文件

上传文件

请使用 upload_file 工具将 page_20260112_143000.html 文件上传到服务器,token 是 xxx

创建并上传 HTML 文件(一步完成,推荐)

请创建一个包含"<h1>欢迎来到我的网站</h1><p>这是首页内容</p>"的 HTML 页面并立即上传到服务器,token 是 xxx

这个工具会:

  1. 在内存中生成完整的 HTML 内容
  2. 自动生成文件名(例如:page_20260112_143000.html
  3. 直接上传到服务器(不保存本地文件)
  4. 返回文件 URL

优势:无需本地文件系统权限,适用于任何沙箱环境!

项目结构

mcp-creat-upload-html/
├── server.py          # MCP 服务器主文件
├── requirements.txt   # Python 依赖
└── README.md         # 项目说明文档

技术栈

  • Python 3.10+
  • MCP (Model Context Protocol) SDK
  • httpx (异步 HTTP 客户端)

注意事项

  1. 确保有足够的文件系统权限来创建和读取文件
  2. 上传大文件时注意网络超时设置(当前为 30 秒)
  3. 上传接口需要网络连接
  4. 文件路径支持相对路径和绝对路径

常见问题

Q: 如何修改上传接口地址? A: 编辑 server.py 文件中的 UPLOAD_API_URL 变量。

Q: 支持哪些文件类型上传? A: 支持所有文件类型,服务器会自动检测 MIME 类型。

Q: HTML 文件编码是什么? A: 使用 UTF-8 编码,确保支持中文等多语言字符。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_html_uploader-1.0.1.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_html_uploader-1.0.1-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file mcp_html_uploader-1.0.1.tar.gz.

File metadata

  • Download URL: mcp_html_uploader-1.0.1.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.5

File hashes

Hashes for mcp_html_uploader-1.0.1.tar.gz
Algorithm Hash digest
SHA256 471e877ad96763965aafe413dd9b05d68f098437c6591b6982734a5dd2b0853f
MD5 a9bc534e0fa33ef62e44e0f9b8bb91d9
BLAKE2b-256 53ceebced14992415f0a66a22161a915a6fe1aba5606db7b06d13877e08536d3

See more details on using hashes here.

File details

Details for the file mcp_html_uploader-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mcp_html_uploader-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 077cda2e4b2fea471417e5154754dc1bd431c00eb2978d6c2870bd1c404e71d8
MD5 2d07caacdf16ab0a787d3d9315cd1a3d
BLAKE2b-256 e23d44d069842c3a827439dbf13ed79e4ddecf20e9b466fc3da2d2a8fe576c60

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page