MCP Local WP
数据与存储by verygoodplugins
通过 Local by Flywheel 访问 WordPress 数据库,可执行只读 MySQL 查询并检查 schema。
什么是 MCP Local WP?
通过 Local by Flywheel 访问 WordPress 数据库,可执行只读 MySQL 查询并检查 schema。
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.
🤔 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:
$quiz_activities = $wpdb->get_results(
$wpdb->prepare(
'SELECT post_id, activity_meta FROM ' . esc_sql( LDLMS_DB::get_table_name( 'user_activity' ) ) . '
WHERE user_id=%d AND activity_type=%s AND activity_status=1 AND activity_completed IS NOT NULL',
$user_id,
'quiz'
),
ARRAY_A
);
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:
$quiz_activities = $wpdb->get_results(
$wpdb->prepare(
'SELECT ua.post_id, ua.activity_id, uam.activity_meta_key, uam.activity_meta_value
FROM ' . esc_sql( LDLMS_DB::get_table_name( 'user_activity' ) ) . ' ua
LEFT JOIN ' . esc_sql( LDLMS_DB::get_table_name( 'user_activity_meta' ) ) . ' uam
ON ua.activity_id = uam.activity_id
WHERE ua.user_id=%d AND ua.activity_type=%s AND ua.activity_completed IS NOT NULL
AND uam.activity_meta_key IN (%s, %s, %s)',
$user_id,
'quiz',
'percentage',
'points',
'total_points'
),
ARRAY_A
);
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:
{
"mcpServers": {
"wordpress-dev": {
"command": "npx",
"args": ["-y", "@verygoodplugins/mcp-local-wp@latest"],
"env": {
"SITE_NAME": "dev"
}
}
}
}
Or use the site ID directly:
{
"env": {
"SITE_ID": "lx97vbzE7"
}
}
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:
{
"siteName": "dev",
"siteId": "lx97vbzE7",
"sitePath": "/Users/.../Local Sites/dev",
"domain": "dev.local",
"selectionMethod": "cwd_detection"
}
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/SHOW/DESCRIBE/EXPLAIN)params(string[]): Optional parameter values for?placeholders
Example Usage:
-- With parameters
SELECT * FROM wp_posts WHERE post_status = ? ORDER BY post_date DESC LIMIT ?;
-- params: ["publish", "5"]
-- Direct queries
SELECT option_name, option_value FROM wp_options WHERE option_name LIKE '%theme%';
SHOW TABLES;
DESCRIBE wp_users;
mysql_schema
Inspect database schema using INFORMATION_SCHEMA.
- No args: lists tables with basic stats
- With
table: returns columns and indexes for that table
Examples:
// List all tables
{
"tool": "mysql_schema",
"args": {}
}
// Inspect a specific table
{
"tool": "mysql_schema",
"args": { "table": "wp_posts" }
}
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).
{
"tool": "mysql_current_site",
"args": {}
}
// Returns:
// {
// "siteName": "dev",
// "siteId": "lx97vbzE7",
// "sitePath": "/Users/.../Local Sites/dev",
// "domain": "dev.local",
// "selectionMethod": "cwd_detection",
// "socketPath": "/Users/.../Local/run/lx97vbzE7/mysql/mysqld.sock"
// }
mysql_list_sites
List all available Local WordPress sites and their running status.
{
"tool": "mysql_list_sites",
"args": {}
}
// Returns:
// {
// "sites": [
// { "id": "lx97vbzE7", "name": "dev", "domain": "dev.local", "running": true },
// { "id": "WP7lolWDi", "name": "staging", "domain": "staging.local", "running": false }
// ],
// "currentSiteId": "lx97vbzE7"
// }
Installation
Prerequisites
- Local by Flywheel installed and running
- An active Local site running
- Node.js 18+ (for local development only)
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):
{
"mcpServers": {
"mcp-local-wp": {
"command": "npx",
"args": [
"-y",
"@verygoodplugins/mcp-local-wp@latest"
]
}
}
}
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
{
"mcpServers": {
"mcp-local-wp": {
"command": "npx",
"args": [
"-y",
"@verygoodplugins/mcp-local-wp@latest"
]
}
}
}
Advanced Setup (Local Development)
For customization or local development:
Install from Source
git clone https://github.com/verygoodplugins/mcp-local-wp.git
cd mcp-local-wp
npm install
npm run build
Local Configuration
{
"mcpServers": {
"mcp-local-wp": {
"command": "node",
"args": [
"/full/path/to/mcp-local-wp/dist/index.js"
]
}
}
}
Custom Environment Variables
For non-Local setups or custom configurations:
{
"mcpServers": {
"mcp-local-wp": {
"command": "npx",
"args": [
"-y",
"@verygoodplugins/mcp-local-wp@latest"
],
"env": {
"MYSQL_DB": "local",
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "root",
"MYSQL_PASS": "root"
}
}
}
}
Site Selection Variables
| Variable | Description | Example |
|---|---|---|
SITE_ID | Explicit site ID (highest priority) | lx97vbzE7 |
SITE_NAME | Site name for lookup | dev |
LOCAL_SITES_JSON | Override path to Local's sites.json | /custom/path/sites.json |
LOCAL_RUN_DIR | Override Local's run directory | /custom/run/path |
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:
ps aux | grep mysqld | grep -v grep
This finds the active MySQL instance and extracts its configuration file path.
2. Dynamic Path Resolution
// From the process args: --defaults-file=/Users/.../Local/run/lx97vbzE7/conf/mysql/my.cnf
// We extract the site directory and build the socket path
const configPath = extractFromProcess();
const siteDir = path.dirname(path.dirname(path.dirname(configPath)));
const socketPath = path.join(siteDir, 'mysql/mysqld.sock');
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
~/Library/Application Support/Local/run/
├── lx97vbzE7/ # Dynamic site ID (changes on restart)
│ ├── conf/mysql/my.cnf # We read this for port info
│ └── mysql/mysqld.sock # We connect via this socket
└── WP7lolWDi/ # Another site (if multiple running)
├── conf/mysql/my.cnf
└── mysql/mysqld.sock
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 any SQL query against your Local WordPress database:
Getting Recent Posts
SELECT ID, post_title, post_date, post_status
FROM wp_posts
WHERE post_type = 'post' AND post_status = 'publish'
ORDER BY post_date DESC
LIMIT 5;
Exploring Database Structure
-- See all tables
SHOW TABLES;
-- Examine a table structure
DESCRIBE wp_posts;
-- Get table info
SHOW TABLE STATUS LIKE 'wp_%';
WordPress-Specific Queries
-- Get site options
SELECT option_name, option_value
FROM wp_options
WHERE option_name IN ('blogname', 'blogdescription', 'admin_email');
-- Find active plugins
SELECT option_value
FROM wp_options
WHERE option_name = 'active_plugins';
-- Get user information
SELECT user_login, user_email, display_name
FROM wp_users
LIMIT 10;
-- Post meta data
SELECT p.post_title, pm.meta_key, pm.meta_value
FROM wp_posts p
JOIN wp_postmeta pm ON p.ID = pm.post_id
WHERE p.post_type = 'post' AND pm.meta_key = '_edit_last';
Development Setup
Running from Source
-
Start a Local site: Make sure you have an active Local by Flywheel site running
-
Clone and build:
bashgit clone https://github.com/verygoodplugins/mcp-local-wp.git cd mcp-local-wp npm install npm run build -
Test the connection:
bashnode dist/index.js
Development Mode
npm run dev
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:
export MYSQL_SOCKET_PATH="/path/to/your/local/site/mysql/mysqld.sock"
export MYSQL_DB="local"
export MYSQL_USER="root"
export MYSQL_PASS="root"
Debugging
Enable debug logging by setting DEBUG:
DEBUG=mcp-local-wp mcp-local-wp
Security
- Read-only operations: Only SELECT/SHOW/DESCRIBE/EXPLAIN are allowed
- Single statement: Multiple statements in one call are blocked
- Local development: Designed for local environments (Local by Flywheel)
- No external connections: Prioritizes Unix socket connections when available
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
常见问题
MCP Local WP 是什么?
通过 Local by Flywheel 访问 WordPress 数据库,可执行只读 MySQL 查询并检查 schema。
相关 Skills
资深架构师
by alirezarezvani
适合系统设计评审、ADR记录和扩展性规划,分析依赖与耦合,权衡单体或微服务、数据库与技术栈选型,并输出Mermaid、PlantUML、ASCII架构图。
✎ 搞系统设计、技术选型和扩展规划时,用它能更快理清架构决策与依赖关系,还能直接产出 Mermaid/PlantUML 图,方案讨论效率很高。
技术栈评估
by alirezarezvani
对比框架、数据库和云服务,结合 5 年 TCO、安全风险、生态活力与迁移复杂度做量化评估,适合技术选型、栈升级和替换路线决策。
✎ 帮你系统比较技术栈优劣,不只看功能,还把TCO、安全性和生态健康度一起量化,选型和迁移决策更稳。
资深数据科学家
by alirezarezvani
覆盖实验设计、特征工程、预测建模、因果推断与模型评估,适合用 Python/R/SQL 做 A/B 测试、时序分析和生产级 ML 落地,支撑数据驱动决策。
✎ 从 A/B 测试、因果分析到预测建模一条龙搞定,既有硬核统计方法也懂业务沟通,特别适合把数据结论真正落地。
相关 MCP Server
PostgreSQL 数据库
编辑精选by Anthropic
PostgreSQL 是让 Claude 直接查询和管理你的数据库的 MCP 服务器。
✎ 这个服务器解决了开发者需要手动编写 SQL 查询的痛点,特别适合数据分析师或后端开发者快速探索数据库结构。不过,由于是参考实现,生产环境使用前务必评估安全风险,别指望它能处理复杂事务。
SQLite 数据库
编辑精选by Anthropic
SQLite 是让 AI 直接查询本地数据库进行数据分析的 MCP 服务器。
✎ 这个服务器解决了 AI 无法直接访问 SQLite 数据库的问题,适合需要快速分析本地数据集的开发者。不过,作为参考实现,它可能缺乏生产级的安全特性,建议在受控环境中使用。
Firecrawl 智能爬虫
编辑精选by Firecrawl
Firecrawl 是让 AI 直接抓取网页并提取结构化数据的 MCP 服务器。
✎ 它解决了手动写爬虫的麻烦,让 Claude 能直接访问动态网页内容。最适合需要实时数据的研究者或开发者,比如监控竞品价格或抓取新闻。但要注意,它依赖第三方 API,可能涉及隐私和成本问题。