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

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

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

Enhancing the VS Code Agent Mode to integrate with Local tools using Model Context Protocol (MCP)

Lomanu4 Оффлайн

Lomanu4

Команда форума
Администратор
Регистрация
1 Мар 2015
Сообщения
1,481
Баллы
155
Enhancing the VS Code Agent Mode to integrate with Local tools using Model Context Protocol (MCP)

Building a Todo List Server with Model Context Protocol (MCP)



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


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


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



This blog post walks through creating a Todo List server using the Model Context Protocol (MCP), demonstrating how to build AI-friendly tools that integrate seamlessly with VS Code.

? Source Code: The complete implementation is available on

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

Table of Contents

  • The Evolution of AI-Assisted Development
  • What is Model Context Protocol (MCP)?
  • Architecture Overview
  • Prerequisites
  • Setting Up the Project
  • Implementing the MCP Server
  • VS Code Integration
  • Using the Todo MCP Server
  • Next Steps and Improvements
  • Troubleshooting
  • Resources
The Evolution of AI-Assisted Development


I have been using VS Code with GitHub Copilot for development purposes. The introduction of text-based chat, which brought GPT capabilities directly into the IDE, was revolutionary.

GitHub Copilot and the Local Tools Gap


GitHub Copilot has revolutionized how developers write code by providing intelligent code suggestions and completions. While it excels at understanding code context and generating relevant snippets, there has been a notable gap in its ability to interact with local development tools, intranet KBs, and execute actions in the development environment. This limitation means that while Copilot can suggest code, it cannot directly help with tasks like running commands, managing files, or interacting with local services.

Agent Mode: Bridging the Gap


The introduction of Agent Mode in GitHub Copilot represents a significant step forward in AI-assisted development. It enables Copilot to:

  • Execute terminal commands
  • Modify files directly
  • Interact with the VS Code environment
  • Handle project-specific tasks

This advancement transformed Copilot from a passive code suggestion tool into an active development partner that can help manage your entire development workflow. While tool execution capabilities brought many advantages, they also came with some inherent challenges. Issues such as maintaining tool code, implementing authentication, and managing authorization capabilities created additional overhead for developers.

MCP: The New Standard for AI Tool Integration


Model Context Protocol (MCP) emerges as the next evolution in this space, providing a standardized way for AI models to interact with development tools and services. Unlike traditional approaches where AI assistants are limited to suggesting code, MCP enables:


  1. Direct Tool Integration
    • AI models can directly invoke local tools
    • Real-time interaction with development environment
    • Standardized communication protocol

  2. Extensible Architecture
    • Custom tool definitions
    • Plugin-based system
    • Easy integration with existing services

  3. Development Environment Awareness
    • Context-aware assistance
    • Access to local resources
    • Real-time feedback loop
What is Model Context Protocol (MCP)?


Model Context Protocol (MCP) is a specification that enables AI models to interact with external tools and services in a standardized way. It defines how tools can expose their functionality through a structured interface that AI models can understand and use.

Key benefits of MCP that I have personally benefited from:

  • Standardized tool definitions with JSON Schema
  • Real-time interaction capabilities
  • Session management
  • Built-in VS Code integration


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



How MCP Tools Work


Each MCP tool follows a standardized structure:


{
name: "toolName",
description: "What the tool does",
parameters: {
// JSON Schema definition of inputs
},
returns: {
// JSON Schema definition of outputs
}
}

When an AI model wants to use a tool:

  1. It sends a request with the tool name and parameters
  2. The MCP server validates the request
  3. The tool executes with the provided parameters
  4. Results are returned in a standardized format

This structured approach ensures:

  • Consistent tool behavior
  • Type safety throughout the system
  • Easy tool discovery and documentation
  • Predictable error handling
Architecture Overview


Here's how the different components interact in our MCP Todo implementation:


graph TD
A[GitHub Copilot] -->|Natural Language Commands| B[VS Code]
B -->|MCP Protocol| C[MCP Todo Server]
C -->|CRUD Operations| D[(LowDB/Database)]
C -->|Real-time Updates| B
B -->|Command Results| A


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



Prerequisites


To follow along, you'll need:

  • Node.js (v22 or higher)
  • VS Code
  • Basic understanding of Express.js
  • npm or yarn package manager
Setting Up the Project

  1. First, create a new project and initialize npm:

mkdir mcp-todo-server
cd mcp-todo-server
npm init -y
  1. Install required dependencies:

npm install @modelcontextprotocol/sdk express lowdb zod

For this demonstration, we're using lowdb to manage tasks in a JSON file without actual integration with an external system. In a production environment, the lowdb functions can be replaced with actual JIRA CRUD API calls for end-to-end implementation.

  1. Create the basic directory structure:

mcp-todo-server/
├── src/
│ ├── config/
│ ├── tools/
│ ├── utils/
│ └── server.js
└── package.json
Implementing the MCP Server

1. Basic Server Setup


We started with a basic Express server that implements the MCP protocol. The server uses StreamableHTTP for real-time communication and session management.

Key components in server.js:

  • Express server setup
  • MCP SDK integration
  • StreamableHTTP transport configuration
  • Session management for maintaining tool state
2. Database Configuration


We used lowdb, a lightweight JSON database, to persist our todos. The database configuration in config/db.js handles:

  • JSON file storage
  • Basic CRUD operations
  • Data persistence between server restarts
3. Implementing Todo Tools


We implemented four main tools for managing todos:


  1. createTodo
    • Creates new todo items
    • Validates input using Zod schema
    • Returns the created todo with a unique ID

  2. listTodos
    • Lists all todos or filters by completion status
    • Formats output for easy reading
    • Supports real-time updates

  3. updateTodo
    • Updates todo completion status
    • Validates input parameters
    • Returns updated todo information

  4. deleteTodo
    • Removes todos by ID
    • Provides completion confirmation
    • Handles error cases gracefully
VS Code Integration


To enable VS Code to use our MCP server, follow these steps:

  1. Enable Agent mode in VS Code. Click on the drop down just before the model listing and select agent from it.


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



  1. Then click on the Gear icon next to the speaker icon in the above image and select "Add more tools" then select "Add MCP Server"


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



  1. Then select HTTP or Server-Sent Events and provide the URL based on the server we created. In this case, it's

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

    . Then select a name for the server.


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




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




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



  1. Alternatively you can Press Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (Mac) to open the Command Palette. Type "Open Settings (JSON)" and select it and add the following configuration:

{
"mcp": {
"servers": {
"my-mcp-server": {
"url": "

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

"
}
}
}
}

You can use the 4th step to verify if the server is added correctly after the first 3 steps are done. The User Settings option has Start, Stop, and Restart options. This step helped me identify if there are any issues with the MCP tools server effectively.


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




  1. Reload VS Code to apply the changes or use the Start, Stop, Restart options in the settings.json as shown above.


  2. After successful addition of the MCP server, you should see the tools listed when you click the gear icon in the Copilot chat window.


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



Using the Todo MCP Server


Here are some example prompts you can use in VS Code with GitHub Copilot to interact with the todo server. Each example includes a screenshot of the actual interaction:

  1. Creating a Todo

Prompt: "Create a new todo item called 'Review PR #123'"
Response: Successfully created todo "Review PR #123"


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



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



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



  1. Listing Todos

Prompt: "Show me all my todos"
Response: Here are your todos:
- Review PR #123 (Not completed)
- Update documentation (Completed)
- Setup test environment (Not completed)


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



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



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



  1. Updating a Todo

Prompt: "Mark the todo about PR review as completed"
Response: Updated "Review PR #123" to completed
  1. Deleting a Todo

Prompt: "Delete the todo about documentation"
Response: Successfully deleted "Update documentation"
  1. Filtering Todos

Prompt: "Show me only completed todos"
Response: Completed todos:
- Review PR #123
Next Steps and Improvements


Potential enhancements for the project:


  1. Authentication
    • Add user authentication
    • Implement role-based access

  2. Advanced Features
    • Due dates for todos
    • Categories/tags
    • Priority levels

  3. Performance
    • Caching
    • Database optimization
    • Rate limiting

  4. Testing
    • Unit tests
    • Integration tests
    • Load testing
Troubleshooting

Common Issues and Solutions


  1. Server Connection Issues
    • Verify the server is running on port 3000
    • Check VS Code settings for correct server URL
    • Ensure no firewall blocking the connection

  2. Tool Registration Problems

Error: Tool 'createTodo' not found
Solution: Check if server is properly initializing tools in server.js

  1. Schema Validation Errors
    • Ensure todo items match the required schema
    • Check Zod validation rules in tool implementations
    • Verify JSON payload format

  2. Real-time Updates Not Working
    • Confirm SSE (Server-Sent Events) connection is established
    • Check browser console for connection errors
    • Verify StreamableHTTP transport configuration
Source Code Reference


Key implementation files:

Conclusion


We've successfully built a fully functional MCP-compatible Todo server that:

  • Implements CRUD operations
  • Maintains persistent storage
  • Provides real-time updates
  • Integrates seamlessly with VS Code

This implementation serves as a great starting point for building more complex MCP tools and understanding how AI models can interact with custom tools through the Model Context Protocol.

Resources


You can also:



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

 
Вверх Снизу