@pi-unipi/mcp 2.1.3 → 2.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-unipi/mcp",
3
- "version": "2.1.3",
3
+ "version": "2.3.0",
4
4
  "description": "MCP server management extension for Pi coding agent — browse, add, configure, and use MCP servers",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -27,7 +27,7 @@
27
27
  "README.md"
28
28
  ],
29
29
  "dependencies": {
30
- "@pi-unipi/core": "2.1.3"
30
+ "@pi-unipi/core": "2.3.0"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "@earendil-works/pi-coding-agent": "^0.80.0",
@@ -31,6 +31,7 @@ import {
31
31
  getProjectConfigDir,
32
32
  } from "../config/manager.js";
33
33
  import { validateMcpConfig, DEFAULT_MCP_CONFIG, DEFAULT_METADATA } from "../config/schema.js";
34
+ import { boxInnerWidth, normalizeWidth, WidthKeyedCache } from "@pi-unipi/core";
34
35
 
35
36
  type Mode = "normal" | "search" | "editor";
36
37
  type StatusKind = "info" | "success" | "warn" | "error";
@@ -158,11 +159,12 @@ export function renderMcpAddOverlay(params?: {
158
159
  // Ctrl+S handles saving; no submit path needed.
159
160
  (editor as any).disableSubmit = true;
160
161
 
161
- let cachedLines: string[] | undefined;
162
+ // Width-keyed so a terminal resize can never serve stale, over-wide lines.
163
+ const lineCache = new WidthKeyedCache();
162
164
  let lastListHeight = 12;
163
165
 
164
166
  function refresh() {
165
- cachedLines = undefined;
167
+ lineCache.clear();
166
168
  tui.requestRender();
167
169
  }
168
170
 
@@ -537,11 +539,13 @@ export function renderMcpAddOverlay(params?: {
537
539
 
538
540
  // ─── Rendering ────────────────────────────────────────────────────
539
541
 
540
- function render(width: number): string[] {
541
- if (cachedLines) return cachedLines;
542
+ function render(rawWidth: number): string[] {
543
+ const width = normalizeWidth(rawWidth);
544
+ const cached = lineCache.get(width);
545
+ if (cached) return cached;
542
546
 
543
547
  const lines: string[] = [];
544
- const innerWidth = Math.max(40, width - 2);
548
+ const innerWidth = boxInnerWidth(width);
545
549
 
546
550
  // Pane widths: account for left │, middle │, right │ borders
547
551
  const leftW = Math.floor((innerWidth - 1) / 2);
@@ -776,8 +780,7 @@ export function renderMcpAddOverlay(params?: {
776
780
  );
777
781
  lines.push(border(`╰${"─".repeat(innerWidth)}╯`));
778
782
 
779
- cachedLines = lines;
780
- return lines;
783
+ return lineCache.set(width, lines);
781
784
  }
782
785
 
783
786
  return { render, invalidate: refresh, handleInput };
@@ -16,6 +16,7 @@ import {
16
16
  getGlobalConfigDir,
17
17
  getProjectConfigDir,
18
18
  } from "../config/manager.js";
19
+ import { boxInnerWidth, normalizeWidth, WidthKeyedCache } from "@pi-unipi/core";
19
20
 
20
21
  /** Server display item */
21
22
  interface ServerDisplayItem {
@@ -65,7 +66,8 @@ export function renderMcpSettingsOverlay(params?: {
65
66
  confirmDelete: null,
66
67
  };
67
68
 
68
- let cachedLines: string[] | undefined;
69
+ // Width-keyed so a terminal resize can never serve stale, over-wide lines.
70
+ const lineCache = new WidthKeyedCache();
69
71
 
70
72
  function refreshServers() {
71
73
  const configDir =
@@ -115,7 +117,7 @@ export function renderMcpSettingsOverlay(params?: {
115
117
  refreshServers();
116
118
 
117
119
  function refresh() {
118
- cachedLines = undefined;
120
+ lineCache.clear();
119
121
  tui.requestRender();
120
122
  }
121
123
 
@@ -275,11 +277,13 @@ export function renderMcpSettingsOverlay(params?: {
275
277
  return content + " ".repeat(pad);
276
278
  }
277
279
 
278
- function render(width: number): string[] {
279
- if (cachedLines) return cachedLines;
280
+ function render(rawWidth: number): string[] {
281
+ const width = normalizeWidth(rawWidth);
282
+ const cached = lineCache.get(width);
283
+ if (cached) return cached;
280
284
 
281
285
  const lines: string[] = [];
282
- const innerWidth = Math.max(22, width - 2);
286
+ const innerWidth = boxInnerWidth(width);
283
287
 
284
288
  // ── Header ──────────────────────────────────────────────────────
285
289
  const header = " MCP Settings ";
@@ -356,8 +360,7 @@ export function renderMcpSettingsOverlay(params?: {
356
360
  );
357
361
  lines.push(theme.fg("accent", `╰${"─".repeat(innerWidth)}╯`));
358
362
 
359
- cachedLines = lines;
360
- return lines;
363
+ return lineCache.set(width, lines);
361
364
  }
362
365
 
363
366
  return { render, invalidate: refresh, handleInput };