@jangmanj/pi-mcp-ext 0.0.0-stage → 0.1.0

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) 2026 JangMan-J
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 CHANGED
@@ -1,3 +1,94 @@
1
- # Temporary Holding Version
1
+ # @jangmanj/pi-mcp-ext
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Stateless MCP `2026-07-28` events and asynchronous tasks for Pi, running alongside `builtin:mcp`.
4
+
5
+ ## What It Adds Next to `builtin:mcp`
6
+
7
+ Pi's `builtin:mcp` extension owns `/mcp`, synchronous `mcp__<server>__<tool>` tool exposure, resource tools, and `mcp-auth.json` sign-in and token refresh. `@jangmanj/pi-mcp-ext` loads in the same Pi session without replacing `builtin:mcp` and adds the `2026-07-28` protocol capabilities on configured `stdio` and Streamable HTTP servers:
8
+
9
+ - **Stateless discovery and change streams**: probes enabled servers with `server/discover` (falling back cleanly when a server speaks an older MCP version) and maintains at most one `subscriptions/listen` stream per modern server when needed.
10
+ - **Events (`io.modelcontextprotocol/events`)**: discovers event types via `events/list`, catches up with `events/poll`, streams live occurrences via `events/stream`, persists replay cursors in the session branch, deduplicates deliveries, and wakes Pi turns with `mcp-event` messages.
11
+ - **Tasks (`io.modelcontextprotocol/tasks`)**: invokes task-augmented MCP tools, tracks `working` and `input_required` tasks across `subscriptions/listen` push notifications and fallback `tasks/get` polling, supplies interactive input via `tasks/update`, cancels via `tasks/cancel`, and wakes Pi turns with `mcp-task` messages.
12
+ - **Task-capability hint**: when a synchronous `mcp__<server>__<tool>` call fails with `-32021` naming `io.modelcontextprotocol/tasks` on a server that supports tasks, appends a hint showing the equivalent `mcp_tasks` call.
13
+ - **Headless settle hold**: keeps `-p` and `--mode json` runs alive while non-terminal tasks or `holdSettle` event subscriptions are active, settling cleanly once deliveries drain.
14
+ - **Read-only configuration and credentials**: reads global `mcp.json`, trusted project `.pi/mcp.json`, session-registered servers, and `mcp-auth.json` without writing or locking config or credential files.
15
+
16
+ ## Install
17
+
18
+ ```sh
19
+ pi install npm:@jangmanj/pi-mcp-ext
20
+ ```
21
+
22
+ ## Tools
23
+
24
+ Both tools register directly (and are callable from `codemode` scripts as `tools.mcp_events(...)` and `tools.mcp_tasks(...)`).
25
+
26
+ ### `mcp_events`
27
+
28
+ Manage MCP `2026-07-28` event discovery, subscriptions, and polling.
29
+
30
+ - `action`: `"servers" | "list" | "subscribe" | "unsubscribe" | "subscriptions" | "poll"`
31
+ - `server?: string` — MCP server name (required for `list`, `subscribe`, `unsubscribe`, `poll`).
32
+ - `name?: string` — event type name (required for `subscribe`, `unsubscribe`, `poll`).
33
+ - `arguments?: Record<string, unknown>` — event filter or subscription arguments validated against the event's `inputSchema`.
34
+ - `delivery?: "auto" | "push" | "poll"` — delivery preference (default `"auto"`, preferring push with poll catch-up).
35
+ - `cursor?: string | null` — explicit starting cursor (`null` starts from now; omit to resume from the persisted session cursor).
36
+ - `maxAgeMs?: number` — optional replay age limit in integer milliseconds.
37
+ - `maxEvents?: number` — optional batch size limit for `action: "poll"`.
38
+ - `holdSettle?: boolean` — keep headless (`-p` / `--mode json`) runs open until an event arrives or `unsubscribe` is called.
39
+
40
+ ### `mcp_tasks`
41
+
42
+ Invoke and manage MCP `2026-07-28` task-augmented tool calls.
43
+
44
+ - `action`: `"call" | "get" | "update" | "cancel" | "active"`
45
+ - `server?: string` — MCP server name (required for `call`, `get`, `update`, `cancel`; optional filter for `active`).
46
+ - `tool?: string` — tool name on `server` for `action: "call"`. Returns the completed tool result immediately if the server finishes synchronously, or tracks the created task if the server returns `resultType: "task"`.
47
+ - `arguments?: Record<string, unknown>` — tool arguments for `action: "call"`.
48
+ - `taskId?: string` — task identifier for `get`, `update`, and `cancel`.
49
+ - `inputResponses?: Record<string, unknown>` — responses keyed by `inputRequests` id for `action: "update"`.
50
+
51
+ `action: "active"` reads the client's session task ledger directly without issuing a server RPC.
52
+
53
+ ## Declarative Subscriptions (`subscribe`)
54
+
55
+ Any server entry in global `mcp.json`, a trusted project `.pi/mcp.json` (full server definition), or `pi.registerMcpServer()` may include an optional `subscribe` array. `builtin:mcp` ignores unknown fields, while `@jangmanj/pi-mcp-ext` activates the declared subscriptions automatically on `session_start` once `server/discover` confirms `io.modelcontextprotocol/events`:
56
+
57
+ ```json
58
+ {
59
+ "mcpServers": {
60
+ "alerts": {
61
+ "url": "https://alerts.example.com/mcp",
62
+ "subscribe": ["*"]
63
+ },
64
+ "ci": {
65
+ "command": "ci-mcp",
66
+ "subscribe": [
67
+ "build.failed",
68
+ {
69
+ "name": "deploy.finished",
70
+ "arguments": { "env": "prod" },
71
+ "delivery": "push",
72
+ "maxAgeMs": 600000,
73
+ "holdSettle": false
74
+ }
75
+ ]
76
+ }
77
+ }
78
+ }
79
+ ```
80
+
81
+ - Each item is `"*"` (all push- or poll-capable events in `events/list`), an event name string, or `{ name, arguments?, delivery?, maxAgeMs?, holdSettle? }`.
82
+ - Defaults are `delivery: "auto"` and `holdSettle: false`, so declarative subscriptions do not hold headless runs open unless `holdSettle: true` is set.
83
+ - Subscriptions resume from the latest persisted session cursor when present, or start from `cursor: null` so restarts do not replay previously delivered events.
84
+ - Invalid `subscribe` values log a warning without blocking the server entry; legacy servers or servers without `io.modelcontextprotocol/events` ignore `subscribe`.
85
+ - Removing an entry from `subscribe` does not cancel an already-persisted subscription; call `mcp_events` with `action: "unsubscribe"` to stop it.
86
+
87
+ ## Development
88
+
89
+ ```sh
90
+ npm run typecheck # Type-check src/ and tests/ with tsc --noEmit
91
+ npm test # Run the node:test suite
92
+ npm run check # Run typecheck and tests
93
+ npm run smoke:pack # Pack tarball, install in a scratch directory, and load in Pi
94
+ ```
package/package.json CHANGED
@@ -1,6 +1,54 @@
1
1
  {
2
2
  "name": "@jangmanj/pi-mcp-ext",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "MCP 2026-07-28 events and tasks for Pi, alongside builtin:mcp",
5
+ "license": "MIT",
6
+ "author": "JangMan-J",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/JangMan-J/pi-mcp-ext.git"
10
+ },
11
+ "homepage": "https://github.com/JangMan-J/pi-mcp-ext#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/JangMan-J/pi-mcp-ext/issues"
14
+ },
15
+ "type": "module",
16
+ "keywords": [
17
+ "pi-package"
18
+ ],
19
+ "files": [
20
+ "src",
21
+ "README.md"
22
+ ],
23
+ "pi": {
24
+ "extensions": [
25
+ "./src/index.ts"
26
+ ]
27
+ },
28
+ "scripts": {
29
+ "test": "node --test tests/*.test.ts",
30
+ "typecheck": "tsc --noEmit",
31
+ "check": "npm run typecheck && npm test",
32
+ "smoke:pack": "node scripts/smoke-pack.mjs",
33
+ "init-package": "node scripts/init-package.mjs",
34
+ "bootstrap:npm": "bash scripts/npm-bootstrap.sh"
35
+ },
36
+ "peerDependencies": {
37
+ "@earendil-works/pi-ai": "*",
38
+ "@earendil-works/pi-coding-agent": ">=1.5.2",
39
+ "typebox": "*"
40
+ },
41
+ "publishConfig": {
42
+ "access": "public"
43
+ },
44
+ "devDependencies": {
45
+ "@earendil-works/pi-ai": "1.5.2",
46
+ "@earendil-works/pi-coding-agent": "1.5.2",
47
+ "@types/node": "~22.19.0",
48
+ "typebox": "1.3.27",
49
+ "typescript": "^7.0.2"
50
+ },
51
+ "engines": {
52
+ "node": ">=22.19.0"
53
+ }
54
+ }