Supports interaction with the server via curl commands for submitting build and flash requests
Provides a web server interface for building and flashing Zephyr projects through HTTP endpoints
Zephyr MCP Server
A Model Context Protocol (MCP) server for Zephyr RTOS development workflows. This server provides a comprehensive set of tools for managing Zephyr projects, including project initialization, firmware flashing, testing, version management, and Git operations with authentication support.
Features
🔧 Core Zephyr Operations
Project Initialization: Initialize Zephyr projects with authentication support
Firmware Flashing: Flash firmware to target boards with various flashers
Testing Framework: Run Twister tests with comprehensive result reporting
Version Management: Switch between Zephyr versions and manage updates
🔐 Authentication Support
Multiple Authentication Methods: Embedded, environment variable, and Git config authentication
Secure Credential Handling: Support for username/token authentication
Connection Testing: Pre-flight Git connection validation
🔄 Git Operations
Branch Management: Checkout specific Git references (SHA, tag, branch)
Mirror Management: Redirect to Zephyr Git mirrors
Configuration Management: Set and retrieve Git configuration status
Related MCP server: azure-devops-mcp
Installation
Prerequisites
Python 3.8+
Zephyr development environment with:
westtoolgittwister(for testing)
Setup
Clone the repository:
Install dependencies:
Run the server:
Available Tools
1. west_init - Initialize Zephyr Project
Initialize a Zephyr project with authentication support.
Parameters:
repo_url(str): Git repository URLbranch(str): Git branch nameproject_dir(str): Local project directoryusername(Optional[str]): Git username for authenticationtoken(Optional[str]): Git token or passwordauth_method(str): Authentication method ("embedded", "env", "config") - Default: "embedded"
Example:
2. west_flash - Flash Firmware
Execute west flash command to flash firmware to target board.
Parameters:
build_dir(str): Build output directoryboard(Optional[str]): Target hardware board modelrunner(Optional[str]): Flasher type (jlink, pyocd, openocd, etc.)probe_id(Optional[str]): Flasher ID/serial numberflash_extra_args(Optional[str]): Additional flash parameters
3. run_twister - Run Twister Tests
Execute twister test or build command and return structured results.
Parameters:
platform(Optional[str]): Target hardware platformtests(Optional[Union[List[str], str]]): Test path or suite nametest_cases(Optional[Union[List[str], str]]): Test case nameenable_slow(bool): Enable slow tests - Default: Falsebuild_only(bool): Build only mode - Default: Falseextra_args(Optional[str]): Additional twister parametersproject_dir(str): Zephyr project root directory
4. git_checkout - Switch Git Reference
Switch to specified Git reference (SHA, tag or branch) in Zephyr project directory.
Parameters:
project_dir(str): Zephyr project directoryref(str): Git reference (SHA, tag or branch name)
5. west_update - Update Zephyr Project
Run west update command in Zephyr project directory.
Parameters:
project_dir(str): Zephyr project directory
6. switch_zephyr_version - Switch Zephyr Version
Switch to specified Zephyr version (SHA or tag) and run west update.
Parameters:
project_dir(str): Zephyr project directoryref(str): Git reference (SHA, tag or branch name)
7. get_zephyr_status - Get Project Status
Get Git status information of Zephyr project.
Parameters:
project_dir(str): Zephyr project directory
8. git_redirect_zephyr_mirror - Redirect to Git Mirror
Redirect Zephyr Git repository to mirror address.
Parameters:
project_dir(str): Zephyr project directorymirror_url(str): Mirror repository URL
9. get_git_redirect_status - Get Redirect Status
Get Git remote redirect status.
Parameters:
project_dir(str): Zephyr project directory
10. set_git_credentials - Set Git Credentials
Set Git authentication credentials (global or project-specific).
Parameters:
username(str): Git usernamepassword(str): Git password/tokenproject_dir(Optional[str]): Project directory for local config
11. test_git_connection - Test Git Connection
Test Git repository connection with authentication.
Parameters:
repo_url(str): Git repository URLusername(Optional[str]): Git usernamepassword(Optional[str]): Git password/tokenproject_dir(Optional[str]): Project directory for config
12. get_git_config_status - Get Git Config Status
Get Git configuration status (global or project-specific).
Parameters:
project_dir(Optional[str]): Project directory for local config
Agent使用说明
Zephyr MCP Agent是一个命令行工具,用于启动和管理Zephyr MCP服务,将Zephyr MCP工具包装成可通过HTTP API访问的服务。
基本使用
命令行参数
--config: 指定配置文件路径(默认: config.json)--list-tools: 列出所有可用工具(按分类显示)--health-check: 执行工具健康检查(显示健康状态摘要和LLM集成状态)--generate-docs: 生成工具文档并保存到指定文件(需要提供文件名参数)--doc-format: 文档格式(可选值: markdown, json, text,默认: markdown)--filter: 使用正则表达式过滤工具--search: 搜索包含关键词的工具--test: 测试模式,验证工具注册但不启动服务
API使用
启动服务后,可以通过以下API端点与Agent交互:
工具调用示例
响应格式:
健康检查功能
运行健康检查命令可以获取工具的健康状态报告:
健康检查会显示:
工具健康状态摘要(健康、警告、错误数量)
LLM集成状态
每个工具的详细信息(状态、参数数量、描述等)
搜索和过滤工具
可以使用关键词搜索工具:
测试模式
测试模式可以验证工具注册是否成功,而不需要启动服务:
测试模式会显示:
注册的工具数量
LLM集成状态
工具分类信息
LLM集成(可选)
如果在配置中启用了LLM集成,还可以使用AI助手接口。Agent启动时会自动注册LLM相关工具(如果配置中启用)。
AI助手示例请求:
https://username:token@github.com/zephyrproject-rtos/zephyr.git
Authentication with Private Repository
Interactive Mode with User Prompting
Parameter Validation
Advanced Interactive Example
Interactive Features
New Interactive Tools
west_init_interactive - Interactive Project Initialization
Enhanced version of west_init with user-friendly features:
Key Features:
Automatic Parameter Prompting: Prompts for missing required parameters
User Confirmation: Shows configuration summary and asks for confirmation
Parameter Validation: Validates inputs before execution
Friendly Error Messages: Provides helpful suggestions and examples
Cancellation Support: Allows users to cancel at any step
Parameters:
All parameters from
west_initare optionalrequire_confirmation(bool): Whether to require user confirmation - Default: Trueauto_prompt(bool): Whether to automatically prompt for missing parameters - Default: True
Usage Examples:
validate_west_init_params - Parameter Validation
Validates west init parameters and provides helpful suggestions:
Features:
Missing Parameter Detection: Identifies missing required parameters
URL Format Validation: Checks Git repository URL format
Branch Name Suggestions: Provides common branch names
Directory Validation: Checks project directory status
Authentication Method Validation: Validates auth method selection
Helpful Suggestions: Provides specific recommendations
Return Values:
status: "valid", "missing_params", or "warnings"missing_params: List of missing required parameterswarnings: List of potential issuessuggestions: List of helpful recommendationsvalidation_details: Detailed validation information
Error Handling
The server provides comprehensive error handling with detailed error messages:
Common Error Scenarios
Missing Tools: Returns clear error if west/git/twister not installed
Authentication Failures: Detailed auth error messages with suggestions
Connection Issues: Git connection test failures with troubleshooting tips
Permission Errors: File system permission issues with resolution steps
Invalid Parameters: Parameter validation with helpful suggestions
Error Response Format
Configuration
Environment Variables
mcp_name: MCP server name (default: "ZephyrMcpServer")GIT_USERNAME: Git username for authenticationGIT_PASSWORD: Git password/token for authenticationGIT_TERMINAL_PROMPT: Disable Git terminal prompts (set to "0")
Git Mirror Configuration
Configure Git to use Zephyr mirrors for faster access:
Development
Adding New Tools
Define the function with proper docstring (bilingual)
Add
@mcp.tool()decoratorInclude comprehensive parameter validation
Add error handling with helpful messages
Update README documentation
Testing
Contributing
Fork the repository
Create a feature branch
Add tests for new functionality
Update documentation
Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For issues and questions:
Create an issue on GitHub
Check existing documentation
Review error messages and suggestions provided by the tools username="your_username", token="your_personal_access_token", auth_method="embedded" )
Running Tests
Error Handling
All tools return structured responses with:
status: "success" or "error"log: Command output logserror: Error message (if any)Additional tool-specific fields
Development
Project Structure
Adding New Tools
To add a new tool:
Define the function with
@mcp.tool()decoratorAdd comprehensive docstring with parameters and return values
Implement error handling
Update this README with tool documentation
Example:
License
This project is licensed under the terms of the LICENSE file in the root of this repository.
Contributing
Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.
Support
For support and questions:
Open an issue on GitHub
Check the documentation
Review the tool examples above