Labsco
gabiteodoru logo

qmcp Server

โ˜… 7

from gabiteodoru

An MCP server for integrating with and querying q/kdb+ databases.

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅโœ“ VerifiedFreeQuick setup

qmcp Server

A Model Context Protocol (MCP) server for q/kdb+ integration.

MCP is an open protocol created by Anthropic that enables AI systems to interact with external tools and data sources. While currently supported by Claude (Desktop and CLI), the open standard allows other LLMs to adopt it in the future.

Open-Source Proof-of-Concept

This repository contains an open-source proof-of-concept demonstrating the core qmcp approach. The Qython translation tool (available at github.com/gabiteodoru/qython) covers ~5% of the q language and is provided for evaluation and experimentation.

Production Results: The full Qython implementation achieves 0.6% failure rate on HumanEval benchmarks, with 10x reliability improvement over native q development. See the complete evaluation: 0.6% Failure Rate: Solving LLM Code Generation for q/kdb+

Commercial Licensing: For access to the full Qython implementation with comprehensive language coverage, contact gabiteodoru@gmail.com

Features

  • Connect to q/kdb+ servers
  • Execute q queries and commands
  • Persistent connection management
  • Intelligent async query handling with configurable timeouts
  • Programmatic query cancellation (Ctrl+C equivalent)
  • Graceful handling of long-running queries
  • NEW: Qython language translator (Experimental Alpha)

Windows Users: WSL Recommendation

โš ๏ธ Important for Windows users: For optimal functionality, it is highly recommended to run both the MCP server and your q session inside WSL (Windows Subsystem for Linux). This ensures the server can interrupt infinite loops and runaway queries that LLMs might accidentally generate.

Running the MCP server on Windows (outside WSL) disables SIGINT-based query interruption functionality, which is critical for escaping problematic queries during AI-assisted development sessions.

Architecture & Design Philosophy

Intended Goals

qmcp is designed to provide AI coding assistants with controlled access to q/kdb+ databases for development and debugging workflows:

  1. Development-Focused: Optimized for coding tools working with debug/dev q servers
  2. Query Control: AI can interrupt long-running queries (equivalent to developer Ctrl+C)
  3. Predictable Behavior: Sequential execution prevents resource conflicts during development
  4. Configurable Timeouts: Customizable timing for different development scenarios

Design Logic

The server architecture makes deliberate choices for AI-assisted development workflows:

Single Connection Model

  • Why: Simplifies development debugging - one connection, clear state
  • Benefit: Matches typical developer workflow with single q session
  • Implementation: One persistent connection per MCP session

Sequential Query Execution

  • Why: Development environments don't need concurrent query support
  • Benefit: Predictable resource usage, easier debugging, prevents query interference
  • Implementation: New queries rejected while another is running

Smart Async Switching with Configurable Timeouts

Fast Query (< async switch timeout)  โ†’  Return result immediately
Slow Query (> async switch timeout)  โ†’  Switch to async mode
                                     โ†’  Auto-interrupt after interrupt timeout (if configured)
  • Why: Keeps AI coding sessions responsive while allowing complex development queries
  • Benefit: Immediate feedback for quick queries, progress tracking for analysis
  • Customization: All timeouts configurable via MCP tools

AI-Controlled Query Interruption

  • Why: AI coding tools need ability to cancel runaway queries (like developer Ctrl+C)
  • How: MCP server locates q process by port and sends SIGINT after configurable timeout
  • Benefit: Prevents development sessions from hanging on problematic queries
  • Limitations: SIGINT functionality disabled when:
    • MCP server runs on Windows (outside WSL)
    • MCP server and q session run on opposite sides of WSL/Windows divide

Development-Oriented Process Management

  • Why: Coding tools work with user-managed development q servers
  • Benefit: Developer controls q server lifecycle, AI controls query execution
  • Design: MCP server provides query interruption capability without server lifecycle management

Why This Design Makes Sense for Coding Tools

  1. Development Workflow: Matches how developers interact with q - single session, iterative queries
  2. AI Safety: Prevents AI from overwhelming development environments with concurrent requests
  3. Debugging-Friendly: Sequential execution makes it easier to trace issues
  4. Responsive: Async handling prevents AI coding sessions from blocking
  5. Configurable: Timeouts can be tuned for different development scenarios

This architecture provides AI coding assistants with effective q/kdb+ access while maintaining the predictable, controlled environment that development workflows require.

WSL2 Port Communication (Windows Users)

Skip this section if you're not on Windows.

Since Claude CLI is WSL-only on Windows, but you might want to use Windows IDEs or tools to connect to your q server, you need proper port communication between WSL2 and Windows.

WSL2 Configuration for Port Communication

.wslconfig File Setup

Location: C:\Users\{YourUsername}\.wslconfig

Add mirrored networking configuration:

# Mirrored networking mode for seamless port communication
networkingMode=mirrored
dnsTunneling=true
firewall=true
autoProxy=true

Restart WSL2

Run from Windows PowerShell/CMD (NOT from within WSL):

wsl --shutdown
# Wait a few seconds, then start WSL again

Verify Configuration

Check if mirrored networking is active:

ip addr show
cat /etc/resolv.conf

Test Port Communication

Test WSL2 โ†’ Windows (localhost):

# In WSL2, start a server
python3 -m http.server 8000

# In Windows browser or PowerShell
curl http://localhost:8000

Test Windows โ†’ WSL2 (localhost):

# In Windows PowerShell
python -m http.server 8001

# In WSL2
curl http://localhost:8001

What Mirrored Networking Provides

  • โœ… Direct localhost communication both ways
  • โœ… No manual port forwarding needed
  • โœ… Better VPN compatibility
  • โœ… Simplified networking (Windows and WSL2 share network interfaces)
  • โœ… Firewall rules automatically handled

โš ๏ธ Port 5000 Special Case

Issue: Port 5000 has limited mirrored networking support due to Windows service binding.

Root Cause:

  • Windows svchost service binds to 127.0.0.1:5000 (localhost only)
  • Localhost-only bindings are not fully mirrored between Windows and WSL2
  • This creates an exception to the general mirrored networking functionality

Port 5000 Communication Matrix:

  • โœ… Windows โ†” Windows: Works (same localhost)
  • โŒ WSL2 โ†” Windows: Fails (different localhost interpretation)
  • โœ… WSL2 โ†” WSL2: Works (same environment)

Solutions for Port 5000:

  1. Use different ports: 5001, 5002, etc. (recommended)
  2. Stop Windows service: If not needed
  3. Traditional port forwarding: For specific use cases

Common Services That May Have Localhost-Only Binding

  • Flask development servers (default 127.0.0.1:5000)
  • UPnP Device Host service
  • Windows Media Player Network Sharing
  • Various development tools

Known Limitations of Mirrored Networking

  1. Localhost-only services: Not fully mirrored (as confirmed with port 5000)
  2. mDNS doesn't work in mirrored mode
  3. Some Docker configurations may have issues
  4. Requires Windows 11 22H2+ (build 22621+)