@fitchmultz/pi-mcp-adapter 5.0.0 → 7.0.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 (129) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/OAUTH.md +3 -3
  3. package/README.md +160 -88
  4. package/dist/app-bridge.bundle.js +75 -33
  5. package/dist/commands.js +9 -6
  6. package/dist/config.js +41 -16
  7. package/dist/direct-tools.d.ts +2 -4
  8. package/dist/direct-tools.js +21 -319
  9. package/dist/gateway-arguments.d.ts +33 -0
  10. package/dist/gateway-arguments.js +63 -0
  11. package/dist/index.js +181 -276
  12. package/dist/init.js +6 -20
  13. package/dist/lifecycle.d.ts +2 -2
  14. package/dist/lifecycle.js +2 -2
  15. package/dist/mcp-auth-flow.js +2 -2
  16. package/dist/mcp-auth.d.ts +1 -1
  17. package/dist/mcp-auth.js +3 -3
  18. package/dist/mcp-code.d.ts +7 -6
  19. package/dist/mcp-code.js +98 -51
  20. package/dist/mcp-oauth-provider.d.ts +5 -5
  21. package/dist/mcp-oauth-provider.js +5 -5
  22. package/dist/mcp-output-guard.d.ts +57 -2
  23. package/dist/mcp-output-guard.js +129 -24
  24. package/dist/mcp-panel.d.ts +3 -3
  25. package/dist/mcp-panel.js +36 -99
  26. package/dist/mcp-script-worker.mjs +5 -2
  27. package/dist/mcp-setup-panel.d.ts +5 -4
  28. package/dist/mcp-setup-panel.js +15 -7
  29. package/dist/mcp-status.js +2 -1
  30. package/dist/mcp-trace.d.ts +1 -1
  31. package/dist/mcp-trace.js +1 -1
  32. package/dist/metadata-cache.d.ts +1 -1
  33. package/dist/metadata-cache.js +25 -88
  34. package/dist/npx-resolver.js +8 -4
  35. package/dist/prompts.d.ts +1 -1
  36. package/dist/prompts.js +1 -1
  37. package/dist/proxy-modes.d.ts +41 -7
  38. package/dist/proxy-modes.js +275 -490
  39. package/dist/resource-tools.d.ts +15 -0
  40. package/dist/resource-tools.js +26 -1
  41. package/dist/sampling-handler.js +5 -1
  42. package/dist/search-ranking.d.ts +0 -2
  43. package/dist/search-ranking.js +70 -137
  44. package/dist/server-manager.d.ts +2 -2
  45. package/dist/server-manager.js +44 -27
  46. package/dist/session-recovery.d.ts +7 -4
  47. package/dist/session-recovery.js +76 -10
  48. package/dist/state.d.ts +1 -1
  49. package/dist/tool-loader.d.ts +32 -0
  50. package/dist/tool-loader.js +152 -0
  51. package/dist/tool-metadata.d.ts +67 -0
  52. package/dist/tool-metadata.js +23 -17
  53. package/dist/tool-registrar.d.ts +4 -4
  54. package/dist/tool-registrar.js +18 -13
  55. package/dist/tool-result-renderer.d.ts +6 -3
  56. package/dist/tool-result-renderer.js +11 -6
  57. package/dist/types.d.ts +11 -36
  58. package/dist/ui-resource-handler.d.ts +2 -2
  59. package/dist/ui-resource-handler.js +2 -2
  60. package/dist/ui-server.js +4 -3
  61. package/dist/ui-stream-types.d.ts +8 -8
  62. package/dist/unix-socket-transport.d.ts +1 -1
  63. package/dist/unix-socket-transport.js +1 -1
  64. package/dist/utils.d.ts +1 -0
  65. package/dist/utils.js +16 -4
  66. package/package.json +37 -96
  67. package/skills/mcp-scripting/SKILL.md +67 -20
  68. package/abort.ts +0 -34
  69. package/agent-dir.ts +0 -24
  70. package/app-bridge.bundle.js +0 -67
  71. package/banner.png +0 -0
  72. package/checkpoint.ts +0 -55
  73. package/commands.ts +0 -619
  74. package/config.ts +0 -1204
  75. package/consent-manager.ts +0 -25
  76. package/direct-tools.ts +0 -408
  77. package/dist/ts-shape.d.ts +0 -2
  78. package/dist/ts-shape.js +0 -147
  79. package/elicitation-handler.ts +0 -349
  80. package/error-signal.ts +0 -21
  81. package/glimpse-ui.ts +0 -80
  82. package/host-html-template.ts +0 -456
  83. package/index.ts +0 -900
  84. package/init.ts +0 -627
  85. package/legacy-migration.ts +0 -47
  86. package/lifecycle.ts +0 -165
  87. package/logger.ts +0 -127
  88. package/mcp-auth-flow.ts +0 -975
  89. package/mcp-auth.ts +0 -793
  90. package/mcp-callback-server.ts +0 -450
  91. package/mcp-code.ts +0 -386
  92. package/mcp-keyring-helper.cjs +0 -89
  93. package/mcp-oauth-provider.ts +0 -774
  94. package/mcp-output-guard.ts +0 -412
  95. package/mcp-panel.ts +0 -978
  96. package/mcp-script-worker.mjs +0 -128
  97. package/mcp-setup-panel.ts +0 -666
  98. package/mcp-status.ts +0 -109
  99. package/mcp-trace.ts +0 -295
  100. package/metadata-cache.ts +0 -333
  101. package/npx-resolver.ts +0 -488
  102. package/onboarding-state.ts +0 -58
  103. package/panel-keys.ts +0 -37
  104. package/prompts.ts +0 -337
  105. package/proxy-modes.ts +0 -1361
  106. package/resource-tools.ts +0 -17
  107. package/runtime-owner.ts +0 -123
  108. package/sampling-handler.ts +0 -273
  109. package/scripts/build.mjs +0 -131
  110. package/scripts/prepare.mjs +0 -102
  111. package/search-ranking.ts +0 -196
  112. package/server-manager.ts +0 -1320
  113. package/session-recovery.ts +0 -316
  114. package/state.ts +0 -64
  115. package/tool-approval.ts +0 -78
  116. package/tool-metadata.ts +0 -235
  117. package/tool-registrar.ts +0 -69
  118. package/tool-result-renderer.ts +0 -286
  119. package/ts-shape.ts +0 -145
  120. package/tsconfig.build.json +0 -13
  121. package/tsconfig.json +0 -16
  122. package/types.ts +0 -810
  123. package/ui-resource-handler.ts +0 -249
  124. package/ui-server.ts +0 -808
  125. package/ui-session.ts +0 -568
  126. package/ui-stream-types.ts +0 -89
  127. package/ui-tool-visibility.ts +0 -25
  128. package/unix-socket-transport.ts +0 -85
  129. package/utils.ts +0 -309
@@ -1,128 +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) => {
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
- return request("call", { path, args });
84
- };
85
- }
86
- if (property === "describe") {
87
- return async (input) => request("describe", { input });
88
- }
89
- if (typeof property !== "string" || RESERVED_TOOL_PROPS.has(property)) return undefined;
90
- return (args) => request("call", { path: property, args });
91
- },
92
- ownKeys() {
93
- throw new Error(TOOLS_ENUMERATION_ERROR);
94
- },
95
- });
96
-
97
- const emit = (value) => {
98
- parentPort.postMessage({ type: "emit", block: toContentBlock(value) });
99
- };
100
-
101
- const capturedConsole = Object.freeze({
102
- log: (...args) => emit(`[console.log] ${formatWithOptions({ colors: false, depth: 4 }, ...args)}`),
103
- info: (...args) => emit(`[console.info] ${formatWithOptions({ colors: false, depth: 4 }, ...args)}`),
104
- warn: (...args) => emit(`[console.warn] ${formatWithOptions({ colors: false, depth: 4 }, ...args)}`),
105
- error: (...args) => emit(`[console.error] ${formatWithOptions({ colors: false, depth: 4 }, ...args)}`),
106
- debug: (...args) => emit(`[console.debug] ${formatWithOptions({ colors: false, depth: 4 }, ...args)}`),
107
- });
108
-
109
- try {
110
- const context = vm.createContext(Object.assign(Object.create(null), {
111
- tools,
112
- emit,
113
- console: capturedConsole,
114
- }), {
115
- codeGeneration: { strings: false, wasm: false },
116
- name: "mcp_script",
117
- });
118
- const script = new vm.Script(`(async () => {\n${workerData.code}\n})()`, { filename: "mcp_script.js" });
119
- const returnValue = await Promise.resolve(script.runInContext(context));
120
- parentPort.postMessage(returnValue === undefined
121
- ? { type: "done" }
122
- : { type: "done", returnBlock: toContentBlock(returnValue) });
123
- } catch (error) {
124
- parentPort.postMessage({
125
- type: "error",
126
- message: error instanceof Error ? error.message : String(error),
127
- });
128
- }