pi-mcp-adapter 2.1.2 → 2.2.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/CHANGELOG.md CHANGED
@@ -5,6 +5,45 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [Unreleased]
9
+
10
+ ## [2.2.1] - 2026-03-23
11
+
12
+ ### Fixed
13
+ - Added `promptSnippet` to MCP proxy tool and direct MCP tools so they appear in the system prompt's Available tools section (required since pi 0.59.0)
14
+
15
+ ## [2.2.0] - 2026-03-16
16
+
17
+ ### Added
18
+ - **MCP UI Integration** - Support for the [MCP UI](https://github.com/MCP-UI-Org/mcp-ui) standard. Tools with `_meta.ui.resourceUri` open interactive UIs:
19
+ - Bidirectional AppBridge communication (tool calls, messages, context updates)
20
+ - Works with both stdio and HTTP MCP servers
21
+ - User consent management for tool calls from UI (configurable: never/once-per-server/always)
22
+ - Keyboard shortcuts: Cmd/Ctrl+Enter to complete, Escape to cancel
23
+ - UI prompts/intents trigger agent turns via `pi.sendMessage({ triggerTurn: true })`
24
+ - `mcp({ action: "ui-messages" })` retrieves accumulated messages from UI sessions
25
+
26
+ - **Session reuse** - When the agent calls the same tool while its UI is already open, results push to the existing window instead of replacing it. Per-call stream IDs with independent sequences. Error results scoped to the individual call.
27
+
28
+ - **Glimpse integration** - MCP UI opens in a native macOS WKWebView window instead of a browser tab when [Glimpse](https://github.com/hazat/glimpse) is installed (`pi install npm:glimpseui`). Falls back to browser on non-macOS or when unavailable. Override with `MCP_UI_VIEWER=browser` or `MCP_UI_VIEWER=glimpse`.
29
+
30
+ - **Logger module** (`logger.ts`) - Centralized logging with levels (debug/info/warn/error), contextual child loggers, and `MCP_UI_DEBUG=1` env var.
31
+
32
+ - **Error types** (`errors.ts`) - Structured errors with recovery hints: `ResourceFetchError`, `ResourceParseError`, `BridgeConnectionError`, `ConsentError`, `SessionError`, `ServerError`, and `wrapError()` helper.
33
+
34
+ - **Test suite** - 178 tests covering consent manager, UI resource handler, host HTML template, logger, and error types.
35
+
36
+ - **Interactive visualizer example** (`examples/interactive-visualizer`) - Minimal MCP server demonstrating charts (bar/line/pie/doughnut via Chart.js), bidirectional messaging, and streaming.
37
+
38
+ ### Fixed
39
+ - Host-iframe timing: bridge now connects before loading iframe, fixing `ui/initialize` timeout on first load
40
+ - All internal `log.info` calls demoted to `log.debug` to eliminate stdout noise during normal use
41
+
42
+ ### Technical Notes
43
+ - Uses local minified AppBridge bundle (408KB) to avoid CDN Zod bundling issues
44
+ - Serves app HTML from `/ui-app` endpoint instead of blob URLs to avoid iframe issues
45
+ - SSE for real-time tool result streaming to browser
46
+
8
47
  ## [2.1.2] - 2026-02-03
9
48
 
10
49
  ### Changed
package/README.md CHANGED
@@ -176,6 +176,65 @@ Direct tools register from the metadata cache (`~/.pi/agent/mcp-cache.json`), so
176
176
 
177
177
  **Subagent integration:** If you use the subagent extension, agents can request direct MCP tools in their frontmatter with `mcp:server-name` syntax. See the subagent README for details.
178
178
 
179
+ ### MCP UI Integration
180
+
181
+ MCP servers can ship interactive UIs via the [MCP UI](https://github.com/MCP-UI-Org/mcp-ui) standard. When you call a tool that has a UI resource, the adapter opens it in a native macOS window via [Glimpse](https://github.com/hazat/glimpse) if available, otherwise falls back to the browser.
182
+
183
+ **How it works:**
184
+
185
+ 1. Agent calls a tool like `launch_dashboard`
186
+ 2. The tool's metadata includes `_meta.ui.resourceUri` pointing to a UI resource
187
+ 3. pi-mcp-adapter fetches the UI HTML and opens it in an iframe
188
+ 4. The UI can call MCP tools and send messages back to the agent
189
+
190
+ **Native rendering:** On macOS, if [Glimpse](https://github.com/hazat/glimpse) is installed (`pi install npm:glimpseui`), UIs open in a native WKWebView window instead of a browser tab. Set `MCP_UI_VIEWER=browser` to force the browser, or `MCP_UI_VIEWER=glimpse` to require native rendering.
191
+
192
+ **Bidirectional communication:** The UI talks back. When it sends a prompt or intent, the message is stored and `triggerTurn()` wakes the agent. The agent retrieves messages via `mcp({ action: "ui-messages" })` and responds, enabling conversational UIs where the app and agent collaborate in real-time.
193
+
194
+ **Session reuse:** When the agent calls the same tool again while its UI is already open, the adapter pushes the new result to the existing window instead of replacing it. This enables live updates — the agent can refine a chart, add data, or respond to user input without losing the current view. Different tools still replace the session as before.
195
+
196
+ **Message types from UI:**
197
+
198
+ | Type | Purpose |
199
+ |------|---------|
200
+ | `prompt` | User message that triggers an agent response |
201
+ | `intent` | Structured action with name + params |
202
+ | `notify` | Fire-and-forget notification |
203
+ | `message` | Generic message payload |
204
+ | (custom) | Any other type forwarded as intent |
205
+
206
+ **Retrieving UI messages:**
207
+
208
+ ```
209
+ mcp({ action: "ui-messages" })
210
+ ```
211
+
212
+ Returns accumulated messages from UI sessions. Each message includes `type`, `sessionId`, `serverName`, `toolName`, and `timestamp`. Prompt messages include `prompt`, intent messages include `intent` and `params`.
213
+
214
+ **Browser controls:**
215
+
216
+ - **Cmd/Ctrl+Enter** — Complete and close
217
+ - **Escape** — Cancel and close
218
+ - **Done/Cancel buttons** — Same as keyboard shortcuts
219
+
220
+ **Technical notes:**
221
+
222
+ - Tool consent gates whether UIs can call MCP tools (never/once-per-server/always)
223
+ - Works with both stdio and HTTP MCP servers
224
+ - Uses a local 408KB AppBridge bundle (MCP SDK + Zod) for browser↔server communication
225
+
226
+ ### Local Example: Interactive Visualizer
227
+
228
+ A minimal MCP UI example at `examples/interactive-visualizer` demonstrating charts, bidirectional messaging, and streaming. From that directory:
229
+
230
+ ```bash
231
+ npm install
232
+ npm run build
233
+ npm run install-local
234
+ ```
235
+
236
+ Restart pi, then ask the agent to show a chart — it calls `show_chart` and opens the UI in Glimpse (macOS) or the browser. Use `npm run uninstall-local` to remove the MCP entry.
237
+
179
238
  ### Import Existing Configs
180
239
 
181
240
  Already have MCP set up elsewhere? Import it:
@@ -203,6 +262,7 @@ Add `.pi/mcp.json` in a project root for project-specific servers. Project confi
203
262
  | Describe | `mcp({ describe: "tool_name" })` |
204
263
  | Call | `mcp({ tool: "...", args: '{"key": "value"}' })` |
205
264
  | Connect | `mcp({ connect: "server-name" })` |
265
+ | UI messages | `mcp({ action: "ui-messages" })` |
206
266
 
207
267
  Search includes both MCP tools and Pi tools (from extensions). Pi tools appear first with `[pi tool]` prefix. Space-separated words are OR'd.
208
268
 
@@ -220,8 +280,6 @@ Tool names are fuzzy-matched on hyphens and underscores — `context7_resolve_li
220
280
 
221
281
  ## How It Works
222
282
 
223
- See [ARCHITECTURE.md](./ARCHITECTURE.md) for the full picture. Short version:
224
-
225
283
  - One `mcp` tool in context (~200 tokens) instead of hundreds
226
284
  - Servers are lazy by default — they connect on first tool call, not at startup
227
285
  - Tool metadata is cached to disk so search/list/describe work without live connections