TextQL MCP Server
Translates natural language to SQL/GraphQL queries and executes them, enabling AI agents to interact with databases through the Model Context Protocol.
README
TextQL MCP Server
A standalone Model Context Protocol (MCP) server implementation that exposes tools for translating natural language to * Query Language (*QL) and executing *QL queries.
Overview
This library provides a standardized interface for AI models and agents to interact with SQL/Graph databases using the Model Context Protocol. The server exposes tools for sending *QL queries and retrieving structured responses.
Features
- Natural Language to
*hQL Translation: Convert natural language questions to SQL/GraphQL queries - Query Execution: Execute SQL/GraphQL queries against your database
- Schema Support: Automatically fetch and use relevant schema information for query refinement
- Extensible Design: Easily integrate with your own database and schema providers
- MCP Standard: Built on the Model Context Protocol for seamless integration with AI agents
Installation
Option 1: Using Conda (Recommended)
-
Clone the repository:
git clone https://github.com/your-username/textql-mcp.git cd textql-mcp -
Create and activate the conda environment:
conda create -n textql-mcp python=3.11 -y conda activate textql-mcp -
Install dependencies:
pip install -r requirements.txt pip install -r requirements-spanner.txt # For Google Cloud Spanner support pip install -e .
Option 2: Using pip
-
Clone the repository:
git clone https://github.com/your-username/textql-mcp.git cd textql-mcp -
Install the required packages:
pip install -r requirements.txt
Quick Start
Running with Google Cloud Spanner:
-
Configure your Google Cloud credentials:
gcloud auth application-default login -
Create a configuration file (e.g.,
config/my_config.yaml):project_id: "my-project-id" instance_id: "my-instance" database_id: "my-database" -
Start the server:
python spanner_wikidata_server.py --config config/my_config.yaml
Running the Server
For Google Cloud Spanner:
# Using the wrapper script
./run_mcp_server.sh
# Or directly via command line
python -m textql_mcp --spanner-instance-id=<instance-id> --spanner-database-id=<database-id>
The server can be configured using YAML configuration files (e.g., config/wikidata_poc.yaml).
Customization
You can customize the server by implementing these interfaces:
SchemaProvider: Provides schema information for queriesQueryExecutor: Executes queries against your databaseAmbiguityDetector: Detects ambiguities in natural language queries
API Reference
Tools
translate_to_gql
Translate a natural language query into a GraphQL query.
Parameters:
natural_language_query(str): The natural language question to translateagent_type(str, optional): The agent type identifier (default: "default")
Returns:
- Dictionary containing the generated GraphQL query and related metadata
query_graph
Execute a query against the database.
Parameters:
gql_query(str): The query to executeagent_type(str, optional): The agent type identifier (default: "default")
Returns:
- Dictionary containing the query results and metadata
process_natural_language_query
Process a natural language query by translating it to *QL and executing it.
Parameters:
natural_language_query(str): The natural language question to processagent_type(str, optional): The agent type identifier (default: "default")max_attempts(int, optional): Maximum number of query refinement attempts (default: 3)
Returns:
- Dictionary containing the final results and execution history
Feature Flags
The TextQL MCP server includes a comprehensive feature flag system that allows you to enable/disable features at runtime without requiring server restarts.
Configuration
Feature flags can be configured in three ways (in order of precedence):
-
Environment Variables (highest priority)
export TEXTQL_FF_ENABLE_QUERY_GRAPH=true export TEXTQL_FF_ENABLE_ADMIN_ENDPOINTS=false -
Configuration File (YAML/TOML)
feature_flags: enable_query_graph: true enable_schema_fetch: true enable_natural_language: false enable_admin_endpoints: false -
Default Values (lowest priority)
Available Feature Flags
| Flag | Description | Default |
|---|---|---|
enable_query_graph |
Enable GraphQL query execution | true |
enable_schema_fetch |
Enable schema information retrieval | true |
enable_natural_language |
Enable natural language processing (experimental) | false |
enable_admin_endpoints |
Enable admin endpoints for runtime management | false |
enable_flag_runtime_updates |
Allow feature flags to be updated at runtime | false |
enable_auth_checks |
Enable authentication checks | false |
enable_rate_limiting |
Enable rate limiting | false |
enable_experimental_features |
Enable experimental features | false |
Usage in Code
from textql_mcp.core.feature_flags import FeatureFlag, feature_flag_required
# Protect a tool with a feature flag
@mcp.tool()
@feature_flag_required(FeatureFlag.ENABLE_QUERY_GRAPH)
def query_graph(gql_query: str, ctx: Context = None):
# Tool implementation
pass
# Check feature flags programmatically
if check_feature_flag(ctx, FeatureFlag.ENABLE_EXPERIMENTAL_FEATURES):
# Execute experimental code
pass
Runtime Updates
If enable_flag_runtime_updates is enabled, you can update feature flags at runtime:
feature_flags = ctx.lifespan_ctx.feature_flags
feature_flags.set_flag(FeatureFlag.ENABLE_ADMIN_ENDPOINTS, True)
License
Apache 2.0 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 模型以安全和受控的方式获取实时的网络信息。