























@@ -1,4 +1,5 @@
11import fs from "node:fs";
2+import { createRequire } from "node:module";
23import path from "node:path";
34import { fileURLToPath } from "node:url";
45import { formatPluginConfigIssue } from "openclaw/plugin-sdk/extension-shared";
@@ -25,6 +26,8 @@ export {
2526} from "./config-schema.js";
26272728export const ACPX_PLUGIN_TOOLS_MCP_SERVER_NAME = "openclaw-plugin-tools";
29+export const ACPX_OPENCLAW_TOOLS_MCP_SERVER_NAME = "openclaw-tools";
30+const requireFromHere = createRequire(import.meta.url);
28312932function isAcpxPluginRoot(dir: string): boolean {
3033return (
@@ -140,6 +143,14 @@ function resolveOpenClawRoot(currentRoot: string): string {
140143return path.resolve(currentRoot, "..");
141144}
142145146+function resolveTsxImportSpecifier(): string {
147+try {
148+return requireFromHere.resolve("tsx");
149+} catch {
150+return "tsx";
151+}
152+}
153+143154export function resolvePluginToolsMcpServerConfig(
144155moduleUrl: string = import.meta.url,
145156): McpServerConfig {
@@ -155,25 +166,56 @@ export function resolvePluginToolsMcpServerConfig(
155166const sourceEntry = path.join(openClawRoot, "src", "mcp", "plugin-tools-serve.ts");
156167return {
157168command: process.execPath,
158-args: ["--import", "tsx", sourceEntry],
169+args: ["--import", resolveTsxImportSpecifier(), sourceEntry],
170+};
171+}
172+173+export function resolveOpenClawToolsMcpServerConfig(
174+moduleUrl: string = import.meta.url,
175+): McpServerConfig {
176+const pluginRoot = resolveAcpxPluginRoot(moduleUrl);
177+const openClawRoot = resolveOpenClawRoot(pluginRoot);
178+const distEntry = path.join(openClawRoot, "dist", "mcp", "openclaw-tools-serve.js");
179+if (fs.existsSync(distEntry)) {
180+return {
181+command: process.execPath,
182+args: [distEntry],
183+};
184+}
185+const sourceEntry = path.join(openClawRoot, "src", "mcp", "openclaw-tools-serve.ts");
186+return {
187+command: process.execPath,
188+args: ["--import", resolveTsxImportSpecifier(), sourceEntry],
159189};
160190}
161191162192function resolveConfiguredMcpServers(params: {
163193mcpServers?: Record<string, McpServerConfig>;
164194pluginToolsMcpBridge: boolean;
195+openClawToolsMcpBridge: boolean;
165196moduleUrl?: string;
166197}): Record<string, McpServerConfig> {
167198const resolved = { ...params.mcpServers };
168-if (!params.pluginToolsMcpBridge) {
169-return resolved;
170-}
171-if (resolved[ACPX_PLUGIN_TOOLS_MCP_SERVER_NAME]) {
199+if (params.pluginToolsMcpBridge && resolved[ACPX_PLUGIN_TOOLS_MCP_SERVER_NAME]) {
172200throw new Error(
173201`mcpServers.${ACPX_PLUGIN_TOOLS_MCP_SERVER_NAME} is reserved when pluginToolsMcpBridge=true`,
174202);
175203}
176-resolved[ACPX_PLUGIN_TOOLS_MCP_SERVER_NAME] = resolvePluginToolsMcpServerConfig(params.moduleUrl);
204+if (params.openClawToolsMcpBridge && resolved[ACPX_OPENCLAW_TOOLS_MCP_SERVER_NAME]) {
205+throw new Error(
206+`mcpServers.${ACPX_OPENCLAW_TOOLS_MCP_SERVER_NAME} is reserved when openClawToolsMcpBridge=true`,
207+);
208+}
209+if (params.pluginToolsMcpBridge) {
210+resolved[ACPX_PLUGIN_TOOLS_MCP_SERVER_NAME] = resolvePluginToolsMcpServerConfig(
211+params.moduleUrl,
212+);
213+}
214+if (params.openClawToolsMcpBridge) {
215+resolved[ACPX_OPENCLAW_TOOLS_MCP_SERVER_NAME] = resolveOpenClawToolsMcpServerConfig(
216+params.moduleUrl,
217+);
218+}
177219return resolved;
178220}
179221@@ -204,9 +246,11 @@ export function resolveAcpxPluginConfig(params: {
204246const cwd = path.resolve(normalized.cwd?.trim() || fallbackCwd);
205247const stateDir = path.resolve(normalized.stateDir?.trim() || path.join(workspaceDir, "state"));
206248const pluginToolsMcpBridge = normalized.pluginToolsMcpBridge === true;
249+const openClawToolsMcpBridge = normalized.openClawToolsMcpBridge === true;
207250const mcpServers = resolveConfiguredMcpServers({
208251mcpServers: normalized.mcpServers,
209252 pluginToolsMcpBridge,
253+ openClawToolsMcpBridge,
210254moduleUrl: params.moduleUrl,
211255});
212256const agents = Object.fromEntries(
@@ -224,6 +268,7 @@ export function resolveAcpxPluginConfig(params: {
224268nonInteractivePermissions:
225269normalized.nonInteractivePermissions ?? DEFAULT_NON_INTERACTIVE_POLICY,
226270 pluginToolsMcpBridge,
271+ openClawToolsMcpBridge,
227272strictWindowsCmdWrapper:
228273normalized.strictWindowsCmdWrapper ?? DEFAULT_STRICT_WINDOWS_CMD_WRAPPER,
229274timeoutSeconds: normalized.timeoutSeconds ?? DEFAULT_ACPX_TIMEOUT_SECONDS,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。