localwp-mcp 0.1.2 → 0.1.4
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 +15 -15
- package/README.md +254 -221
- package/dist/config.d.ts +1 -0
- package/dist/config.js +2 -0
- package/dist/config.js.map +1 -1
- package/dist/local-graphql.d.ts +8 -0
- package/dist/local-graphql.js +78 -0
- package/dist/local-graphql.js.map +1 -0
- package/dist/local-sites.js +17 -11
- package/dist/local-sites.js.map +1 -1
- package/dist/platform-paths.d.ts +1 -0
- package/dist/platform-paths.js +8 -0
- package/dist/platform-paths.js.map +1 -1
- package/dist/site-files.d.ts +196 -0
- package/dist/site-files.js +417 -0
- package/dist/site-files.js.map +1 -0
- package/dist/site-lifecycle.d.ts +33 -0
- package/dist/site-lifecycle.js +66 -0
- package/dist/site-lifecycle.js.map +1 -0
- package/dist/tool-schemas.d.ts +1 -0
- package/dist/tool-schemas.js +4 -0
- package/dist/tool-schemas.js.map +1 -1
- package/dist/tools/delete-site-file.d.ts +2 -0
- package/dist/tools/delete-site-file.js +29 -0
- package/dist/tools/delete-site-file.js.map +1 -0
- package/dist/tools/index.js +16 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/list-site-files.d.ts +2 -0
- package/dist/tools/list-site-files.js +46 -0
- package/dist/tools/list-site-files.js.map +1 -0
- package/dist/tools/read-site-file.d.ts +2 -0
- package/dist/tools/read-site-file.js +30 -0
- package/dist/tools/read-site-file.js.map +1 -0
- package/dist/tools/restart-local-site.d.ts +2 -0
- package/dist/tools/restart-local-site.js +19 -0
- package/dist/tools/restart-local-site.js.map +1 -0
- package/dist/tools/search-site-files.d.ts +2 -0
- package/dist/tools/search-site-files.js +57 -0
- package/dist/tools/search-site-files.js.map +1 -0
- package/dist/tools/start-local-site.d.ts +2 -0
- package/dist/tools/start-local-site.js +19 -0
- package/dist/tools/start-local-site.js.map +1 -0
- package/dist/tools/stop-local-site.d.ts +2 -0
- package/dist/tools/stop-local-site.js +19 -0
- package/dist/tools/stop-local-site.js.map +1 -0
- package/dist/tools/write-site-file.d.ts +2 -0
- package/dist/tools/write-site-file.js +30 -0
- package/dist/tools/write-site-file.js.map +1 -0
- package/dist/types.d.ts +11 -0
- package/dist/wp-cli.js +20 -0
- package/dist/wp-cli.js.map +1 -1
- package/package.json +61 -61
package/LICENSE
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
ISC License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026
|
|
4
|
-
|
|
5
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
-
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
-
copyright notice and this permission notice appear in all copies.
|
|
8
|
-
|
|
9
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,221 +1,254 @@
|
|
|
1
|
-
# localwp-mcp
|
|
2
|
-
|
|
3
|
-
`localwp-mcp` gives AI agents direct access to LocalWP sites through MCP.
|
|
4
|
-
|
|
5
|
-
It automatically finds your Local sites, uses the correct Local PHP and MySQL runtimes for each one, and lets an agent work with WordPress through WP-CLI, MySQL, logs, diagnostics, backups, and restore flows.
|
|
6
|
-
|
|
7
|
-
## What You Can Do
|
|
8
|
-
|
|
9
|
-
- inspect Local sites and their runtime details
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
-
|
|
68
|
-
|
|
69
|
-
- `
|
|
70
|
-
Best
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
- `
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
- which Local
|
|
95
|
-
- whether
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
- `
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
-
|
|
116
|
-
-
|
|
117
|
-
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
- `
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
- `
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
-
|
|
143
|
-
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
- `
|
|
152
|
-
|
|
153
|
-
- `
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
- `
|
|
161
|
-
- `
|
|
162
|
-
- `
|
|
163
|
-
- `restore_backup`
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
- `
|
|
168
|
-
- `
|
|
169
|
-
|
|
170
|
-
- `
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
-
|
|
182
|
-
-
|
|
183
|
-
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
- `
|
|
192
|
-
- `
|
|
193
|
-
- `
|
|
194
|
-
- `
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
1
|
+
# localwp-mcp
|
|
2
|
+
|
|
3
|
+
`localwp-mcp` gives AI agents direct access to LocalWP sites through MCP.
|
|
4
|
+
|
|
5
|
+
It automatically finds your Local sites, uses the correct Local PHP and MySQL runtimes for each one, and lets an agent work with WordPress through WP-CLI, MySQL, logs, diagnostics, backups, and restore flows.
|
|
6
|
+
|
|
7
|
+
## What You Can Do
|
|
8
|
+
|
|
9
|
+
- inspect Local sites and their runtime details
|
|
10
|
+
- start, stop, and restart Local sites
|
|
11
|
+
- list, read, search, write, and delete files inside a selected Local site
|
|
12
|
+
- run WP-CLI against the correct site
|
|
13
|
+
- query the WordPress database
|
|
14
|
+
- allow full database writes when you want unrestricted local development
|
|
15
|
+
- read recent logs and run site health checks
|
|
16
|
+
- export, import, back up, and restore LocalWP sites
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
Use `npx` in your MCP client:
|
|
21
|
+
|
|
22
|
+
```json
|
|
23
|
+
{
|
|
24
|
+
"mcpServers": {
|
|
25
|
+
"localwp": {
|
|
26
|
+
"command": "npx",
|
|
27
|
+
"args": ["localwp-mcp"],
|
|
28
|
+
"env": {
|
|
29
|
+
"LOCALWP_MCP_PROFILE": "safe"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
You can also install it globally:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npm install -g localwp-mcp
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Then use:
|
|
43
|
+
|
|
44
|
+
```json
|
|
45
|
+
{
|
|
46
|
+
"mcpServers": {
|
|
47
|
+
"localwp": {
|
|
48
|
+
"command": "localwp-mcp",
|
|
49
|
+
"env": {
|
|
50
|
+
"LOCALWP_MCP_PROFILE": "safe"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
If you want the MCP to focus on one site by default, set:
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
{
|
|
61
|
+
"LOCAL_SITE_NAME": "example-site"
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Access Modes
|
|
66
|
+
|
|
67
|
+
`localwp-mcp` has 2 access modes:
|
|
68
|
+
|
|
69
|
+
- `safe`
|
|
70
|
+
Best default for most people. Safe WordPress inspection commands, diagnostics, logs, database reads, and backup/export flows.
|
|
71
|
+
- `full-access`
|
|
72
|
+
Best when you want the agent to fully work on your local site, including SQL writes, imports, and restore operations.
|
|
73
|
+
|
|
74
|
+
`safe` is the default.
|
|
75
|
+
|
|
76
|
+
To enable full local access:
|
|
77
|
+
|
|
78
|
+
```json
|
|
79
|
+
{
|
|
80
|
+
"LOCALWP_MCP_PROFILE": "full-access"
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## First Things To Try
|
|
85
|
+
|
|
86
|
+
Start with:
|
|
87
|
+
|
|
88
|
+
- `local_environment_check`
|
|
89
|
+
- `local_doctor`
|
|
90
|
+
- `list_local_sites`
|
|
91
|
+
|
|
92
|
+
Those will tell you:
|
|
93
|
+
|
|
94
|
+
- which Local sites were discovered
|
|
95
|
+
- whether the site is running
|
|
96
|
+
- which Local runtimes were resolved
|
|
97
|
+
- whether WP-CLI and MySQL are reachable
|
|
98
|
+
|
|
99
|
+
## Common Workflows
|
|
100
|
+
|
|
101
|
+
### Inspect a Site
|
|
102
|
+
|
|
103
|
+
Use:
|
|
104
|
+
|
|
105
|
+
- `local_site_info`
|
|
106
|
+
- `local_doctor`
|
|
107
|
+
- `local_logs`
|
|
108
|
+
|
|
109
|
+
### Work With Site Files
|
|
110
|
+
|
|
111
|
+
Use:
|
|
112
|
+
|
|
113
|
+
- `list_site_files`
|
|
114
|
+
- `read_site_file`
|
|
115
|
+
- `search_site_files`
|
|
116
|
+
- `write_site_file`
|
|
117
|
+
- `delete_site_file`
|
|
118
|
+
|
|
119
|
+
These tools are always scoped to the selected site's root directory.
|
|
120
|
+
|
|
121
|
+
- In `safe`, you can list, read, and search files.
|
|
122
|
+
- In `full-access`, you can also write and delete files.
|
|
123
|
+
|
|
124
|
+
### Control a Local Site
|
|
125
|
+
|
|
126
|
+
Use:
|
|
127
|
+
|
|
128
|
+
- `start_local_site`
|
|
129
|
+
- `stop_local_site`
|
|
130
|
+
- `restart_local_site`
|
|
131
|
+
|
|
132
|
+
### Work With WordPress
|
|
133
|
+
|
|
134
|
+
Use:
|
|
135
|
+
|
|
136
|
+
- `execute_wp_cli`
|
|
137
|
+
|
|
138
|
+
Examples:
|
|
139
|
+
|
|
140
|
+
- list plugins
|
|
141
|
+
- inspect options
|
|
142
|
+
- list posts or users
|
|
143
|
+
- run plugin-specific WP-CLI commands
|
|
144
|
+
|
|
145
|
+
### Work With the Database
|
|
146
|
+
|
|
147
|
+
Use:
|
|
148
|
+
|
|
149
|
+
- `mysql_query`
|
|
150
|
+
Read-only SQL in `safe`
|
|
151
|
+
- `mysql_execute`
|
|
152
|
+
Full SQL execution in `full-access`
|
|
153
|
+
- `mysql_schema`
|
|
154
|
+
Table listing and table description helpers
|
|
155
|
+
|
|
156
|
+
### Back Up or Restore a Site
|
|
157
|
+
|
|
158
|
+
Use:
|
|
159
|
+
|
|
160
|
+
- `backup_site`
|
|
161
|
+
- `db_export`
|
|
162
|
+
- `db_import`
|
|
163
|
+
- `restore_backup`
|
|
164
|
+
|
|
165
|
+
`backup_site` supports:
|
|
166
|
+
|
|
167
|
+
- `database`
|
|
168
|
+
- `full`
|
|
169
|
+
|
|
170
|
+
The `full` backup format is folder-based and includes the site's `app`, `conf`, and `logs` directories plus a fresh SQL dump.
|
|
171
|
+
|
|
172
|
+
## Built-In Capabilities
|
|
173
|
+
|
|
174
|
+
### Tools
|
|
175
|
+
|
|
176
|
+
- `list_local_sites`
|
|
177
|
+
- `start_local_site`
|
|
178
|
+
- `stop_local_site`
|
|
179
|
+
- `restart_local_site`
|
|
180
|
+
- `local_environment_check`
|
|
181
|
+
- `local_doctor`
|
|
182
|
+
- `local_logs`
|
|
183
|
+
- `local_site_info`
|
|
184
|
+
- `list_site_files`
|
|
185
|
+
- `read_site_file`
|
|
186
|
+
- `search_site_files`
|
|
187
|
+
- `write_site_file`
|
|
188
|
+
- `delete_site_file`
|
|
189
|
+
- `execute_wp_cli`
|
|
190
|
+
- `mysql_query`
|
|
191
|
+
- `mysql_execute`
|
|
192
|
+
- `mysql_schema`
|
|
193
|
+
- `db_export`
|
|
194
|
+
- `db_import`
|
|
195
|
+
- `backup_site`
|
|
196
|
+
- `restore_backup`
|
|
197
|
+
|
|
198
|
+
### MCP Resources
|
|
199
|
+
|
|
200
|
+
- `localwp://sites`
|
|
201
|
+
- `localwp://sites/{siteName}/summary`
|
|
202
|
+
- `localwp://sites/{siteName}/doctor`
|
|
203
|
+
- `localwp://sites/{siteName}/logs`
|
|
204
|
+
|
|
205
|
+
### MCP Prompts
|
|
206
|
+
|
|
207
|
+
- `diagnose_local_site`
|
|
208
|
+
- `restore_local_site`
|
|
209
|
+
|
|
210
|
+
## Platform Support
|
|
211
|
+
|
|
212
|
+
`localwp-mcp` is designed for:
|
|
213
|
+
|
|
214
|
+
- macOS
|
|
215
|
+
- Windows
|
|
216
|
+
- Linux
|
|
217
|
+
|
|
218
|
+
It supports both current Local `lightning-services` layouts and older `site-binaries` layouts.
|
|
219
|
+
|
|
220
|
+
## Useful Environment Variables
|
|
221
|
+
|
|
222
|
+
Most users only need these:
|
|
223
|
+
|
|
224
|
+
- `LOCALWP_MCP_PROFILE`
|
|
225
|
+
- `LOCAL_SITE_NAME`
|
|
226
|
+
- `LOCAL_SITE_ID`
|
|
227
|
+
- `LOCALWP_MCP_BACKUPS_DIR`
|
|
228
|
+
|
|
229
|
+
Advanced override variables also exist for custom Local layouts, but most installations do not need them.
|
|
230
|
+
|
|
231
|
+
## Troubleshooting
|
|
232
|
+
|
|
233
|
+
If the MCP does not find your site or cannot run WP-CLI/MySQL:
|
|
234
|
+
|
|
235
|
+
1. Start the site in Local.
|
|
236
|
+
2. Run `local_environment_check`.
|
|
237
|
+
3. Run `local_doctor`.
|
|
238
|
+
4. Check `local_logs`.
|
|
239
|
+
|
|
240
|
+
Those tools are the fastest way to see whether the problem is:
|
|
241
|
+
|
|
242
|
+
- site selection
|
|
243
|
+
- Local metadata resolution
|
|
244
|
+
- WP-CLI resolution
|
|
245
|
+
- MySQL connectivity
|
|
246
|
+
- missing or stopped Local services
|
|
247
|
+
|
|
248
|
+
## For Contributors
|
|
249
|
+
|
|
250
|
+
Contributor and maintainer docs live outside the main user guide:
|
|
251
|
+
|
|
252
|
+
- [CONTRIBUTING.md](./CONTRIBUTING.md)
|
|
253
|
+
- [SECURITY.md](./SECURITY.md)
|
|
254
|
+
- [Maintainer Docs](./docs/maintainers/README.md)
|
package/dist/config.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export declare const config: {
|
|
|
9
9
|
readonly localLightningServicesDirs: string[];
|
|
10
10
|
readonly localSitesJson: string;
|
|
11
11
|
readonly localSiteStatusesJson: string;
|
|
12
|
+
readonly localGraphqlConnectionInfoJson: string;
|
|
12
13
|
readonly localWpCliPharCandidates: string[];
|
|
13
14
|
readonly localWpCliConfigCandidates: string[];
|
|
14
15
|
readonly localHelperBinDirCandidates: string[];
|
package/dist/config.js
CHANGED
|
@@ -27,6 +27,8 @@ export const config = {
|
|
|
27
27
|
path.join(process.env.LOCAL_APP_SUPPORT_DIR || defaultLocalAppSupportDir, "sites.json"),
|
|
28
28
|
localSiteStatusesJson: process.env.LOCAL_SITE_STATUSES_JSON ||
|
|
29
29
|
path.join(process.env.LOCAL_APP_SUPPORT_DIR || defaultLocalAppSupportDir, "site-statuses.json"),
|
|
30
|
+
localGraphqlConnectionInfoJson: process.env.LOCAL_GRAPHQL_CONNECTION_INFO ||
|
|
31
|
+
path.join(process.env.LOCAL_APP_SUPPORT_DIR || defaultLocalAppSupportDir, "graphql-connection-info.json"),
|
|
30
32
|
localWpCliPharCandidates: process.env.LOCAL_WP_CLI_PHAR
|
|
31
33
|
? [process.env.LOCAL_WP_CLI_PHAR]
|
|
32
34
|
: getWpCliPharCandidates(platform, localExtraResourcesDirs),
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI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ecycleMutationResult } from "./types.js";
|
|
2
|
+
interface LocalGraphqlError {
|
|
3
|
+
message?: string;
|
|
4
|
+
}
|
|
5
|
+
export declare function startLocalSite(siteId: string): Promise<LocalSiteLifecycleMutationResult>;
|
|
6
|
+
export declare function stopLocalSite(siteId: string): Promise<LocalSiteLifecycleMutationResult>;
|
|
7
|
+
export declare function formatLocalGraphqlErrors(errors?: LocalGraphqlError[]): string;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { readFile } from "fs/promises";
|
|
2
|
+
import { config } from "./config.js";
|
|
3
|
+
import { assertReadable } from "./process-utils.js";
|
|
4
|
+
export async function startLocalSite(siteId) {
|
|
5
|
+
return runSiteLifecycleMutation("startSite", siteId);
|
|
6
|
+
}
|
|
7
|
+
export async function stopLocalSite(siteId) {
|
|
8
|
+
return runSiteLifecycleMutation("stopSite", siteId);
|
|
9
|
+
}
|
|
10
|
+
export function formatLocalGraphqlErrors(errors = []) {
|
|
11
|
+
const messages = errors
|
|
12
|
+
.map((error) => error.message?.trim())
|
|
13
|
+
.filter((message) => Boolean(message));
|
|
14
|
+
return messages.join("; ") || "Local GraphQL request failed.";
|
|
15
|
+
}
|
|
16
|
+
async function runSiteLifecycleMutation(mutationName, siteId) {
|
|
17
|
+
const query = `mutation ($siteID: ID!) { ${mutationName}(id: $siteID) { id name status } }`;
|
|
18
|
+
const payload = await requestLocalGraphql(query, { siteID: siteId });
|
|
19
|
+
const result = payload[mutationName];
|
|
20
|
+
if (!result) {
|
|
21
|
+
throw new Error(`Local GraphQL did not return '${mutationName}' data.`);
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
async function requestLocalGraphql(query, variables) {
|
|
26
|
+
const connection = await readLocalGraphqlConnectionInfo();
|
|
27
|
+
let response;
|
|
28
|
+
try {
|
|
29
|
+
response = await fetch(connection.url, {
|
|
30
|
+
method: "POST",
|
|
31
|
+
headers: {
|
|
32
|
+
"content-type": "application/json",
|
|
33
|
+
authorization: `Bearer ${connection.authToken}`,
|
|
34
|
+
},
|
|
35
|
+
body: JSON.stringify({ query, variables }),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
40
|
+
throw new Error(`Failed to reach Local's GraphQL API at ${connection.url}. Make sure the Local app is running. ${message}`);
|
|
41
|
+
}
|
|
42
|
+
if (!response.ok) {
|
|
43
|
+
throw new Error(`Local GraphQL API responded with HTTP ${response.status} ${response.statusText}.`);
|
|
44
|
+
}
|
|
45
|
+
const payload = (await response.json());
|
|
46
|
+
if (payload.errors?.length) {
|
|
47
|
+
throw new Error(formatLocalGraphqlErrors(payload.errors));
|
|
48
|
+
}
|
|
49
|
+
if (!payload.data) {
|
|
50
|
+
throw new Error("Local GraphQL API returned no data.");
|
|
51
|
+
}
|
|
52
|
+
return payload.data;
|
|
53
|
+
}
|
|
54
|
+
async function readLocalGraphqlConnectionInfo() {
|
|
55
|
+
await assertReadable(config.localGraphqlConnectionInfoJson, "Local GraphQL connection info is not readable. Open the Local app first");
|
|
56
|
+
let parsed;
|
|
57
|
+
try {
|
|
58
|
+
parsed = JSON.parse(await readFile(config.localGraphqlConnectionInfoJson, "utf8"));
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
62
|
+
throw new Error(`Failed to read Local GraphQL connection info from '${config.localGraphqlConnectionInfoJson}': ${message}`);
|
|
63
|
+
}
|
|
64
|
+
if (!isLocalGraphqlConnectionInfo(parsed)) {
|
|
65
|
+
throw new Error(`Local GraphQL connection info is invalid: ${config.localGraphqlConnectionInfoJson}`);
|
|
66
|
+
}
|
|
67
|
+
return parsed;
|
|
68
|
+
}
|
|
69
|
+
function isLocalGraphqlConnectionInfo(value) {
|
|
70
|
+
if (!value || typeof value !== "object") {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
const candidate = value;
|
|
74
|
+
return (typeof candidate.port === "number" &&
|
|
75
|
+
typeof candidate.authToken === "string" &&
|
|
76
|
+
typeof candidate.url === "string");
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=local-graphql.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-graphql.js","sourceRoot":"","sources":["../src/local-graphql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAepD,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,MAAc;IACjD,OAAO,wBAAwB,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;AACvD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,MAAc;IAChD,OAAO,wBAAwB,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;AACtD,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,SAA8B,EAAE;IACvE,MAAM,QAAQ,GAAG,MAAM;SACpB,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC;SACrC,MAAM,CAAC,CAAC,OAAO,EAAqB,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;IAE5D,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,+BAA+B,CAAC;AAChE,CAAC;AAED,KAAK,UAAU,wBAAwB,CACrC,YAAsC,EACtC,MAAc;IAEd,MAAM,KAAK,GAAG,6BAA6B,YAAY,oCAAoC,CAAC;IAC5F,MAAM,OAAO,GAAG,MAAM,mBAAmB,CAEvC,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC7B,MAAM,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAErC,IAAI,C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