TP-Link Router MCP Server
Enables automation and management of TP-Link BE3600 routers through browser automation, supporting port forwarding configuration, network status monitoring, and device management without reverse-engineering the router's encryption.
README
TP-Link BE3600 Router Automation
A Python library for automating TP-Link BE3600 (and similar) routers using Playwright browser automation. This tool bypasses the router's complex encryption scheme by controlling the web interface directly.
Why This Exists
TP-Link BE3600 routers use a sophisticated encryption scheme for their API:
- RSA encryption for key exchange
- AES-GCM for request/response encryption
- Complex signature generation with sequence numbers
Rather than reverse-engineering the entire encryption protocol (which changes between firmware versions), this library uses Playwright browser automation to interact with the router's web UI directly. The browser handles all the encryption natively.
Features
- Login/Authentication - Automated browser-based login
- Port Forwarding Management - List, add, and manage port forwarding rules
- DHCP Settings - View DHCP configuration
- Network Status - Get router status and connected devices
- Screenshot Capture - Debug by capturing UI screenshots
- MCP Server - Model Context Protocol server for AI integration
Supported Routers
- TP-Link BE3600 (Dual-Band Wi-Fi 7) - Primary target
- May work with other TP-Link routers using similar web interfaces
Installation
Prerequisites
- Python 3.10+
- Chromium browser (installed automatically by Playwright)
Install from Source
# Clone the repository
git clone https://github.com/consigcody94/mcp-tplink-router.git
cd mcp-tplink-router
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -e .
# Install Playwright browsers
playwright install chromium
# On Linux, you may need additional dependencies
sudo apt-get install -y libnss3 libnspr4 libatk1.0-0 libatk-bridge2.0-0 \
libcups2 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 \
libxrandr2 libgbm1 libasound2
Quick Start
1. Configure Environment
Create a .env file:
TPLINK_HOST=192.168.0.1
TPLINK_PASSWORD=your_router_password
TPLINK_USERNAME=admin
2. Basic Usage
from mcp_tplink_router.be3600_playwright import BE3600PlaywrightClient
# Initialize the client
client = BE3600PlaywrightClient(
host="192.168.0.1", # Your router's IP
password="your_password" # Router admin password
)
# Login
if client.login():
print(f"Logged in! STOK: {client.stok}")
# Get port forwarding rules
rules = client.get_port_forwarding()
for rule in rules:
print(f"{rule['name']}: {rule['external_port']} -> {rule['internal_ip']}:{rule['internal_port']}")
# Always logout when done
client.logout()
else:
print("Login failed")
3. Adding Port Forwarding Rules
from mcp_tplink_router.be3600_playwright import BE3600PlaywrightClient
client = BE3600PlaywrightClient("192.168.0.1", "your_password")
if client.login():
# Add a single port forward
client.add_port_forward(
name="Web Server",
external_port="80",
internal_ip="192.168.0.100",
internal_port="80",
protocol="TCP" # "TCP", "UDP", or "All"
)
# Add a port range (e.g., for VoIP/RTP)
client.add_port_forward(
name="VoIP RTP",
external_port="10000-10100",
internal_ip="192.168.0.50",
internal_port="10000-10100",
protocol="UDP",
is_port_range=True
)
client.logout()
API Reference
BE3600PlaywrightClient
Constructor
BE3600PlaywrightClient(host: str, password: str, username: str = "admin")
| Parameter | Type | Description |
|---|---|---|
host |
str | Router IP address (e.g., "192.168.0.1") |
password |
str | Admin password |
username |
str | Admin username (default: "admin") |
Methods
| Method | Returns | Description |
|---|---|---|
login() |
bool |
Authenticate with the router |
logout() |
None |
Close browser and clean up |
get_port_forwarding() |
List[Dict] |
Get all port forwarding rules |
add_port_forward(...) |
bool |
Add a new port forwarding rule |
get_status() |
dict |
Get router status |
get_devices() |
List[Dict] |
Get connected devices |
get_dhcp_settings() |
dict |
Get DHCP configuration |
take_screenshot(path) |
str |
Capture screenshot for debugging |
Port Forwarding Rule Format
{
"name": "Web Server",
"internal_ip": "192.168.0.100",
"external_port": "80",
"internal_port": "80",
"protocol": "TCP",
"status": ""
}
Complete Example: FreePBX/VoIP Setup
#!/usr/bin/env python3
"""Configure port forwarding for FreePBX/VoIP."""
import os
from dotenv import load_dotenv
from mcp_tplink_router.be3600_playwright import BE3600PlaywrightClient
load_dotenv()
ROUTER_HOST = os.getenv("TPLINK_HOST", "192.168.0.1")
ROUTER_PASSWORD = os.getenv("TPLINK_PASSWORD")
FREEPBX_IP = "192.168.0.169"
def main():
client = BE3600PlaywrightClient(ROUTER_HOST, ROUTER_PASSWORD)
if not client.login():
print("Failed to login to router")
return
try:
# Add SIP signaling port (UDP 5060)
print("Adding SIP port forwarding...")
client.add_port_forward(
name="FreePBX SIP",
external_port="5060",
internal_ip=FREEPBX_IP,
internal_port="5060",
protocol="UDP"
)
# Add RTP media ports (UDP 10000-20000)
print("Adding RTP port range...")
client.add_port_forward(
name="FreePBX RTP",
external_port="10000-20000",
internal_ip=FREEPBX_IP,
internal_port="10000-20000",
protocol="UDP",
is_port_range=True
)
# Verify rules were added
print("\nCurrent port forwarding rules:")
rules = client.get_port_forwarding()
for rule in rules:
print(f" {rule['name']}: {rule['external_port']} -> "
f"{rule['internal_ip']}:{rule['internal_port']} ({rule['protocol']})")
finally:
client.logout()
if __name__ == "__main__":
main()
MCP Server Usage (AI Integration)
This package includes an MCP (Model Context Protocol) server for use with Claude Desktop and other AI assistants.
Configure Claude Desktop
Add to ~/.config/claude/claude_desktop_config.json:
{
"mcpServers": {
"tplink-router": {
"command": "/path/to/mcp-tplink-router/venv/bin/python",
"args": ["-m", "mcp_tplink_router"],
"env": {
"TPLINK_HOST": "192.168.0.1",
"TPLINK_USERNAME": "admin",
"TPLINK_PASSWORD": "your_password"
}
}
}
}
Available MCP Tools
| Tool | Description |
|---|---|
router_status |
Get router status including WAN info |
list_connected_devices |
List all connected devices |
list_port_forwarding |
List all port forwarding rules |
add_port_forwarding |
Add a new port forwarding rule |
router_diagnostics |
Get diagnostic information |
How It Works
┌─────────────────────────────────────────────────────────────┐
│ Your Python Script │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ BE3600PlaywrightClient │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ 1. Launch headless Chromium via Playwright │ │
│ │ 2. Navigate to router web interface │ │
│ │ 3. Fill login form, click submit │ │
│ │ 4. Capture STOK from network requests │ │
│ │ 5. Store sysauth cookie │ │
│ │ 6. Use JS injection for Vue.js UI interaction │ │
│ │ 7. Parse page content for data extraction │ │
│ └─────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ TP-Link BE3600 Router │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Vue.js Web Interface │ │
│ │ - RSA/AES-GCM encrypted API │ │
│ │ - Handled natively by browser JavaScript │ │
│ └─────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
Key Insight: Instead of reverse-engineering the complex encryption, we let the browser's JavaScript handle it. Playwright automates the browser, and we extract data from the rendered DOM.
Troubleshooting
"Could not find password field"
- The router's web interface may not have loaded completely
- Increase wait times in the client
- Verify router is accessible at the specified IP
"Login failed"
- Verify your password is correct
- Ensure no other admin sessions are active
- Try accessing the router web interface manually first
Chromium crashes on Linux
Install required dependencies:
sudo apt-get install -y libnss3 libnspr4 libatk1.0-0 libatk-bridge2.0-0 \
libcups2 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 \
libxrandr2 libgbm1 libasound2
Debug with Screenshots
client = BE3600PlaywrightClient(host, password)
if client.login():
client.get_port_forwarding()
client.take_screenshot("/tmp/debug.png")
print("Screenshot saved!")
client.logout()
Project Structure
mcp-tplink-router/
├── src/
│ └── mcp_tplink_router/
│ ├── __init__.py
│ ├── be3600_playwright.py # Main Playwright-based client
│ ├── be3600_crypto.py # Direct API client (experimental)
│ ├── server.py # MCP server implementation
│ └── tplink_client.py # Generic TP-Link client
├── examples/
│ ├── list_rules.py
│ ├── add_port_forward.py
│ └── freepbx_setup.py
├── pyproject.toml
├── README.md
├── LICENSE
└── .env.example
Contributing
Contributions are welcome! Please feel free to submit issues and pull requests.
# Development setup
git clone https://github.com/consigcody94/mcp-tplink-router.git
cd mcp-tplink-router
python -m venv venv
source venv/bin/activate
pip install -e ".[dev]"
playwright install chromium
License
MIT License - see LICENSE for details.
Disclaimer
This tool is for personal use only. Use responsibly and in accordance with your router's terms of service. The authors are not responsible for any misuse or damage caused by this tool.
Acknowledgments
- Playwright for browser automation
- tplinkrouterc6u for encryption research
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。