mcp-file-preview HTML预览分析工具
提供HTML文件的预览和分析功能。该服务器能够捕获本地HTML文件的全页截图并分析其结构。
可用工具 (2 个)
该服务在 MCP 协议中暴露的工具,AI 可按需调用
preview_file 3 个参数 需填 1 项
Preview local HTML file and capture screenshot
必填参数:filePath
analyze_content 1 个参数 需填 1 项
Analyze HTML content structure
必填参数:filePath
服务介绍
MCP 文件预览服务器
一个提供 HTML 文件预览和分析功能的模型上下文协议 (MCP) 服务器。该服务器能够捕获本地 HTML 文件的全页面截图并分析其结构。
功能
- 文件预览:捕获带有适当 CSS 样式的 HTML 文件全页面截图
- 内容分析:分析 HTML 结构(标题、段落、图片、链接)
- 本地文件支持:处理本地文件路径和资源
- 截图管理:将截图保存到专用目录
安装
- 克隆仓库:
git clone https://github.com/your-username/mcp-file-preview.git
cd mcp-file-preview
- 安装依赖项:
npm install
- 构建项目:
npm run build
配置
将服务器添加到您的 Claude 或 Cline MCP 设置中:
Claude 桌面应用程序
添加到 ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"file-preview": {
"command": "node",
"args": ["/path/to/mcp-file-preview/build/index.js"]
}
}
}
Cline VSCode 扩展
添加到 VSCode 的 MCP 设置中:
{
"mcpServers": {
"file-preview": {
"command": "node",
"args": ["/path/to/mcp-file-preview/build/index.js"]
}
}
}
使用
服务器提供了两个主要工具:
preview_file
捕获截图并返回 HTML 内容:
<use_mcp_tool>
<server_name>file-preview</server_name>
<tool_name>preview_file</tool_name>
<arguments>
{
"filePath": "/path/to/file.html",
"width": 1024, // optional
"height": 768 // optional
}
</arguments>
</use_mcp_tool>
截图将保存在项目文件夹中的 screenshots/ 目录下。
analyze_content
分析 HTML 结构:
<use_mcp_tool>
<server_name>file-preview</server_name>
<tool_name>analyze_content</tool_name>
<arguments>
{
"filePath": "/path/to/file.html"
}
</arguments>
</use_mcp_tool>
返回以下各项的计数:
- 标题
- 段落
- 图片
- 链接
开发
- 安装依赖项:
npm install @modelcontextprotocol/sdk puppeteer typescript @types/node @types/puppeteer
- 在
src/中进行修改 - 构建:
npm run build
- 本地测试:
npm run dev
实现细节
服务器使用 MCP SDK 的 Server 类进行适当的初始化:
this.server = new Server(
// Metadata object
{
name: 'file-preview-server',
version: '0.1.0'
},
// Options object with capabilities
{
capabilities: {
tools: {
preview_file: {
description: 'Preview local HTML file and capture screenshot',
inputSchema: {
// ... schema definition
}
}
}
}
}
);
要点:
- 服务器构造函数接受单独的元数据和选项对象
- 工具在 capabilities.tools 中声明
- 每个工具需要描述和 inputSchema
- 截图保存到本地
screenshots/目录
调试
- 使用 MCP Inspector:
npx @modelcontextprotocol/inspector
-
连接方式:
- 传输类型:STDIO
- 命令:node
- 参数:/path/to/build/index.js
-
如果工具未出现在下拉菜单中,请检查 Claude OS 日志
贡献
请阅读 CONTRIBUTING.md 以了解我们的行为准则以及提交拉取请求的流程。
许可证
该项目根据 MIT 许可证获得许可 - 有关详细信息,请参阅 LICENSE 文件。