WiFi MCP服务器
提供WiFi网络监控和管理工具的模型上下文协议(MCP)服务器。该服务器可以与Continue.dev、Claude Desktop或任何兼容MCP的客户端集成,使AI助手能够实时访问WiFi信息。
特性
- 📡 WiFi网络扫描:发现可用的无线网络
- 📊 连接状态:获取当前WiFi连接详细信息
- 📶 信号强度:监控信号质量和强度指标
- 🔌 接口管理:列出并管理网络接口
- 🔄 实时更新:实时监控网络状况
先决条件
- Python 3.8或更高版本
- 具有WiFi功能的Linux系统
- 网络管理工具:
iw,iwconfig,ip(通常预装) - 某些网络操作的Root/sudo访问权限
安装
快速设置
# Clone or navigate to the project directory
cd ~/wifi-mcp-server
# Install dependencies
pip install -r requirements.txt
# Optional: Install in development mode
pip install -e .虚拟环境的替代设置
# Create virtual environment
python3 -m venv venv
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt运行演示
1.独立测试
测试不集成MCP的WiFi工具:
# Run standalone tests
python3 standalone_test.py
# Or use the Makefile
make test-standalone2.MCP服务器测试
测试MCP服务器的完整功能:
# Test all MCP tools
python3 test_wifi_server.py ./wifi_mcp_server.py
# Or use the Makefile
make test-mcp3.运行MCP服务器
在stdio模式下启动服务器(用于与MCP客户端集成):
# Run the server directly
python3 wifi_mcp_server.py
# Or using the provided script
./run_server.sh集成示例
VS代码MCP集成
要将WiFi MCP服务器与Visual Studio代码集成,请将以下内容添加到VS代码设置中(~/.config/Code/User/settings.json):
{
"mcp": {
"servers": {
"wifi-mcp-server": {
"type": "stdio",
"command": "~/wifi-mcp-server/wifi_mcp_server.py",
"args": []
}
}
}
}这使得基于MCP的WiFi工具可以直接在VS Code中使用。
可用工具
1. scan_wifi
扫描可用的WiFi网络
参数:
interface(可选):WiFi接口名称(例如“wlan0”)
示例用法:
# In Continue.dev chat:
"Scan for available WiFi networks"2. get_wifi_status
获取当前WiFi连接状态
参数:
interface(可选):WiFi接口名称
示例用法:
# In Continue.dev chat:
"What's my current WiFi status?"3. get_signal_strength
获取详细的信号强度和质量指标
参数:
interface(可选):WiFi接口名称
示例用法:
# In Continue.dev chat:
"Check my WiFi signal strength"4. list_interfaces
列出所有可用的网络接口
示例用法:
# In Continue.dev chat:
"Show me all network interfaces"演示场景
基础网络监控
- 检查当前状态:
"What's my current WiFi status?"- 扫描网络:
"Scan and list available WiFi networks"- 监控信号质量:
"How strong is my WiFi signal?"故障排除工作流
- 网络诊断:
"Help me diagnose my WiFi connection issues"- 比较网络:
"Show me all available networks and their signal strengths"- 接口信息:
"List all my network interfaces and their status"发展
项目结构
wifi-mcp-server/
├── wifi_mcp_server.py # Main MCP server implementation
├── test_wifi_server.py # MCP server test suite
├── standalone_test.py # Standalone functionality tests
├── requirements.txt # Python dependencies
├── setup.py # Package setup configuration
├── Makefile # Build and test commands
└── README.md # This file运行测试
# Run all tests
make test
# Run specific test suites
make test-standalone # Test WiFi functions directly
make test-mcp # Test MCP server functionality
# Run with verbose output
python3 test_wifi_server.py ./wifi_mcp_server.py开发设置
# Set up development environment
make dev-setup
# Install in development mode
make install
# Format code
make lint故障排除
常见问题
- 权限错误:
# Some WiFi operations require sudo
sudo python3 wifi_mcp_server.py- 缺少依赖关系:
pip install mcp- 未找到网络工具:
# Install wireless tools (Ubuntu/Debian)
sudo apt install wireless-tools iw net-tools
# Install wireless tools (CentOS/RHEL)
sudo yum install wireless-tools iw net-tools- MCP服务器未启动:
# Check if MCP library is installed
python3 -c "import mcp; print('MCP installed successfully')"
# Run server with debug output
python3 wifi_mcp_server.py 2>&1 | tee debug.log调试模式
通过设置环境变量启用调试日志记录:
export DEBUG=1
python3 wifi_mcp_server.py检查集成
- 直接测试MCP服务器:
echo '{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0.0"}}}' | python3 wifi_mcp_server.py- 验证Continue.dev集成:
- 检查Continue.dev日志: ~/.continue/logs/continue.log - 查找MCP服务器加载消息 - 使用简单的WiFi查询进行测试
- 检查网络接口:
# List wireless interfaces
iw dev
# Check interface status
ip link show许可证
此项目根据LICENSE文件中指定的条款获得许可。
示例输出
WiFi状态示例
{
"interface": "wlan0",
"connected_ssid": "ExampleSSID",
"access_point": "00:11:22:33:44:55",
"bit_rate": 300.0,
"link_quality": {
"current": 40,
"max": 70
},
"signal_level": -60
}网络扫描示例
{
"interface": "wlan0",
"networks": [
{
"bssid": "00:11:22:33:44:55",
"frequency": 5180.0,
"signal": -60,
"ssid": "ExampleSSID"
},
{
"bssid": "66:77:88:99:AA:BB",
"frequency": 2412.0,
"signal": -50,
"ssid": "GuestNetwork"
}
],
"scan_time": 1234567.890123
}______________________________________________________________________
快速入门演示
1.设置和安装
# Clone or navigate to the project directory
cd ~/wifi-mcp-server
# Option A: Quick setup (system Python)
pip install -r requirements.txt
# Option B: Development setup with virtual environment
make dev-setup
source venv/bin/activate # Activate the virtual environment2.测试WiFi功能
# Test standalone WiFi functions (no MCP required)
python3 standalone_test.py
# Expected output: Lists interfaces, shows WiFi status, etc.3.测试MCP服务器
# Test the full MCP server with all tools
python3 test_wifi_server.py ./wifi_mcp_server.py
# Expected output: JSON responses for scan, status, signal strength4.运行MCP服务器
# Start the server in stdio mode
python3 wifi_mcp_server.py
# The server will wait for JSON-RPC commands via stdin
# Press Ctrl+C to stop5.与VS Code集成
将以下内容添加到您的VS代码设置中(~/.config/Code/User/settings.json):
{
"mcp": {
"servers": {
"wifi-mcp-server": {
"type": "stdio",
"command": "~/wifi-mcp-server/wifi_mcp_server.py",
"args": []
}
}
}
}6.在本地运行代理
# Start the MCP server in HTTP mode
nohup python3 wifi_mcp_server.py --mode http &
python3 ./wifi_agent.py --llm-url http://localhost:8000 -model llama3.1:8b --wifi-server-url http://localhost:8080注: 为了使用英特尔GPU加速运行Olama,我使用了 mattcurf/ollama英特尔gpu Docker服务。这使得在英特尔硬件上能够进行高效的LLM推理。
6.演示命令
集成后,在VS Code聊天中尝试以下命令:
"What's my current WiFi status?"
"Scan for available WiFi networks"
"Check my WiFi signal strength"
"List all network interfaces"