• Что бы вступить в ряды "Принятый кодер" Вам нужно:
    Написать 10 полезных сообщений или тем и Получить 10 симпатий.
    Для того кто не хочет терять время,может пожертвовать средства для поддержки сервеса, и вступить в ряды VIP на месяц, дополнительная информация в лс.

  • Пользаватели которые будут спамить, уходят в бан без предупреждения. Спам сообщения определяется администрацией и модератором.

  • Гость, Что бы Вы хотели увидеть на нашем Форуме? Изложить свои идеи и пожелания по улучшению форума Вы можете поделиться с нами здесь. ----> Перейдите сюда
  • Все пользователи не прошедшие проверку электронной почты будут заблокированы. Все вопросы с разблокировкой обращайтесь по адресу электронной почте : info@guardianelinks.com . Не пришло сообщение о проверке или о сбросе также сообщите нам.

Set Up a MongoDB MCP Server in VS Code Like a Pro

Lomanu4 Оффлайн

Lomanu4

Команда форума
Администратор
Регистрация
1 Мар 2015
Сообщения
1,481
Баллы
155
? What is the Model Context Protocol (MCP)?


The Model Context Protocol (MCP) is an open standard introduced by Anthropic that aims to simplify how AI applications—like chatbots, IDE assistants, or custom agents—connect with external tools, data sources, and systems.

? Think of it like “USB for AI integrations”


Before USB, connecting devices meant dealing with dozens of ports and drivers. Similarly, integrating M different AI apps with N different tools used to require M × N custom integrations—a huge development burden.

MCP changes that to an M + N model:

  • Tool creators only need to build 1 MCP server per tool
  • App developers only need to build 1 MCP client per application
? How it works


MCP follows a client-server architecture:

  • Hosts: AI applications the user interacts with (e.g., Claude, an IDE, a custom agent)
  • Clients: Reside within the host and manage a 1:1 connection to an MCP server
  • Servers: External programs exposing functionality to AI apps via a standard API
? MCP Servers expose 3 components:


  1. Tools (model-controlled):

    Functions the LLM can call to perform actions (e.g., calling a weather API)


  2. Resources (app-controlled):

    Data sources the model can read, similar to GET requests in a REST API

    No heavy computation, no side effects

  3. Prompts (user-controlled):

    Predefined templates that help LLMs use tools/resources in the most effective way

This enables a modular, scalable ecosystem for AI integrations — with minimal duplication and maximum reuse.


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.



?️ Configuring mongodb-mcp-server in VS Code


On the

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

, you'll find four different ways to run the server.

In this tutorial, we'll choose the simplest option — using a connection string directly in the mcp.json file.

Let's run the following command in your terminal:


npm i mongodb-mcp-server

Make sure you're using Node.js version 20 or higher. You can check your version with:


node -v
? Create the .vscode/mcp.json file


Inside your project's .vscode folder, create a file named mcp.json with the following content:


{
"mcpServers": {
"MongoDB": {
"command": "npx",
"args": [
"-y",
"mongodb-mcp-server",
"--connectionString",
"mongodb+srv://username:password@cluster.mongodb.net/myDatabase"
]
}
}
}

Once you've entered your MongoDB connection details, click Start to launch the server.


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.



? Installing GitHub Copilot Extensions


We will install the two GitHub Copilot extensions from the VS Code Marketplace:

  1. GitHub Copilot – the core AI coding assistant.
  2. GitHub Copilot Chat – enables chat-based interactions within your IDE.


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.



? Log in to GitHub Copilot


Then, log in to GitHub Copilot following the instructions provided after installation.

This will authenticate your GitHub account and activate Copilot features in your editor.

? Using Agent Mode with MongoDB


Once you've selected Agent Mode, you can start using natural language to give high-level instructions to your MongoDB database.


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.



For example, you can type prompts like:

"Show me all users who signed up last week"

"Add a new user with the username TestUser7"
The agent will translate these into MongoDB queries and execute them for you.

Let's see what we have in our database in the User collection:


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.



? Running Our Instructions with Chat Copilot on MongoDB



Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.




Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.



Happy coding! ?


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

 
Вверх Снизу