SQL Server Windsurf
STDIO为Windsurf IDE提供SQL Server集成的MCP服务器
为Windsurf IDE提供SQL Server集成的MCP服务器
A standalone MCP (Model Context Protocol) server written in C# that provides SQL Server integration capabilities as an addon to Windsurf IDE.
dotnet build
Configure the application:
appsettings.example.json to appsettings.jsonappsettings.json with your SQL Server details{ "ConnectionStrings": { "DefaultConnection": "Server=your-server;Database=master;User ID=your-username;Password=your-password;TrustServerCertificate=True" }, "LogPath": "C:\\Path\\To\\Your\\LogDirectory\\", "DebugMode": "false" }
Configure the MCP server in Windsurf:
windsurf_mcp_config.json to your Windsurf MCP configuration file (typically located at ~/.codeium/windsurf/mcp_config.json){ "mcpServers": { "sqlMcpService": { "command": "path/to/your/MCPSqlServer.exe", "args": [], "description": "SQL Server MCP Service" } } }
Set up GitHub integration:
git initgit remote add origin <repository-url>git push -u origin masterThe appsettings.json file contains the following configuration options:
ConnectionStrings:DefaultConnection: The SQL Server connection stringLogPath: Directory where log files will be storedDebugMode: Set to "true" to enable detailed debug loggingYou can publish the application as a self-contained executable:
dotnet publish -c Release -r win-x64 --self-contained true -p:PublishSingleFile=true
This will create a single executable file that includes all dependencies.
The MCP server communicates through standard input/output using a JSON-based protocol.
{ "id": "request-id", "action": "action-name", "parameters": { "param1": "value1", "param2": "value2" } }
{ "success": true, "data": { "key": "value" } }
Or in case of error:
{ "success": false, "error": { "code": "error_code", "message": "Error description" } }
{ "action": "connect", "parameters": { "connectionString": "Data Source=server;Initial Catalog=master;Integrated Security=True;" } }
{ "action": "get_databases", "parameters": {} }
{ "action": "get_tables", "parameters": { "database": "AdventureWorks" } }
{ "action": "get_columns", "parameters": { "database": "AdventureWorks", "schema": "Person", "table": "Person" } }
{ "action": "get_procedures", "parameters": { "database": "AdventureWorks" } }
{ "action": "execute_database_query", "parameters": { "database": "AdventureWorks", "query": "SELECT TOP 10 * FROM Person.Person", "parameters": { "param1": "value1" } } }
{ "action": "execute_system_query", "parameters": { "query": "SELECT name FROM sys.databases", "parameters": { "param1": "value1" } } }
{ "action": "execute_procedure", "parameters": { "database": "AdventureWorks", "schema": "dbo", "procedure": "uspGetEmployeeManagers", "parameters": { "BusinessEntityID": 5 } } }
This MCP server can be used from Windsurf IDE to:
The application is organized into the following components:
Program.cs: Main entry point and request handlingJsonRpcHandler.cs: Handles JSON-RPC protocol and dispatches requestsappsettings.jsonLogPath settingContributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)This project is licensed under the MIT License - see the LICENSE file for details.
Common error codes:
invalid_request: Malformed JSON or missing required fieldsconnection_failed: Failed to connect to SQL Servermissing_parameter: Required parameter not providedquery_execution_error: Error executing a SQL querydatabase_not_found: Specified database does not existtable_not_found: Specified table does not exist