pi-mcp-adapter 2.3.5 → 2.4.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 +26 -0
- package/README.md +74 -7
- package/cli.js +152 -86
- package/commands.ts +116 -9
- package/config.ts +566 -126
- package/direct-tools.ts +97 -6
- package/index.ts +97 -78
- package/init.ts +3 -12
- package/mcp-auth-flow.ts +61 -40
- package/mcp-panel.ts +51 -14
- package/mcp-setup-panel.ts +576 -0
- package/metadata-cache.ts +12 -3
- package/onboarding-state.ts +68 -0
- package/package.json +3 -1
- package/proxy-modes.ts +169 -25
- package/tool-metadata.ts +9 -1
- package/types.ts +33 -0
- package/utils.ts +18 -9
package/mcp-panel.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { matchesKey, truncateToWidth, visibleWidth } from "@mariozechner/pi-tui";
|
|
2
|
+
import { isToolExcluded } from "./types.js";
|
|
2
3
|
import type { McpConfig, McpPanelCallbacks, McpPanelResult, ServerProvenance } from "./types.js";
|
|
3
4
|
import { resourceNameToToolName } from "./resource-tools.js";
|
|
4
5
|
import type { MetadataCache, ServerCacheEntry, CachedTool } from "./metadata-cache.js";
|
|
@@ -93,6 +94,8 @@ interface ServerState {
|
|
|
93
94
|
expanded: boolean;
|
|
94
95
|
source: "user" | "project" | "import";
|
|
95
96
|
importKind?: string;
|
|
97
|
+
excludeTools?: string[];
|
|
98
|
+
exposeResources: boolean;
|
|
96
99
|
connectionStatus: ConnectionStatus;
|
|
97
100
|
tools: ToolState[];
|
|
98
101
|
hasCachedData: boolean;
|
|
@@ -105,6 +108,8 @@ interface VisibleItem {
|
|
|
105
108
|
}
|
|
106
109
|
|
|
107
110
|
class McpPanel {
|
|
111
|
+
private noticeLines: string[];
|
|
112
|
+
private prefix: "server" | "none" | "short";
|
|
108
113
|
private servers: ServerState[] = [];
|
|
109
114
|
private cursorIndex = 0;
|
|
110
115
|
private nameQuery = "";
|
|
@@ -130,8 +135,11 @@ class McpPanel {
|
|
|
130
135
|
private callbacks: McpPanelCallbacks,
|
|
131
136
|
tui: { requestRender(): void },
|
|
132
137
|
private done: (result: McpPanelResult) => void,
|
|
138
|
+
noticeLines: string[] = [],
|
|
133
139
|
) {
|
|
134
140
|
this.tui = tui;
|
|
141
|
+
this.noticeLines = noticeLines;
|
|
142
|
+
this.prefix = config.settings?.toolPrefix ?? "server";
|
|
135
143
|
|
|
136
144
|
for (const [serverName, definition] of Object.entries(config.mcpServers)) {
|
|
137
145
|
const prov = provenance.get(serverName);
|
|
@@ -148,6 +156,10 @@ class McpPanel {
|
|
|
148
156
|
const tools: ToolState[] = [];
|
|
149
157
|
if (serverCache) {
|
|
150
158
|
for (const tool of serverCache.tools ?? []) {
|
|
159
|
+
if (isToolExcluded(tool.name, serverName, this.prefix, definition.excludeTools)) {
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
|
|
151
163
|
const isDirect = toolFilter === true || (Array.isArray(toolFilter) && toolFilter.includes(tool.name));
|
|
152
164
|
tools.push({
|
|
153
165
|
name: tool.name,
|
|
@@ -160,6 +172,10 @@ class McpPanel {
|
|
|
160
172
|
if (definition.exposeResources !== false) {
|
|
161
173
|
for (const resource of serverCache.resources ?? []) {
|
|
162
174
|
const baseName = `get_${resourceNameToToolName(resource.name)}`;
|
|
175
|
+
if (isToolExcluded(baseName, serverName, this.prefix, definition.excludeTools)) {
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
|
|
163
179
|
const isDirect = toolFilter === true || (Array.isArray(toolFilter) && toolFilter.includes(baseName));
|
|
164
180
|
const ct: CachedTool = { name: baseName, description: resource.description };
|
|
165
181
|
tools.push({
|
|
@@ -180,6 +196,8 @@ class McpPanel {
|
|
|
180
196
|
expanded: false,
|
|
181
197
|
source: prov?.kind ?? "user",
|
|
182
198
|
importKind: prov?.importKind,
|
|
199
|
+
excludeTools: definition.excludeTools,
|
|
200
|
+
exposeResources: definition.exposeResources !== false,
|
|
183
201
|
connectionStatus: status,
|
|
184
202
|
tools,
|
|
185
203
|
hasCachedData: !!serverCache,
|
|
@@ -385,8 +403,10 @@ class McpPanel {
|
|
|
385
403
|
server.hasCachedData = true;
|
|
386
404
|
}
|
|
387
405
|
this.tui.requestRender();
|
|
388
|
-
}).catch(() => {
|
|
406
|
+
}).catch((error) => {
|
|
389
407
|
server.connectionStatus = "failed";
|
|
408
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
409
|
+
this.authNotice = `Reconnect failed for ${server.name}: ${message}`;
|
|
390
410
|
this.tui.requestRender();
|
|
391
411
|
});
|
|
392
412
|
return;
|
|
@@ -477,6 +497,10 @@ class McpPanel {
|
|
|
477
497
|
|
|
478
498
|
const newTools: ToolState[] = [];
|
|
479
499
|
for (const tool of entry.tools ?? []) {
|
|
500
|
+
if (isToolExcluded(tool.name, server.name, this.prefix, server.excludeTools)) {
|
|
501
|
+
continue;
|
|
502
|
+
}
|
|
503
|
+
|
|
480
504
|
const prev = existingState.get(tool.name);
|
|
481
505
|
const isDirect = prev !== undefined ? prev : false;
|
|
482
506
|
newTools.push({
|
|
@@ -488,18 +512,24 @@ class McpPanel {
|
|
|
488
512
|
});
|
|
489
513
|
}
|
|
490
514
|
|
|
491
|
-
|
|
492
|
-
const
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
isDirect
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
515
|
+
if (server.exposeResources) {
|
|
516
|
+
for (const resource of entry.resources ?? []) {
|
|
517
|
+
const baseName = `get_${resourceNameToToolName(resource.name)}`;
|
|
518
|
+
if (isToolExcluded(baseName, server.name, this.prefix, server.excludeTools)) {
|
|
519
|
+
continue;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
const prev = existingState.get(baseName);
|
|
523
|
+
const isDirect = prev !== undefined ? prev : false;
|
|
524
|
+
const ct: CachedTool = { name: baseName, description: resource.description };
|
|
525
|
+
newTools.push({
|
|
526
|
+
name: baseName,
|
|
527
|
+
description: resource.description ?? `Read resource: ${resource.uri}`,
|
|
528
|
+
isDirect,
|
|
529
|
+
wasDirect: prev !== undefined ? server.tools.find((t) => t.name === baseName)?.wasDirect ?? false : false,
|
|
530
|
+
estimatedTokens: estimateTokens(ct),
|
|
531
|
+
});
|
|
532
|
+
}
|
|
503
533
|
}
|
|
504
534
|
|
|
505
535
|
server.tools = newTools;
|
|
@@ -539,6 +569,12 @@ class McpPanel {
|
|
|
539
569
|
}
|
|
540
570
|
|
|
541
571
|
lines.push(emptyRow());
|
|
572
|
+
if (this.noticeLines.length > 0) {
|
|
573
|
+
for (const notice of this.noticeLines) {
|
|
574
|
+
lines.push(row(fg(t.hint, italic(notice))));
|
|
575
|
+
}
|
|
576
|
+
lines.push(emptyRow());
|
|
577
|
+
}
|
|
542
578
|
lines.push(divider());
|
|
543
579
|
|
|
544
580
|
if (this.servers.length === 0) {
|
|
@@ -708,6 +744,7 @@ export function createMcpPanel(
|
|
|
708
744
|
callbacks: McpPanelCallbacks,
|
|
709
745
|
tui: { requestRender(): void },
|
|
710
746
|
done: (result: McpPanelResult) => void,
|
|
747
|
+
options?: { noticeLines?: string[] },
|
|
711
748
|
): McpPanel & { dispose(): void } {
|
|
712
|
-
return new McpPanel(config, cache, provenance, callbacks, tui, done);
|
|
749
|
+
return new McpPanel(config, cache, provenance, callbacks, tui, done, options?.noticeLines ?? []);
|
|
713
750
|
}
|