Markdown文本转换服务

一个强大的Markdown文档转纯文本服务,支持stdio和HTTP传输协议,可作为本地工具或远程服务使用。

  • by MD-TO-TEXT
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 md-to-text/md_to_text

使用说明

Markdown转文本MCP服务器

一个强大的模型上下文协议(MCP)服务器,可以将Markdown文档转换为纯文本。支持stdio和HTTP传输协议,用作本地工具或远程服务。

特性

  • 📝 完整的Markdown支持:处理所有常见元素,包括标题、列表、链接、图像、代码块、表等。
  • 🎛️ 灵活的转换选项:多种输出格式和样式配置
  • 🔧 双协议支持:stdio模式(克劳德桌面)和HTTP模式(远程客户端)
  • 📁 批处理:目录扫描和批量文件转换
  • 🌐 URL支持:直接处理远程Markdown文件
  • 🔒 安全强化:全面的输入验证和安全保护
  • ⚡ 高性能:具有并发控制的优化转换引擎

快速开始

安装

选项1:克隆和构建

git clone <repository-url>
cd md_to_text_mcp
npm install
npm run build

选项2:与npx一起使用(推荐)

# From npm registry (if published)
npx md_to_text_mcp --help

# From GitHub repository  
npx https://github.com/MD-TO-TEXT/md_to_text --help

# Local development
npm pack
npx ./md_to_text_mcp-1.0.0.tgz --help

基本用法

# Stdio mode (default)
npm start
# or with npx
npx md_to_text_mcp

# HTTP mode
npm run dev:http
# or with npx  
npx md_to_text_mcp --mode http --port 3000

与npx一起使用

npx允许您在不全局安装的情况下运行该工具。以下是如何使用它:

快速测试

# Test the tool help
npx md_to_text_mcp --help

# Run in stdio mode for Claude Desktop
npx md_to_text_mcp --mode stdio

# Start HTTP server
npx md_to_text_mcp --mode http --port 3000

# Custom configuration
npx md_to_text_mcp --mode http --host 0.0.0.0 --port 8080 --cors

来自本地套餐

如果你在本地开发:

# Create package
npm run build
npm pack

# Run with npx
npx ./md_to_text_mcp-1.0.0.tgz --help
npx ./md_to_text_mcp-1.0.0.tgz --mode stdio

通过npx与Claude Desktop集成

您可以通过npx配置Claude Desktop以使用该工具:

{
  "mcpServers": {
    "md-to-text": {
      "command": "npx",
      "args": ["md_to_text_mcp", "--mode", "stdio"],
      "cwd": "/tmp"
    }
  }
}

备注:在Claude Desktop配置中使用npx需要将包发布到npm注册表或在git存储库中可用。

工具

convert_text-文本转换

将Markdown文本直接转换为纯文本。

convert_file-文件转换

读取并转换本地Markdown文件。

convert_url-url转换

从URL获取并转换远程Markdown内容。

batch_convert-批量转换

批量处理目录中的Markdown文件。

转换选项

  • preserveLinks:保留链接URL
  • listStyle:列表样式(项目符号/数字/无)
  • codeHandling:代码处理(保留/删除/内联)
  • tableFormat:表格格式(简单/网格/无)
  • headingStyle:标题样式(哈希/下划线/无)

Claude桌面集成

添加到Claude for Desktop配置文件:

{
  "mcpServers": {
    "md-to-text": {
      "command": "node",
      "args": ["./build/index.js"],
      "cwd": "/path/to/md_to_text_mcp"
    }
  }
}

命令行选项

md-to-text-mcp [OPTIONS]

OPTIONS:
  --mode <mode>         Server mode: 'stdio' or 'http' (default: stdio)
  --port <port>         HTTP server port (default: 3000)
  --host <host>         HTTP server host (default: localhost)
  --cors                Enable CORS for HTTP mode
  --no-cors             Disable CORS for HTTP mode
  --help, -h            Show help message

EXAMPLES:
  md-to-text-mcp                              # stdio mode
  md-to-text-mcp --mode http --port 3000      # HTTP mode
  md-to-text-mcp --mode http --host 0.0.0.0   # Allow external access

环境变量

变量 描述 默认值
MCP_MODE 服务器模式(stdio/http) stdio
MCP_PORT HTTP服务器端口 3000
MCP_HOST HTTP服务器主机 localhost
MAX_FILE_SIZE 最大文件大小(字节) 10485760(10MB)
URL_TIMEOUT URL请求超时(毫秒) 30000(30秒)
ALLOWED_EXTENSIONS 允许的文件扩展名 .md、.markdown、.txt

Docker支持

# Build image
docker build -t md-to-text-mcp .

# Run HTTP mode
docker run -p 3000:3000 md-to-text-mcp

# Health check
curl http://localhost:3000/health

API示例

文本转换

{
  "name": "convert_text",
  "arguments": {
    "markdown": "# Hello World\n\nThis is **bold** text.",
    "options": {
      "preserveLinks": true,
      "listStyle": "bullets"
    }
  }
}

文件转换

{
  "name": "convert_file",
  "arguments": {
    "path": "/path/to/document.md",
    "options": {
      "headingStyle": "underline"
    }
  }
}

URL转换

{
  "name": "convert_url",
  "arguments": {
    "url": "https://raw.githubusercontent.com/user/repo/main/README.md",
    "options": {
      "codeHandling": "remove"
    }
  }
}

批量转换

{
  "name": "batch_convert",
  "arguments": {
    "directory": "/path/to/docs",
    "recursive": true,
    "options": {
      "tableFormat": "simple"
    }
  }
}

安全

服务器包括多层安全:

  • 路径横向保护:阻止访问系统目录
  • 文件大小限制:默认最大10MB
  • URL验证:只允许HTTP/HTTPS协议
  • 私有IP过滤:阻止访问内部网络
  • 内容消毒:删除潜在的恶意内容
  • 请求超时:防止长时间运行的操作

发展

项目结构

src/
├── engine/          # Conversion engine
├── security/        # Security validation
├── tools/           # MCP tool implementations
├── transports/      # Transport protocols
├── types/           # TypeScript type definitions
└── index.ts         # Main entry point

开发命令

npm run build        # Build project
npm run watch        # Watch mode build
npm run dev:stdio    # Development - stdio
npm run dev:http     # Development - HTTP

相关资源

Markdown文档

联机工具

许可证

MIT许可证