mcpField
M
MCP File Preview Server

MCP File Preview Server

本地服务
github.com/seanivore开发工具2496 周前更新

关于 MCP File Preview Server

MCP File Preview Server 为网页开发者提供本地 HTML 预览和结构分析。它可捕获完整页面截图,并统计标题、段落、图片和链接。

主要功能

  1. 01捕获完整页面截图
  2. 02保留 CSS 样式进行预览
  3. 03读取本地文件和资源
  4. 04统计 HTML 元素数量
  5. 05截图保存到专用目录

适用场景

  1. 01检查本地 HTML 页面渲染效果
  2. 02查看页面中的标题、段落、图片和链接数量

MCP 相关

该 MCP 服务向客户端提供 `preview_file` 和 `analyze_content` 工具,分别用于截图预览 HTML 文件和分析其结构。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

mcp.json · 通用配置
{
"mcpServers": {
"file-preview": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/inspector"
]
}
}
}
启动命令npx -y @modelcontextprotocol/inspector

本地服务需要在你的电脑上安装运行环境(如 Node.js 18+)。各客户端的配置文件位置不同,请参考客户端文档。

安装包
npm@modelcontextprotocol/inspector

工具

还没有获取到工具列表

本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。

详细介绍

MCP 文件预览服务

一个提供 HTML 文件预览和分析功能的模型上下文协议(MCP)服务。此服务可为本地 HTML 文件截取整页截图并分析其结构。

功能

  • 文件预览:截取 HTML 文件的整页截图,并正确应用 CSS 样式
  • 内容分析:分析 HTML 结构(标题、段落、图片、链接)
  • 本地文件支持:处理本地文件路径和资源
  • 截图管理:将截图保存到专用目录

安装

  1. 克隆仓库:
git clone https://github.com/your-username/mcp-file-preview.git
cd mcp-file-preview
  1. 安装依赖项:
npm install
  1. 构建项目:
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>

返回以下项目的数量:

  • 标题
  • 段落
  • 图片
  • 链接

开发

  1. 安装依赖项:
npm install @modelcontextprotocol/sdk puppeteer typescript @types/node @types/puppeteer
  1. 在 src/ 中进行更改
  2. 构建:
npm run build
  1. 在本地测试:
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
          }
        }
      }
    }
  }
);

要点:

  • Server 构造函数分别接收元数据对象和选项对象
  • 工具在 capabilities.tools 中声明
  • 每个工具都需要描述和 inputSchema
  • 截图会保存到本地 screenshots/ 目录

调试

  1. 使用 MCP Inspector:
npx @modelcontextprotocol/inspector
  1. 使用以下配置连接:

    • 传输类型:STDIO
    • 命令:node
    • 参数:/path/to/build/index.js
  2. 如果工具未显示在下拉菜单中,请检查 Claude OS 日志

贡献

请阅读 CONTRIBUTING.md,了解我们的行为准则以及提交拉取请求的流程。

许可证

本项目采用 MIT 许可证授权,详情请参阅 LICENSE 文件。

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。