@fitchmultz/pi-mcp-adapter 6.0.0 → 7.1.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.
Files changed (111) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/OAUTH.md +1 -1
  3. package/README.md +27 -18
  4. package/dist/app-bridge.bundle.js +14 -14
  5. package/dist/config.js +41 -16
  6. package/dist/direct-tools.js +1 -1
  7. package/dist/gateway-arguments.d.ts +1 -1
  8. package/dist/index.js +38 -59
  9. package/dist/lifecycle.d.ts +2 -2
  10. package/dist/lifecycle.js +2 -2
  11. package/dist/mcp-auth-flow.js +2 -2
  12. package/dist/mcp-auth.d.ts +1 -1
  13. package/dist/mcp-auth.js +3 -3
  14. package/dist/mcp-code.d.ts +6 -6
  15. package/dist/mcp-code.js +11 -10
  16. package/dist/mcp-oauth-provider.d.ts +5 -5
  17. package/dist/mcp-oauth-provider.js +5 -5
  18. package/dist/mcp-output-guard.d.ts +1 -1
  19. package/dist/mcp-output-guard.js +1 -1
  20. package/dist/mcp-panel.d.ts +2 -2
  21. package/dist/mcp-panel.js +2 -2
  22. package/dist/mcp-setup-panel.d.ts +5 -4
  23. package/dist/mcp-setup-panel.js +15 -7
  24. package/dist/mcp-trace.d.ts +1 -1
  25. package/dist/mcp-trace.js +1 -1
  26. package/dist/npx-resolver.js +8 -4
  27. package/dist/proxy-modes.d.ts +2 -2
  28. package/dist/proxy-modes.js +20 -19
  29. package/dist/sampling-handler.js +1 -0
  30. package/dist/search-ranking.js +6 -2
  31. package/dist/server-manager.d.ts +2 -2
  32. package/dist/server-manager.js +44 -27
  33. package/dist/session-recovery.d.ts +7 -4
  34. package/dist/session-recovery.js +76 -10
  35. package/dist/tool-loader.d.ts +7 -2
  36. package/dist/tool-loader.js +56 -5
  37. package/dist/tool-metadata.d.ts +43 -43
  38. package/dist/tool-result-renderer.d.ts +3 -3
  39. package/dist/tool-result-renderer.js +3 -3
  40. package/dist/ui-resource-handler.d.ts +2 -2
  41. package/dist/ui-resource-handler.js +2 -2
  42. package/dist/ui-server.js +5 -4
  43. package/dist/ui-stream-types.d.ts +8 -8
  44. package/dist/unix-socket-transport.d.ts +1 -1
  45. package/dist/unix-socket-transport.js +1 -1
  46. package/dist/utils.d.ts +1 -0
  47. package/dist/utils.js +14 -0
  48. package/package.json +34 -98
  49. package/skills/mcp-scripting/SKILL.md +2 -0
  50. package/abort.ts +0 -34
  51. package/agent-dir.ts +0 -24
  52. package/app-bridge.bundle.js +0 -109
  53. package/banner.png +0 -0
  54. package/checkpoint.ts +0 -55
  55. package/commands.ts +0 -622
  56. package/config.ts +0 -1204
  57. package/consent-manager.ts +0 -25
  58. package/direct-tools.ts +0 -75
  59. package/elicitation-handler.ts +0 -349
  60. package/error-signal.ts +0 -21
  61. package/gateway-arguments.ts +0 -73
  62. package/glimpse-ui.ts +0 -80
  63. package/host-html-template.ts +0 -456
  64. package/index.ts +0 -767
  65. package/init.ts +0 -613
  66. package/legacy-migration.ts +0 -47
  67. package/lifecycle.ts +0 -165
  68. package/logger.ts +0 -127
  69. package/mcp-auth-flow.ts +0 -975
  70. package/mcp-auth.ts +0 -793
  71. package/mcp-callback-server.ts +0 -450
  72. package/mcp-code.ts +0 -412
  73. package/mcp-keyring-helper.cjs +0 -89
  74. package/mcp-oauth-provider.ts +0 -774
  75. package/mcp-output-guard.ts +0 -530
  76. package/mcp-panel.ts +0 -907
  77. package/mcp-script-worker.mjs +0 -131
  78. package/mcp-setup-panel.ts +0 -666
  79. package/mcp-status.ts +0 -110
  80. package/mcp-trace.ts +0 -295
  81. package/metadata-cache.ts +0 -271
  82. package/npx-resolver.ts +0 -488
  83. package/onboarding-state.ts +0 -58
  84. package/panel-keys.ts +0 -37
  85. package/prompts.ts +0 -337
  86. package/proxy-modes.ts +0 -1109
  87. package/resource-tools.ts +0 -52
  88. package/runtime-owner.ts +0 -123
  89. package/sampling-handler.ts +0 -276
  90. package/scripts/build-app-bridge.mjs +0 -15
  91. package/scripts/build.mjs +0 -132
  92. package/scripts/prepare.mjs +0 -103
  93. package/search-ranking.ts +0 -132
  94. package/server-manager.ts +0 -1320
  95. package/session-recovery.ts +0 -316
  96. package/state.ts +0 -64
  97. package/tool-approval.ts +0 -78
  98. package/tool-loader.ts +0 -153
  99. package/tool-metadata.ts +0 -240
  100. package/tool-registrar.ts +0 -74
  101. package/tool-result-renderer.ts +0 -294
  102. package/tsconfig.build.json +0 -13
  103. package/tsconfig.json +0 -16
  104. package/types.ts +0 -785
  105. package/ui-resource-handler.ts +0 -249
  106. package/ui-server.ts +0 -808
  107. package/ui-session.ts +0 -568
  108. package/ui-stream-types.ts +0 -89
  109. package/ui-tool-visibility.ts +0 -25
  110. package/unix-socket-transport.ts +0 -85
  111. package/utils.ts +0 -307
@@ -1,131 +0,0 @@
1
- import { parentPort, workerData } from "node:worker_threads";
2
- import { formatWithOptions } from "node:util";
3
- import vm from "node:vm";
4
-
5
- const TOOLS_ENUMERATION_ERROR = "tools is not enumerable — use tools.search({ query })";
6
- const RESERVED_TOOL_PROPS = new Set(["then", "catch", "finally", "toJSON", "toString", "valueOf"]);
7
-
8
- // Keep this formatting logic in sync with mcp-code.ts; the standalone worker cannot import the TypeScript host module.
9
- function needsInspectableFormatting(value, stack = new WeakSet()) {
10
- if (value === undefined || typeof value === "bigint" || typeof value === "function" || typeof value === "symbol") return true;
11
- if (typeof value !== "object" || value === null) return false;
12
- if (stack.has(value)) return true;
13
- if (value instanceof Map || value instanceof Set || value instanceof WeakMap || value instanceof WeakSet) return true;
14
- stack.add(value);
15
- try {
16
- return Object.values(value).some((entry) => needsInspectableFormatting(entry, stack));
17
- } finally {
18
- stack.delete(value);
19
- }
20
- }
21
-
22
- function formatValue(value) {
23
- if (typeof value === "string") return value;
24
- try {
25
- if (!needsInspectableFormatting(value)) {
26
- const json = JSON.stringify(value, null, 2);
27
- if (json !== undefined) return json;
28
- }
29
- return formatWithOptions({ colors: false, depth: 6 }, value);
30
- } catch {
31
- return "[unserializable value]";
32
- }
33
- }
34
-
35
- function toContentBlock(value) {
36
- if (typeof value === "object" && value !== null) {
37
- if (value.type === "text" && typeof value.text === "string") {
38
- return { type: "text", text: value.text };
39
- }
40
- if (value.type === "image" && typeof value.data === "string" && typeof value.mimeType === "string") {
41
- return { type: "image", data: value.data, mimeType: value.mimeType };
42
- }
43
- }
44
- return { type: "text", text: formatValue(value) };
45
- }
46
-
47
- let nextRequestId = 0;
48
- const pending = new Map();
49
-
50
- parentPort.on("message", (message) => {
51
- if (message?.type !== "result" || typeof message.id !== "number") return;
52
- const resolve = pending.get(message.id);
53
- if (!resolve) return;
54
- pending.delete(message.id);
55
- resolve(message.envelope);
56
- });
57
-
58
- function request(type, payload) {
59
- return new Promise((resolve) => {
60
- const id = ++nextRequestId;
61
- pending.set(id, resolve);
62
- parentPort.postMessage({ type, id, ...payload });
63
- });
64
- }
65
-
66
- const tools = new Proxy(Object.create(null), {
67
- get(_target, property) {
68
- if (property === "search") {
69
- return async (input) => request("search", { input });
70
- }
71
- if (property === "call") {
72
- return async (path, args, server) => {
73
- // Invalid paths never reach dispatch and therefore never appear in the call trace.
74
- if (typeof path !== "string" || path.trim() === "") {
75
- return {
76
- ok: false,
77
- error: {
78
- code: "invalid_tool_path",
79
- message: "tools.call(path, args) requires a non-empty tool path.",
80
- },
81
- };
82
- }
83
- if (server !== undefined && (typeof server !== "string" || !server)) return { ok: false, error: { code: "invalid_arguments", message: "server must be a non-empty string" } };
84
- return request("call", { path, args, server });
85
- };
86
- }
87
- if (property === "resources" || property === "listResources") return async (input) => request("resources", { input });
88
- if (property === "readResource" || property === "readResult") return async (input) => request(property, { input });
89
- if (property === "describe") {
90
- return async (input) => request("describe", { input });
91
- }
92
- if (typeof property !== "string" || RESERVED_TOOL_PROPS.has(property)) return undefined;
93
- return (args) => request("call", { path: property, args });
94
- },
95
- ownKeys() {
96
- throw new Error(TOOLS_ENUMERATION_ERROR);
97
- },
98
- });
99
-
100
- const emit = (value) => {
101
- parentPort.postMessage({ type: "emit", block: toContentBlock(value) });
102
- };
103
-
104
- const capturedConsole = Object.freeze({
105
- log: (...args) => emit(`[console.log] ${formatWithOptions({ colors: false, depth: 4 }, ...args)}`),
106
- info: (...args) => emit(`[console.info] ${formatWithOptions({ colors: false, depth: 4 }, ...args)}`),
107
- warn: (...args) => emit(`[console.warn] ${formatWithOptions({ colors: false, depth: 4 }, ...args)}`),
108
- error: (...args) => emit(`[console.error] ${formatWithOptions({ colors: false, depth: 4 }, ...args)}`),
109
- debug: (...args) => emit(`[console.debug] ${formatWithOptions({ colors: false, depth: 4 }, ...args)}`),
110
- });
111
-
112
- try {
113
- const context = vm.createContext(Object.assign(Object.create(null), {
114
- tools,
115
- emit,
116
- console: capturedConsole,
117
- }), {
118
- codeGeneration: { strings: false, wasm: false },
119
- name: "mcp_script",
120
- });
121
- const script = new vm.Script(`(async () => {\n${workerData.code}\n})()`, { filename: "mcp_script.js" });
122
- const returnValue = await Promise.resolve(script.runInContext(context));
123
- parentPort.postMessage(returnValue === undefined
124
- ? { type: "done" }
125
- : { type: "done", returnBlock: toContentBlock(returnValue) });
126
- } catch (error) {
127
- parentPort.postMessage({
128
- type: "error",
129
- message: error instanceof Error ? error.message : String(error),
130
- });
131
- }