Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

VS Code MCP Service

VS Code MCP Service

MCP (Model Context Protocol) is an open standard that provides a unified interface allowing AI models (such as Copilot Chat) to discover and invoke external tools, enabling operations such as reading files, calling APIs, and executing tasks.

In VS Code, the MCP client (Copilot) completes tasks through tools provided by MCP servers, which can be deployed locally or remotely.

The figure above is the MCP architecture diagram:

Before using the VS Code MCP service, make sure the latest version of Visual Studio Code is installed.

Then install the relevant VS Code AI extension. We can use Microsoft's GitHub Copilot; simply log in with an account (including Free, Business, or Enterprise plans).

Starting from VS Code version 1.102, MCP support in VS Code is fully available and can be enabled or checked in the settings.


Configure MCP servers

There are several ways to add MCP servers in VS Code:

In this section, we use the workspace settings method.

Example

The following is a simple "Hello World" example of an MCP application in VS Code. First, we create a python file test.py with the following code:

Code of the test.py file

import

sys

import

json

Read the MCP initialization request

_

=

json.

load

(

sys

.

stdin

)

Output the MCP response (standard JSON)

json.

dump

(

{

   

"type"

:

"text"

,

   

"text"

:

"Hello World from MCP!"

}

,

sys

.

stdout

)

Next, we create an MCP server configuration that can return "Hello World".

Create a .vscode/mcp.json file in your workspace folder (create the .vscode directory if it does not exist) and fill in the following configuration (simulating a simple local MCP server):

.vscode/mcp.json file code

{

 

"servers"

:

{

   

"HelloWorldServer"

:

{

     

"type"

:

"stdio"

,

     

"command"

:

"python3"

,

     

"args"

:

[

"test.py"

]

   

}

 

}

}

After saving the file, open the VS Code Command Palette (Ctrl+Shift+P) and run the "MCP: Show Installed Servers" command:

You will see the configured "HelloWorldServer":

Start the server, and it will immediately return the message "Hello World from MCP!"

We can type "execute HelloWorldServer" in the AI chat window to see the output:

In the lower right corner of .vscode/mcp.json there is an "Add Server..." icon, through which we can add more services, including commands to execute or remote http services: