@toolsdk.ai/registry 1.0.114 → 1.0.116

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 (97) hide show
  1. package/README.md +169 -26
  2. package/dist/api/index.d.ts +1 -1
  3. package/dist/api/index.js +23 -25
  4. package/dist/domains/config/config-route.d.ts +2 -0
  5. package/dist/domains/config/config-route.js +31 -0
  6. package/dist/domains/config/config-schema.d.ts +57 -0
  7. package/dist/domains/config/config-schema.js +10 -0
  8. package/dist/domains/config/config-types.d.ts +3 -0
  9. package/dist/domains/executor/executor-factory.d.ts +9 -0
  10. package/dist/domains/executor/executor-factory.js +17 -0
  11. package/dist/domains/executor/executor-types.d.ts +15 -0
  12. package/dist/domains/executor/local-executor.d.ts +12 -0
  13. package/dist/domains/executor/local-executor.js +48 -0
  14. package/dist/domains/executor/sandbox-executor.d.ts +16 -0
  15. package/dist/domains/executor/sandbox-executor.js +83 -0
  16. package/dist/domains/package/package-handler.d.ts +17 -0
  17. package/dist/domains/package/package-handler.js +58 -0
  18. package/dist/domains/package/package-repository.d.ts +9 -0
  19. package/dist/domains/package/package-repository.js +26 -0
  20. package/dist/domains/package/package-route.d.ts +2 -0
  21. package/dist/{api → domains/package}/package-route.js +38 -52
  22. package/dist/domains/package/package-schema.d.ts +244 -0
  23. package/dist/domains/package/package-schema.js +52 -0
  24. package/dist/domains/package/package-so.d.ts +78 -0
  25. package/dist/domains/package/package-so.js +61 -0
  26. package/dist/domains/package/package-so.test.js +378 -0
  27. package/dist/domains/package/package-types.d.ts +9 -0
  28. package/dist/domains/sandbox/clients/daytona-client.d.ts +17 -0
  29. package/dist/domains/sandbox/clients/daytona-client.js +112 -0
  30. package/dist/domains/sandbox/clients/sandock-client.d.ts +19 -0
  31. package/dist/domains/sandbox/clients/sandock-client.js +175 -0
  32. package/dist/domains/sandbox/sandbox-factory.d.ts +8 -0
  33. package/dist/domains/sandbox/sandbox-factory.js +23 -0
  34. package/dist/domains/sandbox/sandbox-pool-so.d.ts +25 -0
  35. package/dist/domains/sandbox/sandbox-pool-so.js +123 -0
  36. package/dist/domains/sandbox/sandbox-types.d.ts +25 -0
  37. package/dist/domains/sandbox/sandbox-types.js +1 -0
  38. package/dist/domains/sandbox/sandbox-utils.d.ts +3 -0
  39. package/dist/domains/sandbox/sandbox-utils.js +109 -0
  40. package/dist/domains/search/search-handler.d.ts +47 -0
  41. package/dist/domains/search/search-handler.js +113 -0
  42. package/dist/domains/search/search-route.d.ts +2 -0
  43. package/dist/domains/search/search-route.js +101 -0
  44. package/dist/domains/search/search-schema.d.ts +384 -0
  45. package/dist/domains/search/search-schema.js +99 -0
  46. package/dist/domains/search/search-so.d.ts +55 -0
  47. package/dist/{search/search-service.js → domains/search/search-so.js} +200 -297
  48. package/dist/shared/config/environment.d.ts +16 -0
  49. package/dist/shared/config/environment.js +41 -0
  50. package/dist/shared/schemas/common-schema.d.ts +249 -0
  51. package/dist/{schema.js → shared/schemas/common-schema.js} +37 -80
  52. package/dist/shared/schemas/index.d.ts +1 -0
  53. package/dist/shared/schemas/index.js +1 -0
  54. package/dist/shared/scripts-helpers/index.d.ts +60 -0
  55. package/dist/shared/scripts-helpers/index.js +61 -0
  56. package/dist/shared/utils/file-util.d.ts +1 -0
  57. package/dist/shared/utils/file-util.js +5 -0
  58. package/dist/shared/utils/index.d.ts +5 -0
  59. package/dist/shared/utils/index.js +5 -0
  60. package/dist/shared/utils/mcp-client-util.d.ts +31 -0
  61. package/dist/shared/utils/mcp-client-util.js +79 -0
  62. package/dist/shared/utils/package-util.d.ts +6 -0
  63. package/dist/shared/utils/package-util.js +53 -0
  64. package/dist/shared/utils/promise-util.d.ts +1 -0
  65. package/dist/shared/utils/promise-util.js +14 -0
  66. package/dist/{utils.d.ts → shared/utils/response-util.d.ts} +6 -2
  67. package/dist/{utils.js → shared/utils/response-util.js} +1 -6
  68. package/dist/shared/utils/string-util.d.ts +1 -0
  69. package/dist/shared/utils/string-util.js +25 -0
  70. package/dist/shared/utils/validation-util.d.ts +12 -0
  71. package/dist/shared/utils/validation-util.js +99 -0
  72. package/indexes/categories-list.json +1 -0
  73. package/indexes/packages-list.json +6 -0
  74. package/package.json +39 -3
  75. package/packages/developer-tools/neurolink.json +23 -0
  76. package/README.dev.md +0 -195
  77. package/dist/api/package-handler.d.ts +0 -18
  78. package/dist/api/package-handler.js +0 -73
  79. package/dist/api/package-route.d.ts +0 -2
  80. package/dist/api/package-so.d.ts +0 -19
  81. package/dist/api/package-so.js +0 -223
  82. package/dist/api/package.test.js +0 -19
  83. package/dist/helper.d.ts +0 -74
  84. package/dist/helper.js +0 -312
  85. package/dist/sandbox/mcp-sandbox-client.d.ts +0 -16
  86. package/dist/sandbox/mcp-sandbox-client.js +0 -229
  87. package/dist/sandbox/mcp-sandbox-client.test.js +0 -491
  88. package/dist/schema.d.ts +0 -806
  89. package/dist/search/search-route.d.ts +0 -3
  90. package/dist/search/search-route.js +0 -305
  91. package/dist/search/search-service.d.ts +0 -120
  92. package/dist/search/search.test.js +0 -100
  93. package/dist/types.d.ts +0 -28
  94. /package/dist/{api/package.test.d.ts → domains/config/config-types.js} +0 -0
  95. /package/dist/{sandbox/mcp-sandbox-client.test.d.ts → domains/executor/executor-types.js} +0 -0
  96. /package/dist/{search/search.test.d.ts → domains/package/package-so.test.d.ts} +0 -0
  97. /package/dist/{types.js → domains/package/package-types.js} +0 -0
@@ -1,223 +0,0 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import { getMcpClient, getPackageConfigByKey, typedAllPackagesList } from "../helper.js";
4
- import { MCPSandboxClient } from "../sandbox/mcp-sandbox-client.js";
5
- import { getDirname } from "../utils";
6
- const __dirname = getDirname(import.meta.url);
7
- export class PackageSO {
8
- constructor(provider = "LOCAL") {
9
- this.sandboxProvider = "LOCAL";
10
- this.sandboxProvider = provider;
11
- }
12
- // Acquire / Release explicit APIs (for external or future use)
13
- static async acquireSandbox(runtime = "python", provider = "DAYTONA") {
14
- const sandboxKey = PackageSO.getSandboxKey(runtime, provider);
15
- const record = PackageSO.sandboxInstances.get(sandboxKey);
16
- if (record) {
17
- record.refCount++;
18
- record.lastUsedAt = Date.now();
19
- return record.client;
20
- }
21
- // Create new instance (note MAX_SANDBOXES check, consistent with constructor logic)
22
- if (PackageSO.sandboxInstances.size >= PackageSO.MAX_SANDBOXES) {
23
- // Try to evict LRU idle instance
24
- let lruKey = null;
25
- let lruTime = Infinity;
26
- for (const [k, r] of PackageSO.sandboxInstances) {
27
- if (r.refCount === 0 && r.lastUsedAt < lruTime) {
28
- lruKey = k;
29
- lruTime = r.lastUsedAt;
30
- }
31
- }
32
- if (lruKey) {
33
- const evict = PackageSO.sandboxInstances.get(lruKey);
34
- if (evict) {
35
- await evict.client
36
- .kill()
37
- .catch((e) => console.error("[PackageSO] Error killing evicted sandbox:", e));
38
- PackageSO.sandboxInstances.delete(lruKey);
39
- }
40
- }
41
- else {
42
- throw new Error("Cannot create new sandbox: max sandboxes reached and none are idle");
43
- }
44
- }
45
- const client = new MCPSandboxClient(runtime, provider);
46
- const newRecord = {
47
- client,
48
- refCount: 1,
49
- lastUsedAt: Date.now(),
50
- provider,
51
- };
52
- PackageSO.sandboxInstances.set(sandboxKey, newRecord);
53
- return client;
54
- }
55
- static async releaseSandbox(runtime = "python", provider = "DAYTONA") {
56
- const sandboxKey = PackageSO.getSandboxKey(runtime, provider);
57
- const record = PackageSO.sandboxInstances.get(sandboxKey);
58
- if (!record)
59
- return;
60
- record.refCount = Math.max(0, record.refCount - 1);
61
- record.lastUsedAt = Date.now();
62
- if (record.refCount === 0) {
63
- try {
64
- await record.client.kill();
65
- PackageSO.sandboxInstances.delete(sandboxKey);
66
- console.log(`[PackageSO] Sandbox ${sandboxKey} closed immediately after use`);
67
- }
68
- catch (error) {
69
- console.error(`[PackageSO] Error closing sandbox ${sandboxKey}:`, error);
70
- }
71
- }
72
- }
73
- // Cleanup all static sandbox instances safely
74
- static async cleanupSandboxInstances() {
75
- const killers = [];
76
- for (const [key, record] of PackageSO.sandboxInstances) {
77
- killers.push((async () => {
78
- try {
79
- await record.client.kill();
80
- }
81
- catch (err) {
82
- console.error("[PackageSO] cleanup error for sandbox", key, err);
83
- }
84
- })());
85
- PackageSO.sandboxInstances.delete(key);
86
- }
87
- await Promise.all(killers);
88
- }
89
- static getSandboxKey(runtime, provider) {
90
- return `sandbox-${provider}-${runtime}`;
91
- }
92
- isSandboxEnabled() {
93
- return this.sandboxProvider === "DAYTONA" || this.sandboxProvider === "SANDOCK";
94
- }
95
- async executeTool(request) {
96
- const mcpServerConfig = getPackageConfigByKey(request.packageName);
97
- if (this.isSandboxEnabled()) {
98
- try {
99
- const result = await this.executeToolInSandbox(request);
100
- return result;
101
- }
102
- catch (error) {
103
- console.warn(`[executeTool] Sandbox mode failed for tool ${request.toolKey} in package ${request.packageName}, falling back to local mode:`, error);
104
- }
105
- }
106
- const { client, closeConnection } = await getMcpClient(mcpServerConfig, request.envs || {});
107
- try {
108
- const result = await client.callTool({
109
- name: request.toolKey,
110
- arguments: request.inputData,
111
- });
112
- console.log(`Tool ${request.toolKey} executed successfully`);
113
- return result;
114
- }
115
- finally {
116
- await closeConnection();
117
- }
118
- }
119
- async executeToolInSandbox(request) {
120
- const mcpServerConfig = getPackageConfigByKey(request.packageName);
121
- const runtime = mcpServerConfig.runtime || "python"; // Default to python if not specified
122
- const sandboxClient = await PackageSO.acquireSandbox(runtime, this.sandboxProvider);
123
- // Initialize if not already initialized (concurrency protection via MCPSandboxClient.initialize)
124
- await sandboxClient.initialize();
125
- try {
126
- const result = await sandboxClient.executeTool(request.packageName, request.toolKey, request.inputData || {}, request.envs);
127
- console.log(`Tool ${request.toolKey} executed successfully in sandbox`);
128
- return result;
129
- }
130
- catch (error) {
131
- // If it's a sandbox not found error, try reinitializing and retrying once
132
- if (error instanceof Error && error.message.includes("sandbox was not found")) {
133
- console.log("[PackageSO] Retrying tool execution after sandbox failure");
134
- await sandboxClient.initialize();
135
- // Retry tool execution
136
- const result = await sandboxClient.executeTool(request.packageName, request.toolKey, request.inputData || {}, request.envs);
137
- console.log(`Tool ${request.toolKey} executed successfully in sandbox (retry)`);
138
- return result;
139
- }
140
- throw error;
141
- }
142
- finally {
143
- // Release reference count
144
- await PackageSO.releaseSandbox(runtime, this.sandboxProvider);
145
- }
146
- }
147
- async listTools(packageName) {
148
- const mcpServerConfig = getPackageConfigByKey(packageName);
149
- if (this.isSandboxEnabled()) {
150
- try {
151
- const tools = await this.listToolsInSandbox(packageName);
152
- return tools;
153
- }
154
- catch (error) {
155
- console.warn(`[listTools] Sandbox mode failed for package ${packageName}, falling back to local mode:`, error);
156
- }
157
- }
158
- const mockEnvs = {};
159
- if (mcpServerConfig.env) {
160
- Object.keys(mcpServerConfig.env).forEach((key) => {
161
- mockEnvs[key] = "mock_value";
162
- });
163
- }
164
- const { client, closeConnection } = await getMcpClient(mcpServerConfig, mockEnvs);
165
- try {
166
- const { tools } = await client.listTools();
167
- console.log(`Tools list retrieved successfully for package ${packageName}`);
168
- return tools;
169
- }
170
- finally {
171
- await closeConnection();
172
- }
173
- }
174
- async listToolsInSandbox(packageName) {
175
- const mcpServerConfig = getPackageConfigByKey(packageName);
176
- const runtime = mcpServerConfig.runtime || "python";
177
- const sandboxClient = await PackageSO.acquireSandbox(runtime, this.sandboxProvider);
178
- try {
179
- // Initialize only if sandbox is not initialized
180
- await sandboxClient.initialize();
181
- const tools = await sandboxClient.listTools(packageName);
182
- console.log(`Tools list retrieved successfully for package ${packageName} in sandbox`);
183
- return tools;
184
- }
185
- catch (error) {
186
- // If it's a sandbox not found error, try reinitializing and retrying once
187
- if (error instanceof Error && error.message.includes("sandbox was not found")) {
188
- console.log("[PackageSO] Retrying tools listing after sandbox failure");
189
- await sandboxClient.initialize();
190
- // Retry listing tools
191
- const tools = await sandboxClient.listTools(packageName);
192
- console.log(`Tools list retrieved successfully for package ${packageName} in sandbox (retry)`);
193
- return tools;
194
- }
195
- throw error;
196
- }
197
- finally {
198
- await PackageSO.releaseSandbox(runtime, this.sandboxProvider);
199
- }
200
- }
201
- async getPackageDetail(packageName) {
202
- const packageInfo = typedAllPackagesList[packageName];
203
- if (!packageInfo) {
204
- throw new Error(`Package ${packageName} not found`);
205
- }
206
- const jsonFilePath = path.join(__dirname, "../../packages/", packageInfo.path);
207
- const jsonStr = fs.readFileSync(jsonFilePath, "utf-8");
208
- const packageConfig = JSON.parse(jsonStr);
209
- let tools;
210
- try {
211
- tools = await this.listTools(packageName);
212
- }
213
- catch (error) {
214
- console.warn(`Warn retrieving tools for package ${packageName}:`, error.message);
215
- // if tools cannot be retrieved, set tools to undefined
216
- tools = undefined;
217
- }
218
- const packageConfigWithTools = Object.assign(Object.assign({}, packageConfig), { tools });
219
- return packageConfigWithTools;
220
- }
221
- }
222
- PackageSO.sandboxInstances = new Map();
223
- PackageSO.MAX_SANDBOXES = 10;
@@ -1,19 +0,0 @@
1
- // npx vitest run src/api/package.test.ts
2
- import { describe, expect, it } from "vitest";
3
- import { PackageSO } from "./package-so";
4
- describe("PackageSO - MCP Tool Execution Service Test", () => {
5
- it("should execute tool successfully", async () => {
6
- const toolSO = new PackageSO();
7
- const request = {
8
- packageName: "mcp-starter",
9
- toolKey: "hello_tool",
10
- inputData: { name: "Mike" },
11
- envs: {},
12
- };
13
- const result = await toolSO.executeTool(request);
14
- expect(result).toEqual({
15
- content: [],
16
- message: "Hello, Mike!",
17
- });
18
- });
19
- });
package/dist/helper.d.ts DELETED
@@ -1,74 +0,0 @@
1
- import { Client } from "@modelcontextprotocol/sdk/client/index.js";
2
- import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
3
- import type { MCPSandboxProvider, MCPServerPackageConfig } from "./types";
4
- export declare const typedAllPackagesList: Record<string, {
5
- path: string;
6
- category?: string | undefined;
7
- validated?: boolean | undefined;
8
- tools?: Record<string, {
9
- description?: string | undefined;
10
- name?: string | undefined;
11
- }> | undefined;
12
- }>;
13
- export declare function getSandboxProvider(): MCPSandboxProvider;
14
- export declare function getPackageConfigByKey(packageKey: string): MCPServerPackageConfig;
15
- export declare function getPackageJSON(packageName: string): any;
16
- export declare function getMcpClient(mcpServerConfig: MCPServerPackageConfig, env?: Record<string, string>): Promise<{
17
- client: Client<{
18
- method: string;
19
- params?: {
20
- [x: string]: unknown;
21
- _meta?: {
22
- [x: string]: unknown;
23
- progressToken?: string | number | undefined;
24
- } | undefined;
25
- } | undefined;
26
- }, {
27
- method: string;
28
- params?: {
29
- [x: string]: unknown;
30
- _meta?: {
31
- [x: string]: unknown;
32
- } | undefined;
33
- } | undefined;
34
- }, {
35
- [x: string]: unknown;
36
- _meta?: {
37
- [x: string]: unknown;
38
- } | undefined;
39
- }>;
40
- transport: StdioClientTransport;
41
- closeConnection: () => Promise<void>;
42
- }>;
43
- export declare function updatePackageJsonDependencies({ packageDeps, enableValidation, }: {
44
- packageDeps: Record<string, string>;
45
- enableValidation?: boolean;
46
- }): void;
47
- export declare function getActualVersion(packageName: string, configuredVersion?: string): string;
48
- export declare function withTimeout<T>(ms: number, promise: Promise<T>): Promise<T>;
49
- export declare function isValidNpmPackage(packageName: string): Promise<boolean>;
50
- interface PyProjectToml {
51
- project?: {
52
- dependencies?: string[];
53
- [key: string]: unknown;
54
- };
55
- [key: string]: unknown;
56
- }
57
- /**
58
- * Parses the pyproject.toml file and returns its content
59
- * @returns Parsed pyproject.toml content
60
- */
61
- export declare function parsePyprojectToml(): PyProjectToml;
62
- /**
63
- * Extracts package name from a dependency string
64
- * @param dep - Dependency string (e.g., "package>=1.0.0")
65
- * @returns Package name without version constraints
66
- */
67
- export declare function extractPackageName(dep: string): string;
68
- /**
69
- * Gets Python dependencies from pyproject.toml
70
- * @returns Array of Python dependency names
71
- */
72
- export declare function getPythonDependencies(): string[];
73
- export declare function extractLastOuterJSON(str: string): string;
74
- export {};
package/dist/helper.js DELETED
@@ -1,312 +0,0 @@
1
- import assert from "node:assert";
2
- import fs from "node:fs";
3
- import * as path from "node:path";
4
- import toml from "@iarna/toml";
5
- import { Client } from "@modelcontextprotocol/sdk/client/index.js";
6
- import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
7
- import axios from "axios";
8
- import semver from "semver";
9
- import allPackagesList from "../indexes/packages-list.json";
10
- import { getDirname } from "../src/utils";
11
- import { MCPServerPackageConfigSchema, PackagesListSchema } from "./schema";
12
- const __dirname = getDirname(import.meta.url);
13
- export const typedAllPackagesList = PackagesListSchema.parse(allPackagesList);
14
- export function getSandboxProvider() {
15
- const provider = (process.env.MCP_SANDBOX_PROVIDER || "LOCAL").toUpperCase();
16
- if (provider === "LOCAL" || provider === "DAYTONA" || provider === "SANDOCK") {
17
- return provider;
18
- }
19
- console.warn(`[helper] Unsupported MCP_SANDBOX_PROVIDER value '${provider}', falling back to LOCAL mode`);
20
- return "LOCAL";
21
- }
22
- export function getPackageConfigByKey(packageKey) {
23
- const value = typedAllPackagesList[packageKey];
24
- if (!value) {
25
- throw new Error(`Package '${packageKey}' not found in packages list.`);
26
- }
27
- const jsonFile = value.path;
28
- // read the JSON file and convert it to MCPServerPackageConfig
29
- const jsonStr = fs.readFileSync(`${__dirname}/../packages/${jsonFile}`, "utf-8");
30
- const mcpServerConfig = MCPServerPackageConfigSchema.parse(JSON.parse(jsonStr));
31
- return mcpServerConfig;
32
- }
33
- export function getPackageJSON(packageName) {
34
- const packageJSONFilePath = `${__dirname}/../node_modules/${packageName}/package.json`;
35
- // Check if the package exists in node_modules
36
- if (!fs.existsSync(packageJSONFilePath)) {
37
- throw new Error(`Package '${packageName}' not found in node_modules. Install it first with: pnpm add ${packageName}`);
38
- }
39
- const packageJSONStr = fs.readFileSync(packageJSONFilePath, "utf8");
40
- const packageJSON = JSON.parse(packageJSONStr);
41
- return packageJSON;
42
- }
43
- async function createMcpClient(mcpServerConfig, transport) {
44
- const { packageName, name } = mcpServerConfig;
45
- const client = new Client({
46
- name: `mcp-server-${name}-client`,
47
- version: "1.0.0",
48
- }, {
49
- capabilities: {
50
- tools: {},
51
- },
52
- });
53
- await client.connect(transport);
54
- const closeConnection = async () => {
55
- try {
56
- await client.close();
57
- }
58
- catch (e) {
59
- console.warn(`${packageName} mcp client close failure.`, e);
60
- }
61
- };
62
- return { client, transport, closeConnection };
63
- }
64
- async function getNodeMcpClient(mcpServerConfig, env) {
65
- const { packageName } = mcpServerConfig;
66
- const packageJSON = getPackageJSON(packageName);
67
- let binFilePath = "";
68
- let binPath;
69
- if (typeof packageJSON.bin === "string") {
70
- binPath = packageJSON.bin;
71
- }
72
- else if (typeof packageJSON.bin === "object") {
73
- binPath = Object.values(packageJSON.bin)[0];
74
- }
75
- else {
76
- binPath = packageJSON.main;
77
- }
78
- assert(binPath, `Package ${packageName} does not have a valid bin path in package.json.`);
79
- binFilePath = `${__dirname}/../node_modules/${packageName}/${binPath}`;
80
- const mcpServerBinPath = mcpServerConfig.bin || binFilePath;
81
- const binArgs = mcpServerConfig.binArgs || [];
82
- const transport = new StdioClientTransport({
83
- args: [mcpServerBinPath, ...binArgs],
84
- command: process.execPath,
85
- env: env || {},
86
- });
87
- return createMcpClient(mcpServerConfig, transport);
88
- }
89
- async function getPyMcpClient(mcpServerConfig, env) {
90
- const { packageName } = mcpServerConfig;
91
- const pythonModuleName = packageName;
92
- const transport = new StdioClientTransport({
93
- command: "uv",
94
- args: ["run", "--directory", "./python-mcp", pythonModuleName],
95
- env: Object.assign(Object.assign({}, Object.fromEntries(Object.entries(process.env).filter(([_, v]) => v !== undefined))), env),
96
- });
97
- return createMcpClient(mcpServerConfig, transport);
98
- }
99
- export async function getMcpClient(mcpServerConfig, env) {
100
- const { runtime } = mcpServerConfig;
101
- if (runtime === "python") {
102
- return getPyMcpClient(mcpServerConfig, env);
103
- }
104
- return getNodeMcpClient(mcpServerConfig, env);
105
- }
106
- export function updatePackageJsonDependencies({ packageDeps, enableValidation = false, }) {
107
- var _a;
108
- // Write package.json dependencies
109
- const packageJsonFile = "./package.json";
110
- const packageJSONStr = fs.readFileSync(packageJsonFile, "utf-8");
111
- const newDeps = {
112
- "@daytonaio/sdk": "0.109.0",
113
- "@e2b/code-interpreter": "^2.0.0",
114
- "@modelcontextprotocol/sdk": "^1.12.0",
115
- "@hono/node-server": "1.15.0",
116
- "@hono/swagger-ui": "^0.5.2",
117
- "@hono/zod-openapi": "^0.16.4",
118
- "@iarna/toml": "^2.2.5",
119
- meilisearch: "^0.33.0",
120
- lodash: "^4.17.21",
121
- zod: "^3.23.30",
122
- axios: "^1.9.0",
123
- hono: "4.8.3",
124
- semver: "^7.5.4",
125
- };
126
- for (const [depName, depVer] of Object.entries(packageDeps)) {
127
- if (!enableValidation || ((_a = typedAllPackagesList[depName]) === null || _a === void 0 ? void 0 : _a.validated)) {
128
- newDeps[depName] = depVer || "latest";
129
- }
130
- }
131
- // const blacklistDeps = new Set([
132
- // "@mcp-server/google-search-mcp",
133
- // "@executeautomation/playwright-mcp-server",
134
- // ]);
135
- // for (const dep of blacklistDeps) {
136
- // if (newDeps[dep]) {
137
- // delete newDeps[dep];
138
- // }
139
- // }
140
- const packageJSON = JSON.parse(packageJSONStr);
141
- packageJSON.dependencies = newDeps;
142
- fs.writeFileSync(packageJsonFile, JSON.stringify(packageJSON, null, 2), "utf-8");
143
- console.log(`Generated new package.json file at ${packageJsonFile}`);
144
- return;
145
- }
146
- export function getActualVersion(packageName, configuredVersion) {
147
- if (configuredVersion && configuredVersion !== "latest") {
148
- return configuredVersion;
149
- }
150
- try {
151
- const packageJsonPath = path.join(__dirname, "../node_modules", packageName, "package.json");
152
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
153
- return packageJson.version;
154
- }
155
- catch (e) {
156
- console.warn(`Failed to read version for ${packageName}, using 'latest' by default`, e.message);
157
- return "latest";
158
- }
159
- }
160
- export function withTimeout(ms, promise) {
161
- return new Promise((resolve, reject) => {
162
- const timer = setTimeout(() => {
163
- reject(new Error(`Operation timed out after ${ms}ms`));
164
- }, ms);
165
- promise.then((res) => {
166
- clearTimeout(timer);
167
- resolve(res);
168
- }, (err) => {
169
- clearTimeout(timer);
170
- reject(err);
171
- });
172
- });
173
- }
174
- function checkDependencyValidity(dependencyData, versionRange) {
175
- // 兼容 "latest" 的情况
176
- if (versionRange === "latest") {
177
- return Object.keys(dependencyData.versions).length > 0;
178
- }
179
- // 使用 semver 检查是否有满足版本范围的有效版本
180
- const versions = Object.keys(dependencyData.versions);
181
- for (const version of versions) {
182
- if (semver.satisfies(version, versionRange)) {
183
- return true;
184
- }
185
- }
186
- return false;
187
- }
188
- async function checkDependencies(dependencies) {
189
- const dependencyCache = {};
190
- const checkSingleDependency = async (depName, depVersionRange) => {
191
- const cacheKey = `${depName}@${depVersionRange}`;
192
- if (dependencyCache[cacheKey] !== undefined) {
193
- return dependencyCache[cacheKey];
194
- }
195
- try {
196
- const depResponse = await axios.get(`https://registry.npmjs.org/${depName}`, {
197
- timeout: 5000,
198
- headers: {
199
- "User-Agent": "MyToolManager/1.0",
200
- },
201
- });
202
- if (depResponse.status !== 200 || !depResponse.data.versions) {
203
- console.error(`Failed to fetch ${depName}`);
204
- dependencyCache[cacheKey] = false;
205
- return false;
206
- }
207
- const isValid = checkDependencyValidity(depResponse.data, depVersionRange);
208
- dependencyCache[cacheKey] = isValid;
209
- if (!isValid) {
210
- console.error(`Invalid or missing: ${depName}`);
211
- }
212
- return isValid;
213
- }
214
- catch (error) {
215
- console.error(`Error fetching ${depName}: ${error.message}`);
216
- dependencyCache[cacheKey] = false;
217
- return false;
218
- }
219
- };
220
- const promises = Object.entries(dependencies).map(([depName, depVersionRange]) => checkSingleDependency(depName, depVersionRange));
221
- const results = await Promise.all(promises);
222
- return results.every((result) => result);
223
- }
224
- export async function isValidNpmPackage(packageName) {
225
- var _a, _b, _c, _d;
226
- try {
227
- // 检查主包是否存在
228
- console.log("checking package:", packageName);
229
- const response = await axios.get(`https://registry.npmjs.org/${packageName}`, {
230
- timeout: 5000,
231
- headers: {
232
- "User-Agent": "MyToolManager/1.0",
233
- },
234
- });
235
- // 检查主包是否被标记为 unpublished
236
- if (response.status !== 200 || !((_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a["dist-tags"]) === null || _b === void 0 ? void 0 : _b.latest)) {
237
- console.error(`Package marked as unpublished: ${packageName}`);
238
- return false;
239
- }
240
- // 获取主包的最新版本信息
241
- const latestVersion = response.data["dist-tags"].latest;
242
- const versionData = (_d = (_c = response.data) === null || _c === void 0 ? void 0 : _c.versions) === null || _d === void 0 ? void 0 : _d[latestVersion];
243
- if (!versionData) {
244
- console.error(`Invalid package: ${packageName} - No version data found`);
245
- return false;
246
- }
247
- // 检查 dependencies 和 devDependencies
248
- console.log(`Checking dependencies for ${packageName}`);
249
- const dependencies = Object.assign(Object.assign({}, versionData.dependencies), versionData.devDependencies);
250
- if (!(await checkDependencies(dependencies))) {
251
- return false;
252
- }
253
- console.log(`Valid package: ${packageName}`);
254
- return true;
255
- }
256
- catch (error) {
257
- console.error(`Error validating package ${packageName}:`, error.message);
258
- return false;
259
- }
260
- }
261
- /**
262
- * Parses the pyproject.toml file and returns its content
263
- * @returns Parsed pyproject.toml content
264
- */
265
- export function parsePyprojectToml() {
266
- const pyprojectPath = "./python-mcp/pyproject.toml";
267
- const content = fs.readFileSync(pyprojectPath, "utf-8");
268
- return toml.parse(content);
269
- }
270
- /**
271
- * Extracts package name from a dependency string
272
- * @param dep - Dependency string (e.g., "package>=1.0.0")
273
- * @returns Package name without version constraints
274
- */
275
- export function extractPackageName(dep) {
276
- return dep.split(/[=<>!]/)[0].trim();
277
- }
278
- /**
279
- * Gets Python dependencies from pyproject.toml
280
- * @returns Array of Python dependency names
281
- */
282
- export function getPythonDependencies() {
283
- var _a;
284
- const data = parsePyprojectToml();
285
- const deps = ((_a = data.project) === null || _a === void 0 ? void 0 : _a.dependencies) || [];
286
- return deps.map(extractPackageName);
287
- }
288
- export function extractLastOuterJSON(str) {
289
- let braceCount = 0;
290
- let end = -1;
291
- let start = -1;
292
- for (let i = str.length - 1; i >= 0; i--) {
293
- const ch = str[i];
294
- if (ch === "}") {
295
- if (end === -1)
296
- end = i;
297
- braceCount++;
298
- }
299
- else if (ch === "{") {
300
- braceCount--;
301
- if (braceCount === 0 && end !== -1) {
302
- start = i;
303
- break;
304
- }
305
- }
306
- }
307
- if (start === -1 || end === -1) {
308
- throw new Error("No valid JSON found in string");
309
- }
310
- const jsonStr = str.slice(start, end + 1);
311
- return jsonStr;
312
- }
@@ -1,16 +0,0 @@
1
- import type { Tool } from "@modelcontextprotocol/sdk/types.js";
2
- import type { MCPSandboxProvider } from "../types";
3
- export declare class MCPSandboxClient {
4
- private sandbox;
5
- private initializing;
6
- private readonly apiKey;
7
- private readonly provider;
8
- private runtime;
9
- constructor(runtime?: "node" | "python" | "java" | "go", provider?: MCPSandboxProvider);
10
- initialize(): Promise<void>;
11
- kill(): Promise<void>;
12
- listTools(packageKey: string): Promise<Tool[]>;
13
- executeTool(packageKey: string, toolName: string, argumentsObj: Record<string, unknown>, envs?: Record<string, string>): Promise<unknown>;
14
- private generateMCPTestCode;
15
- private generateEnvVariables;
16
- }