PDF to Text MCP Server

PDF to Text MCP Server

Converts PDF files to text for use with MCP-compatible applications like Cursor IDE.

Category
访问服务器

README

📄 PDF to Text MCP Server

License: MIT Node.js TypeScript MCP

A Model Context Protocol (MCP) server for converting PDF files to text, designed for seamless integration with Cursor IDE and other MCP-compatible applications.

🚀 Quick Start

# Clone the repository
git clone https://github.com/xxx87/pdf-to-text-mcp.git
cd pdf-to-text-mcp-server

# Install dependencies
yarn install

# Build the project
yarn build

# Test the server
yarn test

✨ Features

  • 📑 Multi-file Support - Convert one or multiple PDF files simultaneously
  • 🔍 Text Extraction - Extract text while preserving document structure
  • Fast Processing - Efficient PDF parsing with pdf-parse library
  • 🔧 MCP Protocol - Full Model Context Protocol compliance
  • 🎯 Cursor Integration - Designed specifically for Cursor IDE
  • 🛡️ TypeScript - Fully typed for better development experience
  • Testing - Comprehensive test suite included

📋 Table of Contents

🛠️ Installation

Prerequisites

  • Node.js 18+
  • Yarn package manager
  • Cursor IDE (for MCP integration)

Local Installation

  1. Clone the repository

    git clone https://github.com/xxx87/pdf-to-text-mcp.git
    cd pdf-to-text-mcp-server
    
  2. Install dependencies

    yarn install
    
  3. Build the project

    yarn build
    
  4. Verify installation

    yarn test
    

🎯 Usage

Running as Standalone Server

yarn start

Integration with Cursor IDE

  1. Add to Cursor Configuration

    Add the following to your Cursor MCP settings:

    {
      "mcpServers": {
        "pdf-to-text": {
          "command": "node",
          "args": ["/absolute/path/to/pdf-to-text-mcp-server/dist/index.js"],
          "cwd": "/absolute/path/to/pdf-to-text-mcp-server"
        }
      }
    }
    

    ⚠️ Important: Replace /absolute/path/to/pdf-to-text-mcp-server with your actual project path.

  2. Using in Cursor

    • Add PDFs: Drag and drop PDF files into Cursor
    • Convert: Use the pdf_to_text tool for automatic conversion
    • Analyze: The extracted text becomes available for AI analysis

Manual MCP Usage

// Example MCP JSON-RPC request
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "pdf_to_text",
    "arguments": {
      "file_paths": ["document1.pdf", "document2.pdf"]
    }
  }
}

⚙️ Configuration

Environment Variables

Variable Description Default
NODE_ENV Environment mode production
LOG_LEVEL Logging level info

Custom Options

The server automatically handles PDF parsing with optimized settings. For custom configurations, modify the pdf-parse options in src/index.ts.

📚 API Reference

Tools

pdf_to_text

Converts PDF files to readable text format.

Parameters:

  • file_paths (string[]): Array of PDF file paths to convert

Returns:

{
  content: [
    {
      type: "text",
      text: string // Extracted text with file separators
    }
  ];
}

Example Response:

{
  "content": [
    {
      "type": "text",
      "text": "Successfully converted 2 PDF file(s) to text:\n\n=== document1.pdf ===\nExtracted content here...\n\n=== document2.pdf ===\nMore content here..."
    }
  ]
}

🏗️ Development

Project Structure

pdf-to-text-mcp-server/
├── src/
│   ├── index.ts              # Main MCP server implementation
│   └── types/
│       └── pdf-parse.d.ts    # Type definitions
├── dist/                     # Compiled JavaScript output
├── test-server.js            # Test utilities
├── package.json              # Project configuration
├── tsconfig.json             # TypeScript configuration
├── cursor-config.json        # Example Cursor configuration
└── README.md                 # This file

Available Scripts

Script Description
yarn build Compile TypeScript to JavaScript
yarn start Run the compiled server
yarn dev Run in development mode with hot reload
yarn test Execute test suite
yarn lint Run code linting

Building from Source

# Development mode with file watching
yarn dev

# Production build
yarn build

# Run tests
yarn test

Dependencies

Package Purpose Version
@modelcontextprotocol/sdk MCP protocol implementation ^0.5.0
pdf-parse PDF text extraction ^1.1.1
zod Runtime type validation ^3.22.4
typescript TypeScript compiler ^5.0.0

🐛 Troubleshooting

Common Issues

Issue Cause Solution
ENOENT: no such file or directory Invalid file path Verify PDF file exists and path is correct
File is not a PDF Wrong file format Ensure file has .pdf extension and is valid
Empty text output Image-based PDF This tool only extracts text-based content
Build errors Missing dependencies Run yarn install to install all dependencies

Debug Mode

Enable verbose logging:

NODE_ENV=development yarn start

Testing

Run the comprehensive test suite:

# Run all tests
yarn test

# Test with specific PDF
echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": "pdf_to_text", "arguments": {"file_paths": ["your-file.pdf"]}}}' | node dist/index.js

🤝 Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

Development Setup

  1. Fork the repository
  2. Clone your fork
  3. Create a feature branch: git checkout -b feature/amazing-feature
  4. Make your changes
  5. Test thoroughly: yarn test
  6. Commit changes: git commit -m 'Add amazing feature'
  7. Push to branch: git push origin feature/amazing-feature
  8. Open a Pull Request

Code Style

  • Follow existing TypeScript conventions
  • Add tests for new features
  • Update documentation as needed
  • Ensure all tests pass

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

📞 Support


<div align="center">

Made with ❤️ for the MCP community

⭐ Star this repo🐛 Report Bug💡 Request Feature

</div>

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选
mcp-server-qdrant

mcp-server-qdrant

这个仓库展示了如何为向量搜索引擎 Qdrant 创建一个 MCP (Managed Control Plane) 服务器的示例。

官方
精选