这是一个提供HTML文件预览和分析功能的Model Context Protocol (MCP)服务器。该服务器能够捕获本地HTML文件的全页截图,并分析其结构。
git clone https://github.com/your-username/mcp-file-preview.git
cd mcp-file-preview
npm install
npm run build
在你的Claude或Cline MCP设置中添加服务器:
在~/Library/Application Support/Claude/claude_desktop_config.json中添加:
{
"mcpServers": {
"file-preview": {
"command": "node",
"args": ["/path/to/mcp-file-preview/build/index.js"]
}
}
}
在VSCode的MCP设置中添加:
{
"mcpServers": {
"file-preview": {
"command": "node",
"args": ["/path/to/mcp-file-preview/build/index.js"]
}
}
}
该服务器提供了两个主要工具:
捕获截图并返回HTML内容:
<use_mcp_tool>
<server_name>file-preview</server_name>
<tool_name>preview_file</tool_name>
<arguments>
{
"filePath": "/path/to/file.html",
"width": 1024, // 可选
"height": 768 // 可选
}
</arguments>
</use_mcp_tool>
截图保存在项目文件夹中的screenshots/目录下。
分析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(
// 元数据对象
{
name: 'file-preview-server',
version: '0.1.0'
},
// 带有功能选项的对象
{
capabilities: {
tools: {
preview_file: {
description: '预览本地HTML文件并捕获截图',
inputSchema: {
// ...模式定义
}
}
}
}
}
);
关键点:
screenshots/目录下npx @modelcontextprotocol/inspector
连接方式:
如果工具没有出现在下拉菜单中,请检查Claude OS日志
请阅读CONTRIBUTING.md,了解我们的行为准则以及提交拉取请求的过程。
本项目采用MIT许可证 - 详情见LICENSE文件。