pi-mcp-adapter 2.20.0 → 2.21.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/CHANGELOG.md +25 -0
- package/README.md +27 -6
- package/agent-plugin-loader.ts +377 -0
- package/commands.ts +7 -5
- package/config.ts +69 -26
- package/index.ts +16 -5
- package/mcp-auth-flow.ts +23 -9
- package/mcp-code.ts +4 -2
- package/mcp-oauth-provider.ts +1 -0
- package/mcp-panel.ts +3 -2
- package/mcp-probe.ts +131 -34
- package/metadata-cache.ts +1 -1
- package/package.json +3 -1
- package/panel-keys.ts +20 -4
- package/server-manager.ts +14 -4
- package/tool-metadata.ts +1 -1
- package/tool-result-renderer.ts +14 -2
- package/types.ts +52 -0
- package/ui-app-bridge-helpers.ts +40 -0
- package/ui-resource-handler.ts +1 -1
- package/ui-server.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [2.21.0] - 2026-08-06
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- Added MCP 2026-07-28 endpoint probing and defaulted curated remote setup presets to automatic protocol negotiation for stateless MCP servers.
|
|
14
|
+
- Added `resolveServerFromToolName` so permission brokers can map prefixed MCP tool names back to their owning server. Thanks @jagaliano for PR #295.
|
|
15
|
+
- Added per-server `oauth.skipIssuerMetadataValidation` for known-misconfigured OAuth servers. Thanks @embik for issue #297.
|
|
16
|
+
- Added a configurable `mcp.panel.save` keybinding for the MCP panel Save action. Thanks @tim-hilde for issue #299.
|
|
17
|
+
- Added `settings.agentPluginPaths` to load MCP servers from Agent Plugins 1.0 packages.
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
- Refined MCP endpoint probing internals with typed strategies while preserving request order, fallback behavior, and diagnostics.
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
- Rejected Agent Plugin command paths that escape the plugin directory and skipped normalized server-name collisions instead of overwriting servers.
|
|
24
|
+
- Stopped `/mcp` from inspecting host-specific config files when host config discovery is disabled. Thanks @rtfmkiesel for issue #292.
|
|
25
|
+
- Stopped optional numeric `mcp` and `mcpScript` tool parameters from leaking TypeBox internal markers into serialized schemas. Thanks @RainbowXie for issue #289 and PR #290.
|
|
26
|
+
- Forwarded RFC 9207 OAuth callback issuers to the MCP SDK during manual authorization completion. Thanks @tkoenig for issue #293 and PR #294, and @ugur-murat-alt for independent live verification.
|
|
27
|
+
- Kept `mcpScript` `tools.describe()` from omitting parameter information when TypeScript shape rendering falls back. Thanks @sheurich for issue #288.
|
|
28
|
+
- Reduced repeated collapsed MCP result rendering allocation after large or truncated tool outputs. Thanks @cp-yu for issue #291.
|
|
29
|
+
|
|
30
|
+
## [2.20.1] - 2026-08-04
|
|
31
|
+
|
|
32
|
+
### Fixed
|
|
33
|
+
- Stopped server-side MCP app helper imports from requiring the legacy `@modelcontextprotocol/sdk` peer at extension load time, fixing peerless Pi installs of 2.20.0. Thanks @aryzing for issue #285 and @DevDominic, @Shinkicast, and @marceloid for confirmations.
|
|
34
|
+
|
|
10
35
|
## [2.20.0] - 2026-08-04
|
|
11
36
|
|
|
12
37
|
### Added
|
package/README.md
CHANGED
|
@@ -58,7 +58,7 @@ Pi also reads Pi-owned override files for settings and host-specific compatibili
|
|
|
58
58
|
- `<Pi agent dir>/mcp.json` — Pi global override (`~/.pi/agent/mcp.json` by default)
|
|
59
59
|
- `.pi/mcp.json` — Pi project override
|
|
60
60
|
|
|
61
|
-
Host-specific configs are detected and shown by `/mcp setup` and `pi-mcp-adapter init`, but they are not loaded automatically. To explicitly opt in to host-config fallback discovery, set `settings.hostConfigDiscovery` to `"on"` or run `pi-mcp-adapter init --discover-host-configs`. The default is `"off"`; `"prompt"` is available for integrations that want detection without activation. Host configs are lower precedence than every shared and Pi-owned source, and `/mcp setup` continues to offer explicit import adoption. Discovery reports source paths, provenance, and same-name conflicts; it never writes to external host files or silently launches commands from them.
|
|
61
|
+
Host-specific configs are detected and shown by `/mcp setup` and `pi-mcp-adapter init`, but they are not loaded automatically. The normal `/mcp` panel does not scan host-specific files when `settings.hostConfigDiscovery` is `"off"`. To explicitly opt in to host-config fallback discovery, set `settings.hostConfigDiscovery` to `"on"` or run `pi-mcp-adapter init --discover-host-configs`. The default is `"off"`; `"prompt"` is available for integrations that want detection without activation. Host configs are lower precedence than every shared and Pi-owned source, and `/mcp setup` continues to offer explicit import adoption. Discovery reports source paths, provenance, and same-name conflicts; it never writes to external host files or silently launches commands from them.
|
|
62
62
|
|
|
63
63
|
Precedence is:
|
|
64
64
|
|
|
@@ -109,6 +109,23 @@ Use the shared MCP files when you want one setup to work across hosts, and Pi-ow
|
|
|
109
109
|
|
|
110
110
|
Pi-specific files are the write targets for imported or shared global servers when Pi needs to persist adapter-only settings such as `directTools`.
|
|
111
111
|
|
|
112
|
+
### Agent Plugins
|
|
113
|
+
|
|
114
|
+
The adapter can load MCP servers from [Agent Plugins](https://agent-plugins.org/) packages when you list plugin directories in `settings.agentPluginPaths`:
|
|
115
|
+
|
|
116
|
+
```json
|
|
117
|
+
{
|
|
118
|
+
"settings": {
|
|
119
|
+
"agentPluginPaths": ["./plugins/acme-tools"]
|
|
120
|
+
},
|
|
121
|
+
"mcpServers": {}
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Each directory must contain a valid Agent Plugins 1.0 `plugin.json`. If it also has a root `mcp.json`, the adapter loads its `mcpServers` entries and prefixes them as `<plugin>__<server>`. The loader uses the Agent Plugins transport declared by each server `type` and skips invalid entries without blocking other servers. For stdio plugin servers, `${PLUGIN_ROOT}` and `${PLUGIN_DATA}` are expanded only in `args`, `env`, and `cwd`; the adapter sets both variables for the child process and stores plugin data under the Pi agent directory.
|
|
126
|
+
|
|
127
|
+
Agent Plugins is a portable package format. Native Pi MCP config remains `.mcp.json`, `~/.config/mcp/mcp.json`, and Pi-owned overrides.
|
|
128
|
+
|
|
112
129
|
### SDK configuration
|
|
113
130
|
|
|
114
131
|
Use `createMcpAdapter` when an SDK or server integration already owns its MCP configuration:
|
|
@@ -181,12 +198,13 @@ In the configuration examples below, `30000` is illustrative only. If `requestTi
|
|
|
181
198
|
| `headers` | HTTP headers; supports `${VAR}` and `$env:VAR` interpolation. A value beginning with `!` runs a command when the HTTP server connects or OAuth authenticates; use `!!` for a literal leading `!`. |
|
|
182
199
|
| `auth` | `"bearer"` or `"oauth"` |
|
|
183
200
|
| `oauth.grantType` | `"authorization_code"` (default) or `"client_credentials"` for non-interactive machine auth |
|
|
184
|
-
| `oauth.clientId` | Pre-registered OAuth client ID;
|
|
201
|
+
| `oauth.clientId` | Pre-registered OAuth client ID. MCP 2026 prefers pre-registered clients or Client ID Metadata Documents; this adapter falls back to Dynamic Client Registration when the ID is omitted and the server supports it. |
|
|
185
202
|
| `oauth.clientSecret` | OAuth client secret for confidential clients; a value beginning with `!` runs a command when OAuth authenticates, while `!!` escapes a literal leading `!` |
|
|
186
203
|
| `oauth.scope` | Requested OAuth scopes |
|
|
187
204
|
| `oauth.redirectUri` | Exact localhost redirect URI for browser OAuth, including port and path, for providers that pre-register callbacks |
|
|
188
|
-
| `oauth.clientName` | Client display name advertised during
|
|
189
|
-
| `oauth.clientUri` | Client homepage URI advertised during
|
|
205
|
+
| `oauth.clientName` | Client display name advertised during Dynamic Client Registration fallback |
|
|
206
|
+
| `oauth.clientUri` | Client homepage URI advertised during Dynamic Client Registration fallback |
|
|
207
|
+
| `oauth.skipIssuerMetadataValidation` | `true` disables the OAuth authorization-server metadata issuer check for this server. This weakens OAuth mix-up protection and should only be used for known-misconfigured internal servers while their metadata is being fixed. |
|
|
190
208
|
| `bearerToken` / `bearerTokenEnv` | Token or env var name; `bearerToken` supports `${VAR}` and `$env:VAR` interpolation. A leading `!` in `bearerToken` runs a command when the HTTP server connects; use `!!` for a literal leading `!`. |
|
|
191
209
|
| `lifecycle` | `"lazy"` (default), `"eager"`, `"keep-alive"`, or `"lazy-keep-alive"` |
|
|
192
210
|
| `idleTimeout` | Minutes before idle disconnect (overrides global) |
|
|
@@ -205,7 +223,7 @@ In the configuration examples below, `30000` is illustrative only. If `requestTi
|
|
|
205
223
|
|
|
206
224
|
The adapter defaults to `protocolVersion: "legacy"`. Omitting the field uses the classic MCP initialize sequence without `server/discover` or 2026 headers, preserving compatibility with deployed 2025-era servers.
|
|
207
225
|
|
|
208
|
-
Use `"auto"` to probe for MCP 2026-07-28 and conservatively fall back to the classic handshake when the server provides legacy evidence. For stdio servers, the SDK probes with a short-lived sibling process before starting the session process, so each fresh auto connection adds one process spawn and can wait for the configured request timeout. Explicit Unix sockets are custom transports and probe in place. HTTP auto negotiation uses the actual Streamable HTTP connection; the adapter falls back to legacy SSE only when the endpoint definitively rejects Streamable HTTP (for example 404/405/406/415), never for authentication failures, cancellation, timeouts, or server errors.
|
|
226
|
+
Use `"auto"` to probe for MCP 2026-07-28 and conservatively fall back to the classic handshake when the server provides legacy evidence. Set it for Cloudflare Workers `createMcpHandler` and other MCP SDK v2 stateless servers. The adapter keeps `"legacy"` as the global default for compatibility. For stdio servers, the SDK probes with a short-lived sibling process before starting the session process, so each fresh auto connection adds one process spawn and can wait for the configured request timeout. Explicit Unix sockets are custom transports and probe in place. HTTP auto negotiation uses the actual Streamable HTTP connection; the adapter falls back to legacy SSE only when the endpoint definitively rejects Streamable HTTP (for example 404/405/406/415), never for authentication failures, cancellation, timeouts, or server errors.
|
|
209
227
|
|
|
210
228
|
Use `"2026-07-28"` to pin that revision. Pinning has no legacy or SSE fallback and fails if the server does not offer the requested version.
|
|
211
229
|
|
|
@@ -213,6 +231,8 @@ The stable SDK handles era-specific request envelopes, result decoding, list-cha
|
|
|
213
231
|
|
|
214
232
|
For pre-registered browser OAuth clients, set `oauth.redirectUri` to the exact callback registered with the provider, for example `"http://localhost:3118/callback"`. Dynamic clients normally omit it and use a lazy OS-assigned localhost callback port.
|
|
215
233
|
|
|
234
|
+
If an internal authorization server publishes mismatched OAuth metadata and cannot be fixed immediately, set `oauth.skipIssuerMetadataValidation: true` on that server only. This is security-weakening. It disables the RFC 8414 issuer echo check and should not be used for public or untrusted servers.
|
|
235
|
+
|
|
216
236
|
Secret values in `headers`, `bearerToken`, `oauth.clientSecret`, and stdio `env` may use a leading `!command` to obtain their value at connection or authentication time. The command runs with stdin and stderr suppressed, stdout is limited to 1 MiB and trimmed, and it must finish within 10 seconds with non-empty output; failures stop the connection or authentication flow. Commands are not run during OAuth discovery or while reading, merging, previewing, hashing, or rendering configuration. Use `!!` to escape a literal leading `!`; ordinary and escaped values retain environment interpolation.
|
|
217
237
|
|
|
218
238
|
### Shared MCP processes with rmcp-mux
|
|
@@ -294,6 +314,7 @@ When any enabled server uses `eager` or `keep-alive`, initialization also starts
|
|
|
294
314
|
| `showStatusIcon` | Show the plug icon in MCP status and connection text (default: `true`). Set to `false` for plain `MCP: ...` text. |
|
|
295
315
|
| `mcpFooterStatus` | MCP footer verbosity: `"full"` (default), `"compact"` for `MCP connected/enabled`, or `"off"` to clear the persistent footer status. `/mcp status` remains available. |
|
|
296
316
|
| `hostConfigDiscovery` | Host-specific config policy: `"off"` (default), `"prompt"` (detect/report only), or `"on"` (explicitly load detected host configs as the lowest-precedence fallback) |
|
|
317
|
+
| `agentPluginPaths` | Agent Plugins package directories to load MCP servers from. Relative paths resolve from the active project cwd. |
|
|
297
318
|
| `approveTools` | `true` to require approval before every MCP tool call, or an array of glob patterns such as `["github_delete_*", "notion_update_*"]`. Per-server `approveTools` overrides this. |
|
|
298
319
|
| `oauthDir` | Legacy OAuth `tokens.json` import directory for this MCP config. Relative paths resolve from the active project cwd. `MCP_OAUTH_DIR` still wins when set. Persistent OAuth credentials are stored in the OS credential store, not this directory. |
|
|
299
320
|
| `mcpServers.<name>.oauth.authorizationParams` | Extra authorization URL parameters for provider-specific OAuth extensions. Flow-owned parameters such as `client_id`, `redirect_uri`, `scope`, `state`, `code_challenge`, `response_type`, and `resource` cannot be overridden. |
|
|
@@ -509,7 +530,7 @@ If prompt-cache stability matters more than automatic direct-tool hot-loading, s
|
|
|
509
530
|
|
|
510
531
|
When you change direct-tool toggles in `/mcp`, the extension updates direct tool registration in the current session. Broader setup writes from `/mcp setup` still use Pi's normal reload flow because they can add or restructure MCP config files.
|
|
511
532
|
|
|
512
|
-
**Interactive configuration:** Run `/mcp` to open an interactive panel showing all servers with connection status, tools, and direct/proxy toggles. You can reconnect servers and toggle tools between direct and proxy from the same overlay. For OAuth, press Enter on a server that needs auth or `ctrl+a` on any OAuth server.
|
|
533
|
+
**Interactive configuration:** Run `/mcp` to open an interactive panel showing all servers with connection status, tools, and direct/proxy toggles. You can reconnect servers and toggle tools between direct and proxy from the same overlay. For OAuth, press Enter on a server that needs auth or `ctrl+a` on any OAuth server. The Save action defaults to `ctrl+s` and can be remapped with the `mcp.panel.save` keybinding.
|
|
513
534
|
|
|
514
535
|
**Guided first-run setup:** Run `/mcp setup` to inspect detected shared MCP files, adopt compatibility imports from other hosts, open discovered config paths, preview exact before/after file diffs for writes, scaffold a minimal project `.mcp.json`, add a curated known server (DeepWiki, Context7, Notion, GitHub, or Chrome DevTools), or quick-add RepoPrompt into a standard/shared MCP file.
|
|
515
536
|
|
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { isAbsolute, relative, resolve, sep } from "node:path";
|
|
3
|
+
import { getAgentPath } from "./agent-dir.ts";
|
|
4
|
+
import type { McpConfig, ServerEntry } from "./types.ts";
|
|
5
|
+
|
|
6
|
+
const PLUGIN_SCHEMA = "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json";
|
|
7
|
+
const MCP_SCHEMA = "https://agent-plugins.org/schemas/1.0.0/mcp.schema.json";
|
|
8
|
+
const PLUGIN_NAME_PATTERN = /^(?!.*(?:--|\.\.))[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?$/;
|
|
9
|
+
const PLUGIN_MANIFEST_FIELDS = new Set([
|
|
10
|
+
"$schema",
|
|
11
|
+
"name",
|
|
12
|
+
"version",
|
|
13
|
+
"description",
|
|
14
|
+
"author",
|
|
15
|
+
"homepage",
|
|
16
|
+
"repository",
|
|
17
|
+
"license",
|
|
18
|
+
"keywords",
|
|
19
|
+
"extensions",
|
|
20
|
+
]);
|
|
21
|
+
const MCP_CONFIG_FIELDS = new Set(["$schema", "mcpServers"]);
|
|
22
|
+
const STDIO_FIELDS = new Set(["type", "command", "args", "env", "cwd"]);
|
|
23
|
+
const HTTP_FIELDS = new Set(["type", "url", "headers"]);
|
|
24
|
+
|
|
25
|
+
interface AgentPluginManifest {
|
|
26
|
+
name: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface AgentPluginSummary {
|
|
30
|
+
path: string;
|
|
31
|
+
name?: string;
|
|
32
|
+
serverCount: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function loadAgentPluginConfigs(paths: unknown, cwd = process.cwd()): McpConfig {
|
|
36
|
+
const mcpServers: Record<string, ServerEntry> = {};
|
|
37
|
+
for (const pluginPath of getPluginPaths(paths)) {
|
|
38
|
+
const loaded = loadAgentPluginMcpConfig(pluginPath, cwd);
|
|
39
|
+
if (!loaded) continue;
|
|
40
|
+
for (const [serverName, server] of Object.entries(loaded.mcpServers)) {
|
|
41
|
+
if (mcpServers[serverName]) {
|
|
42
|
+
console.warn(`Agent Plugin at ${resolvePluginPath(pluginPath, cwd)} skips duplicate normalized MCP server ${serverName}`);
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
mcpServers[serverName] = server;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return { mcpServers };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function getAgentPluginSummaries(paths: unknown, cwd = process.cwd()): AgentPluginSummary[] {
|
|
52
|
+
return getPluginPaths(paths).map(path => {
|
|
53
|
+
const pluginRoot = resolvePluginPath(path, cwd);
|
|
54
|
+
const loaded = loadAgentPluginMcpConfig(path, cwd);
|
|
55
|
+
const manifest = loaded ? readPluginManifest(pluginRoot, false) : null;
|
|
56
|
+
return {
|
|
57
|
+
path: pluginRoot,
|
|
58
|
+
...(manifest?.name ? { name: manifest.name } : {}),
|
|
59
|
+
serverCount: loaded ? Object.keys(loaded.mcpServers).length : 0,
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function getPluginPaths(paths: unknown): string[] {
|
|
65
|
+
return Array.isArray(paths) ? paths.filter((path): path is string => typeof path === "string") : [];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function loadAgentPluginMcpConfig(path: string, cwd: string): McpConfig | null {
|
|
69
|
+
const pluginRoot = resolvePluginPath(path, cwd);
|
|
70
|
+
const manifest = readPluginManifest(pluginRoot, true);
|
|
71
|
+
if (!manifest) return null;
|
|
72
|
+
|
|
73
|
+
const mcpPath = resolve(pluginRoot, "mcp.json");
|
|
74
|
+
if (!existsSync(mcpPath)) return { mcpServers: {} };
|
|
75
|
+
if (!statSync(mcpPath).isFile()) {
|
|
76
|
+
console.warn(`Agent Plugin ${manifest.name} has invalid MCP config: mcp.json is not a regular file`);
|
|
77
|
+
return { mcpServers: {} };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
let raw: unknown;
|
|
81
|
+
try {
|
|
82
|
+
raw = JSON.parse(readFileSync(mcpPath, "utf8"));
|
|
83
|
+
} catch (error) {
|
|
84
|
+
console.warn(`Agent Plugin ${manifest.name} has invalid MCP config: failed to parse mcp.json`, error);
|
|
85
|
+
return { mcpServers: {} };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return translateAgentPluginMcpConfig(raw, manifest, pluginRoot);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function readPluginManifest(pluginRoot: string, report: boolean): AgentPluginManifest | null {
|
|
92
|
+
const manifestPath = resolve(pluginRoot, "plugin.json");
|
|
93
|
+
if (!existsSync(manifestPath)) {
|
|
94
|
+
if (report) console.warn(`Agent Plugin at ${pluginRoot} is invalid: missing plugin.json`);
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
if (!statSync(manifestPath).isFile()) {
|
|
98
|
+
if (report) console.warn(`Agent Plugin at ${pluginRoot} is invalid: plugin.json is not a regular file`);
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
let raw: unknown;
|
|
103
|
+
try {
|
|
104
|
+
raw = JSON.parse(readFileSync(manifestPath, "utf8"));
|
|
105
|
+
} catch (error) {
|
|
106
|
+
if (report) console.warn(`Agent Plugin at ${pluginRoot} is invalid: failed to parse plugin.json`, error);
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
110
|
+
if (report) console.warn(`Agent Plugin at ${pluginRoot} is invalid: plugin.json must be an object`);
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const manifest = raw as Record<string, unknown>;
|
|
115
|
+
for (const key of Object.keys(manifest)) {
|
|
116
|
+
if (!PLUGIN_MANIFEST_FIELDS.has(key) && report) {
|
|
117
|
+
console.warn(`Agent Plugin at ${pluginRoot} ignores unknown plugin.json field: ${key}`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (manifest.$schema !== PLUGIN_SCHEMA) {
|
|
121
|
+
if (report) console.warn(`Agent Plugin at ${pluginRoot} is invalid: unsupported plugin.json $schema`);
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
if (typeof manifest.name !== "string" || manifest.name.length < 1 || manifest.name.length > 64 || !PLUGIN_NAME_PATTERN.test(manifest.name)) {
|
|
125
|
+
if (report) console.warn(`Agent Plugin at ${pluginRoot} is invalid: plugin.json name is invalid`);
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
if (manifest.extensions !== undefined && (!manifest.extensions || typeof manifest.extensions !== "object" || Array.isArray(manifest.extensions))) {
|
|
129
|
+
if (report) console.warn(`Agent Plugin ${manifest.name} ignores non-object plugin.json extensions`);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return { name: manifest.name };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function translateAgentPluginMcpConfig(raw: unknown, manifest: AgentPluginManifest, pluginRoot: string): McpConfig {
|
|
136
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
137
|
+
console.warn(`Agent Plugin ${manifest.name} has invalid MCP config: mcp.json must be an object`);
|
|
138
|
+
return { mcpServers: {} };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const mcpConfig = raw as Record<string, unknown>;
|
|
142
|
+
for (const key of Object.keys(mcpConfig)) {
|
|
143
|
+
if (!MCP_CONFIG_FIELDS.has(key)) {
|
|
144
|
+
console.warn(`Agent Plugin ${manifest.name} has invalid MCP config: unknown top-level field ${key}`);
|
|
145
|
+
return { mcpServers: {} };
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (mcpConfig.$schema !== MCP_SCHEMA) {
|
|
149
|
+
console.warn(`Agent Plugin ${manifest.name} has invalid MCP config: unsupported mcp.json $schema`);
|
|
150
|
+
return { mcpServers: {} };
|
|
151
|
+
}
|
|
152
|
+
if (!mcpConfig.mcpServers || typeof mcpConfig.mcpServers !== "object" || Array.isArray(mcpConfig.mcpServers)) {
|
|
153
|
+
console.warn(`Agent Plugin ${manifest.name} has invalid MCP config: mcpServers must be an object`);
|
|
154
|
+
return { mcpServers: {} };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const mcpServers: Record<string, ServerEntry> = {};
|
|
158
|
+
for (const [serverName, entry] of Object.entries(mcpConfig.mcpServers)) {
|
|
159
|
+
const translated = translateAgentPluginServer(manifest, pluginRoot, serverName, entry);
|
|
160
|
+
if (!translated) continue;
|
|
161
|
+
|
|
162
|
+
const normalizedName = formatAgentPluginServerName(manifest.name, serverName);
|
|
163
|
+
if (mcpServers[normalizedName]) {
|
|
164
|
+
console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: normalized server name ${normalizedName} already exists`);
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
mcpServers[normalizedName] = translated;
|
|
168
|
+
}
|
|
169
|
+
return { mcpServers };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function translateAgentPluginServer(
|
|
173
|
+
manifest: AgentPluginManifest,
|
|
174
|
+
pluginRoot: string,
|
|
175
|
+
serverName: string,
|
|
176
|
+
entry: unknown,
|
|
177
|
+
): ServerEntry | null {
|
|
178
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
179
|
+
console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: entry must be an object`);
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const raw = entry as Record<string, unknown>;
|
|
184
|
+
if (raw.type === "stdio") return translateStdioServer(manifest, pluginRoot, serverName, raw);
|
|
185
|
+
if (raw.type === "streamable-http" || raw.type === "sse") return translateHttpServer(manifest, serverName, raw, raw.type);
|
|
186
|
+
|
|
187
|
+
console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: unsupported type`);
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function translateStdioServer(
|
|
192
|
+
manifest: AgentPluginManifest,
|
|
193
|
+
pluginRoot: string,
|
|
194
|
+
serverName: string,
|
|
195
|
+
raw: Record<string, unknown>,
|
|
196
|
+
): ServerEntry | null {
|
|
197
|
+
for (const key of Object.keys(raw)) {
|
|
198
|
+
if (!STDIO_FIELDS.has(key)) return skipServer(manifest, serverName, `unknown field ${key}`);
|
|
199
|
+
}
|
|
200
|
+
if (typeof raw.command !== "string" || raw.command.length === 0) return skipServer(manifest, serverName, "command must be a non-empty string");
|
|
201
|
+
if (!isBareCommand(raw.command) && !raw.command.startsWith("./")) return skipServer(manifest, serverName, "command must be bare or plugin-relative");
|
|
202
|
+
|
|
203
|
+
const args = translateStringArray(raw.args, manifest, serverName, "args");
|
|
204
|
+
if (args === null) return null;
|
|
205
|
+
const env = translateEnv(raw.env, manifest, serverName);
|
|
206
|
+
if (env === null) return null;
|
|
207
|
+
|
|
208
|
+
const command = raw.command.startsWith("./") ? resolveContainedPath(pluginRoot, raw.command, pluginRoot) : raw.command;
|
|
209
|
+
if (command === null) return skipServer(manifest, serverName, "command must stay inside the plugin directory");
|
|
210
|
+
|
|
211
|
+
const pluginDataDir = getAgentPath("agent-plugin-data", manifest.name);
|
|
212
|
+
const cwd = resolvePluginCwd(raw.cwd, pluginRoot, pluginDataDir);
|
|
213
|
+
if (cwd === null) return skipServer(manifest, serverName, "cwd must be plugin-relative, PLUGIN_ROOT-rooted, or PLUGIN_DATA-rooted");
|
|
214
|
+
|
|
215
|
+
return {
|
|
216
|
+
command,
|
|
217
|
+
args: args.map(value => expandPluginPlaceholders(value, pluginRoot, pluginDataDir)),
|
|
218
|
+
env: {
|
|
219
|
+
...Object.fromEntries(Object.entries(env).map(([key, value]) => [key, expandPluginPlaceholders(value, pluginRoot, pluginDataDir)])),
|
|
220
|
+
PLUGIN_ROOT: pluginRoot,
|
|
221
|
+
PLUGIN_DATA: pluginDataDir,
|
|
222
|
+
},
|
|
223
|
+
cwd,
|
|
224
|
+
pluginDataDir,
|
|
225
|
+
literalEnv: true,
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function translateHttpServer(
|
|
230
|
+
manifest: AgentPluginManifest,
|
|
231
|
+
serverName: string,
|
|
232
|
+
raw: Record<string, unknown>,
|
|
233
|
+
type: "streamable-http" | "sse",
|
|
234
|
+
): ServerEntry | null {
|
|
235
|
+
for (const key of Object.keys(raw)) {
|
|
236
|
+
if (!HTTP_FIELDS.has(key)) return skipServer(manifest, serverName, `unknown field ${key}`);
|
|
237
|
+
}
|
|
238
|
+
if (typeof raw.url !== "string" || raw.url.length === 0) return skipServer(manifest, serverName, "url must be a non-empty string");
|
|
239
|
+
if (!isValidAgentPluginUrl(raw.url)) return skipServer(manifest, serverName, "url must be an allowed absolute HTTP(S) URL");
|
|
240
|
+
const headers = translateHeaders(raw.headers, manifest, serverName);
|
|
241
|
+
if (headers === null) return null;
|
|
242
|
+
|
|
243
|
+
return {
|
|
244
|
+
url: raw.url,
|
|
245
|
+
httpTransport: type,
|
|
246
|
+
...(headers ? { headers } : {}),
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function formatAgentPluginServerName(pluginName: string, serverName: string): string {
|
|
251
|
+
const pluginPart = pluginName.replace(/[^A-Za-z0-9_-]+/g, "_").replace(/^[_-]+|[_-]+$/g, "") || "plugin";
|
|
252
|
+
const serverPart = serverName.replace(/[^A-Za-z0-9_-]+/g, "_").replace(/^[_-]+|[_-]+$/g, "") || "server";
|
|
253
|
+
return `${pluginPart}__${serverPart}`;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function skipServer(manifest: AgentPluginManifest, serverName: string, reason: string): null {
|
|
257
|
+
console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: ${reason}`);
|
|
258
|
+
return null;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function translateStringArray(value: unknown, manifest: AgentPluginManifest, serverName: string, field: string): string[] | null {
|
|
262
|
+
if (value === undefined) return [];
|
|
263
|
+
if (!Array.isArray(value) || value.some(item => typeof item !== "string")) {
|
|
264
|
+
console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: ${field} must be an array of strings`);
|
|
265
|
+
return null;
|
|
266
|
+
}
|
|
267
|
+
return value;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function translateEnv(value: unknown, manifest: AgentPluginManifest, serverName: string): Record<string, string> | null {
|
|
271
|
+
if (value === undefined) return {};
|
|
272
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
273
|
+
console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: env must be an object of strings`);
|
|
274
|
+
return null;
|
|
275
|
+
}
|
|
276
|
+
const env: Record<string, string> = {};
|
|
277
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
278
|
+
if (key === "PLUGIN_ROOT" || key === "PLUGIN_DATA") {
|
|
279
|
+
console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: env must not define ${key}`);
|
|
280
|
+
return null;
|
|
281
|
+
}
|
|
282
|
+
if (typeof entry !== "string") {
|
|
283
|
+
console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: env values must be strings`);
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
env[key] = entry;
|
|
287
|
+
}
|
|
288
|
+
return env;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function translateHeaders(value: unknown, manifest: AgentPluginManifest, serverName: string): Record<string, string> | undefined | null {
|
|
292
|
+
if (value === undefined) return undefined;
|
|
293
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
294
|
+
console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: headers must be an object of strings`);
|
|
295
|
+
return null;
|
|
296
|
+
}
|
|
297
|
+
const headers: Record<string, string> = {};
|
|
298
|
+
const seen = new Set<string>();
|
|
299
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
300
|
+
if (typeof entry !== "string") {
|
|
301
|
+
console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: header values must be strings`);
|
|
302
|
+
return null;
|
|
303
|
+
}
|
|
304
|
+
const normalized = key.toLowerCase();
|
|
305
|
+
if (seen.has(normalized)) {
|
|
306
|
+
console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: duplicate header ${key}`);
|
|
307
|
+
return null;
|
|
308
|
+
}
|
|
309
|
+
seen.add(normalized);
|
|
310
|
+
headers[key] = entry;
|
|
311
|
+
}
|
|
312
|
+
try {
|
|
313
|
+
new Headers(headers);
|
|
314
|
+
} catch {
|
|
315
|
+
console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: headers are not valid HTTP fields`);
|
|
316
|
+
return null;
|
|
317
|
+
}
|
|
318
|
+
return Object.keys(headers).length > 0 ? headers : undefined;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function resolvePluginPath(path: string, cwd: string): string {
|
|
322
|
+
if (path === "~") return resolve(process.env.HOME ?? "", ".");
|
|
323
|
+
if (path.startsWith("~/")) return resolve(process.env.HOME ?? "", path.slice(2));
|
|
324
|
+
return isAbsolute(path) ? resolve(path) : resolve(cwd, path);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
function isBareCommand(command: string): boolean {
|
|
328
|
+
return !command.includes("/") && !command.includes("\\") && !command.includes("${PLUGIN_ROOT}") && !command.includes("${PLUGIN_DATA}");
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function resolvePluginCwd(value: unknown, pluginRoot: string, pluginDataDir: string): string | null {
|
|
332
|
+
if (value === undefined) return pluginRoot;
|
|
333
|
+
if (typeof value !== "string") return null;
|
|
334
|
+
if (value.startsWith("./")) return resolveContainedPath(pluginRoot, value, pluginRoot);
|
|
335
|
+
if (value === "${PLUGIN_ROOT}" || value.startsWith("${PLUGIN_ROOT}/")) {
|
|
336
|
+
return resolveContainedPath(pluginRoot, value.replace("${PLUGIN_ROOT}", "."), pluginRoot);
|
|
337
|
+
}
|
|
338
|
+
if (value === "${PLUGIN_DATA}" || value.startsWith("${PLUGIN_DATA}/")) {
|
|
339
|
+
return resolveContainedPath(pluginDataDir, value.replace("${PLUGIN_DATA}", "."), pluginDataDir);
|
|
340
|
+
}
|
|
341
|
+
return null;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function resolveContainedPath(root: string, value: string, containmentRoot: string): string | null {
|
|
345
|
+
const resolved = resolve(root, value);
|
|
346
|
+
const rel = relative(containmentRoot, resolved);
|
|
347
|
+
if (rel === "" || (!rel.startsWith("..") && !rel.startsWith(sep) && !isAbsolute(rel))) return resolved;
|
|
348
|
+
return null;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
function expandPluginPlaceholders(value: string, pluginRoot: string, pluginDataDir: string): string {
|
|
352
|
+
return value
|
|
353
|
+
.replaceAll("${PLUGIN_ROOT}", pluginRoot)
|
|
354
|
+
.replaceAll("${PLUGIN_DATA}", pluginDataDir);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
function isValidAgentPluginUrl(value: string): boolean {
|
|
358
|
+
if (value.includes("${") || value.includes("$env:") || value.includes("{env:")) return false;
|
|
359
|
+
|
|
360
|
+
let url: URL;
|
|
361
|
+
try {
|
|
362
|
+
url = new URL(value);
|
|
363
|
+
} catch {
|
|
364
|
+
return false;
|
|
365
|
+
}
|
|
366
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") return false;
|
|
367
|
+
if (url.username || url.password || url.hash) return false;
|
|
368
|
+
if (url.protocol === "https:") return true;
|
|
369
|
+
return isLoopbackHost(url.hostname);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function isLoopbackHost(hostname: string): boolean {
|
|
373
|
+
const host = hostname.toLowerCase();
|
|
374
|
+
if (host === "localhost" || host === "127.0.0.1" || host === "::1" || host === "[::1]") return true;
|
|
375
|
+
if (/^127(?:\.\d{1,3}){3}$/.test(host)) return true;
|
|
376
|
+
return false;
|
|
377
|
+
}
|
package/commands.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { isServerDisabled, type McpAuthResult, type McpConfig, type McpPanelCall
|
|
|
4
4
|
import {
|
|
5
5
|
ensureCompatibilityImports,
|
|
6
6
|
getMcpDiscoverySummary,
|
|
7
|
+
getMcpStandardConfigSummary,
|
|
7
8
|
getProjectConfigPath,
|
|
8
9
|
type KnownServerPreset,
|
|
9
10
|
getServerProvenance,
|
|
@@ -354,7 +355,7 @@ export interface PanelFlowResult {
|
|
|
354
355
|
}
|
|
355
356
|
|
|
356
357
|
function buildSharedConfigNoticeLines(configOverridePath: string | undefined, cwd: string): { lines: string[]; fingerprint: string | null } {
|
|
357
|
-
const discovery =
|
|
358
|
+
const discovery = getMcpStandardConfigSummary(configOverridePath, cwd);
|
|
358
359
|
const onboardingState = loadOnboardingState();
|
|
359
360
|
if (!discovery.hasSharedServers || onboardingState.sharedConfigHintShown) {
|
|
360
361
|
return { lines: [], fingerprint: null };
|
|
@@ -377,6 +378,7 @@ export async function openMcpSetup(
|
|
|
377
378
|
ctx: ExtensionContext,
|
|
378
379
|
configOverridePath?: string,
|
|
379
380
|
mode: "empty" | "setup" = "setup",
|
|
381
|
+
options: { includeHostConfigs?: boolean } = {},
|
|
380
382
|
): Promise<PanelFlowResult> {
|
|
381
383
|
if (!ctx.hasUI) return { configChanged: false };
|
|
382
384
|
if (state.programmaticConfig) {
|
|
@@ -384,7 +386,7 @@ export async function openMcpSetup(
|
|
|
384
386
|
return { configChanged: false };
|
|
385
387
|
}
|
|
386
388
|
|
|
387
|
-
const discovery = getMcpDiscoverySummary(configOverridePath, ctx.cwd);
|
|
389
|
+
const discovery = getMcpDiscoverySummary(configOverridePath, ctx.cwd, options);
|
|
388
390
|
const onboardingState = loadOnboardingState();
|
|
389
391
|
const { createMcpSetupPanel } = await import("./mcp-setup-panel.ts");
|
|
390
392
|
let configChanged = false;
|
|
@@ -393,7 +395,7 @@ export async function openMcpSetup(
|
|
|
393
395
|
previewImports: (imports: ImportKind[]) => previewCompatibilityImports(imports, configOverridePath),
|
|
394
396
|
previewStarterProject: () => previewStarterProjectConfig(ctx.cwd),
|
|
395
397
|
previewRepoPrompt: () => {
|
|
396
|
-
const repoPrompt = getMcpDiscoverySummary(configOverridePath, ctx.cwd).repoPrompt;
|
|
398
|
+
const repoPrompt = getMcpDiscoverySummary(configOverridePath, ctx.cwd, options).repoPrompt;
|
|
397
399
|
if (!repoPrompt.entry || !repoPrompt.targetPath || !repoPrompt.serverName) return null;
|
|
398
400
|
return previewSharedServerEntry(repoPrompt.targetPath, repoPrompt.serverName, repoPrompt.entry);
|
|
399
401
|
},
|
|
@@ -409,7 +411,7 @@ export async function openMcpSetup(
|
|
|
409
411
|
return { path };
|
|
410
412
|
},
|
|
411
413
|
addRepoPrompt: async () => {
|
|
412
|
-
const repoPrompt = getMcpDiscoverySummary(configOverridePath, ctx.cwd).repoPrompt;
|
|
414
|
+
const repoPrompt = getMcpDiscoverySummary(configOverridePath, ctx.cwd, options).repoPrompt;
|
|
413
415
|
if (!repoPrompt.entry || !repoPrompt.targetPath || !repoPrompt.serverName) {
|
|
414
416
|
throw new Error("RepoPrompt is not available to add from this setup screen.");
|
|
415
417
|
}
|
|
@@ -514,7 +516,7 @@ export async function openMcpPanel(
|
|
|
514
516
|
return { configChanged: false };
|
|
515
517
|
}
|
|
516
518
|
if (Object.keys(state.config.mcpServers).length === 0) {
|
|
517
|
-
return openMcpSetup(state, pi, ctx, configOverridePath, "empty");
|
|
519
|
+
return openMcpSetup(state, pi, ctx, configOverridePath, "empty", { includeHostConfigs: false });
|
|
518
520
|
}
|
|
519
521
|
|
|
520
522
|
const config = state.config;
|