Skip to content

Commit 7051175

Browse files
committed
correct mcp server init and registration with angie
1 parent 2de89b1 commit 7051175

File tree

10 files changed

+2583
-335
lines changed

10 files changed

+2583
-335
lines changed
Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ The integration enables Angie to:
1313

1414
The integration consists of two main components:
1515

16-
1. **PHP REST API** (`class-angie.php`): WordPress REST API endpoints for task management
17-
2. **MCP Server** (`src/mcp-server.ts`): TypeScript-based MCP server that bridges Angie AI with the REST API
16+
1. **PHP REST API** (`class-angie-api.php`): WordPress REST API endpoints for task management
17+
2. **MCP Server** (`src/progress-planner-mcp-server.ts`): TypeScript-based MCP server that bridges Angie AI with the REST API, bundled with Vite for browser compatibility
1818

1919
## Installation
2020

@@ -29,7 +29,7 @@ The integration consists of two main components:
2929

3030
1. **Install Dependencies:**
3131
```bash
32-
cd third-party/angie
32+
cd classes/third-party/angie
3333
npm install
3434
```
3535

@@ -38,12 +38,16 @@ The integration consists of two main components:
3838
npm run build
3939
```
4040

41-
This will compile the TypeScript code and generate `dist/mcp-server.js`.
41+
This will:
42+
- Compile TypeScript to JavaScript (`tsc`)
43+
- Bundle all dependencies with Vite into a single ES module
44+
- Generate `dist/progress-planner-mcp-server.js` (bundled, ~442KB)
4245

4346
3. **Development Mode:**
4447
For active development, use watch mode:
4548
```bash
46-
npm run watch
49+
npm run watch # TypeScript watch mode
50+
npm run dev # Vite dev server (for testing)
4751
```
4852

4953
The integration is automatically enabled when Progress Planner is active. The MCP server script will be automatically enqueued when the Angie plugin is detected.
@@ -237,8 +241,24 @@ To get a complete list of available task IDs, use the "Get Active Tasks" endpoin
237241

238242
### File Structure
239243

240-
- **Main Integration Class:** `/code/classes/rest/class-angie.php`
241-
- **Registration:** The class is automatically instantiated in `/code/classes/class-base.php`
244+
- **Main Integration Class:** `classes/third-party/angie/class-integration.php`
245+
- **REST API Class:** `classes/third-party/angie/class-angie-api.php`
246+
- **MCP Server Source:** `classes/third-party/angie/src/progress-planner-mcp-server.ts`
247+
- **MCP Server Bundle:** `classes/third-party/angie/dist/progress-planner-mcp-server.js`
248+
- **Build Configuration:** `classes/third-party/angie/vite.config.ts`
249+
- **Registration:** The integration is automatically instantiated in `classes/class-base.php`
250+
251+
### Build Process
252+
253+
The MCP server uses:
254+
- **TypeScript** for type-safe development
255+
- **Vite** for bundling dependencies (Angie SDK, MCP SDK, Zod) into a single ES module
256+
- **ES Modules** for browser compatibility
257+
258+
The build process (`npm run build`) does the following:
259+
1. Compiles TypeScript (`tsc`) - generates type definitions
260+
2. Bundles with Vite - resolves all `import` statements and creates a single file
261+
3. Outputs `dist/progress-planner-mcp-server.js` - ready for browser use
242262

243263
### How It Works
244264

@@ -321,14 +341,29 @@ Check the debug log at `/wp-content/debug.log` for error messages.
321341

322342
**Solution:** This typically happens if the value hasn't changed. WordPress's `update_option()` returns false when the new value is the same as the old value.
323343

344+
### Module resolution errors in browser
345+
346+
**Solution:** Ensure you've run `npm run build` after making changes. The build process bundles all dependencies. Clear your browser cache (hard refresh: Cmd+Shift+R / Ctrl+Shift+F5) to load the new bundled file.
347+
324348
## Contributing
325349

326350
To extend this integration:
327351

328-
1. Add new methods to `/code/classes/rest/class-angie.php`
329-
2. Register new routes in the `register_rest_endpoint()` method
330-
3. Follow WordPress REST API best practices
331-
4. Update this documentation
352+
1. **Add new REST API endpoints:**
353+
- Add new methods to `classes/third-party/angie/class-angie-api.php`
354+
- Register new routes in the `register_rest_endpoint()` method
355+
356+
2. **Add new MCP tools:**
357+
- Edit `classes/third-party/angie/src/progress-planner-mcp-server.ts`
358+
- Use `server.tool()` to register new tools (see example code)
359+
- Rebuild with `npm run build`
360+
361+
3. **Development workflow:**
362+
- Edit TypeScript source files in `src/`
363+
- Run `npm run build` to rebuild
364+
- Clear browser cache to see changes
365+
- Follow WordPress REST API best practices
366+
- Update this documentation
332367

333368
## Support
334369

third-party/angie/class-angie.php renamed to classes/third-party/angie/class-angie-api.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
* @package Progress_Planner
1111
*/
1212

13-
namespace Progress_Planner\Rest;
13+
namespace Progress_Planner\Third_Party\Angie;
14+
15+
use Progress_Planner\Rest\Base;
1416

1517
/**
1618
* Angie Integration REST-API class.
1719
*/
18-
class Angie extends Base {
20+
class Angie_API extends Base {
1921

2022
/**
2123
* Register the REST-API endpoints.
@@ -59,13 +61,13 @@ public function register_rest_endpoint() {
5961
'callback' => [ $this, 'complete_task' ],
6062
'permission_callback' => [ $this, 'check_permissions' ],
6163
'args' => [
62-
'task_id' => [
64+
'task_id' => [
6365
'required' => true,
6466
'type' => 'string',
6567
'description' => 'The task ID to complete (e.g., "core-blogdescription")',
6668
'sanitize_callback' => 'sanitize_text_field',
6769
],
68-
'value' => [
70+
'value' => [
6971
'required' => false,
7072
'type' => 'string',
7173
'description' => 'The value to set for the task (e.g., blog description text)',
@@ -107,11 +109,11 @@ public function get_active_tasks() {
107109

108110
$tasks_to_return = [];
109111
foreach ( $tasks as $task ) {
110-
$task_data = $task->get_data();
112+
$task_data = $task->get_data();
111113
$tasks_to_return[] = [
112114
'id' => $task_data['task_id'],
113-
'title' => $task_data['title'],
114-
'description' => $task_data['description'],
115+
'title' => $task_data['post_title'],
116+
'description' => $task_data['post_content'],
115117
'url' => $task_data['url'],
116118
'priority' => $task_data['priority'] ?? 0,
117119
'status' => 'active',
@@ -147,11 +149,11 @@ public function get_completed_tasks() {
147149

148150
$tasks_to_return = [];
149151
foreach ( $tasks as $task ) {
150-
$task_data = $task->get_data();
152+
$task_data = $task->get_data();
151153
$tasks_to_return[] = [
152154
'id' => $task_data['task_id'],
153-
'title' => $task_data['title'],
154-
'description' => $task_data['description'],
155+
'title' => $task_data['post_title'],
156+
'description' => $task_data['post_content'],
155157
'url' => $task_data['url'],
156158
'priority' => $task_data['priority'] ?? 0,
157159
'status' => 'completed',
@@ -287,9 +289,9 @@ private function complete_blog_description_task( $value ) {
287289

288290
return new \WP_REST_Response(
289291
[
290-
'success' => true,
291-
'message' => \__( 'Blog description has been set successfully and the task has been marked as completed.', 'progress-planner' ),
292-
'task_id' => 'core-blogdescription',
292+
'success' => true,
293+
'message' => \__( 'Blog description has been set successfully and the task has been marked as completed.', 'progress-planner' ),
294+
'task_id' => 'core-blogdescription',
293295
'blog_description' => $value,
294296
],
295297
200

third-party/angie/class-integration.php renamed to classes/third-party/angie/class-integration.php

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace Progress_Planner\Third_Party\Angie;
1414

15+
use Progress_Planner\Third_Party\Angie\Angie_API;
1516
/**
1617
* Main Angie Integration class.
1718
*/
@@ -21,25 +22,14 @@ class Integration {
2122
* Constructor.
2223
*/
2324
public function __construct() {
24-
// Load REST API endpoints.
25-
require_once __DIR__ . '/class-angie.php';
2625

2726
// Initialize REST API.
28-
add_action( 'rest_api_init', [ $this, 'init_rest_api' ] );
27+
new Angie_API();
2928

3029
// Enqueue MCP server script.
3130
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
3231
}
3332

34-
/**
35-
* Initialize REST API endpoints.
36-
*
37-
* @return void
38-
*/
39-
public function init_rest_api() {
40-
new \Progress_Planner\Rest\Angie();
41-
}
42-
4333
/**
4434
* Enqueue scripts for Angie integration.
4535
*
@@ -52,8 +42,8 @@ public function enqueue_scripts() {
5242
}
5343

5444
// Enqueue the MCP server script.
55-
$script_path = PROGRESS_PLANNER_DIR . '/third-party/angie/dist/mcp-server.js';
56-
$script_url = PROGRESS_PLANNER_URL . '/third-party/angie/dist/mcp-server.js';
45+
$script_path = \constant( 'PROGRESS_PLANNER_DIR' ) . '/classes/third-party/angie/dist/progress-planner-mcp-server.js';
46+
$script_url = \constant( 'PROGRESS_PLANNER_URL' ) . '/classes/third-party/angie/dist/progress-planner-mcp-server.js';
5747

5848
if ( file_exists( $script_path ) ) {
5949
wp_enqueue_script(
@@ -64,6 +54,24 @@ public function enqueue_scripts() {
6454
true
6555
);
6656

57+
// Add type="module" attribute to the script tag for ES modules.
58+
add_filter(
59+
'script_loader_tag',
60+
function ( $tag, $handle ) {
61+
if ( 'progress-planner-angie-mcp' === $handle ) {
62+
// Ensure type="module" is added and remove any existing type attribute.
63+
if ( false !== strpos( $tag, 'type=' ) ) {
64+
$tag = preg_replace( '/type=["\'][^"\']*["\']/', 'type="module"', $tag );
65+
} else {
66+
$tag = str_replace( '<script ', '<script type="module" ', $tag );
67+
}
68+
}
69+
return $tag;
70+
},
71+
10,
72+
2
73+
);
74+
6775
// Pass WordPress site URL and nonce to the script.
6876
wp_localize_script(
6977
'progress-planner-angie-mcp',
@@ -72,7 +80,7 @@ public function enqueue_scripts() {
7280
'restUrl' => rest_url( 'progress-planner/v1/angie' ),
7381
'nonce' => wp_create_nonce( 'wp_rest' ),
7482
'siteUrl' => get_site_url(),
75-
'pluginUrl' => PROGRESS_PLANNER_URL,
83+
'pluginUrl' => \constant( 'PROGRESS_PLANNER_URL' ),
7684
]
7785
);
7886
}

0 commit comments

Comments
 (0)