pi-mcp-adapter 2.5.4 → 2.6.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/server-manager.ts CHANGED
@@ -10,14 +10,14 @@ import type {
10
10
  ServerDefinition,
11
11
  ServerStreamResultPatchNotification,
12
12
  Transport,
13
- } from "./types.js";
14
- import { serverStreamResultPatchNotificationSchema } from "./types.js";
15
- import { resolveNpxBinary } from "./npx-resolver.js";
16
- import { logger } from "./logger.js";
17
- import { McpOAuthProvider } from "./mcp-oauth-provider.js";
18
- import { supportsOAuth } from "./mcp-auth-flow.js";
19
- import { registerSamplingHandler, type ServerSamplingConfig } from "./sampling-handler.js";
20
- import { interpolateEnvRecord, resolveBearerToken, resolveConfigPath } from "./utils.js";
13
+ } from "./types.ts";
14
+ import { serverStreamResultPatchNotificationSchema } from "./types.ts";
15
+ import { resolveNpxBinary } from "./npx-resolver.ts";
16
+ import { logger } from "./logger.ts";
17
+ import { McpOAuthProvider } from "./mcp-oauth-provider.ts";
18
+ import { supportsOAuth } from "./mcp-auth-flow.ts";
19
+ import { registerSamplingHandler, type ServerSamplingConfig } from "./sampling-handler.ts";
20
+ import { interpolateEnvRecord, resolveBearerToken, resolveConfigPath } from "./utils.ts";
21
21
 
22
22
  interface ServerConnection {
23
23
  client: Client;
package/state.ts CHANGED
@@ -1,10 +1,10 @@
1
- import type { ExtensionContext } from "@mariozechner/pi-coding-agent";
2
- import type { ConsentManager } from "./consent-manager.js";
3
- import type { McpLifecycleManager } from "./lifecycle.js";
4
- import type { McpServerManager } from "./server-manager.js";
5
- import type { ToolMetadata, McpConfig, UiSessionMessages, UiStreamSummary } from "./types.js";
6
- import type { UiResourceHandler } from "./ui-resource-handler.js";
7
- import type { UiServerHandle } from "./ui-server.js";
1
+ import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
2
+ import type { ConsentManager } from "./consent-manager.ts";
3
+ import type { McpLifecycleManager } from "./lifecycle.ts";
4
+ import type { McpServerManager } from "./server-manager.ts";
5
+ import type { ToolMetadata, McpConfig, UiSessionMessages, UiStreamSummary } from "./types.ts";
6
+ import type { UiResourceHandler } from "./ui-resource-handler.ts";
7
+ import type { UiServerHandle } from "./ui-server.ts";
8
8
 
9
9
  export interface CompletedUiSession {
10
10
  serverName: string;
@@ -18,7 +18,7 @@ export interface CompletedUiSession {
18
18
  export type SendMessageFn = (
19
19
  message: {
20
20
  customType: string;
21
- content: Array<{ type: string; text: string }>;
21
+ content: Array<{ type: "text"; text: string }>;
22
22
  display?: string;
23
23
  details?: unknown;
24
24
  },
package/tool-metadata.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { getToolUiResourceUri } from "@modelcontextprotocol/ext-apps/app-bridge";
2
- import type { McpExtensionState } from "./state.js";
3
- import type { ToolMetadata, McpTool, McpResource, ServerEntry } from "./types.js";
4
- import { formatToolName, isToolExcluded } from "./types.js";
5
- import { resourceNameToToolName } from "./resource-tools.js";
6
- import { extractToolUiStreamMode } from "./utils.js";
2
+ import type { McpExtensionState } from "./state.ts";
3
+ import type { ToolMetadata, McpTool, McpResource, ServerEntry } from "./types.ts";
4
+ import { formatToolName, isToolExcluded } from "./types.ts";
5
+ import { resourceNameToToolName } from "./resource-tools.ts";
6
+ import { extractToolUiStreamMode } from "./utils.ts";
7
7
 
8
8
  export function buildToolMetadata(
9
9
  tools: McpTool[],
package/tool-registrar.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  // NOTE: Tools are NOT registered with Pi - only the unified `mcp` proxy tool is registered.
3
3
  // This keeps the LLM context small (1 tool instead of 100s).
4
4
 
5
- import type { McpContent, ContentBlock } from "./types.js";
5
+ import type { McpContent, ContentBlock } from "./types.ts";
6
6
 
7
7
  /**
8
8
  * Transform MCP content types to Pi content blocks.
@@ -0,0 +1,65 @@
1
+ import type { AgentToolResult, ToolRenderResultOptions } from "@earendil-works/pi-coding-agent";
2
+ import { Text } from "@earendil-works/pi-tui";
3
+
4
+ type McpToolResultDetails = Record<string, unknown> & { error?: unknown };
5
+ type McpToolContentBlock = AgentToolResult<McpToolResultDetails>["content"][number];
6
+
7
+ interface RenderTheme {
8
+ fg: (name: string, text: string) => string;
9
+ }
10
+
11
+ interface McpToolRenderContext {
12
+ isError: boolean;
13
+ }
14
+
15
+ export interface McpToolResultDisplay {
16
+ lines: string[];
17
+ truncated: boolean;
18
+ }
19
+
20
+ function blockToLines(block: McpToolContentBlock): string[] {
21
+ if (block.type === "text") {
22
+ return block.text.split("\n");
23
+ }
24
+ return [`[image: ${block.mimeType}]`];
25
+ }
26
+
27
+ export function formatMcpToolResultLines(
28
+ result: Pick<AgentToolResult<McpToolResultDetails>, "content">,
29
+ expanded: boolean,
30
+ maxCollapsedLines = 3,
31
+ ): McpToolResultDisplay {
32
+ const allLines = result.content.flatMap(blockToLines);
33
+ const lines = allLines.length > 0 ? allLines : ["(empty result)"];
34
+
35
+ if (expanded || lines.length <= maxCollapsedLines) {
36
+ return { lines, truncated: false };
37
+ }
38
+
39
+ return {
40
+ lines: [...lines.slice(0, maxCollapsedLines), "…"],
41
+ truncated: true,
42
+ };
43
+ }
44
+
45
+ export function renderMcpToolResult(
46
+ result: AgentToolResult<McpToolResultDetails>,
47
+ options: ToolRenderResultOptions,
48
+ theme: RenderTheme,
49
+ context?: McpToolRenderContext,
50
+ ) {
51
+ if (options.isPartial) {
52
+ return new Text(theme.fg("warning", "Running MCP tool..."), 0, 0);
53
+ }
54
+
55
+ const hasErrorDetails = Boolean(result.details.error);
56
+ const display = formatMcpToolResultLines(result, options.expanded || context?.isError === true || hasErrorDetails);
57
+ const output = display.lines
58
+ .map((line) => line === "…" ? theme.fg("muted", line) : theme.fg("toolOutput", line))
59
+ .join("\n");
60
+ const hint = display.truncated && !options.expanded
61
+ ? `\n${theme.fg("muted", "(Ctrl+O to expand)")}`
62
+ : "";
63
+
64
+ return new Text(`${output}${hint}`, 0, 0);
65
+ }
package/types.ts CHANGED
@@ -2,8 +2,8 @@
2
2
  import type { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
3
3
  import type { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
4
4
  import type { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
5
- import type { TextContent, ImageContent } from "@mariozechner/pi-ai";
6
- import type { UiStreamMode } from "./ui-stream-types.js";
5
+ import type { TextContent, ImageContent } from "@earendil-works/pi-ai";
6
+ import type { UiStreamMode } from "./ui-stream-types.ts";
7
7
 
8
8
  // Transport type (stdio + HTTP)
9
9
  export type Transport =
@@ -137,7 +137,7 @@ export {
137
137
  type UiStreamResultPatchNotification,
138
138
  type ServerStreamResultPatchNotification,
139
139
  type UiStreamSummary,
140
- } from "./ui-stream-types.js";
140
+ } from "./ui-stream-types.ts";
141
141
 
142
142
  export interface UiMessageParams {
143
143
  role?: string;
@@ -365,10 +365,17 @@ export interface ServerProvenance {
365
365
  importKind?: string;
366
366
  }
367
367
 
368
+ export interface McpAuthResult {
369
+ ok: boolean;
370
+ message?: string;
371
+ }
372
+
368
373
  export interface McpPanelCallbacks {
369
374
  reconnect: (serverName: string) => Promise<boolean>;
375
+ canAuthenticate: (serverName: string) => boolean;
376
+ authenticate: (serverName: string) => Promise<McpAuthResult>;
370
377
  getConnectionStatus: (serverName: string) => "connected" | "idle" | "failed" | "needs-auth";
371
- refreshCacheAfterReconnect: (serverName: string) => import("./metadata-cache.js").ServerCacheEntry | null;
378
+ refreshCacheAfterReconnect: (serverName: string) => import("./metadata-cache.ts").ServerCacheEntry | null;
372
379
  }
373
380
 
374
381
  export interface McpPanelResult {
@@ -1,9 +1,9 @@
1
1
  import { RESOURCE_MIME_TYPE } from "@modelcontextprotocol/ext-apps/app-bridge";
2
2
  import type { ReadResourceResult } from "@modelcontextprotocol/sdk/types.js";
3
- import { ResourceFetchError, ResourceParseError } from "./errors.js";
4
- import { logger } from "./logger.js";
5
- import type { McpServerManager } from "./server-manager.js";
6
- import type { UiResourceContent, UiResourceMeta } from "./types.js";
3
+ import { ResourceFetchError, ResourceParseError } from "./errors.ts";
4
+ import { logger } from "./logger.ts";
5
+ import type { McpServerManager } from "./server-manager.ts";
6
+ import type { UiResourceContent, UiResourceMeta } from "./types.ts";
7
7
 
8
8
  interface ResourceContentRecord {
9
9
  uri?: string;
package/ui-server.ts CHANGED
@@ -7,11 +7,11 @@ import type {
7
7
  CallToolRequest,
8
8
  CallToolResult,
9
9
  } from "@modelcontextprotocol/sdk/types.js";
10
- import type { ConsentManager } from "./consent-manager.js";
11
- import { ServerError, wrapError } from "./errors.js";
12
- import { buildHostHtmlTemplate, buildCspMetaContent, applyCspMeta } from "./host-html-template.js";
13
- import { logger } from "./logger.js";
14
- import type { McpServerManager } from "./server-manager.js";
10
+ import type { ConsentManager } from "./consent-manager.ts";
11
+ import { ServerError, wrapError } from "./errors.ts";
12
+ import { buildHostHtmlTemplate, buildCspMetaContent, applyCspMeta } from "./host-html-template.ts";
13
+ import { logger } from "./logger.ts";
14
+ import type { McpServerManager } from "./server-manager.ts";
15
15
  import {
16
16
  extractUiPromptText,
17
17
  getVisualizationStreamEnvelope,
@@ -27,7 +27,7 @@ import {
27
27
  type UiResourceContent,
28
28
  type UiSessionMessages,
29
29
  type UiStreamSummary,
30
- } from "./types.js";
30
+ } from "./types.ts";
31
31
 
32
32
  const MAX_BODY_SIZE = 2 * 1024 * 1024;
33
33
  const ABANDONED_GRACE_MS = 60_000;
package/ui-session.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { randomUUID } from "node:crypto";
2
2
  import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
3
- import type { McpExtensionState } from "./state.js";
3
+ import type { McpExtensionState } from "./state.ts";
4
4
  import {
5
5
  extractUiPromptText,
6
6
  UI_STREAM_HOST_CONTEXT_KEY,
@@ -10,10 +10,10 @@ import {
10
10
  type UiMessageParams,
11
11
  type UiModelContextParams,
12
12
  type UiStreamMode,
13
- } from "./types.js";
14
- import { logger } from "./logger.js";
15
- import { startUiServer, type UiServerHandle } from "./ui-server.js";
16
- import { isGlimpseAvailable, openGlimpseWindow } from "./glimpse-ui.js";
13
+ } from "./types.ts";
14
+ import { logger } from "./logger.ts";
15
+ import { startUiServer, type UiServerHandle } from "./ui-server.ts";
16
+ import { isGlimpseAvailable, openGlimpseWindow } from "./glimpse-ui.ts";
17
17
 
18
18
  let activeGlimpseWindow: { close(): void } | null = null;
19
19
 
package/utils.ts CHANGED
@@ -1,7 +1,7 @@
1
- import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
1
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
2
  import { homedir, platform } from "node:os";
3
3
  import { join } from "node:path";
4
- import type { McpConfig, ServerEntry } from "./types.js";
4
+ import type { McpConfig, ServerEntry } from "./types.ts";
5
5
 
6
6
  async function execOpen(pi: ExtensionAPI, target: string, browser?: string) {
7
7
  const os = platform();