feat: Install mcp with initialization scripts

This commit is contained in:
Marek Fiala
2025-10-17 14:16:48 +02:00
parent 7c517deb35
commit c4347a682d
5 changed files with 29 additions and 31 deletions
+1 -19
View File
@@ -292,7 +292,7 @@ The MCP server also provides these resources:
- ``project://devices``: Get list of connected ESP devices
.. note::
The MCP server requires the ``mcp`` Python package to be installed. Install it with: ``pip install "mcp[cli]"`` or ``python -m pip install mcp``.
The MCP server requires the ``mcp`` Python package to be installed. Install it with: ``./install.sh --enable-mcp``.
Adding ESP-IDF MCP Server to IDEs
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -305,24 +305,6 @@ Use the Claude CLI to add the ESP-IDF MCP server:
claude mcp add esp-idf python /path/to/esp-idf/tools/idf.py mcp-server --env IDF_PATH=/path/to/esp-idf
**Cursor and Other IDEs:**
For IDEs that support MCP via JSON configuration (such as Cursor), add the following to your MCP settings:
.. code-block:: json
{
"mcpServers": {
"esp-idf": {
"command": "python",
"args": ["/path/to/esp-idf/tools/idf.py", "mcp-server"],
"env": {
"IDF_PATH": "/path/to/esp-idf"
}
}
}
}
Global Options
==============
+1 -1
View File
@@ -292,7 +292,7 @@ MCP 服务器还提供以下资源:
- ``project://devices``:获取已连接的 ESP 设备列表
.. note::
MCP 服务器需要安装 ``mcp`` Python 包。使用以下命令安装:``pip install "mcp[cli]"````python -m pip install mcp``
MCP 服务器需要安装 ``mcp`` Python 包。使用以下命令安装:``./install.sh --enable-mcp``
将 ESP-IDF MCP 服务器添加到 IDE
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+13 -11
View File
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
# SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0
import json
@@ -6,8 +6,6 @@ import os
import subprocess
import sys
from typing import Any
from typing import Dict
from typing import Optional
from click.core import Context
@@ -25,19 +23,23 @@ except ImportError:
MCP_AVAILABLE = False
def action_extensions(base_actions: Dict, project_path: str) -> Dict:
def action_extensions(base_actions: dict, project_path: str) -> dict:
"""ESP-IDF MCP Server Extension"""
def start_mcp_server(action_name: str, ctx: Context, args: PropertyDict, **kwargs: Any) -> None:
"""Start MCP server for ESP-IDF project integration"""
if not MCP_AVAILABLE:
raise FatalError(
'MCP dependencies not available. Install with: pip install "mcp[cli]"\n'
'Or use: python -m pip install mcp'
)
raise FatalError('MCP dependencies not available. Install with: ./install.sh --enable-mcp')
current_project = None
# Use current working directory if available, fallback to project_path
current_project = os.getcwd() if os.path.exists(os.path.join(os.getcwd(), 'CMakeLists.txt')) else project_path
for project_dir in [os.getcwd(), project_path]:
if project_dir and os.path.exists(os.path.join(project_dir, 'CMakeLists.txt')):
current_project = project_dir
break
if not current_project:
raise FatalError('Open the MCP server in a valid ESP-IDF project directory.')
print(f'Starting ESP-IDF MCP Server for project: {current_project}')
print(f'Target: {get_target(current_project)}')
@@ -89,7 +91,7 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict:
return f'Error setting target: {str(e)}'
@mcp.tool()
def flash_project(port: Optional[str] = None) -> str:
def flash_project(port: str | None = None) -> str:
"""Flash the built project to connected device"""
try:
flash_args = []
@@ -113,7 +115,7 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict:
return f'Error flashing: {str(e)}'
@mcp.tool()
def monitor_serial(port: Optional[str] = None) -> str:
def monitor_serial(port: str | None = None) -> str:
"""Start serial monitor (returns immediately, monitor runs in background)"""
try:
monitor_args = []
+6
View File
@@ -30,6 +30,12 @@
"description": "Packages for IDE support in ESP-IDF",
"optional": true,
"requirement_path": "tools/requirements/requirements.ide.txt"
},
{
"name": "mcp",
"description": "Packages for MCP (Model Context Protocol) server functionality",
"optional": true,
"requirement_path": "tools/requirements/requirements.mcp.txt"
}
]
}
+8
View File
@@ -0,0 +1,8 @@
# Python package requirements for MCP (Model Context Protocol) server functionality in ESP-IDF.
# This feature can be enabled by running "install.{sh,bat,ps1,fish} --enable-mcp"
#
# This file lists Python packages without version specifiers. Version details
# are stored in a separate constraints file. For more information, visit:
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/tools/idf-tools.html
mcp[cli]