Thursday, June 12, 2025

MCP server that connects VS Code to SQL Server

In this tutorial we will configure VS Code to use an MCP Server that connects to a SQL Server database. In a similar manner, you can also connect to SQLite, PostgresDB, and MySQL. This is a very compelling proposition because it allows developers to use AI to assist in generating code that dynamically interacts with data in a relational database.

Prerequisites

You will need to install the following software in order to proceed:

  • Visual Studio Code with the GitHub Copilot Chat extension
  • Docker Desktop
  • Latest versions of node.js, npm, and npx

The database

We will run a SQL Server database with the Northwind database in a Docker container. Therefore:

  • Start Docker Desktop on your computer
  • Run a SQL Server container by executing this command in a terminal window:


docker run --cap-add SYS_PTRACE -e ACCEPT_EULA=1 -e MSSQL_SA_PASSWORD=SqlPassword! -p 1333:1433 --name nw -d melmasry/my-sqlserver-northwind:latest

The database MCP Server

We will be using the MCP Server from the mcp-database-server GitHub Repo. Visit https://github.com/executeautomation/mcp-database-server for more details

Install and configure the SQL Server MCP server

In a suitable working directory, clone the repo, then build, and publish the code by executing these commands in a terminal window:

 
git clone https://github.com/executeautomation/mcp-database-server.git<
cd mcp-database-server
npm installnpm run build

We will next install the MCP server globally with:

  
npm install -g @executeautomation/database-server

To use the MCP server with our SQL Server database, run the following terminal window command:

  
node dist/src/index.js --sqlserver --server localhost --port 1333 --database Northwind --user sa --password SqlPassword!

Keep the above terminal window open and running.

Configuring VS Code

Open VS Code. Click on the settings gear in the bottom-left corner, followed by Settings.

In the search field, enter MCP, then click on "Edit in settings.json".

Under the mcp >> servers section, add the following MCP server settings:


"sqlserver": {
  "command": "npx",
  "args": [
	"-y",
	"@executeautomation/database-server",
	"--sqlserver",
	"--server", "localhost",
	"--port", "1333",
	"--database", "Northwind",
	"--user", "sa",
	"--password", "SqlPassword!"
  ]
}

Click on Start:

Open the GitHub Copilot Chat panel:


In the GitHub Copilot Chat panel, choose any Claude model followed by Agent Mode.

Click on the tools icon in the prompt window.

This will show you a list of commands that the MCP server can carry out with SQL Server

We can now start querying the database using natural language. Start with this prompt:

 
You have access to the Northwind database through an MCP server. What are the tables in the database?

It detects that it can use the list_tables command.

Click on Continue. I got the following output:

Similarly, you can ask another questions like: 


Display the contents of the suppliers table.

Yet, another question:


What are the products supplied by "Exotic Liquids"?

Conclusion

It is very easy to connect VS Code with a relational database MCP server. In addition, you can similarly connect any C# application. MCO Servers open up a ton of possiblities for AI aided software development. 

Wednesday, June 11, 2025

Getting started with MCP Server in Visual Studio Code

In this tutorial, you will learn how to enable and use MCP servers in Visual Studio Code. The simple example we will use is the Timer MCP Server.

What is MCP?

Model Context Protocol (MCP) is an open standard developed by Anthropic, the company behind Claude. 

MCP is an open protocol that enables seamless integration between AI apps & agents and your tools & data sources.

Prerequisites

  • Visual Studio Code
  • Github Copilot Chat extension
  • Docker Desktop

Getting Started

Start VS Code and click on the GitHub Copilot Chat icon.


Choose any Claude model and Agent mode. A tools button appears.


When you click on the tools button, you will see the tools that VS-Code GitHub Copilot Chat is using:

In Visual Studio Code, click on the gear in the bottom-left, then choose settings:

In the filter field, type MCP.


Note that Discovery is enabled and 'Chat' > 'Mcp' is also enabled. These are early days so Mcp is in preview.

Click on 'Mcp' >> 'Edit in settings.json'. The file will open in the editor. Note the mcp section with a sample mcp-server-time server:


"mcp": {   
  "inputs": [],
  "servers": {
    "mcp-server-time": {
      "command": "python",
      "args": [
        "-m",
        "mcp_server_time",
        "--local-timezone=America/Los_Angeles"
      ],
      "env": {}
    }
  }
}

In the chat window, click on the blue refresh tool.


If you do not have Python installed on your computer, you will get an error in the chat window:


Tap on the red error icon and choose “Show Output”.

The error is because python is not installed on the computer and, therefore, the MCP server cannot start.

Let us fix that by using an alternative way to run the MCP server without the need for Python. We will use Docker instead. Therefore, start your Docker Desktop.

Go to https://github.com/modelcontextprotocol/servers. Search for Time and click on it.

Find “Configure for Claude.app” >> “Using Docker”.


Copy the JSON code under mcpServers:

"mcpServers": {
 
  "time": {
    "command": "docker",
    "args": ["run", "-i", "--rm", "mcp/time"]
  }  
}

Back in settings.json, comment out (or delete) previous MCP servers under “mcp >> servers”. Paste the JSON code under mcp >> servers in settings.json. This is what the section will look like:


Click on the blue refresh tool again in the chat box. This time you should not experience any errors.


The time server now shows up among the available mcp servers when you click on tools.


Inside settings.json, start the server if it is not already started.

This will start the mcp/time server in Docker.

In the GitHub Copilot Chat window, enter: What is the current time?

It detects the running MCP server that knows how to handle requests for current time:


Click on Continue and you will get a response like this:

You can ask it to convert the time to another time zone with: What is that in pacific time zone?

Again, it will resort to our Time MCP server for assistance.

Click on Continue to get your answer.

You can even ask the time in another country. Example: What time is it in Cairo, Egypt?

Again, it uses our MCP Time server:


Click on Continue.

Finally, let us ask it to refresh the current time, with: Refresh the time in Egypt.


Conclusion

The ecosystem for MCP servers is growing rapidly. There are already many servers that you can explore at https://github.com/modelcontextprotocol/servers. In my next article, I will show you how youv can integrate the GitHub MCP server into VS Code.