mirror of
https://github.com/espressif/esp-idf.git
synced 2026-04-27 19:13:21 +00:00
feat: Install mcp with initialization scripts
This commit is contained in:
@@ -292,7 +292,7 @@ The MCP server also provides these resources:
|
|||||||
- ``project://devices``: Get list of connected ESP devices
|
- ``project://devices``: Get list of connected ESP devices
|
||||||
|
|
||||||
.. note::
|
.. 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
|
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
|
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
|
Global Options
|
||||||
==============
|
==============
|
||||||
|
|
||||||
|
|||||||
@@ -292,7 +292,7 @@ MCP 服务器还提供以下资源:
|
|||||||
- ``project://devices``:获取已连接的 ESP 设备列表
|
- ``project://devices``:获取已连接的 ESP 设备列表
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
MCP 服务器需要安装 ``mcp`` Python 包。使用以下命令安装:``pip install "mcp[cli]"`` 或 ``python -m pip install mcp``。
|
MCP 服务器需要安装 ``mcp`` Python 包。使用以下命令安装:``./install.sh --enable-mcp``。
|
||||||
|
|
||||||
将 ESP-IDF MCP 服务器添加到 IDE
|
将 ESP-IDF MCP 服务器添加到 IDE
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|||||||
@@ -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
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
import json
|
import json
|
||||||
@@ -6,8 +6,6 @@ import os
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from typing import Dict
|
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
from click.core import Context
|
from click.core import Context
|
||||||
|
|
||||||
@@ -25,19 +23,23 @@ except ImportError:
|
|||||||
MCP_AVAILABLE = False
|
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"""
|
"""ESP-IDF MCP Server Extension"""
|
||||||
|
|
||||||
def start_mcp_server(action_name: str, ctx: Context, args: PropertyDict, **kwargs: Any) -> None:
|
def start_mcp_server(action_name: str, ctx: Context, args: PropertyDict, **kwargs: Any) -> None:
|
||||||
"""Start MCP server for ESP-IDF project integration"""
|
"""Start MCP server for ESP-IDF project integration"""
|
||||||
if not MCP_AVAILABLE:
|
if not MCP_AVAILABLE:
|
||||||
raise FatalError(
|
raise FatalError('MCP dependencies not available. Install with: ./install.sh --enable-mcp')
|
||||||
'MCP dependencies not available. Install with: pip install "mcp[cli]"\n'
|
|
||||||
'Or use: python -m pip install mcp'
|
|
||||||
)
|
|
||||||
|
|
||||||
|
current_project = None
|
||||||
# Use current working directory if available, fallback to project_path
|
# 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'Starting ESP-IDF MCP Server for project: {current_project}')
|
||||||
print(f'Target: {get_target(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)}'
|
return f'Error setting target: {str(e)}'
|
||||||
|
|
||||||
@mcp.tool()
|
@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"""
|
"""Flash the built project to connected device"""
|
||||||
try:
|
try:
|
||||||
flash_args = []
|
flash_args = []
|
||||||
@@ -113,7 +115,7 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict:
|
|||||||
return f'Error flashing: {str(e)}'
|
return f'Error flashing: {str(e)}'
|
||||||
|
|
||||||
@mcp.tool()
|
@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)"""
|
"""Start serial monitor (returns immediately, monitor runs in background)"""
|
||||||
try:
|
try:
|
||||||
monitor_args = []
|
monitor_args = []
|
||||||
|
|||||||
@@ -30,6 +30,12 @@
|
|||||||
"description": "Packages for IDE support in ESP-IDF",
|
"description": "Packages for IDE support in ESP-IDF",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"requirement_path": "tools/requirements/requirements.ide.txt"
|
"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"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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]
|
||||||
Reference in New Issue
Block a user