SQL Server Table Assistant - Modal Context Protocol
SQL Server Agent tool (with MCP)
hblaDCOM
README
SQL Server Table Assistant - Modal Context Protocol
This application lets you interact with a specific SQL Server table using natural language, leveraging the Modal Context Protocol as a communication layer between LLMs and your data source.
This project is based on the mcp-sql-server-natural-lang repository by Aman Pachori, with modifications to focus on single table access.
Key Features:
- Talk to Your Table: Chat with a specific SQL Server table using plain English
- No-Code Table Operations: Query, insert, update, and delete data through natural conversations
- Secure, Limited Access: Connect to only one table with restricted credentials for enhanced security
- MCP-Enhanced Accuracy: Achieve precise table interactions through Modal Context Protocol
- Context-Aware Conversations: Maintain context across multiple queries
What is MCP?
MCP (Modal Context Protocol) is a methodology that standardizes how context is bound to LLMs, providing a standard way to connect AI models to different data sources and tools.
Single Table Mode
This application runs in "Single Table Mode" which provides several advantages:
- Enhanced Security: Access is limited to a single table rather than the entire database
- Simpler Permissions: Users need minimal permissions (just for the specific table)
- Focused Experience: The assistant is specialized for working with just one table
- Reduced Risk: Prevents accidental access to sensitive data in other tables
Prerequisites
Before you get started, make sure you have the following:
- Python 3.12+ installed on your machine
- A valid Azure OpenAI deployment with API access
- SQL Server with a table that you want to interact with
- Limited user credentials with access to only that table
Getting Started
Follow these steps to get the project up and running:
1. Clone the Repository
git clone https://github.com/yourusername/sql-server-table-assistant.git
cd sql-server-table-assistant
2. Install Dependencies
pip install -r requirements.txt
3. Setup Environment Variables
Create a .env file in the root of the project and add the following:
# Azure OpenAI Configuration (required)
AZURE_OPENAI_API_KEY=your_azure_openai_api_key
AZURE_OPENAI_ENDPOINT=https://your-resource-name.openai.azure.com
AZURE_OPENAI_API_VERSION=2023-05-15
AZURE_OPENAI_DEPLOYMENT_ID=your-deployment-name
# SQL Server Configuration
MSSQL_SERVER=localhost
MSSQL_DATABASE=your_database_name
MSSQL_USERNAME=your_username
MSSQL_PASSWORD=your_password
MSSQL_DRIVER={ODBC Driver 18 for SQL Server}
# Table Configuration
MSSQL_TABLE_SCHEMA=dbo
MSSQL_TABLE_NAME=your_table_name
Running the Table Assistant
Once you've set up your environment and dependencies, you're ready to interact with the Table Assistant.
Run the Client Script
Execute the following command to start the assistant:
python mcp-ssms-client.py
Once the script starts, it will prompt you with the table name and available commands. You can then type your requests in plain English. For example:
Table Assistant is ready. You are working with table: dbo.Employees
Type your questions about the table in natural language, and I'll translate them to SQL.
Special commands: /diagnose - Run diagnostics, /refresh_schema - Refresh table schema
Enter your Query: Show me all employees with a salary over $50,000
The assistant will:
- Translate your natural language to a SQL query
- Show you the query for approval
- Execute it after your confirmation
- Return and explain the results
Diagnostics and Troubleshooting
The application includes built-in diagnostic tools:
- Use
/diagnoseto run comprehensive table access diagnostics - Use
/refresh_schemato refresh the table schema - Check the
logsdirectory for detailed log files - Review permissions if you encounter access issues
Security Considerations
This application implements several security features:
- Single table access: Queries are restricted to the configured table
- Query validation: All SQL queries are shown for user approval before execution
- Transaction safety: INSERT/UPDATE/DELETE tests use transactions with rollback
- Error tracing: Detailed error logs help diagnose issues without exposing sensitive information
Connection Issues
If you encounter connection issues:
- Verify your server name or IP address is correct
- Ensure the SQL Server is running and accepts remote connections
- Check firewall settings to allow SQL Server traffic
- Verify that the ODBC driver specified in your .env file is installed
- Test connectivity with other tools like SSMS or sqlcmd
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgements
- Original MCP SQL Server Natural Language implementation by Aman Pachori
- Built with Modal Context Protocol (MCP)
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
MCP Package Docs Server
Facilitates LLMs to efficiently access and fetch structured documentation for packages in Go, Python, and NPM, enhancing software development with multi-language support and performance optimization.
Claude Code MCP
An implementation of Claude Code as a Model Context Protocol server that enables using Claude's software engineering capabilities (code generation, editing, reviewing, and file operations) through the standardized MCP interface.
@kazuph/mcp-taskmanager
Model Context Protocol server for Task Management. This allows Claude Desktop (or any MCP client) to manage and execute tasks in a queue-based system.
Linear MCP Server
Enables interaction with Linear's API for managing issues, teams, and projects programmatically through the Model Context Protocol.
mermaid-mcp-server
A Model Context Protocol (MCP) server that converts Mermaid diagrams to PNG images.
Jira-Context-MCP
MCP server to provide Jira Tickets information to AI coding agents like Cursor
Linear MCP Server
A Model Context Protocol server that integrates with Linear's issue tracking system, allowing LLMs to create, update, search, and comment on Linear issues through natural language interactions.
Sequential Thinking MCP Server
This server facilitates structured problem-solving by breaking down complex issues into sequential steps, supporting revisions, and enabling multiple solution paths through full MCP integration.