wp-devdocs-mcp 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Marcel Schmitz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,407 @@
1
+ # wp-devdocs-mcp
2
+
3
+ <p align="center">
4
+ <img src="assets/banner.jpg" alt="Before: AI guessing hook names. After: Verified database, no more hallucinations." width="600">
5
+ </p>
6
+
7
+ **Give your AI coding assistant a verified WordPress hook database instead of letting it guess.**
8
+
9
+ wp-devdocs-mcp is a local [MCP server](https://modelcontextprotocol.io/) that indexes every action, filter, block registration, and JS API call from WordPress, WooCommerce, Gutenberg, or any plugin you work with. It gives AI tools like Claude Code a verified database to search and validate against instead of relying on training data.
10
+
11
+ Works with Claude Code, Cursor, Windsurf, and any MCP-compatible client.
12
+
13
+ ## Why This Exists
14
+
15
+ AI coding assistants are changing how we build WordPress plugins. Tools like Claude Code, Cursor, and Windsurf can scaffold entire plugins in minutes — but they all share the same blind spot: **hook names come from training data, not from the actual source code**.
16
+
17
+ Most of the time this works fine. Models like Claude Sonnet nail common hooks almost every time. But "most of the time" isn't good enough when you're shipping production code, and not every model is Claude Sonnet. Across the landscape of LLMs doing code generation today:
18
+
19
+ - **Some models invent hooks that don't exist** — `woocommerce_email_after_order_details` sounds right but isn't real
20
+ - **Some use deprecated namespaces** — `wp.editor.InspectorControls` instead of `wp.blockEditor.InspectorControls`
21
+ - **Most miss newer hooks** — suggesting `pre_get_posts` for WooCommerce order queries when HPOS uses `woocommerce_order_list_table_prepare_items_query_args`
22
+ - **Parameters get mixed up** — wrong argument count or order in callback signatures
23
+ - **No model knows your custom plugins** — private or proprietary hooks are invisible to every model's training data
24
+
25
+ The core issue is simple: we can't rely 100% on any model to produce correct WordPress hook names from memory alone. Even the best models benefit from verification, and the rest genuinely need it. You only find out about hallucinated hooks when the code doesn't work — and in an agentic workflow where the AI writes, tests, and iterates autonomously, one bad hook name can send it down a rabbit hole of debugging something that was never going to work.
26
+
27
+ ## The Solution
28
+
29
+ **Feed the LLM real data.** Instead of hoping the model remembers the right hook name, give it a verified database to query.
30
+
31
+ wp-devdocs-mcp parses the actual source code of any WordPress plugin and builds a searchable index of every hook with its exact name, type, parameters, file location, and surrounding code context. Your AI assistant queries this index before writing code — so every hook name in the generated code is verified against the real source.
32
+
33
+ This fits naturally into agentic coding workflows. When Claude Code (or any MCP-compatible assistant) needs to use a WordPress hook, it:
34
+
35
+ 1. **Searches** the indexed database for relevant hooks
36
+ 2. **Validates** the exact hook name exists before writing it into code
37
+ 3. **Reads the context** — parameters, docblock, surrounding code — to use it correctly
38
+
39
+ No hallucination. No guessing. No debugging phantom hooks.
40
+
41
+ **What gets indexed:**
42
+
43
+ | Type | Examples |
44
+ |------|---------|
45
+ | PHP actions | `do_action()`, `do_action_ref_array()` |
46
+ | PHP filters | `apply_filters()`, `apply_filters_ref_array()` |
47
+ | JS hooks | `addAction()`, `addFilter()`, `applyFilters()`, `doAction()` |
48
+ | Block registrations | `registerBlockType()`, `registerBlockVariation()` |
49
+ | JS API usages | `wp.blocks.*`, `wp.blockEditor.*`, `wp.data.*`, etc. |
50
+ | Markdown documentation | Handbooks parsed into searchable pages *(since v1.1.0)* |
51
+
52
+ **What the AI gets for each hook:**
53
+
54
+ - Exact name (with dynamic name detection for hooks like `woocommerce_thankyou_{$payment_method}`)
55
+ - Type (action / filter / js_action / js_filter)
56
+ - Parameters and count
57
+ - File path and line number
58
+ - Enclosing function and class
59
+ - Docblock
60
+ - Code window (8 lines before, 4 after)
61
+ - Source plugin name
62
+
63
+ ## Quick Start
64
+
65
+ ```bash
66
+ # Clone and install
67
+ git clone https://github.com/pluginslab/wp-devdocs-mcp.git
68
+ cd wp-devdocs-mcp
69
+ npm install
70
+
71
+ # Add all preset sources at once (since v1.1.0)
72
+ npx wp-hooks quick-add-all
73
+
74
+ # Or add individual presets (since v1.1.0)
75
+ npx wp-hooks quick-add wp-core
76
+ npx wp-hooks quick-add woocommerce
77
+ npx wp-hooks quick-add gutenberg-source
78
+ npx wp-hooks quick-add plugin-handbook
79
+ ```
80
+
81
+ Or add sources manually (works in all versions):
82
+
83
+ ```bash
84
+ # WooCommerce (uses trunk branch)
85
+ npx wp-hooks source:add \
86
+ --name woocommerce \
87
+ --type github-public \
88
+ --repo https://github.com/woocommerce/woocommerce \
89
+ --subfolder plugins/woocommerce \
90
+ --branch trunk
91
+ ```
92
+
93
+ That's it. 3,500+ hooks indexed in under a minute.
94
+
95
+ ### Connect to Your AI Assistant
96
+
97
+ Add the MCP server to your configuration. Create or edit `.mcp.json` in your project root (or `~/.claude/.mcp.json` globally):
98
+
99
+ ```json
100
+ {
101
+ "mcpServers": {
102
+ "wp-devdocs": {
103
+ "command": "npx",
104
+ "args": ["--prefix", "/absolute/path/to/wp-devdocs-mcp", "wp-devdocs-mcp"]
105
+ }
106
+ }
107
+ }
108
+ ```
109
+
110
+ Now when you ask Claude Code to write WordPress plugin code, it will automatically search and validate hook names against your indexed sources before generating code.
111
+
112
+ The server auto-updates stale sources (>24h) in the background on each start. Disable with `WP_MCP_AUTO_UPDATE=false`. *(since v1.1.0)*
113
+
114
+ ## Available Presets *(since v1.1.0)*
115
+
116
+ Pre-configured sources you can add with a single command:
117
+
118
+ | Preset | What It Indexes |
119
+ |--------|----------------|
120
+ | `wp-core` | WordPress core hooks (wordpress-develop, trunk) |
121
+ | `gutenberg-source` | Gutenberg plugin source code |
122
+ | `gutenberg-docs` | Gutenberg/block editor documentation |
123
+ | `woocommerce` | WooCommerce plugin hooks (plugins/woocommerce) |
124
+ | `plugin-handbook` | Plugin developer handbook |
125
+ | `rest-api-handbook` | REST API documentation |
126
+ | `wp-cli-handbook` | WP-CLI reference |
127
+ | `admin-handbook` | Advanced administration handbook |
128
+
129
+ ## Indexing Sources
130
+
131
+ ### WordPress Core
132
+
133
+ ```bash
134
+ npx wp-hooks source:add \
135
+ --name wordpress \
136
+ --type github-public \
137
+ --repo https://github.com/WordPress/wordpress-develop \
138
+ --branch trunk
139
+ ```
140
+
141
+ Expected output:
142
+
143
+ ```
144
+ Source "wordpress" added successfully.
145
+
146
+ Indexing "wordpress"...
147
+ Fetching source: wordpress (github-public)...
148
+ Indexing source: wordpress from ~/.wp-devdocs-mcp/cache/WordPress--wordpress-develop
149
+ Found 2025 files to check in wordpress
150
+
151
+ Indexing complete:
152
+ Files processed: 2025
153
+ Files skipped: 0
154
+ Hooks inserted: 3459
155
+ Hooks updated: 0
156
+ Hooks unchanged: 0
157
+ Blocks indexed: 0
158
+ APIs indexed: 140
159
+ ```
160
+
161
+ ### Gutenberg
162
+
163
+ ```bash
164
+ npx wp-hooks source:add \
165
+ --name gutenberg \
166
+ --type github-public \
167
+ --repo https://github.com/WordPress/gutenberg \
168
+ --branch trunk
169
+ ```
170
+
171
+ ### WooCommerce
172
+
173
+ ```bash
174
+ npx wp-hooks source:add \
175
+ --name woocommerce \
176
+ --type github-public \
177
+ --repo https://github.com/woocommerce/woocommerce \
178
+ --subfolder plugins/woocommerce \
179
+ --branch trunk
180
+ ```
181
+
182
+ ### Any Public Plugin
183
+
184
+ ```bash
185
+ # Example: Advanced Custom Fields
186
+ npx wp-hooks source:add \
187
+ --name acf \
188
+ --type github-public \
189
+ --repo https://github.com/AdvancedCustomFields/acf
190
+
191
+ # Example: WPGraphQL
192
+ npx wp-hooks source:add \
193
+ --name wpgraphql \
194
+ --type github-public \
195
+ --repo https://github.com/wp-graphql/wp-graphql
196
+ ```
197
+
198
+ ### Your Private Plugins
199
+
200
+ For private GitHub repos, store your token in an environment variable (never in the config):
201
+
202
+ ```bash
203
+ export GITHUB_TOKEN=ghp_xxxxxxxxxxxx
204
+
205
+ npx wp-hooks source:add \
206
+ --name my-private-plugin \
207
+ --type github-private \
208
+ --repo https://github.com/yourorg/your-plugin \
209
+ --token-env GITHUB_TOKEN
210
+ ```
211
+
212
+ ### Local Plugin Development
213
+
214
+ Point directly at a folder on your machine — great for plugins you're actively developing:
215
+
216
+ ```bash
217
+ npx wp-hooks source:add \
218
+ --name my-local-plugin \
219
+ --type local-folder \
220
+ --path /path/to/wp-content/plugins/my-plugin
221
+ ```
222
+
223
+ ### Documentation Sources *(since v1.1.0)*
224
+
225
+ Index markdown handbooks and documentation alongside source code:
226
+
227
+ ```bash
228
+ npx wp-hooks source:add \
229
+ --name my-docs \
230
+ --type github-public \
231
+ --repo https://github.com/org/docs-repo \
232
+ --content-type docs
233
+ ```
234
+
235
+ ### Source Options
236
+
237
+ | Option | Description |
238
+ |--------|-------------|
239
+ | `--name` | Unique name for this source (required) |
240
+ | `--type` | `github-public`, `github-private`, or `local-folder` (required) |
241
+ | `--repo` | GitHub repository URL |
242
+ | `--subfolder` | Only index a subfolder within the repo |
243
+ | `--branch` | Git branch (default: `main` — use `trunk` for WordPress/WooCommerce repos) |
244
+ | `--token-env` | Environment variable name holding a GitHub token (private repos) |
245
+ | `--path` | Local folder path |
246
+ | `--content-type` | `source` (default) or `docs` *(since v1.1.0)* |
247
+ | `--no-index` | Register the source without indexing it yet |
248
+
249
+ ## What Gets Indexed
250
+
251
+ **Source code** (`--content-type source`, default):
252
+ - PHP hooks: `do_action()`, `apply_filters()`, `*_ref_array()` variants
253
+ - JS hooks: `addAction()`, `addFilter()`, `applyFilters()`, `doAction()`
254
+ - Block registrations: `registerBlockType()`, `registerBlockVariation()`
255
+ - JS API usages: `wp.blocks.*`, `wp.blockEditor.*`, `wp.data.*`, etc.
256
+
257
+ **Documentation** (`--content-type docs`) *(since v1.1.0)*:
258
+ - Markdown handbooks parsed into searchable pages with metadata, code examples, and categorization
259
+ - Specialized parsers for block editor docs, plugin handbook, REST API reference, WP-CLI handbook, and admin handbook
260
+
261
+ Each hook record includes: exact name, type, parameters, file path, line number, enclosing function/class, docblock, surrounding code context, and dynamic name detection.
262
+
263
+ ## MCP Tools
264
+
265
+ Seven tools are exposed to your AI assistant (four original + three added in v1.1.0):
266
+
267
+ ### `search_hooks`
268
+
269
+ Full-text search with BM25 ranking across all indexed hooks. Supports filters for type, source, dynamic hooks, and removed hooks.
270
+
271
+ ### `validate_hook`
272
+
273
+ Exact-match check — returns `VALID` with file locations, `NOT_FOUND` with similar suggestions, or `REMOVED` for deprecated hooks. This is how the AI confirms a hook name before using it in code.
274
+
275
+ ### `get_hook_context`
276
+
277
+ Returns the full code window around a hook: the line itself, 8 lines before, 4 lines after, the docblock, enclosing function, and class. Gives the AI enough context to use the hook correctly.
278
+
279
+ ### `search_block_apis`
280
+
281
+ Searches block registrations (`registerBlockType`, etc.) and JavaScript API usages (`wp.blockEditor.*`, `wp.data.*`, etc.). Only matches on structured fields (block name, API call, namespace) — not surrounding code — to prevent false positives.
282
+
283
+ ### `search_docs` *(since v1.1.0)*
284
+
285
+ Full-text search across indexed WordPress documentation. Supports filters for document type (guide, tutorial, reference, API, howto, FAQ), category, and source.
286
+
287
+ ### `get_doc` *(since v1.1.0)*
288
+
289
+ Retrieve the full content of a specific documentation page by its ID. Returns the page title, content, metadata, code examples, and related links.
290
+
291
+ ### `list_docs` *(since v1.1.0)*
292
+
293
+ Browse available documentation with optional filters for type, category, and source. Useful for discovering what documentation is indexed.
294
+
295
+ ## CLI Reference
296
+
297
+ ```
298
+ Source management:
299
+ wp-hooks source:add Add a source and index it
300
+ wp-hooks source:list List all sources with indexed status
301
+ wp-hooks source:remove Remove a source and all its data
302
+
303
+ Presets (since v1.1.0):
304
+ wp-hooks quick-add <name> Add a preset source
305
+ wp-hooks quick-add-all Add all preset sources
306
+
307
+ Indexing:
308
+ wp-hooks index Re-index all sources (or --source <name>, --force)
309
+ wp-hooks update Fetch and re-index stale sources (--source, --force) (since v1.1.0)
310
+
311
+ Search:
312
+ wp-hooks search <query> Search hooks (--type, --source, --include-removed)
313
+ wp-hooks search-blocks <q> Search block registrations and JS APIs
314
+ wp-hooks search-docs <q> Search documentation (--type, --category, --source) (since v1.1.0)
315
+ wp-hooks validate <name> Check if a hook name exists (exit code 0/1)
316
+
317
+ Maintenance:
318
+ wp-hooks stats Hook/block/API/doc counts per source
319
+ wp-hooks rebuild-index Rebuild FTS indexes if out of sync
320
+ ```
321
+
322
+ ### CLI Examples
323
+
324
+ ```bash
325
+ # Search for checkout-related hooks
326
+ npx wp-hooks search "woocommerce_checkout"
327
+
328
+ # Search only filters
329
+ npx wp-hooks search "woocommerce_product" --type filter
330
+
331
+ # Validate a specific hook name
332
+ npx wp-hooks validate "woocommerce_before_order_itemmeta"
333
+
334
+ # Search for Gutenberg block APIs
335
+ npx wp-hooks search-blocks "InspectorControls"
336
+
337
+ # Search documentation (since v1.1.0)
338
+ npx wp-hooks search-docs "custom post type"
339
+
340
+ # Add all presets at once (since v1.1.0)
341
+ npx wp-hooks quick-add-all
342
+
343
+ # Re-index a specific source after updates
344
+ npx wp-hooks index --source woocommerce
345
+
346
+ # Update stale sources (since v1.1.0)
347
+ npx wp-hooks update
348
+
349
+ # Force full re-index (ignore file modification cache)
350
+ npx wp-hooks index --force
351
+
352
+ # See what you have indexed
353
+ npx wp-hooks stats
354
+ ```
355
+
356
+ ## How It Works
357
+
358
+ 1. **Sources** are registered via the CLI — each points to a GitHub repo or local folder
359
+ 2. **Indexing** clones/pulls the repo, scans PHP and JS/TS files, and extracts hooks using regex-based parsers
360
+ 3. **Documentation indexing** *(since v1.1.0)* parses markdown handbooks using specialized parsers that extract metadata, code examples, and categorization
361
+ 4. **Storage** uses SQLite with FTS5 full-text search and WAL mode for fast concurrent reads
362
+ 5. **Incremental updates** skip files that haven't changed (mtime + content hash)
363
+ 6. **Soft-delete tracking** marks hooks that were previously indexed but no longer found as `removed`
364
+ 7. **Auto-update** *(since v1.1.0)* refreshes stale sources (>24h) in the background on server start
365
+ 8. **The MCP server** exposes the database as tools over stdio — your AI assistant queries it in real-time
366
+
367
+ ### Data Storage
368
+
369
+ All data lives in `~/.wp-devdocs-mcp/`:
370
+
371
+ ```
372
+ ~/.wp-devdocs-mcp/
373
+ hooks.db # SQLite database (FTS5, WAL mode)
374
+ cache/ # Cloned repositories
375
+ ```
376
+
377
+ ## Version History
378
+
379
+ ### v1.1.0
380
+
381
+ - **Documentation indexing** — 7 specialized parsers for WordPress handbooks (block editor, plugin, REST API, WP-CLI, admin, general)
382
+ - **3 new MCP tools** — `search_docs`, `get_doc`, `list_docs` for querying indexed documentation
383
+ - **Preset system** — 8 pre-configured sources with `quick-add` and `quick-add-all` CLI commands
384
+ - **Auto-update** — background refresh of stale sources (>24h) on each server start (opt-out: `WP_MCP_AUTO_UPDATE=false`)
385
+ - **`update` CLI command** — manual fetch and re-index of stale sources
386
+ - **`search-docs` CLI command** — search documentation from the terminal
387
+ - **`--content-type` option** — distinguish between source code and documentation sources
388
+ - **Enhanced `source:list`** — shows content type and last-indexed time
389
+
390
+ ### v1.0.1
391
+
392
+ - Bug fixes (transaction-wrapped deletions, prepared statement cache, cross-platform paths)
393
+ - JSDoc annotations, ESLint 9 integration
394
+
395
+ ### v1.0.0
396
+
397
+ - Initial release — PHP/JS hook extraction, block registration tracking, SQLite FTS5 search, incremental indexing, 4 MCP tools (`search_hooks`, `validate_hook`, `get_hook_context`, `search_block_apis`)
398
+
399
+ ## Requirements
400
+
401
+ - Node.js 20+
402
+ - Git
403
+ - ~500MB disk space per large plugin source (WooCommerce, Gutenberg)
404
+
405
+ ## License
406
+
407
+ MIT