@qusic/pi-dynamic-mcp 0.0.0-stage → 0.20261015.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/LICENSE +21 -0
- package/README.md +10 -2
- package/dynamic-mcp.ts +61 -0
- package/package.json +36 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bang Lee
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Pi extensions
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Small [Pi](https://github.com/earendil-works/pi) extensions for personal use, published separately for easy installation across machines.
|
|
4
|
+
|
|
5
|
+
| Extension | npm | Install | Description |
|
|
6
|
+
| --- | --- | --- | --- |
|
|
7
|
+
| [compact-filter](./compact-filter.ts) | [](https://www.npmjs.com/package/@qusic/pi-compact-filter) | `pi install npm:@qusic/pi-compact-filter` | Prune stale tracked paths from Pi's compaction context. |
|
|
8
|
+
| [copilot-sync](./copilot-sync.ts) | [](https://www.npmjs.com/package/@qusic/pi-copilot-sync) | `pi install npm:@qusic/pi-copilot-sync` | Sync live GitHub Copilot model capabilities into Pi. |
|
|
9
|
+
| [copilot2api](./copilot2api.ts) | [](https://www.npmjs.com/package/@qusic/pi-copilot2api) | `pi install npm:@qusic/pi-copilot2api` | Add copilot2api as a native Pi provider with live model discovery. |
|
|
10
|
+
| [dynamic-mcp](./dynamic-mcp.ts) | [](https://www.npmjs.com/package/@qusic/pi-dynamic-mcp) | `pi install npm:@qusic/pi-dynamic-mcp` | Dynamically manage MCP servers for the current Pi session. |
|
|
11
|
+
| [session-trim](./session-trim.ts) | [](https://www.npmjs.com/package/@qusic/pi-session-trim) | `pi install npm:@qusic/pi-session-trim` | Speed up loading large Pi sessions by pruning superseded history. |
|
package/dynamic-mcp.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// npm-description: Dynamically manage MCP servers for the current Pi session.
|
|
2
|
+
// npm-keywords: mcp, model-context-protocol, dynamic-mcp, session-scoped, stdio, streamable-http
|
|
3
|
+
|
|
4
|
+
import { StringEnum, Type } from "@earendil-works/pi-ai";
|
|
5
|
+
import type { ExtensionAPI, McpServerConfig } from "@earendil-works/pi-coding-agent";
|
|
6
|
+
|
|
7
|
+
// Pi's McpServerConfig and validator: https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/mcp-servers.ts
|
|
8
|
+
// This model-facing subset is validated again by registerMcpServer.
|
|
9
|
+
const parameters = Type.Object({
|
|
10
|
+
action: StringEnum(["add", "remove", "list"] as const),
|
|
11
|
+
name: Type.Optional(Type.String({ description: "Server name for add or remove" })),
|
|
12
|
+
config: Type.Optional(
|
|
13
|
+
Type.Object({
|
|
14
|
+
command: Type.Optional(Type.String({ description: "Stdio executable, not a shell command" })),
|
|
15
|
+
args: Type.Optional(Type.Array(Type.String())),
|
|
16
|
+
cwd: Type.Optional(Type.String()),
|
|
17
|
+
env: Type.Optional(Type.Record(Type.String(), Type.String())),
|
|
18
|
+
url: Type.Optional(Type.String({ description: "Streamable HTTP URL" })),
|
|
19
|
+
headers: Type.Optional(Type.Record(Type.String(), Type.String())),
|
|
20
|
+
description: Type.Optional(Type.String()),
|
|
21
|
+
timeout: Type.Optional(Type.Number()),
|
|
22
|
+
}),
|
|
23
|
+
),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export default function (pi: ExtensionAPI) {
|
|
27
|
+
const managed = new Map<string, "stdio" | "http">();
|
|
28
|
+
|
|
29
|
+
pi.registerTool({
|
|
30
|
+
name: "mcp",
|
|
31
|
+
label: "MCP",
|
|
32
|
+
description:
|
|
33
|
+
"Manage session MCP servers: add(name, config) with command/args (stdio) or url (HTTP), remove(name), or list(). list shows servers added by this tool, not connection status. env and headers support ${VAR}.",
|
|
34
|
+
parameters,
|
|
35
|
+
async execute(_id, { action, name, config }) {
|
|
36
|
+
let text: string;
|
|
37
|
+
if (action === "list") {
|
|
38
|
+
text = [...managed].map(([name, type]) => `${name} (${type})`).join("\n") || "No MCP servers added by this tool";
|
|
39
|
+
} else if (!name) {
|
|
40
|
+
throw new Error("Server name is required");
|
|
41
|
+
} else if (action === "remove") {
|
|
42
|
+
if (!managed.has(name)) throw new Error(`Server "${name}" was not added by this extension`);
|
|
43
|
+
pi.unregisterMcpServer(name);
|
|
44
|
+
managed.delete(name);
|
|
45
|
+
text = `Removed "${name}"`;
|
|
46
|
+
} else {
|
|
47
|
+
if (!config || Boolean(config.command) === Boolean(config.url)) {
|
|
48
|
+
throw new Error("Provide either command (stdio) or url (HTTP) in config");
|
|
49
|
+
}
|
|
50
|
+
const common = { description: config.description, timeout: config.timeout };
|
|
51
|
+
const serverConfig: McpServerConfig = config.url
|
|
52
|
+
? { ...common, url: config.url, headers: config.headers }
|
|
53
|
+
: { ...common, command: config.command!, args: config.args, cwd: config.cwd, env: config.env };
|
|
54
|
+
pi.registerMcpServer(name, serverConfig);
|
|
55
|
+
managed.set(name, config.url ? "http" : "stdio");
|
|
56
|
+
text = `Registered "${name}"; connection starts in the background`;
|
|
57
|
+
}
|
|
58
|
+
return { content: [{ type: "text", text }], details: undefined };
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@qusic/pi-dynamic-mcp",
|
|
3
|
+
"version": "0.20261015.0",
|
|
4
|
+
"homepage": "https://github.com/Qusic/pi-extensions#readme",
|
|
5
|
+
"bugs": {
|
|
6
|
+
"url": "https://github.com/Qusic/pi-extensions/issues"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/Qusic/pi-extensions.git"
|
|
11
|
+
},
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"pi": {
|
|
15
|
+
"extensions": [
|
|
16
|
+
"./*.ts"
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"@earendil-works/pi-ai": "*",
|
|
21
|
+
"@earendil-works/pi-agent-core": "*",
|
|
22
|
+
"@earendil-works/pi-coding-agent": "*"
|
|
23
|
+
},
|
|
24
|
+
"description": "Dynamically manage MCP servers for the current Pi session.",
|
|
25
|
+
"keywords": [
|
|
26
|
+
"pi-package",
|
|
27
|
+
"pi-extension",
|
|
28
|
+
"pi",
|
|
29
|
+
"pi-coding-agent",
|
|
30
|
+
"mcp",
|
|
31
|
+
"model-context-protocol",
|
|
32
|
+
"dynamic-mcp",
|
|
33
|
+
"session-scoped",
|
|
34
|
+
"stdio",
|
|
35
|
+
"streamable-http"
|
|
36
|
+
]
|
|
37
|
+
}
|