-
Notifications
You must be signed in to change notification settings - Fork 1
MCP_WINDOWS_SUPPORT
ThemisDB MCP (Model Context Protocol) server now includes full cross-platform support for stdio transport on Windows, Linux, and macOS. The implementation uses platform-specific APIs for efficient non-blocking I/O.
| Platform | Support | Implementation | Status |
|---|---|---|---|
| Windows | ✅ Full | Win32 API (ReadFile/PeekNamedPipe) | Production-Ready |
| Linux | ✅ Full | POSIX (select() on STDIN_FILENO) | Production-Ready |
| macOS | ✅ Full | POSIX (select() on STDIN_FILENO) | Production-Ready |
| Other | Compile-time warning | Not Tested |
The Windows stdio transport uses the following Win32 APIs:
// Get stdin handle
HANDLE h_stdin = GetStdHandle(STD_INPUT_HANDLE);
// Check for available data (non-blocking)
DWORD bytes_available = 0;
PeekNamedPipe(h_stdin, NULL, 0, NULL, &bytes_available, NULL);
// Read data when available
DWORD bytes_read = 0;
ReadFile(h_stdin, buffer, buffer_size, &bytes_read, NULL);-
Non-blocking I/O: Uses
PeekNamedPipe()to check for data availability without blocking - Async Processing: Integrates with Boost.Asio io_context for event-driven processing
- Console and Pipe Support: Handles both console input and piped input from Claude Desktop
- JSON Message Parsing: Line-buffered input with incremental JSON parsing
- Graceful Shutdown: Proper cleanup on EOF or stop signal
The Windows implementation uses a hybrid approach:
- PeekNamedPipe() - Check if data is available (works for pipe handles)
- Fallback to ReadFile() - For console handles where PeekNamedPipe fails
- Sleep/Yield - Brief sleep (100ms) when no data available to prevent busy-waiting
- EOF Detection - Properly handles stdin closure
- Visual Studio 2019 or later (MSVC compiler)
- CMake 3.15+
- Windows 10 or later
- Boost (included or system-installed)
# Configure with MCP enabled
cmake -B build -S . `
-DTHEMIS_ENABLE_MCP=ON `
-DCMAKE_BUILD_TYPE=Release `
-G "Visual Studio 16 2019"
# Build
cmake --build build --config Release
# Test
cd build\Release
.\themis_server.exe --mcp-stdio<!-- Include in your .vcxproj or via CMake -->
<PreprocessorDefinitions>
THEMIS_ENABLE_MCP;
_WIN32_WINNT=0x0601; <!-- Windows 7+ -->
WIN32_LEAN_AND_MEAN;
%(PreprocessorDefinitions)
</PreprocessorDefinitions>Create or edit %APPDATA%\Claude\claude_desktop_config.json:
{
"mcpServers": {
"themisdb": {
"command": "C:\\path\\to\\themis_server.exe",
"args": ["--mcp-stdio"]
}
}
}# Start server
$process = Start-Process -FilePath ".\themis_server.exe" `
-ArgumentList "--mcp-stdio" `
-NoNewWindow -PassThru `
-RedirectStandardInput "input.json" `
-RedirectStandardOutput "output.json"
# Send initialize request
@"
{"jsonrpc":"2.0","method":"initialize","params":{"protocolVersion":"2024-11-05","clientInfo":{"name":"test","version":"1.0"}},"id":1}
"@ | Out-File -FilePath "input.json" -Encoding utf8
# Wait and read response
Start-Sleep -Seconds 1
Get-Content "output.json"
# Cleanup
Stop-Process -Id $process.IdREM Start server with piped I/O
echo {"jsonrpc":"2.0","method":"initialize","params":{"protocolVersion":"2024-11-05"},"id":1} | themis_server.exe --mcp-stdioThe Windows implementation automatically detects the input type:
| Input Type | Detection | Behavior |
|---|---|---|
| Console (cmd.exe) |
PeekNamedPipe() fails |
Uses ReadFile() with line buffering |
| Pipe (Claude Desktop) |
PeekNamedPipe() succeeds |
Efficient non-blocking reads |
| Redirected File | Same as pipe | Standard file I/O |
Windows uses CRLF (\r\n) but the implementation handles both:
- Reads until
\nregardless of\rpresence - Outputs with
\nonly (standard JSON-RPC) - Compatible with both Windows and Unix-style line endings
The Windows implementation uses:
- Console: UTF-8 code page (65001) when available
- Pipes: Binary-safe read/write, expects UTF-8 JSON
- Fallback: ASCII-safe operation for compatibility
| Metric | Value | Notes |
|---|---|---|
| Latency | ~1-5ms | Per request/response |
| Throughput | 100-500 req/s | Depends on JSON size |
| CPU Usage | <5% | With 100ms polling interval |
| Memory | ~2-5 MB | Base overhead per instance |
| Feature | Windows | POSIX | Winner |
|---|---|---|---|
| Latency | 1-5ms | 1-3ms | POSIX (slight) |
| CPU Idle | Comparable | Comparable | Tie |
| Code Size | Larger | Smaller | POSIX |
| Compatibility | Win7+ | All Unix | Both |
Cause: Server not run with proper stdin redirection
Solution: Ensure stdin is available:
# Good: stdin from pipe
echo '{"id":1}' | .\themis_server.exe --mcp-stdio
# Good: stdin from file
.\themis_server.exe --mcp-stdio < input.json
# Bad: stdin is terminal but not attached
Start-Process themis_server.exe -WindowStyle Hidden # No stdin!Cause: Incompatible stdin handle type
Solution: The implementation falls back automatically. Enable debug logging:
$env:SPDLOG_LEVEL="debug"
.\themis_server.exe --mcp-stdioCause: Path or configuration errors
Solution:
- Use absolute paths in
claude_desktop_config.json - Escape backslashes:
"C:\\path\\to\\file" - Check permissions: Ensure exe is not blocked
- View Claude logs:
%APPDATA%\Claude\logs
Cause: Busy-waiting on stdin
Solution: Adjust polling interval (recompile):
// In mcp_server.cpp, change:
std::this_thread::sleep_for(std::chrono::milliseconds(100)); // Default
// To:
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // Less aggressiveThe codebase uses preprocessor directives for platform selection:
#if defined(_WIN32)
// Windows-specific code
HANDLE h_stdin = GetStdHandle(STD_INPUT_HANDLE);
PeekNamedPipe(h_stdin, ...);
#elif defined(__unix__) || defined(__APPLE__)
// POSIX-specific code
select(STDIN_FILENO + 1, &readfds, ...);
#else
#warning "Platform not supported for stdio transport"
#endifAt runtime, the server logs the detected platform:
[info] MCP stdio transport started
[debug] Platform: Windows (Win32 API)
[debug] Stdin handle: 0x00000003
- UAC: No elevation required for normal operation
- AppContainer: Compatible with sandboxed Claude Desktop
- Code Signing: Recommended for distribution to avoid SmartScreen warnings
- Antivirus: May flag stdin/stdout manipulation; whitelist if needed
- All input validated before parsing JSON
- No shell command execution from stdin
- Parameterized queries prevent injection attacks
- Memory-safe C++ patterns throughout
# Build with tests
cmake -B build -S . -DTHEMIS_ENABLE_MCP=ON -DTHEMIS_BUILD_TESTS=ON
cmake --build build --config Release
# Run MCP tests
cd build\Release
.\themis_tests.exe --gtest_filter="MCPServerTest.*"# Test stdio transport
$testInput = @"
{"jsonrpc":"2.0","method":"initialize","params":{"protocolVersion":"2024-11-05"},"id":1}
{"jsonrpc":"2.0","method":"tools/list","id":2}
"@
$testInput | .\themis_server.exe --mcp-stdio | Out-File results.json
Get-Content results.json# Send 1000 requests
1..1000 | ForEach-Object {
@"
{"jsonrpc":"2.0","method":"tools/call","params":{"name":"get_entity","arguments":{"key":"test:$_"}},"id":$_}
"@
} | .\themis_server.exe --mcp-stdio- I/O Completion Ports: Use IOCP for true async I/O on Windows
- Named Pipes: Support for IPC via
\\.\pipe\themisdb - UTF-16 Console: Native wide character support
- Performance Monitoring: ETW (Event Tracing for Windows) integration
- Windows Service: Run as background service
Windows-specific improvements are welcome! Areas of interest:
- Async I/O with IOCP (eliminates polling)
- Better console detection and handling
- Windows Service wrapper
- MSI installer for distribution
- PowerShell module for scripting
- ✅ Windows stdio transport implementation
- ✅ Cross-platform conditional compilation
- ✅ Non-blocking I/O on all platforms
- ✅ Production-ready for Windows 7+, Linux, macOS
- v1.1.0: I/O Completion Ports for Windows
- v1.2.0: Named pipes support
- v1.3.0: Windows Service integration
Platform Support Summary: ThemisDB MCP server now provides full cross-platform stdio support, enabling LLM integration via Claude Desktop on Windows, Linux, and macOS with production-grade performance and reliability.
- Architecture-ACCESS-MODEL-IMPLEMENTATION-SUMMARY
- Architecture-ADR-003-pg-dump-sql-parser
- Architecture-BASEENTITY-PRINCIPLE
- Architecture-CACHE-STORAGE-INTEGRATION
- Architecture-CMAKE-ARCHITECTURE
- Architecture-CMAKE-FLAGS-REFERENCE
- Architecture-CMAKE-MODULAR-ARCHITECTURE
- Architecture-CONCERNS-ARCHITECTURE-DIAGRAM
- Architecture-CONCERNS-IMPLEMENTATION-SUMMARY
- Architecture-CONTENT-MODEL
- Architecture-COPILOT-THEMISDB-GRAPH-RAG-BACKEND-ARCHITECTURE
- Architecture-CRYPTO-AND-KEYS
- Architecture-FEATURE-FLAGS-REFERENCE
- Architecture-GPU-ARCHITECTURE-REVIEW-TEMPLATE
- Architecture-HTTP-SHUTDOWN-HARDENING
- Architecture-MIGRATION-GUIDE-CONCERNS
- Architecture-MIGRATION-GUIDE-v13-v14
- Architecture-MODULARIZATION-GUIDE
- Architecture-MODULAR-ARCHITECTURE-ROADMAP
- Architecture-MODULE-ARCHITECTURE-INDEX
- Architecture-P1D01-ISSMPLUGIN-DESIGN-REVIEW
- Architecture-P1-D01-ISSMPLUGIN-DESIGN-REVIEW
- Architecture-P1-D08-MAMBA-GOVERNANCE-CONTRACT
- Architecture-P1-P2-IMPLEMENTATION-COMPLETION-INDEX
- Architecture-PHASE0-COMPLETION-ASSESSMENT
- Architecture-PHASE3-QUERYENGINE-DI-ARCHITECTURE
- Architecture-PHASE4-INDEX-MANAGER-DI
- Architecture-POSTGRESQL-WIRE-PROTOCOL
- Architecture-QUERYENGINE-IMPLEMENTATION-GUIDE
- Architecture-QUERY-SCHEDULING
- Architecture-RAFT-CONSENSUS-DESIGN
- Architecture-README
- Architecture-README-SSM-HYBRID-IMPLEMENTATION
- Architecture-REFACTORING-SUMMARY
- Architecture-RESOURCE-POOLING
- Architecture-SOURCE-DIRECTORY-GUIDE
- Architecture-THEMIS-CORE-GUIDE
- Architecture-UNIFIED-ACCESS-MODEL
- Architecture-WAL-GRPC-MTLS-CONFIGURATION
- Architecture-WIRE-PROTOCOL-RETRY
- Architecture-boltzmann-observability-draft
- Architecture-experimental-logarithmic-vector-storage
- Architecture-llm-wiki-mvp-adr
- Architecture-rewrite-engine-architecture
- Architecture-rope-api-architecture
- Architecture-ssm-gguf-mamba-status
- Architecture-ssm-hybrid-analysis
- Architecture-ssm-hybrid-rollout-plan
- Architecture-ssm-plugin-interface-design-review
- Architecture-transaction-coordinators
- Architecture-wiki-secondary-index
- Architecture-wire-protocol
- Governance-DISABLED-STUB-POLICY
- Governance-DOCS-PR-POLICY
- Governance-GA-PROMOTION-SIGN-OFF
- Governance-GITHUB-MILESTONES-SETUP
- Governance-MATURITY-CLAIM-VERIFICATION-CHECKLIST
- Governance-MATURITY-EVIDENCE-REGISTRY
- Governance-MERGE-GATE-BOT-CONFIG
- Governance-MERGE-GATE-STATUS-LIVE
- Governance-PHASE3-ENFORCEMENT-RUNBOOK
- Governance-PHASE-1-CLOSURE-REPORT
- Governance-PHASE-CLOSURE-POLICY
- Governance-PHASE-DEPENDENCY-GRAPH
- Governance-PLUGIN-SUBMODULE-ROLLBACK
- Governance-PRODUCTION-READY-2026-DELIVERY-PLAN
- Governance-PR-VERSION-TARGETING
- Governance-PR-VERSION-TARGETING-BACKFILL
- Governance-QUERY-MODULE-STATUS
- Governance-README
- Governance-RELEASE-PROMOTION-GATE-POLICY
- Governance-RELEASE-VALIDATION-CHECKLIST
- Governance-SECURITY-MODULE-5671-EVIDENCE-SUMMARY
- Governance-SHARDING-P6-RESIDUAL-RISK-ACCEPTANCE
- Governance-SOURCECODE-COMPLIANCE-GOVERNANCE
- Governance-UPDATES-DEVELOPMENT-STATUS-SIGN-OFF
- Governance-WAVE-C-IMPLEMENTATION-COMPLETE
- Module-acceleration-Roadmap
- Module-access-model-Roadmap
- Module-ai-Roadmap
- Module-analytics-Roadmap
- Module-api-Roadmap
- Module-aql-Roadmap
- Module-auth-Roadmap
- Module-base-Roadmap
- Module-cache-Roadmap
- Module-cdc-Roadmap
- Module-chaos-Roadmap
- Module-chimera-Roadmap
- Module-config-Roadmap
- Module-content-Roadmap
- Module-core-Roadmap
- Module-distributed-knowledge-Roadmap
- Module-distributed-tensor-Roadmap
- Module-document-Roadmap
- Module-ethics-ai-Roadmap
- Module-evaluation-Roadmap
- Module-execution-Roadmap
- Module-exporters-Roadmap
- Module-failover-Roadmap
- Module-geo-Roadmap
- Module-governance-Roadmap
- Module-gpu-Roadmap
- Module-graph-Roadmap
- Module-image-analysis-Roadmap
- Module-importers-Roadmap
- Module-index-Roadmap
- Module-ingestion-Roadmap
- Module-llama-cpp-Roadmap
- Module-llm-Roadmap
- Module-llm-streaming-Roadmap
- Module-llm-wiki-Roadmap
- Module-maintenance-Roadmap
- Module-metadata-Roadmap
- Module-network-Roadmap
- Module-observability-Roadmap
- Module-onnx-clip-Roadmap
- Module-performance-Roadmap
- Module-plugins-Roadmap
- Module-process-Roadmap
- Module-projects-Roadmap
- Module-prompt-engineering-Roadmap
- Module-query-Roadmap
- Module-rag-Roadmap
- Module-replication-Roadmap
- Module-retrieval-Roadmap
- Module-rpc-grpc-Roadmap
- Module-scheduler-Roadmap
- Module-scraper-Roadmap
- Module-search-Roadmap
- Module-security-Roadmap
- Module-server-Roadmap
- Module-sharding-Roadmap
- Module-stable-diffusion-Roadmap
- Module-storage-Roadmap
- Module-temporal-Roadmap
- Module-tensor-Roadmap
- Module-themis-Roadmap
- Module-timeseries-Roadmap
- Module-toolbox-Roadmap
- Module-training-Roadmap
- Module-transaction-Roadmap
- Module-updates-Roadmap
- Module-user-storage-encrypted-Roadmap
- Module-utils-Roadmap
- Module-vector-search-Roadmap
- Module-voice-Roadmap
- Module-whisper-Roadmap