6.4 KiB
MCP Tools Documentation
Your MCP server now has 4 specialized tools for working with the MS SQL Server Infra database.
🔧 Available Tools
1. execute_sql
Description: Execute custom read-only SQL queries
Parameters:
query(string, required): SQL SELECT query to execute
Example:
{
"query": "SELECT TOP 10 Teil, Bez, Hersteller FROM TEILE WHERE Hersteller LIKE '%Bosch%'"
}
Use Cases:
- Complex queries with JOINs
- Aggregations (COUNT, SUM, AVG, etc.)
- Custom filtering and sorting
- Any read-only data analysis
2. list_tables
Description: List all available tables in the Infra database
Parameters: None
Example:
{}
Returns:
[
{ "TABLE_NAME": "TEILE" },
...
]
Use Cases:
- Discover what tables exist
- Explore database structure
- Find table names for queries
3. describe_table
Description: Get detailed schema information for a specific table
Parameters:
table_name(string, required): Name of the table to describe
Example:
{
"table_name": "TEILE"
}
Returns:
[
{
"COLUMN_NAME": "Teil",
"DATA_TYPE": "nchar",
"CHARACTER_MAXIMUM_LENGTH": 15,
"IS_NULLABLE": "YES",
"COLUMN_DEFAULT": null
},
{
"COLUMN_NAME": "Bez",
"DATA_TYPE": "nchar",
"CHARACTER_MAXIMUM_LENGTH": 160,
"IS_NULLABLE": "YES",
"COLUMN_DEFAULT": null
},
...
]
Use Cases:
- Understand table structure before querying
- Check column data types
- Verify column names
- See which columns allow NULL values
4. search_parts
Description: Quick search across the TEILE table
Parameters:
search_term(string, required): Term to search forlimit(number, optional): Max results per table (default: 50)
Example:
{
"search_term": "Bosch",
"limit": 20
}
Returns:
[
{
"TableName": "TEILE",
"Teil": "10.1.000040",
"Art": "2",
"Gruppe": "CA",
"Bez": "ITT1 Bosch LST-Motorkabel 15m",
"Bez2": "ITT1 Bosch LST motor cable 15m",
"Hersteller": "SDS",
"WarenNr": null
},
...
]
Searches in:
- Teil (Part number)
- Bez (Description)
- Bez2 (Description 2)
- Hersteller (Manufacturer)
Use Cases:
- Quick part lookup
- Find parts by manufacturer
- Search by description
- Find part numbers
🔒 Security Features
All tools enforce read-only access:
- ✅ Only SELECT queries allowed
- ✅ Blocks INSERT, UPDATE, DELETE, DROP, etc.
- ✅ Prevents query chaining with semicolons
- ✅ Blocks stored procedure execution
- ✅ SQL injection protection with parameter escaping
📝 Usage in Cursor/AI
The AI can now use these tools automatically. Examples:
Question: "Show me all Bosch parts"
AI will use: search_parts tool with { "search_term": "Bosch" }
Question: "What columns does TEILE have?"
AI will use: describe_table tool with { "table_name": "TEILE" }
Question: "List all tables in the database"
AI will use: list_tables tool
Question: "Find all parts with weight over 1kg"
AI will use: execute_sql tool with a custom query
🧪 Testing the MCP Server
Test Tool Listing
# Use Cursor's MCP inspector or call the server directly
# The server should list all 4 tools
Test Execute SQL
Query:
{
"name": "execute_sql",
"arguments": {
"query": "SELECT TOP 5 Teil, Bez FROM TEILE"
}
}
Test Search Parts
Query:
{
"name": "search_parts",
"arguments": {
"search_term": "Kabel",
"limit": 10
}
}
Test List Tables
Query:
{
"name": "list_tables",
"arguments": {}
}
Test Describe Table
Query:
{
"name": "describe_table",
"arguments": {
"table_name": "TEILE"
}
}
Note: The former import tables
SDS_TeileandSDS_Teile_**are no longer used.
All queries should now use the productiveTEILEtable instead.
🔄 Restart MCP Server
After making changes, restart Cursor to reload the MCP server:
- Close Cursor completely
- Reopen Cursor
- The MCP server will start automatically
Or check Cursor's MCP server status in Settings → MCP Servers
📊 Tool Selection Guide
| Task | Best Tool | Why |
|---|---|---|
| Quick part search | search_parts |
Optimized for common searches |
| Complex filtering | execute_sql |
Full SQL flexibility |
| Explore database | list_tables |
See what's available |
| Check columns | describe_table |
Understand table structure |
| Joins/aggregations | execute_sql |
Custom query needed |
| Multi-table search | search_parts |
Searches across tables |
🎯 Example Workflows
Workflow 1: Find a Part
- Use
search_partsto find parts by keyword - Use
describe_tableif you need more column details - Use
execute_sqlfor precise filtering
Workflow 2: Explore New Table
- Use
list_tablesto see all tables - Use
describe_tableto understand structure - Use
execute_sqlto query data
Workflow 3: Complex Analysis
- Use
describe_tableto check available columns - Use
execute_sqlwith JOINs/aggregations - Use
search_partsfor quick validation
🚨 Error Handling
All tools return helpful error messages:
Error Example:
{
"error": "Forbidden keyword detected: DELETE. Only SELECT queries are allowed!"
}
Common Errors:
- "Only SELECT queries are allowed" → Tried to modify data
- "Multiple statements not allowed" → Query contains semicolon
- "Table not found" → Table name doesn't exist
- "Invalid column name" → Column doesn't exist in table
📈 Performance Tips
- Use LIMIT: Add
TOP Nto queries for faster results - Specific columns: Select only needed columns, not
* - Index-aware: Filter on Teil (likely indexed) when possible
- Use search_parts: For simple searches, it's optimized
- Avoid LIKE %term%: If possible, use
LIKE 'term%'(faster)
🔐 Best Practices
- ✅ Use describe_table before complex queries
- ✅ Start with small limits (TOP 10) when testing
- ✅ Validate table names with list_tables first
- ✅ Use search_parts for simple part lookups
- ✅ Keep queries focused - one question per query
- ❌ Don't try to modify data (will be blocked)
- ❌ Don't chain multiple queries with semicolons
- ❌ Don't use stored procedures or functions