@execbox/core 0.6.0 → 0.7.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/README.md +28 -7
- package/dist/{errors-DlbJQYs7.d.ts → errors-BIWv-QIC.d.ts} +2 -2
- package/dist/{errors-DlbJQYs7.d.ts.map → errors-BIWv-QIC.d.ts.map} +1 -1
- package/dist/{errors-B9ADBuDH.d.cts → errors-y4C-EIWT.d.cts} +2 -2
- package/dist/{errors-B9ADBuDH.d.cts.map → errors-y4C-EIWT.d.cts.map} +1 -1
- package/dist/{executor-B7q7K_27.d.ts → executor-BOTd9xNK.d.ts} +2 -2
- package/dist/{executor-B7q7K_27.d.ts.map → executor-BOTd9xNK.d.ts.map} +1 -1
- package/dist/{executor-BsE5nF-j.d.cts → executor-CtbrvTQ_.d.cts} +2 -2
- package/dist/{executor-BsE5nF-j.d.cts.map → executor-CtbrvTQ_.d.cts.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/mcp/index.cjs +101 -34
- package/dist/mcp/index.cjs.map +1 -1
- package/dist/mcp/index.d.cts +24 -4
- package/dist/mcp/index.d.cts.map +1 -1
- package/dist/mcp/index.d.ts +24 -4
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +101 -34
- package/dist/mcp/index.js.map +1 -1
- package/dist/protocol/index.cjs +6 -2
- package/dist/protocol/index.cjs.map +1 -1
- package/dist/protocol/index.d.cts +2 -2
- package/dist/protocol/index.d.cts.map +1 -1
- package/dist/protocol/index.d.ts +2 -2
- package/dist/protocol/index.d.ts.map +1 -1
- package/dist/protocol/index.js +6 -2
- package/dist/protocol/index.js.map +1 -1
- package/dist/{resolveProvider-Bfj27oYs.js → resolveProvider-CMrXPuTx.js} +12 -1
- package/dist/resolveProvider-CMrXPuTx.js.map +1 -0
- package/dist/{resolveProvider-CszBWDOY.cjs → resolveProvider-DFAg6No5.cjs} +12 -1
- package/dist/resolveProvider-DFAg6No5.cjs.map +1 -0
- package/dist/{runner-CsrfDub-.cjs → runner-BEY9nWc7.cjs} +2 -1
- package/dist/runner-BEY9nWc7.cjs.map +1 -0
- package/dist/{runner-BqYkAnOm.js → runner-BWAVLBi6.js} +2 -1
- package/dist/runner-BWAVLBi6.js.map +1 -0
- package/dist/{runner-ClFrFnz9.d.ts → runner-Cy18Z0u0.d.cts} +26 -2
- package/dist/runner-Cy18Z0u0.d.cts.map +1 -0
- package/dist/{runner-DSgvu6Ad.d.cts → runner-DXLu0eJV.d.ts} +26 -2
- package/dist/runner-DXLu0eJV.d.ts.map +1 -0
- package/dist/runtime.cjs +2 -2
- package/dist/runtime.d.cts +4 -4
- package/dist/runtime.d.ts +4 -4
- package/dist/runtime.js +1 -1
- package/package.json +1 -1
- package/dist/resolveProvider-Bfj27oYs.js.map +0 -1
- package/dist/resolveProvider-CszBWDOY.cjs.map +0 -1
- package/dist/runner-BqYkAnOm.js.map +0 -1
- package/dist/runner-ClFrFnz9.d.ts.map +0 -1
- package/dist/runner-CsrfDub-.cjs.map +0 -1
- package/dist/runner-DSgvu6Ad.d.cts.map +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# @execbox/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Provider, schema, and MCP adapter contracts for execbox. Use it to resolve host
|
|
4
|
+
tools into callable guest namespaces before running code with an executor such
|
|
5
|
+
as `@execbox/quickjs`.
|
|
4
6
|
|
|
5
7
|
[](https://www.npmjs.com/package/@execbox/core)
|
|
6
8
|
[](https://github.com/aallam/execbox/blob/main/LICENSE)
|
|
@@ -10,11 +12,12 @@ Core execution contract for execbox. Use it to resolve host tools into callable
|
|
|
10
12
|
|
|
11
13
|
- you want to expose host capabilities to guest code through explicit tool providers
|
|
12
14
|
- you want one execution contract across inline and worker-hosted QuickJS
|
|
13
|
-
- you want to wrap MCP servers or clients into callable namespaces
|
|
15
|
+
- you want to wrap MCP servers or clients into callable namespaces
|
|
14
16
|
|
|
15
17
|
## Pair It With an Executor
|
|
16
18
|
|
|
17
|
-
`@execbox/core` defines the provider and tool boundary
|
|
19
|
+
`@execbox/core` defines the provider and tool boundary. Guest execution happens
|
|
20
|
+
in an executor package.
|
|
18
21
|
|
|
19
22
|
| Package | Start here when |
|
|
20
23
|
| -------------------------------------------------------------------- | --------------------------------------------------------------- |
|
|
@@ -28,12 +31,28 @@ Most users start with QuickJS:
|
|
|
28
31
|
npm install @execbox/core @execbox/quickjs
|
|
29
32
|
```
|
|
30
33
|
|
|
34
|
+
## Provider Boundary
|
|
35
|
+
|
|
36
|
+
Providers are explicit capability grants. `resolveProvider()` validates the
|
|
37
|
+
namespace, normalizes tool schemas, creates guest-safe tool names, wraps tool
|
|
38
|
+
execution with schema checks, and keeps original-to-safe name maps for callers
|
|
39
|
+
that need to explain MCP or generated tool names.
|
|
40
|
+
|
|
41
|
+
Tool inputs and results should be JSON-compatible data. Keep host-only values
|
|
42
|
+
such as clients, handles, secrets, and tenant routing inside the tool
|
|
43
|
+
implementation.
|
|
44
|
+
|
|
31
45
|
## Runtime Implementer Surface
|
|
32
46
|
|
|
33
47
|
Most application code can skip this section.
|
|
34
48
|
|
|
35
49
|
Application code should usually import from `@execbox/core` or `@execbox/core/mcp`.
|
|
36
|
-
The `@execbox/core/protocol` and `@execbox/core/runtime` subpaths exist for
|
|
50
|
+
The `@execbox/core/protocol` and `@execbox/core/runtime` subpaths exist for
|
|
51
|
+
execbox-owned runtime packages. `@execbox/core/protocol` carries the
|
|
52
|
+
worker-hosted QuickJS message contract, while `@execbox/core/runtime` contains
|
|
53
|
+
the manifest dispatcher, runtime option defaults, timeout helpers, log
|
|
54
|
+
formatting, code normalization, and error normalization used to keep runtime
|
|
55
|
+
implementations aligned.
|
|
37
56
|
|
|
38
57
|
## Smallest Working Usage
|
|
39
58
|
|
|
@@ -69,7 +88,8 @@ console.log(result);
|
|
|
69
88
|
|
|
70
89
|
## MCP Support
|
|
71
90
|
|
|
72
|
-
Use `@execbox/core/mcp` when you want MCP on either side of the
|
|
91
|
+
Use `@execbox/core/mcp` when you want MCP on either side of the provider
|
|
92
|
+
boundary:
|
|
73
93
|
|
|
74
94
|
- wrap an upstream MCP server or client into a provider with `createMcpToolProvider()` or `openMcpToolProvider()`
|
|
75
95
|
- expose execbox code execution back out through an MCP server with `codeMcpServer()`
|
|
@@ -84,8 +104,9 @@ Use `@execbox/core/mcp` when you want MCP on either side of the boundary:
|
|
|
84
104
|
## Read Next
|
|
85
105
|
|
|
86
106
|
- [Getting Started](https://execbox.aallam.com/getting-started)
|
|
107
|
+
- [Providers & Tools](https://execbox.aallam.com/providers-and-tools)
|
|
108
|
+
- [Runtime Choices](https://execbox.aallam.com/runtime-choices)
|
|
109
|
+
- [MCP Integration](https://execbox.aallam.com/mcp-integration)
|
|
87
110
|
- [Examples](https://execbox.aallam.com/examples)
|
|
88
111
|
- [Security & Boundaries](https://execbox.aallam.com/security)
|
|
89
112
|
- [Architecture Overview](https://execbox.aallam.com/architecture/)
|
|
90
|
-
- [Core Architecture](https://execbox.aallam.com/architecture/execbox-core)
|
|
91
|
-
- [MCP And Protocol](https://execbox.aallam.com/architecture/execbox-mcp-and-protocol)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
* Public TypeScript declarations for this package entrypoint.
|
|
4
4
|
*/
|
|
5
|
-
import { u as ExecuteErrorCode } from "./runner-
|
|
5
|
+
import { u as ExecuteErrorCode } from "./runner-DXLu0eJV.js";
|
|
6
6
|
|
|
7
7
|
//#region src/errors.d.ts
|
|
8
8
|
|
|
@@ -26,4 +26,4 @@ declare function isExecuteFailure(value: unknown): value is ExecuteFailure;
|
|
|
26
26
|
declare function isJsonSerializable(value: unknown, active?: Set<object>, memo?: WeakSet<object>): boolean;
|
|
27
27
|
//#endregion
|
|
28
28
|
export { isExecuteFailure as n, isJsonSerializable as r, ExecuteFailure as t };
|
|
29
|
-
//# sourceMappingURL=errors-
|
|
29
|
+
//# sourceMappingURL=errors-BIWv-QIC.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors-
|
|
1
|
+
{"version":3,"file":"errors-BIWv-QIC.d.ts","names":[],"sources":["../src/errors.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;AAKA,CAAA,CAAA;AACQ,OAAA,CAAA,KAAA,CADK,cAAA,CAAA,OAAA,CAAuB,KAAA,CAC5B;EAKY,IAAA,CAAA,CALZ,gBAKY;EANgB,CAAA,CAAA;;AAgBpC,CAAA,CAAA,CAAA,CAAA;EAOgB,WAAA,CAAA,IAAA,CAAA,CAjBI,gBAmBZ,CAAA,CAAA,OACF,CAAA,CAAA,MAAA,CAAA;;;;;iBAVU,gBAAA,2BAA2C;;;;iBAO3C,kBAAA,0BAER,oBACF"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
* Public TypeScript declarations for this package entrypoint.
|
|
4
4
|
*/
|
|
5
|
-
import { u as ExecuteErrorCode } from "./runner-
|
|
5
|
+
import { u as ExecuteErrorCode } from "./runner-Cy18Z0u0.cjs";
|
|
6
6
|
|
|
7
7
|
//#region src/errors.d.ts
|
|
8
8
|
|
|
@@ -26,4 +26,4 @@ declare function isExecuteFailure(value: unknown): value is ExecuteFailure;
|
|
|
26
26
|
declare function isJsonSerializable(value: unknown, active?: Set<object>, memo?: WeakSet<object>): boolean;
|
|
27
27
|
//#endregion
|
|
28
28
|
export { isExecuteFailure as n, isJsonSerializable as r, ExecuteFailure as t };
|
|
29
|
-
//# sourceMappingURL=errors-
|
|
29
|
+
//# sourceMappingURL=errors-y4C-EIWT.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors-
|
|
1
|
+
{"version":3,"file":"errors-y4C-EIWT.d.cts","names":[],"sources":["../src/errors.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;AAKA,CAAA,CAAA;AACQ,OAAA,CAAA,KAAA,CADK,cAAA,CAAA,OAAA,CAAuB,KAAA,CAC5B;EAKY,IAAA,CAAA,CALZ,gBAKY;EANgB,CAAA,CAAA;;AAgBpC,CAAA,CAAA,CAAA,CAAA;EAOgB,WAAA,CAAA,IAAA,CAAA,CAjBI,gBAmBZ,CAAA,CAAA,OACF,CAAA,CAAA,MAAA,CAAA;;;;;iBAVU,gBAAA,2BAA2C;;;;iBAO3C,kBAAA,0BAER,oBACF"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
* Public TypeScript declarations for this package entrypoint.
|
|
4
4
|
*/
|
|
5
|
-
import { d as ExecuteResult, m as ResolvedToolProvider, t as ExecutionOptions } from "./runner-
|
|
5
|
+
import { d as ExecuteResult, m as ResolvedToolProvider, t as ExecutionOptions } from "./runner-DXLu0eJV.js";
|
|
6
6
|
|
|
7
7
|
//#region src/executor/executor.d.ts
|
|
8
8
|
|
|
@@ -26,4 +26,4 @@ interface Executor {
|
|
|
26
26
|
}
|
|
27
27
|
//#endregion
|
|
28
28
|
export { ExecutorPoolOptions as n, Executor as t };
|
|
29
|
-
//# sourceMappingURL=executor-
|
|
29
|
+
//# sourceMappingURL=executor-BOTd9xNK.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor-
|
|
1
|
+
{"version":3,"file":"executor-BOTd9xNK.d.ts","names":[],"sources":["../src/executor/executor.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AAOA,CAAA,CAAA,CAAA,QAAA,CAAA,OAAA,CAAA,QAAA,CAAA,GAAA,CAAA,QAAA,CAAA,eAAA,CAAA,IAAA,CAAA,GAAA,CAAA;AAUA,CAAA,CAAA,CAAA,IAAA,CAAA,IAAA,CAAA,MAAA,CAAA,KAAA,CAAA,KAAA,CAAA,QAAA,CAAA,CAAA,CAAA,KAAA,CAAA,KAAA,CAAA,OAAA,CAAA,GAAA,CAAA,SAAA;;AAIc,SAAA,CAdG,mBAAA,CAcH;EACD,aAAA,CAAA,CAAA,CAAA,MAAA;EAAR,OAAA,CAAA,CAAA,MAAA;EACS,OAAA,CAAA,CAAA,CAAA,MAAA;EACc,OAAA,CAAA,CAAA,CAAA,OAAA,CAAA,CAAA,CAAA,MAAA;;;;;UAPX,QAAA;mCAGF,kCACD,mBACT,QAAQ;cACC;4BACc"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
* Public TypeScript declarations for this package entrypoint.
|
|
4
4
|
*/
|
|
5
|
-
import { d as ExecuteResult, m as ResolvedToolProvider, t as ExecutionOptions } from "./runner-
|
|
5
|
+
import { d as ExecuteResult, m as ResolvedToolProvider, t as ExecutionOptions } from "./runner-Cy18Z0u0.cjs";
|
|
6
6
|
|
|
7
7
|
//#region src/executor/executor.d.ts
|
|
8
8
|
|
|
@@ -26,4 +26,4 @@ interface Executor {
|
|
|
26
26
|
}
|
|
27
27
|
//#endregion
|
|
28
28
|
export { ExecutorPoolOptions as n, Executor as t };
|
|
29
|
-
//# sourceMappingURL=executor-
|
|
29
|
+
//# sourceMappingURL=executor-CtbrvTQ_.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor-
|
|
1
|
+
{"version":3,"file":"executor-CtbrvTQ_.d.cts","names":[],"sources":["../src/executor/executor.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AAOA,CAAA,CAAA,CAAA,QAAA,CAAA,OAAA,CAAA,QAAA,CAAA,GAAA,CAAA,QAAA,CAAA,eAAA,CAAA,IAAA,CAAA,GAAA,CAAA;AAUA,CAAA,CAAA,CAAA,IAAA,CAAA,IAAA,CAAA,MAAA,CAAA,KAAA,CAAA,KAAA,CAAA,QAAA,CAAA,CAAA,CAAA,KAAA,CAAA,KAAA,CAAA,OAAA,CAAA,GAAA,CAAA,SAAA;;AAIc,SAAA,CAdG,mBAAA,CAcH;EACD,aAAA,CAAA,CAAA,CAAA,MAAA;EAAR,OAAA,CAAA,CAAA,MAAA;EACS,OAAA,CAAA,CAAA,CAAA,MAAA;EACc,OAAA,CAAA,CAAA,CAAA,OAAA,CAAA,CAAA,CAAA,MAAA;;;;;UAPX,QAAA;mCAGF,kCACD,mBACT,QAAQ;cACC;4BACc"}
|
package/dist/index.cjs
CHANGED
package/dist/index.d.cts
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
* Public TypeScript declarations for this package entrypoint.
|
|
4
4
|
*/
|
|
5
|
-
import { _ as
|
|
6
|
-
import { n as ExecutorPoolOptions, t as Executor } from "./executor-
|
|
7
|
-
import { n as isExecuteFailure, t as ExecuteFailure } from "./errors-
|
|
5
|
+
import { _ as ToolExecutionContext, d as ExecuteResult, f as JsonSchema, g as ToolDescriptor, h as ToolAnnotations, l as ExecuteError, m as ResolvedToolProvider, n as ExecutorRuntimeOptions, p as ResolvedToolDescriptor, t as ExecutionOptions, u as ExecuteErrorCode, v as ToolProvider, y as ToolSchema } from "./runner-Cy18Z0u0.cjs";
|
|
6
|
+
import { n as ExecutorPoolOptions, t as Executor } from "./executor-CtbrvTQ_.cjs";
|
|
7
|
+
import { n as isExecuteFailure, t as ExecuteFailure } from "./errors-y4C-EIWT.cjs";
|
|
8
8
|
|
|
9
9
|
//#region src/provider/resolveProvider.d.ts
|
|
10
10
|
/**
|
|
@@ -12,5 +12,5 @@ import { n as isExecuteFailure, t as ExecuteFailure } from "./errors-B9ADBuDH.cj
|
|
|
12
12
|
*/
|
|
13
13
|
declare function resolveProvider(provider: ToolProvider): ResolvedToolProvider;
|
|
14
14
|
//#endregion
|
|
15
|
-
export { type ExecuteError, type ExecuteErrorCode, ExecuteFailure, type ExecuteResult, type ExecutionOptions, type Executor, type ExecutorPoolOptions, type ExecutorRuntimeOptions, type JsonSchema, type ResolvedToolDescriptor, type ResolvedToolProvider, type ToolDescriptor, type ToolExecutionContext, type ToolProvider, type ToolSchema, isExecuteFailure, resolveProvider };
|
|
15
|
+
export { type ExecuteError, type ExecuteErrorCode, ExecuteFailure, type ExecuteResult, type ExecutionOptions, type Executor, type ExecutorPoolOptions, type ExecutorRuntimeOptions, type JsonSchema, type ResolvedToolDescriptor, type ResolvedToolProvider, type ToolAnnotations, type ToolDescriptor, type ToolExecutionContext, type ToolProvider, type ToolSchema, isExecuteFailure, resolveProvider };
|
|
16
16
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/provider/resolveProvider.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/provider/resolveProvider.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;iBAgFgB,eAAA,WAA0B,eAAe"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
* Public TypeScript declarations for this package entrypoint.
|
|
4
4
|
*/
|
|
5
|
-
import { _ as
|
|
6
|
-
import { n as ExecutorPoolOptions, t as Executor } from "./executor-
|
|
7
|
-
import { n as isExecuteFailure, t as ExecuteFailure } from "./errors-
|
|
5
|
+
import { _ as ToolExecutionContext, d as ExecuteResult, f as JsonSchema, g as ToolDescriptor, h as ToolAnnotations, l as ExecuteError, m as ResolvedToolProvider, n as ExecutorRuntimeOptions, p as ResolvedToolDescriptor, t as ExecutionOptions, u as ExecuteErrorCode, v as ToolProvider, y as ToolSchema } from "./runner-DXLu0eJV.js";
|
|
6
|
+
import { n as ExecutorPoolOptions, t as Executor } from "./executor-BOTd9xNK.js";
|
|
7
|
+
import { n as isExecuteFailure, t as ExecuteFailure } from "./errors-BIWv-QIC.js";
|
|
8
8
|
|
|
9
9
|
//#region src/provider/resolveProvider.d.ts
|
|
10
10
|
/**
|
|
@@ -12,5 +12,5 @@ import { n as isExecuteFailure, t as ExecuteFailure } from "./errors-DlbJQYs7.js
|
|
|
12
12
|
*/
|
|
13
13
|
declare function resolveProvider(provider: ToolProvider): ResolvedToolProvider;
|
|
14
14
|
//#endregion
|
|
15
|
-
export { type ExecuteError, type ExecuteErrorCode, ExecuteFailure, type ExecuteResult, type ExecutionOptions, type Executor, type ExecutorPoolOptions, type ExecutorRuntimeOptions, type JsonSchema, type ResolvedToolDescriptor, type ResolvedToolProvider, type ToolDescriptor, type ToolExecutionContext, type ToolProvider, type ToolSchema, isExecuteFailure, resolveProvider };
|
|
15
|
+
export { type ExecuteError, type ExecuteErrorCode, ExecuteFailure, type ExecuteResult, type ExecutionOptions, type Executor, type ExecutorPoolOptions, type ExecutorRuntimeOptions, type JsonSchema, type ResolvedToolDescriptor, type ResolvedToolProvider, type ToolAnnotations, type ToolDescriptor, type ToolExecutionContext, type ToolProvider, type ToolSchema, isExecuteFailure, resolveProvider };
|
|
16
16
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/provider/resolveProvider.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/provider/resolveProvider.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;iBAgFgB,eAAA,WAA0B,eAAe"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { n as isExecuteFailure, t as ExecuteFailure } from "./errors-DdWVEGU8.js";
|
|
2
|
-
import { t as resolveProvider } from "./resolveProvider-
|
|
2
|
+
import { t as resolveProvider } from "./resolveProvider-CMrXPuTx.js";
|
|
3
3
|
|
|
4
4
|
export { ExecuteFailure, isExecuteFailure, resolveProvider };
|
package/dist/mcp/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_resolveProvider = require('../resolveProvider-
|
|
1
|
+
const require_resolveProvider = require('../resolveProvider-DFAg6No5.cjs');
|
|
2
2
|
require('../errors-xD8r6fCf.cjs');
|
|
3
3
|
let zod = require("zod");
|
|
4
4
|
zod = require_resolveProvider.__toESM(zod);
|
|
@@ -25,16 +25,26 @@ const MCP_CALL_TOOL_RESULT_TYPE = [
|
|
|
25
25
|
"};"
|
|
26
26
|
].join("\n");
|
|
27
27
|
/**
|
|
28
|
+
* Generates one wrapped MCP tool declaration exposed to guest code.
|
|
29
|
+
*/
|
|
30
|
+
function generateMcpWrappedToolType(provider, safeName) {
|
|
31
|
+
const tool = provider.tools[safeName];
|
|
32
|
+
if (!tool) throw new Error(`Unknown wrapped MCP tool: ${safeName}`);
|
|
33
|
+
return [require_resolveProvider.renderDocComment([...tool.description ? [tool.description, ""] : [], "Wrapped MCP tool. Inspect structuredContent first, then fall back to content text items."]), `function ${safeName}(input: ${require_resolveProvider.schemaToType(tool.inputSchema)}): Promise<McpCallToolResult>;`].filter(Boolean).join("\n");
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
28
36
|
* Generates the wrapped MCP tool namespace declarations exposed to guest code.
|
|
29
37
|
*/
|
|
30
38
|
function generateMcpWrappedToolTypes(provider) {
|
|
31
|
-
const declarations = [MCP_CALL_TOOL_RESULT_TYPE];
|
|
32
|
-
for (const [safeName, tool] of Object.entries(provider.tools)) {
|
|
33
|
-
const comment = require_resolveProvider.renderDocComment([...tool.description ? [tool.description, ""] : [], "Wrapped MCP tool. Inspect structuredContent first, then fall back to content text items."]);
|
|
34
|
-
declarations.push([comment, `function ${safeName}(input: ${require_resolveProvider.schemaToType(tool.inputSchema)}): Promise<McpCallToolResult>;`].filter(Boolean).join("\n"));
|
|
35
|
-
}
|
|
39
|
+
const declarations = [MCP_CALL_TOOL_RESULT_TYPE, ...Object.keys(provider.tools).map((safeName) => generateMcpWrappedToolType(provider, safeName))];
|
|
36
40
|
return require_resolveProvider.renderNamespaceDeclaration(provider.name, declarations);
|
|
37
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Generates the wrapped MCP tool namespace declaration for one selected tool.
|
|
44
|
+
*/
|
|
45
|
+
function generateMcpWrappedSingleToolTypes(provider, safeName) {
|
|
46
|
+
return require_resolveProvider.renderNamespaceDeclaration(provider.name, [MCP_CALL_TOOL_RESULT_TYPE, generateMcpWrappedToolType(provider, safeName)]);
|
|
47
|
+
}
|
|
38
48
|
|
|
39
49
|
//#endregion
|
|
40
50
|
//#region src/mcp/createMcpToolProvider.ts
|
|
@@ -53,6 +63,9 @@ async function closeAll(closers) {
|
|
|
53
63
|
const rejected = (await Promise.allSettled(closers.map((close) => close()))).find((result) => result.status === "rejected");
|
|
54
64
|
if (rejected) throw rejected.reason;
|
|
55
65
|
}
|
|
66
|
+
function asJsonSchema(schema) {
|
|
67
|
+
return typeof schema === "object" && schema !== null ? schema : void 0;
|
|
68
|
+
}
|
|
56
69
|
async function openMcpToolClient(source, clientInfo) {
|
|
57
70
|
if ("client" in source) return {
|
|
58
71
|
client: source.client,
|
|
@@ -86,11 +99,13 @@ async function openMcpToolProvider(source, options = {}) {
|
|
|
86
99
|
const connection = await openMcpToolClient(source, options.clientInfo ?? DEFAULT_MCP_TOOL_CLIENT_INFO);
|
|
87
100
|
try {
|
|
88
101
|
const toolsResponse = await connection.client.listTools();
|
|
102
|
+
const toolsByOriginalName = new Map(toolsResponse.tools.map((tool) => [tool.name, tool]));
|
|
89
103
|
const provider = {
|
|
90
104
|
name: options.namespace ?? "mcp",
|
|
91
105
|
tools: {}
|
|
92
106
|
};
|
|
93
107
|
for (const tool of toolsResponse.tools) provider.tools[tool.name] = {
|
|
108
|
+
annotations: tool.annotations,
|
|
94
109
|
description: tool.description,
|
|
95
110
|
execute: async (input, context) => {
|
|
96
111
|
const argumentsObject = typeof input === "object" && input !== null ? input : void 0;
|
|
@@ -102,13 +117,25 @@ async function openMcpToolProvider(source, options = {}) {
|
|
|
102
117
|
inputSchema: tool.inputSchema
|
|
103
118
|
};
|
|
104
119
|
const resolvedProvider = require_resolveProvider.resolveProvider(provider);
|
|
120
|
+
const toolDefinitions = Object.fromEntries(Object.entries(resolvedProvider.tools).map(([safeName, descriptor]) => {
|
|
121
|
+
const upstreamTool = toolsByOriginalName.get(descriptor.originalName);
|
|
122
|
+
return [safeName, {
|
|
123
|
+
annotations: descriptor.annotations,
|
|
124
|
+
description: descriptor.description,
|
|
125
|
+
inputSchema: descriptor.inputSchema,
|
|
126
|
+
originalName: descriptor.originalName,
|
|
127
|
+
outputSchema: asJsonSchema(upstreamTool?.outputSchema),
|
|
128
|
+
safeName: descriptor.safeName
|
|
129
|
+
}];
|
|
130
|
+
}));
|
|
105
131
|
return {
|
|
106
132
|
close: connection.close,
|
|
107
133
|
provider: {
|
|
108
134
|
...resolvedProvider,
|
|
109
135
|
types: generateMcpWrappedToolTypes(resolvedProvider)
|
|
110
136
|
},
|
|
111
|
-
serverInfo: getMcpToolSourceServerInfo(source)
|
|
137
|
+
serverInfo: getMcpToolSourceServerInfo(source),
|
|
138
|
+
toolDefinitions
|
|
112
139
|
};
|
|
113
140
|
} catch (error) {
|
|
114
141
|
await connection.close().catch(() => {});
|
|
@@ -126,6 +153,18 @@ async function createMcpToolProvider(source, options = {}) {
|
|
|
126
153
|
//#endregion
|
|
127
154
|
//#region src/mcp/codeMcpServer.ts
|
|
128
155
|
const DEFAULT_MAX_TEXT_CHARS = 24e3;
|
|
156
|
+
const CODE_EXECUTION_TOOL_ANNOTATIONS = {
|
|
157
|
+
destructiveHint: true,
|
|
158
|
+
idempotentHint: false,
|
|
159
|
+
openWorldHint: true,
|
|
160
|
+
readOnlyHint: false
|
|
161
|
+
};
|
|
162
|
+
const READ_ONLY_TOOL_ANNOTATIONS = {
|
|
163
|
+
destructiveHint: false,
|
|
164
|
+
idempotentHint: true,
|
|
165
|
+
openWorldHint: false,
|
|
166
|
+
readOnlyHint: true
|
|
167
|
+
};
|
|
129
168
|
const DEFAULT_MCP_CODE_WRAPPER_SERVER_INFO = {
|
|
130
169
|
name: "mcp-code-wrapper",
|
|
131
170
|
version: "0.0.0"
|
|
@@ -136,32 +175,41 @@ function truncateText(text, maxTextChars) {
|
|
|
136
175
|
function renderText(value, maxTextChars) {
|
|
137
176
|
return truncateText(JSON.stringify(value, null, 2), maxTextChars);
|
|
138
177
|
}
|
|
139
|
-
function searchTools(
|
|
178
|
+
function searchTools(toolDefinitions, namespace, query, limit) {
|
|
140
179
|
const normalizedQuery = query?.toLowerCase().trim();
|
|
141
|
-
const matches = Object.entries(provider.tools).map(([safeName, descriptor]) => ({
|
|
142
|
-
description: descriptor.description,
|
|
143
|
-
inputSchema: descriptor.inputSchema,
|
|
144
|
-
originalName: descriptor.originalName,
|
|
145
|
-
outputSchema: descriptor.outputSchema,
|
|
146
|
-
safeName
|
|
147
|
-
})).filter((tool) => {
|
|
148
|
-
if (!normalizedQuery) return true;
|
|
149
|
-
return [
|
|
150
|
-
tool.originalName,
|
|
151
|
-
tool.safeName,
|
|
152
|
-
tool.description ?? ""
|
|
153
|
-
].some((field) => field.toLowerCase().includes(normalizedQuery));
|
|
154
|
-
}).slice(0, limit);
|
|
155
180
|
return {
|
|
156
|
-
namespace
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
181
|
+
namespace,
|
|
182
|
+
tools: Object.values(toolDefinitions).filter((tool) => {
|
|
183
|
+
if (!normalizedQuery) return true;
|
|
184
|
+
return [
|
|
185
|
+
tool.originalName,
|
|
186
|
+
tool.safeName,
|
|
187
|
+
tool.description ?? ""
|
|
188
|
+
].some((field) => field.toLowerCase().includes(normalizedQuery));
|
|
189
|
+
}).slice(0, limit).map((tool) => ({
|
|
190
|
+
annotations: tool.annotations,
|
|
191
|
+
description: tool.description,
|
|
192
|
+
originalName: tool.originalName,
|
|
193
|
+
safeName: tool.safeName
|
|
194
|
+
}))
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
function getToolDetails(provider, toolDefinitions, safeName) {
|
|
198
|
+
const tool = toolDefinitions[safeName];
|
|
199
|
+
if (!tool) throw new Error(`Unknown wrapped MCP tool: ${safeName}`);
|
|
200
|
+
return {
|
|
201
|
+
annotations: tool.annotations,
|
|
202
|
+
description: tool.description,
|
|
203
|
+
inputSchema: tool.inputSchema,
|
|
204
|
+
originalName: tool.originalName,
|
|
205
|
+
outputSchema: tool.outputSchema,
|
|
206
|
+
safeName: tool.safeName,
|
|
207
|
+
types: generateMcpWrappedSingleToolTypes(provider, safeName)
|
|
161
208
|
};
|
|
162
209
|
}
|
|
163
210
|
function registerExecuteTool(server, name, provider, executor, maxTextChars, description) {
|
|
164
211
|
server.registerTool.bind(server)(name, {
|
|
212
|
+
annotations: CODE_EXECUTION_TOOL_ANNOTATIONS,
|
|
165
213
|
description,
|
|
166
214
|
inputSchema: { code: zod.string() }
|
|
167
215
|
}, async (args) => {
|
|
@@ -176,15 +224,32 @@ function registerExecuteTool(server, name, provider, executor, maxTextChars, des
|
|
|
176
224
|
};
|
|
177
225
|
});
|
|
178
226
|
}
|
|
179
|
-
function registerSearchTool(server, name,
|
|
227
|
+
function registerSearchTool(server, name, namespace, toolDefinitions, maxTextChars) {
|
|
180
228
|
server.registerTool.bind(server)(name, {
|
|
181
|
-
|
|
229
|
+
annotations: READ_ONLY_TOOL_ANNOTATIONS,
|
|
230
|
+
description: `Search wrapped MCP tools exposed under the ${namespace} namespace. Returns concise catalog entries only; call the details tool for schemas.`,
|
|
182
231
|
inputSchema: {
|
|
183
232
|
limit: zod.number().int().optional(),
|
|
184
233
|
query: zod.string().optional()
|
|
185
234
|
}
|
|
186
235
|
}, async (args) => {
|
|
187
|
-
const structuredContent = searchTools(
|
|
236
|
+
const structuredContent = searchTools(toolDefinitions, namespace, args.query, args.limit ?? 20);
|
|
237
|
+
return {
|
|
238
|
+
content: [{
|
|
239
|
+
text: renderText(structuredContent, maxTextChars),
|
|
240
|
+
type: "text"
|
|
241
|
+
}],
|
|
242
|
+
structuredContent
|
|
243
|
+
};
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
function registerDetailsTool(server, name, provider, toolDefinitions, maxTextChars) {
|
|
247
|
+
server.registerTool.bind(server)(name, {
|
|
248
|
+
annotations: READ_ONLY_TOOL_ANNOTATIONS,
|
|
249
|
+
description: `Return the full schema and generated TypeScript declaration for one wrapped ${provider.name} MCP tool.`,
|
|
250
|
+
inputSchema: { safeName: zod.string() }
|
|
251
|
+
}, async (args) => {
|
|
252
|
+
const structuredContent = getToolDetails(provider, toolDefinitions, args.safeName);
|
|
188
253
|
return {
|
|
189
254
|
content: [{
|
|
190
255
|
text: renderText(structuredContent, maxTextChars),
|
|
@@ -211,8 +276,9 @@ function attachOwnedClose(server, closeOwnedResources) {
|
|
|
211
276
|
*/
|
|
212
277
|
async function codeMcpServer(source, options) {
|
|
213
278
|
const maxTextChars = options.maxTextChars ?? DEFAULT_MAX_TEXT_CHARS;
|
|
214
|
-
const mode = options.mode ?? "
|
|
279
|
+
const mode = options.mode ?? "progressive";
|
|
215
280
|
const names = {
|
|
281
|
+
details: options.names?.details ?? "mcp_get_tool_details",
|
|
216
282
|
execute: options.names?.execute ?? "mcp_execute_code",
|
|
217
283
|
search: options.names?.search ?? "mcp_search_tools",
|
|
218
284
|
single: options.names?.single ?? "mcp_code"
|
|
@@ -224,9 +290,10 @@ async function codeMcpServer(source, options) {
|
|
|
224
290
|
const provider = handle.provider;
|
|
225
291
|
const server = new __modelcontextprotocol_sdk_server_mcp_js.McpServer(options.serverInfo ?? handle.serverInfo ?? DEFAULT_MCP_CODE_WRAPPER_SERVER_INFO);
|
|
226
292
|
try {
|
|
227
|
-
if (mode === "both" || mode === "
|
|
228
|
-
registerSearchTool(server, names.search, provider, maxTextChars);
|
|
229
|
-
|
|
293
|
+
if (mode === "both" || mode === "progressive") {
|
|
294
|
+
registerSearchTool(server, names.search, provider.name, handle.toolDefinitions, maxTextChars);
|
|
295
|
+
registerDetailsTool(server, names.details, provider, handle.toolDefinitions, maxTextChars);
|
|
296
|
+
registerExecuteTool(server, names.execute, provider, options.executor, maxTextChars, `Execute JavaScript against the wrapped ${provider.name} MCP tool namespace. Use the search and details tools before writing code.`);
|
|
230
297
|
}
|
|
231
298
|
if (mode === "both" || mode === "single") registerExecuteTool(server, names.single, provider, options.executor, maxTextChars, `Execute JavaScript against the wrapped ${provider.name} MCP tool namespace.\n\n${provider.types}`);
|
|
232
299
|
return attachOwnedClose(server, handle.close);
|
package/dist/mcp/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["renderDocComment","schemaToType","renderNamespaceDeclaration","InMemoryTransport","Client","closePromise: Promise<void> | undefined","provider: ToolProvider","resolveProvider","z","closePromise: Promise<void> | undefined","McpServer"],"sources":["../../src/mcp/mcpWrappedToolTypes.ts","../../src/mcp/createMcpToolProvider.ts","../../src/mcp/codeMcpServer.ts"],"sourcesContent":["import type { ResolvedToolProvider } from \"../types\";\nimport { schemaToType } from \"../typegen/jsonSchema\";\nimport {\n renderDocComment,\n renderNamespaceDeclaration,\n} from \"../typegen/render\";\n\nconst MCP_CALL_TOOL_RESULT_TYPE = [\n \"type McpCallToolResult = {\",\n \" content: Array<{\",\n \" type: string;\",\n \" text?: string;\",\n \" data?: string;\",\n \" mimeType?: string;\",\n \" resource?: unknown;\",\n \" uri?: string;\",\n \" name?: string;\",\n \" description?: string;\",\n \" }>;\",\n \" structuredContent?: unknown;\",\n \" isError?: boolean;\",\n \" _meta?: Record<string, unknown>;\",\n \"};\",\n].join(\"\\n\");\n\n/**\n * Generates the wrapped MCP tool namespace declarations exposed to guest code.\n */\nexport function generateMcpWrappedToolTypes(\n provider: ResolvedToolProvider,\n): string {\n const declarations = [MCP_CALL_TOOL_RESULT_TYPE];\n\n for (const [safeName, tool] of Object.entries(provider.tools)) {\n const comment = renderDocComment([\n ...(tool.description ? [tool.description, \"\"] : []),\n \"Wrapped MCP tool. Inspect structuredContent first, then fall back to content text items.\",\n ]);\n\n declarations.push(\n [\n comment,\n `function ${safeName}(input: ${schemaToType(tool.inputSchema)}): Promise<McpCallToolResult>;`,\n ]\n .filter(Boolean)\n .join(\"\\n\"),\n );\n }\n\n return renderNamespaceDeclaration(provider.name, declarations);\n}\n","import { Client } from \"@modelcontextprotocol/sdk/client/index.js\";\nimport { InMemoryTransport } from \"@modelcontextprotocol/sdk/inMemory.js\";\nimport type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport type { Implementation } from \"@modelcontextprotocol/sdk/types.js\";\n\nimport { resolveProvider } from \"../provider/resolveProvider\";\nimport type { ResolvedToolProvider, ToolProvider } from \"../types\";\nimport { generateMcpWrappedToolTypes } from \"./mcpWrappedToolTypes\";\n\n/**\n * Caller-owned MCP client source used by the convenience wrapper API.\n */\nexport type McpToolClientSource = {\n client: Client;\n serverInfo?: Implementation;\n};\n\n/**\n * Local MCP server source that requires explicit lifecycle cleanup.\n */\nexport type McpToolServerSource = {\n server: McpServer;\n serverInfo?: Implementation;\n};\n\n/**\n * Source used to discover MCP tools for wrapping.\n */\nexport type McpToolSource = McpToolClientSource | McpToolServerSource;\n\nconst DEFAULT_MCP_TOOL_CLIENT_INFO = {\n name: \"mcp-tool-client\",\n version: \"0.0.0\",\n} satisfies Implementation;\n\n/**\n * Returns the upstream server identity when the source can provide one.\n */\nexport function getMcpToolSourceServerInfo(\n source: McpToolSource,\n): Implementation | undefined {\n if (source.serverInfo) {\n return source.serverInfo;\n }\n\n if (\"client\" in source) {\n return source.client.getServerVersion();\n }\n\n return undefined;\n}\n\n/**\n * Options for wrapping MCP tools into a code-execution provider.\n */\nexport interface CreateMcpToolProviderOptions {\n /** Namespace exposed to guest code for the wrapped tools. */\n namespace?: string;\n /** Implementation metadata exposed to local `{ server }` sources as the client identity. */\n clientInfo?: Implementation;\n}\n\n/**\n * Explicit handle for a wrapped MCP provider and any owned source connections.\n */\nexport interface McpToolProviderHandle {\n /** Resolved provider exposed to the executor or wrapper server. */\n provider: ResolvedToolProvider;\n /** Best-effort upstream server identity when available. */\n serverInfo?: Implementation;\n /** Releases any internal MCP client/server connection opened for the provider. */\n close: () => Promise<void>;\n}\n\ninterface OpenMcpToolClientResult {\n client: Client;\n close: () => Promise<void>;\n}\n\nasync function closeAll(closers: Array<() => Promise<void>>): Promise<void> {\n const results = await Promise.allSettled(closers.map((close) => close()));\n const rejected = results.find(\n (result): result is PromiseRejectedResult => result.status === \"rejected\",\n );\n\n if (rejected) {\n throw rejected.reason;\n }\n}\n\nasync function openMcpToolClient(\n source: McpToolSource,\n clientInfo: Implementation,\n): Promise<OpenMcpToolClientResult> {\n if (\"client\" in source) {\n return {\n client: source.client,\n close: async () => {},\n };\n }\n\n if (source.server.isConnected()) {\n throw new Error(\"{ server } sources must be unconnected local MCP servers\");\n }\n\n const [clientTransport, serverTransport] =\n InMemoryTransport.createLinkedPair();\n const client = new Client(clientInfo);\n let closePromise: Promise<void> | undefined;\n let serverConnected = false;\n\n try {\n await source.server.connect(serverTransport);\n serverConnected = true;\n await client.connect(clientTransport);\n } catch (error) {\n await Promise.allSettled([\n Promise.resolve().then(() => client.close()),\n serverConnected\n ? Promise.resolve().then(() => source.server.close())\n : Promise.resolve(),\n ]);\n throw error;\n }\n\n return {\n client,\n close: async () => {\n closePromise ??= closeAll([\n () => client.close(),\n () => source.server.close(),\n ]);\n return closePromise;\n },\n };\n}\n\n/**\n * Opens an MCP tool source as a resolved execution provider with explicit cleanup.\n */\nexport async function openMcpToolProvider(\n source: McpToolSource,\n options: CreateMcpToolProviderOptions = {},\n): Promise<McpToolProviderHandle> {\n const connection = await openMcpToolClient(\n source,\n options.clientInfo ?? DEFAULT_MCP_TOOL_CLIENT_INFO,\n );\n\n try {\n const toolsResponse = await connection.client.listTools();\n const provider: ToolProvider = {\n name: options.namespace ?? \"mcp\",\n tools: {},\n };\n\n for (const tool of toolsResponse.tools) {\n provider.tools[tool.name] = {\n description: tool.description,\n execute: async (input, context) => {\n const argumentsObject =\n typeof input === \"object\" && input !== null\n ? (input as Record<string, unknown>)\n : undefined;\n\n return connection.client.callTool(\n {\n arguments: argumentsObject,\n name: tool.name,\n },\n undefined,\n { signal: context.signal },\n );\n },\n inputSchema: tool.inputSchema,\n };\n }\n\n const resolvedProvider = resolveProvider(provider);\n\n return {\n close: connection.close,\n provider: {\n ...resolvedProvider,\n types: generateMcpWrappedToolTypes(resolvedProvider),\n },\n serverInfo: getMcpToolSourceServerInfo(source),\n };\n } catch (error) {\n await connection.close().catch(() => {});\n throw error;\n }\n}\n\n/**\n * Wraps MCP tools from a caller-owned MCP client as a resolved execution provider.\n */\nexport async function createMcpToolProvider(\n source: McpToolClientSource,\n options: CreateMcpToolProviderOptions = {},\n): Promise<ResolvedToolProvider> {\n if (\"server\" in (source as unknown as McpToolSource)) {\n throw new Error(\n \"createMcpToolProvider() no longer accepts { server } sources. Use openMcpToolProvider() to receive a cleanup handle for owned local MCP server connections.\",\n );\n }\n\n const handle = await openMcpToolProvider(source, options);\n return handle.provider;\n}\n","import { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport type { Implementation } from \"@modelcontextprotocol/sdk/types.js\";\nimport * as z from \"zod\";\n\nimport type { Executor } from \"../executor/executor\";\nimport type { ResolvedToolProvider } from \"../types\";\nimport {\n openMcpToolProvider,\n type CreateMcpToolProviderOptions,\n type McpToolSource,\n} from \"./createMcpToolProvider\";\n\n/**\n * Options for exposing wrapped MCP tool execution through an MCP server.\n */\nexport interface CodeMcpServerOptions extends CreateMcpToolProviderOptions {\n /** Executor used to run guest JavaScript against the wrapped provider. */\n executor: Executor;\n /** Implementation metadata exposed to downstream clients as the wrapper server identity. */\n serverInfo?: Implementation;\n /** Maximum number of text characters returned in text content blocks. */\n maxTextChars?: number;\n /** Wrapper tool layout to expose on the returned server. */\n mode?: \"both\" | \"single\" | \"split\";\n /** Optional custom names for the wrapper tools. */\n names?: {\n execute?: string;\n search?: string;\n single?: string;\n };\n}\n\nconst DEFAULT_MAX_TEXT_CHARS = 24_000;\nconst DEFAULT_MCP_CODE_WRAPPER_SERVER_INFO = {\n name: \"mcp-code-wrapper\",\n version: \"0.0.0\",\n} satisfies Implementation;\n\nfunction truncateText(text: string, maxTextChars: number): string {\n return text.length <= maxTextChars ? text : text.slice(0, maxTextChars);\n}\n\nfunction renderText(value: unknown, maxTextChars: number): string {\n return truncateText(JSON.stringify(value, null, 2), maxTextChars);\n}\n\nfunction searchTools(\n provider: ResolvedToolProvider,\n query: string | undefined,\n limit: number,\n): Record<string, unknown> {\n const normalizedQuery = query?.toLowerCase().trim();\n const matches = Object.entries(provider.tools)\n .map(([safeName, descriptor]) => ({\n description: descriptor.description,\n inputSchema: descriptor.inputSchema,\n originalName: descriptor.originalName,\n outputSchema: descriptor.outputSchema,\n safeName,\n }))\n .filter((tool) => {\n if (!normalizedQuery) {\n return true;\n }\n\n return [tool.originalName, tool.safeName, tool.description ?? \"\"].some(\n (field) => field.toLowerCase().includes(normalizedQuery),\n );\n })\n .slice(0, limit);\n\n return {\n namespace: provider.name,\n originalToSafeName: provider.originalToSafeName,\n safeToOriginalName: provider.safeToOriginalName,\n tools: matches,\n types: provider.types,\n };\n}\n\nfunction registerExecuteTool(\n server: McpServer,\n name: string,\n provider: ResolvedToolProvider,\n executor: Executor,\n maxTextChars: number,\n description: string,\n): void {\n // Cast required: McpServer.registerTool's generic signature doesn't support\n // the narrow input/output shape we need for the code-execution tool.\n const registerTool = server.registerTool.bind(server) as (\n toolName: string,\n config: {\n description: string;\n inputSchema: Record<string, z.ZodTypeAny>;\n },\n handler: (args: { code: string }) => Promise<{\n content: Array<{ text: string; type: \"text\" }>;\n isError: boolean;\n structuredContent: Record<string, unknown>;\n }>,\n ) => void;\n\n registerTool(\n name,\n {\n description,\n inputSchema: {\n code: z.string(),\n },\n },\n async (args: { code: string }) => {\n const execution = await executor.execute(args.code, [provider]);\n\n return {\n content: [{ text: renderText(execution, maxTextChars), type: \"text\" }],\n isError: !execution.ok,\n // ExecuteResult is JSON-safe; cast satisfies the SDK's generic record type.\n structuredContent: execution as Record<string, unknown>,\n };\n },\n );\n}\n\nfunction registerSearchTool(\n server: McpServer,\n name: string,\n provider: ResolvedToolProvider,\n maxTextChars: number,\n): void {\n // Cast required: same rationale as registerExecuteTool above.\n const registerTool = server.registerTool.bind(server) as (\n toolName: string,\n config: {\n description: string;\n inputSchema: Record<string, z.ZodTypeAny>;\n },\n handler: (args: { limit?: number; query?: string }) => Promise<{\n content: Array<{ text: string; type: \"text\" }>;\n structuredContent: Record<string, unknown>;\n }>,\n ) => void;\n\n registerTool(\n name,\n {\n description: `Search wrapped MCP tools exposed under the ${provider.name} namespace.`,\n inputSchema: {\n limit: z.number().int().optional(),\n query: z.string().optional(),\n },\n },\n async (args: { limit?: number; query?: string }) => {\n const structuredContent = searchTools(\n provider,\n args.query,\n args.limit ?? 20,\n );\n return {\n content: [\n { text: renderText(structuredContent, maxTextChars), type: \"text\" },\n ],\n structuredContent,\n };\n },\n );\n}\n\nfunction attachOwnedClose(\n server: McpServer,\n closeOwnedResources: () => Promise<void>,\n): McpServer {\n const originalClose = server.close.bind(server);\n let closePromise: Promise<void> | undefined;\n\n server.close = async () => {\n closePromise ??= (async () => {\n const results = await Promise.allSettled([\n originalClose(),\n closeOwnedResources(),\n ]);\n const rejected = results.find(\n (result): result is PromiseRejectedResult =>\n result.status === \"rejected\",\n );\n\n if (rejected) {\n throw rejected.reason;\n }\n })();\n\n return closePromise;\n };\n\n return server;\n}\n\n/**\n * Creates an MCP server that exposes code-execution tools for a wrapped MCP source.\n */\nexport async function codeMcpServer(\n source: McpToolSource,\n options: CodeMcpServerOptions,\n): Promise<McpServer> {\n const maxTextChars = options.maxTextChars ?? DEFAULT_MAX_TEXT_CHARS;\n const mode = options.mode ?? \"both\";\n const names = {\n execute: options.names?.execute ?? \"mcp_execute_code\",\n search: options.names?.search ?? \"mcp_search_tools\",\n single: options.names?.single ?? \"mcp_code\",\n };\n const handle = await openMcpToolProvider(source, {\n clientInfo: options.clientInfo,\n namespace: options.namespace ?? \"mcp\",\n });\n const provider = handle.provider;\n const server = new McpServer(\n options.serverInfo ??\n handle.serverInfo ??\n DEFAULT_MCP_CODE_WRAPPER_SERVER_INFO,\n );\n\n try {\n if (mode === \"both\" || mode === \"split\") {\n registerSearchTool(server, names.search, provider, maxTextChars);\n registerExecuteTool(\n server,\n names.execute,\n provider,\n options.executor,\n maxTextChars,\n `Execute JavaScript against the wrapped ${provider.name} MCP tool namespace.`,\n );\n }\n\n if (mode === \"both\" || mode === \"single\") {\n registerExecuteTool(\n server,\n names.single,\n provider,\n options.executor,\n maxTextChars,\n `Execute JavaScript against the wrapped ${provider.name} MCP tool namespace.\\n\\n${provider.types}`,\n );\n }\n\n return attachOwnedClose(server, handle.close);\n } catch (error) {\n await handle.close().catch(() => {});\n throw error;\n }\n}\n"],"mappings":";;;;;;;;;AAOA,MAAM,4BAA4B;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC,KAAK,KAAK;;;;AAKZ,SAAgB,4BACd,UACQ;CACR,MAAM,eAAe,CAAC,0BAA0B;AAEhD,MAAK,MAAM,CAAC,UAAU,SAAS,OAAO,QAAQ,SAAS,MAAM,EAAE;EAC7D,MAAM,UAAUA,yCAAiB,CAC/B,GAAI,KAAK,cAAc,CAAC,KAAK,aAAa,GAAG,GAAG,EAAE,EAClD,2FACD,CAAC;AAEF,eAAa,KACX,CACE,SACA,YAAY,SAAS,UAAUC,qCAAa,KAAK,YAAY,CAAC,gCAC/D,CACE,OAAO,QAAQ,CACf,KAAK,KAAK,CACd;;AAGH,QAAOC,mDAA2B,SAAS,MAAM,aAAa;;;;;ACnBhE,MAAM,+BAA+B;CACnC,MAAM;CACN,SAAS;CACV;;;;AAKD,SAAgB,2BACd,QAC4B;AAC5B,KAAI,OAAO,WACT,QAAO,OAAO;AAGhB,KAAI,YAAY,OACd,QAAO,OAAO,OAAO,kBAAkB;;AAiC3C,eAAe,SAAS,SAAo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,gBAAgB;CAC7C,MAAM,OAAO,QAAQ,QAAQ;CAC7B,MAAM,QAAQ;EACZ,SAAS,QAAQ,OAAO,WAAW;EACnC,QAAQ,QAAQ,OAAO,UAAU;EACjC,QAAQ,QAAQ,OAAO,UAAU;EAClC;CACD,MAAM,SAAS,MAAM,oBAAoB,QAAQ;EAC/C,YAAY,QAAQ;EACpB,WAAW,QAAQ,aAAa;EACjC,CAAC;CACF,MAAM,WAAW,OAAO;CACxB,MAAM,SAAS,IAAIC,mDACjB,QAAQ,cACN,OAAO,cACP,qCACH;AAED,KAAI;AACF,MAAI,SAAS,UAAU,SAAS,SAAS;AACvC,sBAAmB,QAAQ,MAAM,QAAQ,UAAU,aAAa;AAChE,uBACE,QACA,MAAM,SACN,UACA,QAAQ,UACR,cACA,0CAA0C,SAAS,KAAK,sBACzD;;AAGH,MAAI,SAAS,UAAU,SAAS,SAC9B,qBACE,QACA,MAAM,QACN,UACA,QAAQ,UACR,cACA,0CAA0C,SAAS,KAAK,0BAA0B,SAAS,QAC5F;AAGH,SAAO,iBAAiB,QAAQ,OAAO,MAAM;UACtC,OAAO;AACd,QAAM,OAAO,OAAO,CAAC,YAAY,GAAG;AACpC,QAAM"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["renderDocComment","schemaToType","renderNamespaceDeclaration","InMemoryTransport","Client","closePromise: Promise<void> | undefined","provider: ToolProvider","resolveProvider","z","closePromise: Promise<void> | undefined","McpServer"],"sources":["../../src/mcp/mcpWrappedToolTypes.ts","../../src/mcp/createMcpToolProvider.ts","../../src/mcp/codeMcpServer.ts"],"sourcesContent":["import type { ResolvedToolProvider } from \"../types\";\nimport { schemaToType } from \"../typegen/jsonSchema\";\nimport {\n renderDocComment,\n renderNamespaceDeclaration,\n} from \"../typegen/render\";\n\nconst MCP_CALL_TOOL_RESULT_TYPE = [\n \"type McpCallToolResult = {\",\n \" content: Array<{\",\n \" type: string;\",\n \" text?: string;\",\n \" data?: string;\",\n \" mimeType?: string;\",\n \" resource?: unknown;\",\n \" uri?: string;\",\n \" name?: string;\",\n \" description?: string;\",\n \" }>;\",\n \" structuredContent?: unknown;\",\n \" isError?: boolean;\",\n \" _meta?: Record<string, unknown>;\",\n \"};\",\n].join(\"\\n\");\n\n/**\n * Generates one wrapped MCP tool declaration exposed to guest code.\n */\nexport function generateMcpWrappedToolType(\n provider: ResolvedToolProvider,\n safeName: string,\n): string {\n const tool = provider.tools[safeName];\n\n if (!tool) {\n throw new Error(`Unknown wrapped MCP tool: ${safeName}`);\n }\n\n const comment = renderDocComment([\n ...(tool.description ? [tool.description, \"\"] : []),\n \"Wrapped MCP tool. Inspect structuredContent first, then fall back to content text items.\",\n ]);\n\n return [\n comment,\n `function ${safeName}(input: ${schemaToType(tool.inputSchema)}): Promise<McpCallToolResult>;`,\n ]\n .filter(Boolean)\n .join(\"\\n\");\n}\n\n/**\n * Generates the wrapped MCP tool namespace declarations exposed to guest code.\n */\nexport function generateMcpWrappedToolTypes(\n provider: ResolvedToolProvider,\n): string {\n const declarations = [\n MCP_CALL_TOOL_RESULT_TYPE,\n ...Object.keys(provider.tools).map((safeName) =>\n generateMcpWrappedToolType(provider, safeName),\n ),\n ];\n\n return renderNamespaceDeclaration(provider.name, declarations);\n}\n\n/**\n * Generates the wrapped MCP tool namespace declaration for one selected tool.\n */\nexport function generateMcpWrappedSingleToolTypes(\n provider: ResolvedToolProvider,\n safeName: string,\n): string {\n return renderNamespaceDeclaration(provider.name, [\n MCP_CALL_TOOL_RESULT_TYPE,\n generateMcpWrappedToolType(provider, safeName),\n ]);\n}\n","import { Client } from \"@modelcontextprotocol/sdk/client/index.js\";\nimport { InMemoryTransport } from \"@modelcontextprotocol/sdk/inMemory.js\";\nimport type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport type { Implementation } from \"@modelcontextprotocol/sdk/types.js\";\n\nimport { resolveProvider } from \"../provider/resolveProvider\";\nimport type {\n JsonSchema,\n ResolvedToolProvider,\n ToolAnnotations,\n ToolProvider,\n} from \"../types\";\nimport { generateMcpWrappedToolTypes } from \"./mcpWrappedToolTypes\";\n\n/**\n * Caller-owned MCP client source used by the convenience wrapper API.\n */\nexport type McpToolClientSource = {\n client: Client;\n serverInfo?: Implementation;\n};\n\n/**\n * Local MCP server source that requires explicit lifecycle cleanup.\n */\nexport type McpToolServerSource = {\n server: McpServer;\n serverInfo?: Implementation;\n};\n\n/**\n * Source used to discover MCP tools for wrapping.\n */\nexport type McpToolSource = McpToolClientSource | McpToolServerSource;\n\nconst DEFAULT_MCP_TOOL_CLIENT_INFO = {\n name: \"mcp-tool-client\",\n version: \"0.0.0\",\n} satisfies Implementation;\n\n/**\n * Returns the upstream server identity when the source can provide one.\n */\nexport function getMcpToolSourceServerInfo(\n source: McpToolSource,\n): Implementation | undefined {\n if (source.serverInfo) {\n return source.serverInfo;\n }\n\n if (\"client\" in source) {\n return source.client.getServerVersion();\n }\n\n return undefined;\n}\n\n/**\n * Options for wrapping MCP tools into a code-execution provider.\n */\nexport interface CreateMcpToolProviderOptions {\n /** Namespace exposed to guest code for the wrapped tools. */\n namespace?: string;\n /** Implementation metadata exposed to local `{ server }` sources as the client identity. */\n clientInfo?: Implementation;\n}\n\n/**\n * Full wrapped MCP tool metadata used by progressive discovery surfaces.\n */\nexport interface McpWrappedToolDefinition {\n /** Optional MCP-compatible behavior hints copied from the upstream tool. */\n annotations?: ToolAnnotations;\n /** Optional human-readable description copied from the upstream tool. */\n description?: string;\n /** Normalized input schema used for wrapped tool argument validation. */\n inputSchema?: JsonSchema;\n /** Original upstream MCP tool name. */\n originalName: string;\n /** Upstream output schema for the tool's `structuredContent`, when provided. */\n outputSchema?: JsonSchema;\n /** Sanitized tool name visible in guest code. */\n safeName: string;\n}\n\n/**\n * Explicit handle for a wrapped MCP provider and any owned source connections.\n */\nexport interface McpToolProviderHandle {\n /** Resolved provider exposed to the executor or wrapper server. */\n provider: ResolvedToolProvider;\n /** Best-effort upstream server identity when available. */\n serverInfo?: Implementation;\n /** Full wrapped MCP tool definitions keyed by safe guest-visible name. */\n toolDefinitions: Record<string, McpWrappedToolDefinition>;\n /** Releases any internal MCP client/server connection opened for the provider. */\n close: () => Promise<void>;\n}\n\ninterface OpenMcpToolClientResult {\n client: Client;\n close: () => Promise<void>;\n}\n\nasync function closeAll(closers: Array<() => Promise<void>>): Promise<void> {\n const results = await Promise.allSettled(closers.map((close) => close()));\n const rejected = results.find(\n (result): result is PromiseRejectedResult => result.status === \"rejected\",\n );\n\n if (rejected) {\n throw rejected.reason;\n }\n}\n\nfunction asJsonSchema(schema: unknown): JsonSchema | undefined {\n return typeof schema === \"object\" && schema !== null\n ? (schema as JsonSchema)\n : undefined;\n}\n\nasync function openMcpToolClient(\n source: McpToolSource,\n clientInfo: Implementation,\n): Promise<OpenMcpToolClientResult> {\n if (\"client\" in source) {\n return {\n client: source.client,\n close: async () => {},\n };\n }\n\n if (source.server.isConnected()) {\n throw new Error(\"{ server } sources must be unconnected local MCP servers\");\n }\n\n const [clientTransport, serverTransport] =\n InMemoryTransport.createLinkedPair();\n const client = new Client(clientInfo);\n let closePromise: Promise<void> | undefined;\n let serverConnected = false;\n\n try {\n await source.server.connect(serverTransport);\n serverConnected = true;\n await client.connect(clientTransport);\n } catch (error) {\n await Promise.allSettled([\n Promise.resolve().then(() => client.close()),\n serverConnected\n ? Promise.resolve().then(() => source.server.close())\n : Promise.resolve(),\n ]);\n throw error;\n }\n\n return {\n client,\n close: async () => {\n closePromise ??= closeAll([\n () => client.close(),\n () => source.server.close(),\n ]);\n return closePromise;\n },\n };\n}\n\n/**\n * Opens an MCP tool source as a resolved execution provider with explicit cleanup.\n */\nexport async function openMcpToolProvider(\n source: McpToolSource,\n options: CreateMcpToolProviderOptions = {},\n): Promise<McpToolProviderHandle> {\n const connection = await openMcpToolClient(\n source,\n options.clientInfo ?? DEFAULT_MCP_TOOL_CLIENT_INFO,\n );\n\n try {\n const toolsResponse = await connection.client.listTools();\n const toolsByOriginalName = new Map(\n toolsResponse.tools.map((tool) => [tool.name, tool] as const),\n );\n const provider: ToolProvider = {\n name: options.namespace ?? \"mcp\",\n tools: {},\n };\n\n for (const tool of toolsResponse.tools) {\n provider.tools[tool.name] = {\n annotations: tool.annotations,\n description: tool.description,\n execute: async (input, context) => {\n const argumentsObject =\n typeof input === \"object\" && input !== null\n ? (input as Record<string, unknown>)\n : undefined;\n\n return connection.client.callTool(\n {\n arguments: argumentsObject,\n name: tool.name,\n },\n undefined,\n { signal: context.signal },\n );\n },\n inputSchema: tool.inputSchema,\n };\n }\n\n const resolvedProvider = resolveProvider(provider);\n const toolDefinitions = Object.fromEntries(\n Object.entries(resolvedProvider.tools).map(([safeName, descriptor]) => {\n const upstreamTool = toolsByOriginalName.get(descriptor.originalName);\n\n return [\n safeName,\n {\n annotations: descriptor.annotations,\n description: descriptor.description,\n inputSchema: descriptor.inputSchema,\n originalName: descriptor.originalName,\n outputSchema: asJsonSchema(upstreamTool?.outputSchema),\n safeName: descriptor.safeName,\n },\n ];\n }),\n );\n\n return {\n close: connection.close,\n provider: {\n ...resolvedProvider,\n types: generateMcpWrappedToolTypes(resolvedProvider),\n },\n serverInfo: getMcpToolSourceServerInfo(source),\n toolDefinitions,\n };\n } catch (error) {\n await connection.close().catch(() => {});\n throw error;\n }\n}\n\n/**\n * Wraps MCP tools from a caller-owned MCP client as a resolved execution provider.\n */\nexport async function createMcpToolProvider(\n source: McpToolClientSource,\n options: CreateMcpToolProviderOptions = {},\n): Promise<ResolvedToolProvider> {\n if (\"server\" in (source as unknown as McpToolSource)) {\n throw new Error(\n \"createMcpToolProvider() no longer accepts { server } sources. Use openMcpToolProvider() to receive a cleanup handle for owned local MCP server connections.\",\n );\n }\n\n const handle = await openMcpToolProvider(source, options);\n return handle.provider;\n}\n","import { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport type { Implementation } from \"@modelcontextprotocol/sdk/types.js\";\nimport * as z from \"zod\";\n\nimport type { Executor } from \"../executor/executor\";\nimport type { ResolvedToolProvider, ToolAnnotations } from \"../types\";\nimport {\n openMcpToolProvider,\n type CreateMcpToolProviderOptions,\n type McpWrappedToolDefinition,\n type McpToolSource,\n} from \"./createMcpToolProvider\";\nimport { generateMcpWrappedSingleToolTypes } from \"./mcpWrappedToolTypes\";\n\n/**\n * Options for exposing wrapped MCP tool execution through an MCP server.\n */\nexport interface CodeMcpServerOptions extends CreateMcpToolProviderOptions {\n /** Executor used to run guest JavaScript against the wrapped provider. */\n executor: Executor;\n /** Implementation metadata exposed to downstream clients as the wrapper server identity. */\n serverInfo?: Implementation;\n /** Maximum number of text characters returned in text content blocks. */\n maxTextChars?: number;\n /** Wrapper tool layout to expose on the returned server. */\n mode?: \"both\" | \"progressive\" | \"single\";\n /** Optional custom names for the wrapper tools. */\n names?: {\n details?: string;\n execute?: string;\n search?: string;\n single?: string;\n };\n}\n\nconst DEFAULT_MAX_TEXT_CHARS = 24_000;\nconst CODE_EXECUTION_TOOL_ANNOTATIONS = {\n destructiveHint: true,\n idempotentHint: false,\n openWorldHint: true,\n readOnlyHint: false,\n} satisfies ToolAnnotations;\nconst READ_ONLY_TOOL_ANNOTATIONS = {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n} satisfies ToolAnnotations;\nconst DEFAULT_MCP_CODE_WRAPPER_SERVER_INFO = {\n name: \"mcp-code-wrapper\",\n version: \"0.0.0\",\n} satisfies Implementation;\n\nfunction truncateText(text: string, maxTextChars: number): string {\n return text.length <= maxTextChars ? text : text.slice(0, maxTextChars);\n}\n\nfunction renderText(value: unknown, maxTextChars: number): string {\n return truncateText(JSON.stringify(value, null, 2), maxTextChars);\n}\n\nfunction searchTools(\n toolDefinitions: Record<string, McpWrappedToolDefinition>,\n namespace: string,\n query: string | undefined,\n limit: number,\n): Record<string, unknown> {\n const normalizedQuery = query?.toLowerCase().trim();\n const matches = Object.values(toolDefinitions)\n .filter((tool) => {\n if (!normalizedQuery) {\n return true;\n }\n\n return [tool.originalName, tool.safeName, tool.description ?? \"\"].some(\n (field) => field.toLowerCase().includes(normalizedQuery),\n );\n })\n .slice(0, limit)\n .map((tool) => ({\n annotations: tool.annotations,\n description: tool.description,\n originalName: tool.originalName,\n safeName: tool.safeName,\n }));\n\n return {\n namespace,\n tools: matches,\n };\n}\n\nfunction getToolDetails(\n provider: ResolvedToolProvider,\n toolDefinitions: Record<string, McpWrappedToolDefinition>,\n safeName: string,\n): Record<string, unknown> {\n const tool = toolDefinitions[safeName];\n\n if (!tool) {\n throw new Error(`Unknown wrapped MCP tool: ${safeName}`);\n }\n\n return {\n annotations: tool.annotations,\n description: tool.description,\n inputSchema: tool.inputSchema,\n originalName: tool.originalName,\n outputSchema: tool.outputSchema,\n safeName: tool.safeName,\n types: generateMcpWrappedSingleToolTypes(provider, safeName),\n };\n}\n\nfunction registerExecuteTool(\n server: McpServer,\n name: string,\n provider: ResolvedToolProvider,\n executor: Executor,\n maxTextChars: number,\n description: string,\n): void {\n // Cast required: McpServer.registerTool's generic signature doesn't support\n // the narrow input/output shape we need for the code-execution tool.\n const registerTool = server.registerTool.bind(server) as (\n toolName: string,\n config: {\n annotations: ToolAnnotations;\n description: string;\n inputSchema: Record<string, z.ZodTypeAny>;\n },\n handler: (args: { code: string }) => Promise<{\n content: Array<{ text: string; type: \"text\" }>;\n isError: boolean;\n structuredContent: Record<string, unknown>;\n }>,\n ) => void;\n\n registerTool(\n name,\n {\n annotations: CODE_EXECUTION_TOOL_ANNOTATIONS,\n description,\n inputSchema: {\n code: z.string(),\n },\n },\n async (args: { code: string }) => {\n const execution = await executor.execute(args.code, [provider]);\n\n return {\n content: [{ text: renderText(execution, maxTextChars), type: \"text\" }],\n isError: !execution.ok,\n // ExecuteResult is JSON-safe; cast satisfies the SDK's generic record type.\n structuredContent: execution as Record<string, unknown>,\n };\n },\n );\n}\n\nfunction registerSearchTool(\n server: McpServer,\n name: string,\n namespace: string,\n toolDefinitions: Record<string, McpWrappedToolDefinition>,\n maxTextChars: number,\n): void {\n // Cast required: same rationale as registerExecuteTool above.\n const registerTool = server.registerTool.bind(server) as (\n toolName: string,\n config: {\n annotations: ToolAnnotations;\n description: string;\n inputSchema: Record<string, z.ZodTypeAny>;\n },\n handler: (args: { limit?: number; query?: string }) => Promise<{\n content: Array<{ text: string; type: \"text\" }>;\n structuredContent: Record<string, unknown>;\n }>,\n ) => void;\n\n registerTool(\n name,\n {\n annotations: READ_ONLY_TOOL_ANNOTATIONS,\n description: `Search wrapped MCP tools exposed under the ${namespace} namespace. Returns concise catalog entries only; call the details tool for schemas.`,\n inputSchema: {\n limit: z.number().int().optional(),\n query: z.string().optional(),\n },\n },\n async (args: { limit?: number; query?: string }) => {\n const structuredContent = searchTools(\n toolDefinitions,\n namespace,\n args.query,\n args.limit ?? 20,\n );\n return {\n content: [\n { text: renderText(structuredContent, maxTextChars), type: \"text\" },\n ],\n structuredContent,\n };\n },\n );\n}\n\nfunction registerDetailsTool(\n server: McpServer,\n name: string,\n provider: ResolvedToolProvider,\n toolDefinitions: Record<string, McpWrappedToolDefinition>,\n maxTextChars: number,\n): void {\n // Cast required: same rationale as registerExecuteTool above.\n const registerTool = server.registerTool.bind(server) as (\n toolName: string,\n config: {\n annotations: ToolAnnotations;\n description: string;\n inputSchema: Record<string, z.ZodTypeAny>;\n },\n handler: (args: { safeName: string }) => Promise<{\n content: Array<{ text: string; type: \"text\" }>;\n structuredContent: Record<string, unknown>;\n }>,\n ) => void;\n\n registerTool(\n name,\n {\n annotations: READ_ONLY_TOOL_ANNOTATIONS,\n description: `Return the full schema and generated TypeScript declaration for one wrapped ${provider.name} MCP tool.`,\n inputSchema: {\n safeName: z.string(),\n },\n },\n async (args: { safeName: string }) => {\n const structuredContent = getToolDetails(\n provider,\n toolDefinitions,\n args.safeName,\n );\n return {\n content: [\n { text: renderText(structuredContent, maxTextChars), type: \"text\" },\n ],\n structuredContent,\n };\n },\n );\n}\n\nfunction attachOwnedClose(\n server: McpServer,\n closeOwnedResources: () => Promise<void>,\n): McpServer {\n const originalClose = server.close.bind(server);\n let closePromise: Promise<void> | undefined;\n\n server.close = async () => {\n closePromise ??= (async () => {\n const results = await Promise.allSettled([\n originalClose(),\n closeOwnedResources(),\n ]);\n const rejected = results.find(\n (result): result is PromiseRejectedResult =>\n result.status === \"rejected\",\n );\n\n if (rejected) {\n throw rejected.reason;\n }\n })();\n\n return closePromise;\n };\n\n return server;\n}\n\n/**\n * Creates an MCP server that exposes code-execution tools for a wrapped MCP source.\n */\nexport async function codeMcpServer(\n source: McpToolSource,\n options: CodeMcpServerOptions,\n): Promise<McpServer> {\n const maxTextChars = options.maxTextChars ?? DEFAULT_MAX_TEXT_CHARS;\n const mode = options.mode ?? \"progressive\";\n const names = {\n details: options.names?.details ?? \"mcp_get_tool_details\",\n execute: options.names?.execute ?? \"mcp_execute_code\",\n search: options.names?.search ?? \"mcp_search_tools\",\n single: options.names?.single ?? \"mcp_code\",\n };\n const handle = await openMcpToolProvider(source, {\n clientInfo: options.clientInfo,\n namespace: options.namespace ?? \"mcp\",\n });\n const provider = handle.provider;\n const server = new McpServer(\n options.serverInfo ??\n handle.serverInfo ??\n DEFAULT_MCP_CODE_WRAPPER_SERVER_INFO,\n );\n\n try {\n if (mode === \"both\" || mode === \"progressive\") {\n registerSearchTool(\n server,\n names.search,\n provider.name,\n handle.toolDefinitions,\n maxTextChars,\n );\n registerDetailsTool(\n server,\n names.details,\n provider,\n handle.toolDefinitions,\n maxTextChars,\n );\n registerExecuteTool(\n server,\n names.execute,\n provider,\n options.executor,\n maxTextChars,\n `Execute JavaScript against the wrapped ${provider.name} MCP tool namespace. Use the search and details tools before writing code.`,\n );\n }\n\n if (mode === \"both\" || mode === \"single\") {\n registerExecuteTool(\n server,\n names.single,\n provider,\n options.executor,\n maxTextChars,\n `Execute JavaScript against the wrapped ${provider.name} MCP tool namespace.\\n\\n${provider.types}`,\n );\n }\n\n return attachOwnedClose(server, handle.close);\n } catch (error) {\n await handle.close().catch(() => {});\n throw error;\n }\n}\n"],"mappings":";;;;;;;;;A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