|
| 1 | +## Plan: Fully Unattended MCP Tool Execution (Headless Entry) |
| 2 | + |
| 3 | +This plan adds a pure Node.js headless execution path for MCP-driven tool calls, while reusing the existing MCP and invocation architecture and avoiding duplicate runtime pathways. |
| 4 | + |
| 5 | +### Scope |
| 6 | + |
| 7 | +- Add a CLI/headless entrypoint that runs without Electron UI. |
| 8 | +- Add a headless execution mode to MCP call flow. |
| 9 | +- Require explicit tool opt-in using `invocation.headless: true` in `pptb.config.json`. |
| 10 | +- Reuse existing registry, schema conversion, connection/auth, and invocation logging where possible. |
| 11 | +- Validate using MCP Inspector. |
| 12 | + |
| 13 | +### Non-Goals |
| 14 | + |
| 15 | +- No automatic conversion of UI tools to headless execution. |
| 16 | +- No replacement of existing windowed invocation behavior. |
| 17 | +- No streaming transport in v1 (polling only for long-running jobs). |
| 18 | + |
| 19 | +### Phase 1: CLI Foundation |
| 20 | + |
| 21 | +1. Create `src/cli/index.ts`, `src/cli/constants.ts`, `src/cli/utils.ts`. |
| 22 | +1. Add `bin` entry in `package.json` for `pptb-cli`. |
| 23 | +1. Add dedicated build target (`tsconfig.cli.json`) and compile `dist/cli/index.js`. |
| 24 | +1. Keep implementation minimal and safe until headless manager is introduced. |
| 25 | + |
| 26 | +### Phase 2: MCP Protocol Extension |
| 27 | + |
| 28 | +1. Extend MCP request envelope with `executionMode: "headless"`. |
| 29 | +1. Keep existing default behavior as `windowed` for backward compatibility. |
| 30 | +1. Define response model for async job-based execution (`jobId`, `statusUrl`, `status`). |
| 31 | + |
| 32 | +### Phase 3: Headless Invocation Runtime |
| 33 | + |
| 34 | +1. Add `headlessToolInvocationManager` to run and track headless jobs. |
| 35 | +1. Enforce opt-in: only tools with `invocation.headless: true` are callable in headless mode. |
| 36 | +1. Add deterministic timeout handling and status transitions. |
| 37 | + |
| 38 | +### Phase 4: Auth and Connection Strategy |
| 39 | + |
| 40 | +1. Do not expose `connectionId` externally. |
| 41 | +1. Accept caller-provided auth token in MCP request metadata/body or connection name that is created in PPTB. |
| 42 | +1. If auth token is provided, inject token into a constrained headless tool API surface. |
| 43 | +1. If connection name is provided, authenticate using existing connection and inject token into headless tool API surface. |
| 44 | + |
| 45 | +### Phase 5: Progress and Status |
| 46 | + |
| 47 | +1. Implement polling endpoint for long-running executions. |
| 48 | +1. Return progress metadata and final result via status endpoint. |
| 49 | +1. Keep transport stateless and MCP Inspector-friendly. |
| 50 | + |
| 51 | +### Phase 6: Documentation |
| 52 | + |
| 53 | +1. Update `docs/MCP_IMPLEMENTATION.md` with headless request/response contract. |
| 54 | +1. Add dedicated net-new doc under `docs/` describing architecture changes. |
| 55 | +1. Add author guidance for implementing `invokeHeadless(...)` in tools. |
| 56 | + |
| 57 | +### Phase 7: Validation (Manual validation) |
| 58 | + |
| 59 | +1. Start headless server via CLI. |
| 60 | +1. Validate `list-tools` includes headless-eligible tools only. |
| 61 | +1. Validate `call-tool` with `executionMode=headless`. |
| 62 | +1. Validate status polling, timeout, and error paths. |
| 63 | +1. Confirm existing windowed mode remains unchanged. |
| 64 | + |
| 65 | +### Reuse Map (No Duplication) |
| 66 | + |
| 67 | +- Reuse: `src/main/mcp/agentToolRegistry.ts` for tool discovery. |
| 68 | +- Reuse: `src/main/mcp/schemaConverter.ts` for schema consistency. |
| 69 | +- Reuse: `src/main/mcp/agentInvocationLogger.ts` for audit trail. |
| 70 | +- Reuse: `src/main/mcp/mcpServer.ts` as primary request router (extended, not duplicated). |
| 71 | +- Reuse: existing invocation metadata patterns and correlation IDs. |
| 72 | + |
| 73 | +### Deliverables |
| 74 | + |
| 75 | +- CLI/headless bootstrap scaffold. |
| 76 | +- Headless execution manager. |
| 77 | +- MCP protocol extension for headless mode. |
| 78 | +- Polling endpoint for progress and results. |
| 79 | +- Net-new implementation documentation. |
| 80 | +- Manual verification checklist for MCP Inspector. |
0 commit comments