
MCP Local WP
io.github.verygoodplugins由 GitHub 账号 verygoodplugins 发布v2.0.0更新于 Oct 27, 2026
WordPress database access via Local by Flywheel. Execute read-only MySQL queries and inspect schema.
概览
让 AI 助手以只读方式访问 Local by Flywheel 的 WordPress 数据库,查看表结构并执行 SELECT 查询。
- 可以做什么
- 执行只读 SQL(SELECT、WITH 公共表表达式、SHOW、DESCRIBE、EXPLAIN),支持绑定参数
- 查看数据库结构:分页列出表名,可按前缀过滤并附带统计信息,或查看单表的列与索引
- 查询当前连接的站点信息(名称、ID、路径、域名、socket)及其选择方式
- 列出所有 Local 站点及其运行状态
- 在显式开启后,额外提供独立的写入工具执行 INSERT/UPDATE/DELETE
- 适用场景
- 适合在 Local by Flywheel 中开发或调试 WordPress 插件与主题时使用,让助手看到真实的表结构和数据,而不是猜测字段名,例如处理 WooCommerce 或 LearnDash 的自定义表。
- 运行要求
- 需安装 Local by Flywheel 并至少有一个站点在运行,以及 Node.js 24 或更高版本(通过 npx 或源码运行)。可选环境变量用于选择站点(SITE_ID、SITE_NAME、LOCAL_SITES_JSON、LOCAL_RUN_DIR)或手动连接(MYSQL_HOST、MYSQL_SOCKET_PATH、MYSQL_DB、MYSQL_PORT、MYSQL_USER、MYSQL_PASS)。仅支持桌面客户端,使用 stdio 传输。
安装
在 SourceWeft 中
- 打开 控制台中的 MCP Local WP,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
MCP Server Local WP
🎯 What if your AI assistant could actually SEE your WordPress database?
A Model Context Protocol (MCP) server that gives AI assistants like Claude and Cursor direct, read-only access to your Local by Flywheel WordPress database. No more guessing table structures. No more writing SQL queries blind. Your AI can now understand your actual data.
Upgrading to 2.0
Version 2.0 requires Node.js 24 or newer and uses MCP SDK v2. Existing tool names and site selectors remain available. Query results are now { "rows": [...] }; schema listing returns { "tables": [...], "hasMore": false, "nextAfter": null } with bounded pages of table names. Successful tools return matching structured and JSON-text results, and failures set isError: true.
Database and Local configuration are resolved lazily, so MCP tool discovery works without a running site. Explicit MYSQL_HOST or MYSQL_SOCKET_PATH selects the manual connection. Keep stdin open until all tool responses arrive; EOF closes the session. The parent watchdog also cleans up abandoned stdio servers.
🤔 What's an MCP Server?
Think of MCP (Model Context Protocol) as a secure bridge between AI assistants and your development tools. Instead of copying and pasting database schemas or query results, MCP servers let AI assistants directly interact with your tools while you maintain complete control.
Without MCP: "Hey AI, I think there's a table called wp_something with a column that might be named user_meta... can you write a query?"
With MCP: "Hey AI, check what's in my database and write the exact query I need."
💡 The WordPress Developer's Dilemma
Picture this: You're debugging a LearnDash integration issue. Quiz results aren't syncing properly. You fire up Cursor to help diagnose the problem, but without database access, even the most advanced AI is just making educated guesses about your table structures.
The Real-World Impact
Here's an actual support ticket we were working on. The task was simple: fetch quiz activity data from LearnDash tables.
❌ Before MCP Server (AI Flying Blind):
The AI tried its best, suggesting this query:
Problem? The activity_meta column doesn't exist! LearnDash stores metadata in a completely separate table with a different structure. Without database access, the AI made reasonable but incorrect assumptions. You'd spend the next 20 minutes manually correcting table names, discovering relationships, and rewriting the query.
✅ After MCP Server (AI With X-Ray Vision):
With database access, the AI immediately saw the actual table structure and wrote:
The difference? The AI could see that metadata lives in a separate user_activity_meta table, understood the relationship through activity_id, and knew exactly which meta keys were available. First try. Zero guesswork. Problem solved.
🚀 Why This Changes Everything
When your AI assistant can read your database:
- No more schema guessing - It sees your actual tables and columns
- Accurate JOIN operations - It understands table relationships
- Real data validation - It can verify that data exists before suggesting queries
- Plugin-aware development - It adapts to any plugin's custom tables (WooCommerce, LearnDash, etc.)
- Instant debugging - "Show me all users who haven't completed quiz ID 42" becomes a 5-second task
🔧 The Local by Flywheel Challenge We Solved
When using the original mcp-server-mysql with Local by Flywheel, developers face several challenges:
- Dynamic Paths: Local by Flywheel generates unique identifiers for each site (like
lx97vbzE7) that change when sites are restarted - Socket vs Port Confusion: Local uses both Unix sockets and TCP ports, but the configuration can be tricky
- Hardcoded Configurations: Most setups require manual path updates every time Local restarts
Our Solution
This MCP server automatically detects your active Local by Flywheel MySQL instance by:
- Process Detection: Scans running processes to find active
mysqldinstances - Config Parsing: Extracts MySQL configuration from the active Local site
- Dynamic Connection: Connects using the correct socket path or port automatically
- Fallback Support: Falls back to environment variables for non-Local setups
Multi-Site Support
When you have multiple Local sites, the server uses priority-based site selection to ensure you're always connected to the right database:
Selection Priority
SITE_IDenv var - Direct site ID (highest priority)SITE_NAMEenv var - Human-readable site name lookup- Working directory detection - If your cwd is within a Local site path, that site is used
- Process detection - First running Local mysqld found
- Filesystem fallback - Most recently modified socket
Explicit Site Selection
Specify which site to connect to in your MCP config:
Or use the site ID directly:
Working Directory Detection
When using Claude Code or Cursor, the server automatically detects which site you're working in based on your current directory. If you're editing files in /Users/.../Local Sites/dev/app/public/wp-content/plugins/my-plugin/, the server connects to the "dev" site's database automatically.
Verifying Your Connection
Use the mysql_current_site tool to see which site you're connected to:
Use mysql_list_sites to see all available sites and their status.
Tools Available
mysql_query
Execute read-only SQL against your Local WordPress database.
Input fields:
sql(string): Single read-only statement (SELECT, including WITH CTEs, or SHOW/DESCRIBE/EXPLAIN)params((string | number | boolean | null)[]): Optional parameter values for?placeholders
Example Usage:
mysql_schema
Inspect database schema using INFORMATION_SCHEMA.
- No args: lists up to 100 table names, sorted by their binary name, with
hasMoreandnextAfter - Listing options:
prefix(case-sensitive literal prefix),limit(1–200),after(previous page'snextAfter), andincludeStats(defaults to false) - With
table: returns columns and indexes for that table
When hasMore is true, pass nextAfter as after to fetch the next page, keeping the same prefix. The last page has hasMore: false and nextAfter: null. Listing rows contain only table_name by default; includeStats: true adds engine, estimated row count, data bytes and index bytes. % and _ in a prefix are literal characters. Use table alone for detailed inspection; listing options cannot be combined with it. Each page reflects the current schema, so changes to tables between requests can affect the listing.
Examples:
mysql_current_site
Get information about the currently connected Local WordPress site.
Returns the site name, ID, path, domain, socket path, and how the site was selected (env var, cwd detection, or auto-detection).
mysql_list_sites
List all available Local WordPress sites and their running status.
Installation
Prerequisites
- Local by Flywheel installed and running
- An active Local site running
- Node.js 24+
Quick Setup (Recommended)
The easiest way to get started - no installation required:
Cursor IDE Configuration
Add this to your Cursor MCP configuration file (.cursor/mcp.json):
Claude Desktop Configuration
Add this to your Claude Desktop configuration file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\\Claude\\claude_desktop_config.json
Advanced Setup (Local Development)
For customization or local development:
Install from Source
Local Configuration
Custom Environment Variables
For non-Local setups or custom configurations:
Site Selection Variables
How It Works with Local by Flywheel
This MCP server was created because connecting to Local by Flywheel MySQL was "kind of difficult to get working" with existing MCP servers. Here's the story of what we solved:
The Original Problem
When we first tried to use mcp-server-mysql with Local by Flywheel, we encountered several issues:
- Dynamic Socket Paths: Local generates paths like
/Users/.../Local/run/lx97vbzE7/mysql/mysqld.sockwherelx97vbzE7changes each time you restart Local - Configuration Complexity: The original server required hardcoded paths that would break every time Local restarted
- Host/Port Confusion: Local's MySQL configuration can be tricky with both socket and TCP connections available
Our Solution Process
We solved this step by step:
1. Process-Based Detection
Instead of guessing paths, we scan for the actual running MySQL process:
This finds the active MySQL instance and extracts its configuration file path.
2. Dynamic Path Resolution
3. Automatic Configuration
The server automatically configures itself with:
- Correct socket path for the active Local site
- Proper database name (
local) - Default credentials (
root/root) - Fallback to environment variables if needed
Why This Approach Works
✅ Restart Resilient: Works every time you restart Local by Flywheel
✅ Site Switching: Automatically adapts if you switch between Local sites
✅ Zero Maintenance: No need to manually update paths ever again
✅ Error Handling: Provides clear error messages if MySQL isn't running
Local Directory Structure We Handle
The server intelligently finds the active site and connects to the right MySQL instance.
Usage Examples
Once connected, you can use the mysql_query tool to execute a permitted read-only SQL query against your Local WordPress database:
Getting Recent Posts
Exploring Database Structure
WordPress-Specific Queries
Development Setup
Running from Source
-
Start a Local site: Make sure you have an active Local by Flywheel site running
-
Clone and build:
-
Test the connection:
Development Mode
This runs the server with TypeScript watching for changes.
Linting & Formatting
- Lint:
npm run lint - Fix lint:
npm run lint:fix - Format:
npm run format - Check formatting:
npm run format:check
Standards are unified across MCP servers via ESLint + Prettier.
Troubleshooting
Common Issues
-
"No active MySQL process found"
- Ensure Local by Flywheel is running
- Make sure at least one site is started in Local
- Check that the site's database is running
-
"MySQL socket not found"
- Verify the Local site is fully started
- Try stopping and restarting the site in Local
- Check Local's logs for MySQL startup issues
-
Connection refused
- Ensure the Local site's MySQL service is running
- Check if another process is using the MySQL port
- Try restarting Local by Flywheel
-
Permission denied
- Make sure the MySQL socket file has correct permissions
- Check if your user has access to Local's directories
Manual Configuration
If auto-detection fails, you can manually configure the connection:
Debugging
Enable debug logging by setting DEBUG:
Security
mysql_query accepts one SELECT/SHOW/DESCRIBE/DESC/EXPLAIN statement, including SELECT queries beginning with WITH or WITH RECURSIVE. CTE query bodies and the final query expression must resolve to SELECT, including nested WITH … SELECT and parenthesized queries; WITH … UPDATE/DELETE is rejected. MariaDB’s CYCLE … RESTRICT clause is supported for cycle detection. A tokenizer checks real SQL tokens using the connection's SQL mode. Executable MySQL/MariaDB comments, optimizer hints, file output, SELECT INTO, locking reads, advisory-lock functions, and EXPLAIN ANALYZE are rejected throughout the statement, including CTE bodies. Ordinary comments and semicolons in quoted values are supported.
Every read runs in a database-enforced read-only transaction on a dedicated connection. Setup failures stop execution; failed cleanup discards the connection. MYSQL_ALLOW_WRITES=true exposes mysql_write on a separate connection; it never disables protection for mysql_query. Write statements permit INSERT/UPDATE/DELETE. UPDATE/DELETE require column comparisons to bound parameters in WHERE, optionally grouped with AND/OR; IN, BETWEEN and LIKE also support bound values. Bare placeholder and literal-only predicates are rejected. Schema operations and write subqueries remain blocked.
For extra protection, configure a dedicated account with SELECT grants on the chosen database and no FILE or EXECUTE privileges. MYSQL_USER and MYSQL_PASS apply to auto-detected Local sites as well as manual connections. The server does not create users or change grants. Read-only transactions are not a sandbox for temporary tables or arbitrary native extensions; use least-privilege credentials for untrusted databases.
This server supports local development, with Unix sockets when available and TCP for explicit connections. Report vulnerabilities privately through GitHub Security Advisories or [email protected].
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Development Guidelines
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature-name - Make your changes and add tests
- Ensure TypeScript compiles:
npm run build - Submit a pull request
License
GPL-3.0-or-later - see the LICENSE file for details. As a WordPress-focused tool, we embrace the copyleft philosophy to ensure this remains free and open for the community.
Support
- GitHub Issues: Report bugs or request features
- Documentation: This README and inline code documentation
- Community: Join the Model Context Protocol community discussions
Related Projects
- mcp-server-mysql - The original MySQL MCP server that inspired this WordPress-specific version
- Local by Flywheel - The local WordPress development environment this server is designed for
- Model Context Protocol - The protocol specification
Built with 🧡 by Jack Arturo at Very Good Plugins · Made with love for the open-source community
来源:README.md,提交 5e6a1fb
工具
0版本历史
2- v2.0.0最新Oct 12, 2026
- v1.1.0Sep 16, 2026
评分
已满足适用检查项的 40%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分
请在仓库或注册中心条目中声明许可证。