Claude Document Management MCP Server
This MCP server enables Claude AI to read and edit documents through natural language, leveraging tools, resources, and prompts for document management in a Ruby-based CLI application.
README
CLI Project Ruby
A production-ready Ruby-based interactive CLI that integrates the Model Context Protocol (MCP) with Claude AI for intelligent document management through a natural chat interface.
Description
This application demonstrates enterprise-grade MCP integration by combining a Ruby MCP client/server architecture with Anthropic's Claude API. Users interact with Claude through a sophisticated terminal interface, enabling AI-driven document operations via natural language commands.
Value Proposition:
- Zero-friction document management: Edit and read documents through conversational AI
- MCP-native architecture: Built on the Model Context Protocol for extensible tool integration
- Developer-friendly: Railway pattern services, Zeitwerk autoloading, and comprehensive debugging tools
- Production patterns: ServiceResult state management, interface enforcement, and structured logging
Architecture Overview:
- Client layer: MCP client + Anthropic API integration with TTY-enhanced console
- Server layer: MCP server exposing document tools, resources, and prompt templates
- Shared core: Railway-pattern services, abstract interfaces, and dual-output logging
Prerequisites
- Ruby 4.0.5
- Bundler
- Overmind (for process management)
- Node.js 24.11 (for MCP inspector)
Installation
-
Clone the repository
-
Install dependencies:
bundle install npm install -
Configure environment variables:
cp .env.example .envEdit
.envand set:ANTHROPIC_API_KEY- Your Anthropic API keyCLAUDE_MODEL- Claude model to use (e.g.,claude-3-5-sonnet-20241022)
Running the Application
Using Overmind (Recommended)
# Start all processes from Procfile
overmind start
# Specific processes
overmind start -l client_server
overmind start -l inspector
# Connect to STDIO of process
Manual Start
Run the main application:
# Start MCP client-server
bundle exec ruby client_server.rb
# Start MCP server only
bundle exec ruby server.rb
# Start MCP inspector
npx @modelcontextprotocol/inspector bundle exec ruby server.rb
Usage Guide
Document References
Check server/docs.json as the single source of truth.
Use @document syntax to reference documents in your messages:
You: Can you read @report.pdf?
Claude: [uses ReadDocument tool to fetch content]
You: Please update @plan.md with the new timeline
Claude: [uses EditDocument tool to modify content]
Slash Commands
Execute special commands with the / prefix:
/clear- Clear conversation history/exit- Exit the application- Additional local commands can be defined in the client configuration
- Additional prompt commands can be defined in the server configuration
Keywords
- exit, quit, q: Exit the application
Keyboard Shortcuts
- Escape key: Cancel current input and return to prompt
- Ctrl+C: Interrupt tool execution or exit application
- Ctrl+D: Submit multiline input (in multiline mode)
Input Modes
Single-line mode (default):
- Type message and press Enter
- Suitable for quick queries and commands
Multiline mode (when needed):
- Press Shift+Enter to start multiline input
- Type across multiple lines
- Press Enter to submit
- Press Escape to cancel
MCP Components
The application implements a complete MCP server with the following component layers:
Tools Layer
Executable operations that Claude can invoke to perform actions:
- ReadDocument: Retrieve document content by ID
- EditDocument: Modify document content with new text
Resources Layer
Discoverable data sources exposed via URI patterns:
- Direct resources: Static listings (e.g.,
docs://documentsfor all documents) - Templated resources: Dynamic URIs with parameters (e.g.,
docs://documents/{doc_id}for specific documents)
Prompts Layer
Reusable prompt templates for common operations:
- FormatPrompt: Template for document formatting instructions
- Additional prompts can be defined for specialized workflows
All components follow base class patterns (BaseTool, BaseResource, BasePrompt) enabling consistent implementation and easy extension.
Project Structure
.
├── client_server.rb # Entry point for CLI application (MCP Client + Server)
├── server.rb # MCP server implementation
├── Procfile # Overmind/Foreman process definitions
├── core/ # Core classes
├── application_service.rb # callable service
├── constants.rb # global constants
├── service_result.rb # railway pattern service result
├── interface.rb # interface implementation in Ruby
└── application_logger.rb # text file logger for client/server
├── client/ # Client classes
├── server/ # Server classes
└── lib/ # Shared libraries
└── tty_patch/ # TTY-prompt monkey patch
Dependencies
- anthropic - Anthropic API client
- mcp - Model Context Protocol implementation
- tty-prompt - Interactive command line prompts
- zeitwerk - Code loader
Development
Debug mode is available via the debug gem. Set breakpoints using debugger or binding.break.
Server logs are available in log/server.log.
MCP inspector could be used for debugging server-side tooling.
Troubleshooting
Debug Logging
Enable detailed debug output by setting the LOG_LEVEL environment variable:
# In .env file
LOG_LEVEL=debug # DEBUG level
# Or inline
LOG_LEVEL=debug bundle exec ruby client_server.rb
Logs are written to logs/server.log.
Interactive Debugging with binding.break
Insert breakpoints anywhere in the code:
def process_message(message)
binding.break # Execution pauses here
# ... rest of method
end
When execution hits the breakpoint:
- Inspect variables:
message,self, local scope - Step through code:
step,next,continue - Evaluate expressions: type any Ruby code
- Exit debugger:
continueorc
Common debugging scenarios:
# In client/chat_manager.rb
def handle_tool_use(tool_call)
binding.break # Debug tool execution
# ...
end
# In server/tools/read_document.rb
def call(arguments)
binding.break # Debug tool implementation
# ...
end
NB. On server-side debugging could be challenging after server start, due to the asynchronous nature of MCP. Prefer logger or inspector instead
MCP Inspector
The MCP Inspector provides a web UI for testing MCP server components without running the full client:
Start inspector:
# Via Overmind
overmind start -l inspector
# Or manually
npx @modelcontextprotocol/inspector bundle exec ruby server.rb
Inspector features:
- Browse available tools, resources, and prompts
- Test tool execution with custom arguments
- View resource URIs and content
- Inspect prompt templates
- Monitor MCP protocol messages
Typical workflow:
- Open browser to inspector URL (shown in terminal)
- Verify tools are registered correctly
- Test
ReadDocumentwith sample document IDs - Test
EditDocumentwith content modifications - Check resource listings for
docs://documents - Validate prompt templates
Common Issues
Issue: "Cannot connect to MCP server"
- Try to start the server using
bundle exec ruby server.rb - Check the raised exception
- Check
logs/server.logfor server errors
Issue: "Tool execution fails"
- Enable DEBUG logging:
LOG_LEVEL=0 - Repeat your workflow
- Check
logs/client.logfor client errors - Check
logs/server.logfor server errors
Issue: "Multiline input works incorrect"
- Try Ctrl+D to submit (not Enter)
- Check terminal compatibility (some terminals don't support raw mode)
Issue: "Environment variables not loaded"
- Verify
.envfile exists and has correct format - Check
ANTHROPIC_API_KEYis set (not empty) - Restart application after
.envchanges
TODO:
- [ ] Add Tasks
- [ ] Add RSpec coverage
- [ ] Add Rubocop
- [ ] Add Sorbet
- [ ] Try HTTP MCP
- [ ] Add OAuth2
- [ ] Think how to polish monkey patches
License
MIT License
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。