@alfe.ai/openclaw-mcp-bundler 0.0.1
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/dist/index.cjs +7 -0
- package/dist/index.d.cts +45 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/plugin.cjs +2 -0
- package/dist/plugin.d.cts +88 -0
- package/dist/plugin.d.cts.map +1 -0
- package/dist/plugin.d.ts +88 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +2 -0
- package/dist/plugin2.cjs +162 -0
- package/dist/plugin2.d.cts +2 -0
- package/dist/plugin2.d.ts +2 -0
- package/dist/plugin2.js +153 -0
- package/dist/plugin2.js.map +1 -0
- package/openclaw.plugin.json +16 -0
- package/package.json +40 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
5
|
+
const require_plugin = require("./plugin2.cjs");
|
|
6
|
+
exports.default = require_plugin.plugin;
|
|
7
|
+
exports.detectNativeBundleMcp = require_plugin.detectNativeBundleMcp;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { t as plugin } from "./plugin.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/cli-backend-detect.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Determine whether the active agent's CLI backend already has native bundle-MCP
|
|
7
|
+
* support. If so, our plugin should no-op so we don't double-register tools.
|
|
8
|
+
*
|
|
9
|
+
* As of OpenClaw 2026.4 only `claude-cli` and `codex-cli` ship with
|
|
10
|
+
* `bundleMcp: true`. We hardcode that allowlist for now; future backends
|
|
11
|
+
* shipping with bundleMcp:true will need to be added here (or, ideally,
|
|
12
|
+
* OpenClaw exposes a public API to query the resolved backend's bundleMcp
|
|
13
|
+
* flag and we call that instead — see project_openclaw_mcp_bundler.md TODO).
|
|
14
|
+
*
|
|
15
|
+
* This detection is best-effort: if we can't determine the backend (no
|
|
16
|
+
* runtime config available), we default to "no native MCP" (return false)
|
|
17
|
+
* so our plugin DOES register. Worst case is benign duplicate tool names
|
|
18
|
+
* with `-2` suffix on claude-cli, which is recoverable; missing tools on
|
|
19
|
+
* MiniMax is the bug we exist to fix.
|
|
20
|
+
*/
|
|
21
|
+
interface ConfigLike {
|
|
22
|
+
agents?: {
|
|
23
|
+
defaults?: {
|
|
24
|
+
model?: string;
|
|
25
|
+
cliBackends?: Record<string, unknown>;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Read the active agent's primary model and infer its CLI backend.
|
|
31
|
+
* Returns true if that backend has native bundleMcp support.
|
|
32
|
+
*
|
|
33
|
+
* Heuristic mapping (matches what OpenClaw's plugin-setup-cli-backend
|
|
34
|
+
* registry resolves to today):
|
|
35
|
+
* - model id containing "claude" or "anthropic" → claude-cli
|
|
36
|
+
* - model id containing "codex" or "gpt-5-codex" or "openai/codex" → codex-cli
|
|
37
|
+
* - everything else → no native bundle-mcp
|
|
38
|
+
*
|
|
39
|
+
* If `agents.defaults.cliBackends` explicitly configures one of the native
|
|
40
|
+
* backends, we trust that override.
|
|
41
|
+
*/
|
|
42
|
+
declare function detectNativeBundleMcp(cfg: ConfigLike | undefined): boolean;
|
|
43
|
+
//#endregion
|
|
44
|
+
export { plugin as default, detectNativeBundleMcp };
|
|
45
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/cli-backend-detect.ts"],"mappings":";;;;;;;;AAyCA;;;;;;;;;;;;UAtBU,UAAA;;;;oBAIU;;;;;;;;;;;;;;;;;iBAkBJ,qBAAA,MAA2B"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { t as plugin } from "./plugin.js";
|
|
2
|
+
|
|
3
|
+
//#region src/cli-backend-detect.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Determine whether the active agent's CLI backend already has native bundle-MCP
|
|
7
|
+
* support. If so, our plugin should no-op so we don't double-register tools.
|
|
8
|
+
*
|
|
9
|
+
* As of OpenClaw 2026.4 only `claude-cli` and `codex-cli` ship with
|
|
10
|
+
* `bundleMcp: true`. We hardcode that allowlist for now; future backends
|
|
11
|
+
* shipping with bundleMcp:true will need to be added here (or, ideally,
|
|
12
|
+
* OpenClaw exposes a public API to query the resolved backend's bundleMcp
|
|
13
|
+
* flag and we call that instead — see project_openclaw_mcp_bundler.md TODO).
|
|
14
|
+
*
|
|
15
|
+
* This detection is best-effort: if we can't determine the backend (no
|
|
16
|
+
* runtime config available), we default to "no native MCP" (return false)
|
|
17
|
+
* so our plugin DOES register. Worst case is benign duplicate tool names
|
|
18
|
+
* with `-2` suffix on claude-cli, which is recoverable; missing tools on
|
|
19
|
+
* MiniMax is the bug we exist to fix.
|
|
20
|
+
*/
|
|
21
|
+
interface ConfigLike {
|
|
22
|
+
agents?: {
|
|
23
|
+
defaults?: {
|
|
24
|
+
model?: string;
|
|
25
|
+
cliBackends?: Record<string, unknown>;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Read the active agent's primary model and infer its CLI backend.
|
|
31
|
+
* Returns true if that backend has native bundleMcp support.
|
|
32
|
+
*
|
|
33
|
+
* Heuristic mapping (matches what OpenClaw's plugin-setup-cli-backend
|
|
34
|
+
* registry resolves to today):
|
|
35
|
+
* - model id containing "claude" or "anthropic" → claude-cli
|
|
36
|
+
* - model id containing "codex" or "gpt-5-codex" or "openai/codex" → codex-cli
|
|
37
|
+
* - everything else → no native bundle-mcp
|
|
38
|
+
*
|
|
39
|
+
* If `agents.defaults.cliBackends` explicitly configures one of the native
|
|
40
|
+
* backends, we trust that override.
|
|
41
|
+
*/
|
|
42
|
+
declare function detectNativeBundleMcp(cfg: ConfigLike | undefined): boolean;
|
|
43
|
+
//#endregion
|
|
44
|
+
export { plugin as default, detectNativeBundleMcp };
|
|
45
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/cli-backend-detect.ts"],"mappings":";;;;;;;;AAyCA;;;;;;;;;;;;UAtBU,UAAA;;;;oBAIU;;;;;;;;;;;;;;;;;iBAkBJ,qBAAA,MAA2B"}
|
package/dist/index.js
ADDED
package/dist/plugin.cjs
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
//#region ../mcp-bundler/dist/index.d.ts
|
|
2
|
+
//#region src/types.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Shape of a single MCP server entry — matches OpenClaw `mcp.servers.{name}`.
|
|
5
|
+
* Either a stdio child process spec or a remote URL spec.
|
|
6
|
+
*/
|
|
7
|
+
type McpServerConfig = StdioServerConfig | RemoteServerConfig;
|
|
8
|
+
interface StdioServerConfig {
|
|
9
|
+
command: string;
|
|
10
|
+
args?: string[];
|
|
11
|
+
env?: Record<string, string>;
|
|
12
|
+
cwd?: string;
|
|
13
|
+
}
|
|
14
|
+
interface RemoteServerConfig {
|
|
15
|
+
url: string;
|
|
16
|
+
transport?: 'sse' | 'streamable-http';
|
|
17
|
+
headers?: Record<string, string>;
|
|
18
|
+
connectionTimeoutMs?: number;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/plugin.d.ts
|
|
22
|
+
|
|
23
|
+
interface Logger {
|
|
24
|
+
debug(msg: string, ...args: unknown[]): void;
|
|
25
|
+
info(msg: string, ...args: unknown[]): void;
|
|
26
|
+
warn(msg: string, ...args: unknown[]): void;
|
|
27
|
+
error(msg: string, ...args: unknown[]): void;
|
|
28
|
+
}
|
|
29
|
+
interface ConfigSnapshot {
|
|
30
|
+
agents?: {
|
|
31
|
+
defaults?: {
|
|
32
|
+
model?: string;
|
|
33
|
+
cliBackends?: Record<string, unknown>;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
mcp?: {
|
|
37
|
+
servers?: Record<string, McpServerConfig>;
|
|
38
|
+
sessionIdleTtlMs?: number;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
interface AgentToolResult {
|
|
42
|
+
content: Record<string, unknown>[];
|
|
43
|
+
details?: Record<string, unknown>;
|
|
44
|
+
}
|
|
45
|
+
interface AgentTool {
|
|
46
|
+
name: string;
|
|
47
|
+
label?: string;
|
|
48
|
+
description: string;
|
|
49
|
+
parameters: Record<string, unknown>;
|
|
50
|
+
execute: (toolCallId: string, params: unknown, signal?: AbortSignal, onUpdate?: (update: unknown) => void) => Promise<AgentToolResult>;
|
|
51
|
+
}
|
|
52
|
+
interface ToolFactoryContext {
|
|
53
|
+
config?: ConfigSnapshot;
|
|
54
|
+
runtimeConfig?: ConfigSnapshot;
|
|
55
|
+
getRuntimeConfig?: () => ConfigSnapshot | undefined;
|
|
56
|
+
}
|
|
57
|
+
interface OpenClawPluginApi {
|
|
58
|
+
logger: Logger;
|
|
59
|
+
config?: ConfigSnapshot;
|
|
60
|
+
pluginConfig?: {
|
|
61
|
+
disabled?: boolean;
|
|
62
|
+
};
|
|
63
|
+
registrationMode?: string;
|
|
64
|
+
runtime?: {
|
|
65
|
+
config?: {
|
|
66
|
+
current?: () => ConfigSnapshot | undefined;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
registerTool: (tool: AgentTool | ((ctx: ToolFactoryContext) => AgentTool | AgentTool[] | null | undefined), opts?: {
|
|
70
|
+
name?: string;
|
|
71
|
+
names?: string[];
|
|
72
|
+
optional?: boolean;
|
|
73
|
+
}) => void;
|
|
74
|
+
}
|
|
75
|
+
declare const plugin: {
|
|
76
|
+
id: string;
|
|
77
|
+
name: string;
|
|
78
|
+
description: string;
|
|
79
|
+
version: string;
|
|
80
|
+
contracts: {
|
|
81
|
+
tools: string[];
|
|
82
|
+
};
|
|
83
|
+
activate(api: OpenClawPluginApi): void;
|
|
84
|
+
deactivate(api: OpenClawPluginApi): void;
|
|
85
|
+
};
|
|
86
|
+
//#endregion
|
|
87
|
+
export { plugin as t };
|
|
88
|
+
//# sourceMappingURL=plugin.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.cts","names":["McpServerConfig","StdioServerConfig","RemoteServerConfig","Record","McpTransportKind","McpToolDescriptor","ReconcileDiff","Logger","McpToolCallResult","BundlerOptions","STDIO_ENV_DENYLIST","Set","sanitizeStdioEnv","ConnectionDeps","McpClientHandle","Promise","AbortSignal","Connection","defaultConnect","McpBundler","sanitizeNameSegment","buildNamespacedToolName","disambiguateAgainst","ReadonlySet"],"sources":["../../mcp-bundler/dist/index.d.ts","../src/plugin.ts"],"sourcesContent":["//#region src/types.d.ts\n/**\n * Shape of a single MCP server entry — matches OpenClaw `mcp.servers.{name}`.\n * Either a stdio child process spec or a remote URL spec.\n */\ntype McpServerConfig = StdioServerConfig | RemoteServerConfig;\ninterface StdioServerConfig {\n command: string;\n args?: string[];\n env?: Record<string, string>;\n cwd?: string;\n}\ninterface RemoteServerConfig {\n url: string;\n transport?: 'sse' | 'streamable-http';\n headers?: Record<string, string>;\n connectionTimeoutMs?: number;\n}\ntype McpTransportKind = 'stdio' | 'sse' | 'streamable-http';\n/**\n * One tool surfaced from one MCP server, after namespacing.\n */\ninterface McpToolDescriptor {\n /** Namespaced name as the LLM sees it: `{serverName}__{originalName}`, sanitized + max 64 chars. */\n prefixed: string;\n /** Server name (key in `mcp.servers.*`). */\n server: string;\n /** Original tool name as advertised by the MCP server. */\n original: string;\n /** Human label for the tool (truncated description, suitable for UI). */\n label: string;\n /** Full description from the MCP server. */\n description: string;\n /** JSON Schema (object) for tool parameters. */\n parameters: Record<string, unknown>;\n}\ninterface ReconcileDiff {\n added: string[];\n removed: string[];\n changed: string[];\n unchanged: string[];\n}\ninterface Logger {\n debug: (msg: string, meta?: Record<string, unknown>) => void;\n info: (msg: string, meta?: Record<string, unknown>) => void;\n warn: (msg: string, meta?: Record<string, unknown>) => void;\n error: (msg: string, meta?: Record<string, unknown>) => void;\n}\ninterface McpToolCallResult {\n content: Record<string, unknown>[];\n isError?: boolean;\n}\ninterface BundlerOptions {\n logger?: Logger;\n /** Idle TTL for spawned children (ms). 0 disables. Default: 600_000 (10 min). */\n idleTtlMs?: number;\n /** Sweep interval for idle reaping (ms). Default: 60_000 (1 min). */\n idleSweepIntervalMs?: number;\n}\n//# sourceMappingURL=types.d.ts.map\n//#endregion\n//#region src/connection.d.ts\n/** Env keys OpenClaw rejects from stdio MCP env blocks. Filter them out before spawning. */\ndeclare const STDIO_ENV_DENYLIST: Set<string>;\ndeclare function sanitizeStdioEnv(env: Record<string, string> | undefined): Record<string, string>;\ninterface ConnectionDeps {\n /**\n * Factory for an MCP Client connected to the given config. Injected so tests\n * can mock without spawning real processes. In production this wraps\n * `@modelcontextprotocol/sdk/client`.\n */\n connect: (server: McpServerConfig) => Promise<McpClientHandle>;\n}\n/**\n * Minimal interface our connection layer needs from an MCP client. Mirrors\n * the @modelcontextprotocol/sdk Client surface but kept narrow so we can\n * mock cleanly in tests.\n */\ninterface McpClientHandle {\n listTools(): Promise<{\n name: string;\n description?: string;\n inputSchema: Record<string, unknown>;\n }[]>;\n callTool(name: string, args: unknown, opts?: {\n signal?: AbortSignal;\n }): Promise<McpToolCallResult>;\n close(): Promise<void>;\n}\n/**\n * One Connection per MCP server. Owns lifecycle (lazy-spawn, close, refresh-lock).\n * Refresh-lock pattern adapted from AIWerk `index.ts:219-250` — prevents\n * reconnect + `notifications/tools/list_changed` race.\n */\ndeclare class Connection {\n readonly name: string;\n readonly config: McpServerConfig;\n private readonly deps;\n private readonly logger;\n private client;\n private tools;\n private connectInFlight;\n private refreshInFlight;\n private refreshQueued;\n private lastUsedAt;\n constructor(params: {\n name: string;\n config: McpServerConfig;\n deps: ConnectionDeps;\n logger?: Logger;\n });\n /** Returns the most recent known tool list. May be empty if the server hasn't connected yet. */\n snapshotTools(): McpToolDescriptor[];\n /** Whether an MCP child process / remote connection has been established. */\n isConnected(): boolean;\n /** Idle timestamp for reaping. */\n idleSinceMs(): number;\n /**\n * Lazy connect + tool discovery. Safe to call concurrently; in-flight\n * connects coalesce.\n */\n ensureConnected(): Promise<void>;\n private connectAndDiscover;\n /**\n * Re-discover tools. Used on reconnect or `tools/list_changed` notification.\n * Refresh-lock collapses concurrent refreshes; if one is in flight, the next\n * is queued (max 1 queued, since N>1 queued provides no extra freshness).\n */\n refresh(): Promise<void>;\n callTool(originalName: string, args: unknown, signal?: AbortSignal): Promise<McpToolCallResult>;\n /**\n * Close the underlying transport. Idempotent. If a connect is in flight\n * (warmup racing with reconcile-removal), wait for it to settle and then\n * close the client it produced — otherwise the child process is orphaned.\n */\n close(): Promise<void>;\n /**\n * Stable hash of the config for diff detection in `reconcile`.\n * Two configs with the same hash are equivalent (no restart needed).\n */\n configFingerprint(): string;\n}\n/**\n * Build the production `connect` factory using the official MCP SDK.\n * Kept in a separate function so tests can substitute a mock without\n * pulling the SDK into the test bundle.\n */\ndeclare function defaultConnect(server: McpServerConfig): Promise<McpClientHandle>;\n//# sourceMappingURL=connection.d.ts.map\n//#endregion\n//#region src/bundler.d.ts\n/**\n * Provider-agnostic MCP server bundler. Holds N MCP server connections,\n * exposes a unified namespaced tool catalog, and routes calls to the right\n * server.\n *\n * Designed to be embedded in any host (OpenClaw plugin, AI proxy, Lambda).\n * Public surface is intentionally synchronous where the host needs sync\n * (snapshot, listTools), async only where I/O is unavoidable.\n */\ndeclare class McpBundler {\n private readonly logger;\n private readonly connections;\n private readonly idleTtlMs;\n private readonly idleSweepIntervalMs;\n private idleSweepTimer;\n private readonly deps;\n private disposed;\n private reconcileLatch;\n constructor(opts?: BundlerOptions, deps?: ConnectionDeps);\n /**\n * Diff `desired` against current connections, spawn newcomers, dispose\n * removals, hot-restart on config change. Pull-based — call whenever the\n * host's config snapshot may have changed. Cheap if no diff.\n *\n * Lazy: newly-added servers are NOT eagerly connected; they connect on the\n * first `callTool()` (or first `listTools()` after `forceDiscover()`).\n * This avoids paying spawn cost for servers the agent never uses.\n */\n reconcile(desired: Record<string, McpServerConfig>): Promise<ReconcileDiff>;\n private doReconcile;\n /**\n * Synchronous snapshot of all currently-known tools across connected servers.\n * Servers that have not connected yet contribute nothing. Intended for use\n * inside OpenClaw's plugin tool factory which must be sync.\n *\n * Tool names are namespaced and disambiguated (suffix `-2`, `-3` on collision)\n * so cross-server name clashes never produce duplicate registrations.\n */\n listTools(): McpToolDescriptor[];\n /**\n * Eagerly connect to every configured server and discover tools. Used by\n * hosts that want a hot list rather than the lazy default. Errors are\n * swallowed per-server (logged), so one bad server doesn't fail the batch.\n */\n warmup(): Promise<void>;\n /**\n * Invoke a tool by its namespaced name. Routes to the originating server.\n * Errors are returned as `{ isError: true, content: [...] }` so a failing\n * tool doesn't crash the host.\n */\n callTool(prefixed: string, args: unknown, signal?: AbortSignal): Promise<McpToolCallResult>;\n /**\n * Resolve a namespaced tool name back to its server connection and original\n * tool name. Returns undefined if the tool is not currently advertised.\n */\n private routeToolName;\n /**\n * Tear down all connections and stop background tasks. Idempotent.\n * Call from `registerRuntimeLifecycle({ cleanup })` in the host plugin.\n */\n dispose(): Promise<void>;\n private startIdleSweep;\n private sweepIdle;\n}\n//# sourceMappingURL=bundler.d.ts.map\n//#endregion\n//#region src/tool-naming.d.ts\n/**\n * Tool name sanitization and collision handling.\n *\n * OpenClaw constraint: tool names must match `[A-Za-z0-9_-]` and be ≤64 chars.\n * Pattern mirrored from `openclaw/src/agents/pi-bundle-mcp-names.ts`.\n *\n * Strategy: prefix every tool with its server name (`{server}__{tool}`),\n * sanitize disallowed chars to `_`, truncate, then suffix-disambiguate\n * (`-2`, `-3`, ...) on collision.\n */\ndeclare function sanitizeNameSegment(value: string): string;\ndeclare function buildNamespacedToolName(server: string, tool: string): string;\n/**\n * Disambiguate a candidate name against an existing set by appending `-2`, `-3`, etc.\n * Mutates nothing; returns the chosen name. Caller is responsible for inserting it\n * into the set.\n */\ndeclare function disambiguateAgainst(candidate: string, taken: ReadonlySet<string>): string;\n//# sourceMappingURL=tool-naming.d.ts.map\n\n//#endregion\nexport { type BundlerOptions, Connection, type ConnectionDeps, type Logger, McpBundler, type McpClientHandle, type McpServerConfig, type McpToolCallResult, type McpToolDescriptor, type McpTransportKind, type ReconcileDiff, type RemoteServerConfig, STDIO_ENV_DENYLIST, type StdioServerConfig, buildNamespacedToolName, defaultConnect, disambiguateAgainst, sanitizeNameSegment, sanitizeStdioEnv };\n//# sourceMappingURL=index.d.ts.map"],"mappings":";;;;;;KAKKA,eAAAA,GAAkBC,iBAAsC,GAAlBC,kBAAkB;AAAA,UACnDD,iBAAAA,CAAiB;EAGb,OAGJC,EAAAA,MAAAA;;QAHFC;;ACGwF;AAUhF,UDVND,kBAAAA,CCiBc;EAAA,GAAA,EAAA,MAAA;WACgC,CAAA,EAAA,KAAA,GAAA,iBAAA;SACrB,CAAA,EDhBvBC,MCgBuB,CAAA,MAAA,EAAA,MAAA,CAAA;qBAAf,CAAA,EAAA,MAAA;;;;;AATJ,UAAN,MAAA,CAOA;EAAc,KAAA,CAAA,GAAA,EAAA,MAAA,EAAA,GAAA,IAAA,EAAA,OAAA,EAAA,CAAA,EAAA,IAAA;MACgC,CAAA,GAAA,EAAA,MAAA,EAAA,GAAA,IAAA,EAAA,OAAA,EAAA,CAAA,EAAA,IAAA;MACrB,CAAA,GAAA,EAAA,MAAA,EAAA,GAAA,IAAA,EAAA,OAAA,EAAA,CAAA,EAAA,IAAA;OAAf,CAAA,GAAA,EAAA,MAAA,EAAA,GAAA,IAAA,EAAA,OAAA,EAAA,CAAA,EAAA,IAAA;;AAAM,UAFhB,cAAA,CAKe;EAAA,MAAA,CAAA,EAAA;IACd,QAAA,CAAA,EAAA;MACC,KAAA,C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aw `mcp.servers.{name}`.
|
|
5
|
+
* Either a stdio child process spec or a remote URL spec.
|
|
6
|
+
*/
|
|
7
|
+
type McpServerConfig = StdioServerConfig | RemoteServerConfig;
|
|
8
|
+
interface StdioServerConfig {
|
|
9
|
+
command: string;
|
|
10
|
+
args?: string[];
|
|
11
|
+
env?: Record<string, string>;
|
|
12
|
+
cwd?: string;
|
|
13
|
+
}
|
|
14
|
+
interface RemoteServerConfig {
|
|
15
|
+
url: string;
|
|
16
|
+
transport?: 'sse' | 'streamable-http';
|
|
17
|
+
headers?: Record<string, string>;
|
|
18
|
+
connectionTimeoutMs?: number;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/plugin.d.ts
|
|
22
|
+
|
|
23
|
+
interface Logger {
|
|
24
|
+
debug(msg: string, ...args: unknown[]): void;
|
|
25
|
+
info(msg: string, ...args: unknown[]): void;
|
|
26
|
+
warn(msg: string, ...args: unknown[]): void;
|
|
27
|
+
error(msg: string, ...args: unknown[]): void;
|
|
28
|
+
}
|
|
29
|
+
interface ConfigSnapshot {
|
|
30
|
+
agents?: {
|
|
31
|
+
defaults?: {
|
|
32
|
+
model?: string;
|
|
33
|
+
cliBackends?: Record<string, unknown>;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
mcp?: {
|
|
37
|
+
servers?: Record<string, McpServerConfig>;
|
|
38
|
+
sessionIdleTtlMs?: number;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
interface AgentToolResult {
|
|
42
|
+
content: Record<string, unknown>[];
|
|
43
|
+
details?: Record<string, unknown>;
|
|
44
|
+
}
|
|
45
|
+
interface AgentTool {
|
|
46
|
+
name: string;
|
|
47
|
+
label?: string;
|
|
48
|
+
description: string;
|
|
49
|
+
parameters: Record<string, unknown>;
|
|
50
|
+
execute: (toolCallId: string, params: unknown, signal?: AbortSignal, onUpdate?: (update: unknown) => void) => Promise<AgentToolResult>;
|
|
51
|
+
}
|
|
52
|
+
interface ToolFactoryContext {
|
|
53
|
+
config?: ConfigSnapshot;
|
|
54
|
+
runtimeConfig?: ConfigSnapshot;
|
|
55
|
+
getRuntimeConfig?: () => ConfigSnapshot | undefined;
|
|
56
|
+
}
|
|
57
|
+
interface OpenClawPluginApi {
|
|
58
|
+
logger: Logger;
|
|
59
|
+
config?: ConfigSnapshot;
|
|
60
|
+
pluginConfig?: {
|
|
61
|
+
disabled?: boolean;
|
|
62
|
+
};
|
|
63
|
+
registrationMode?: string;
|
|
64
|
+
runtime?: {
|
|
65
|
+
config?: {
|
|
66
|
+
current?: () => ConfigSnapshot | undefined;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
registerTool: (tool: AgentTool | ((ctx: ToolFactoryContext) => AgentTool | AgentTool[] | null | undefined), opts?: {
|
|
70
|
+
name?: string;
|
|
71
|
+
names?: string[];
|
|
72
|
+
optional?: boolean;
|
|
73
|
+
}) => void;
|
|
74
|
+
}
|
|
75
|
+
declare const plugin: {
|
|
76
|
+
id: string;
|
|
77
|
+
name: string;
|
|
78
|
+
description: string;
|
|
79
|
+
version: string;
|
|
80
|
+
contracts: {
|
|
81
|
+
tools: string[];
|
|
82
|
+
};
|
|
83
|
+
activate(api: OpenClawPluginApi): void;
|
|
84
|
+
deactivate(api: OpenClawPluginApi): void;
|
|
85
|
+
};
|
|
86
|
+
//#endregion
|
|
87
|
+
export { plugin as t };
|
|
88
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","names":["McpServerConfig","StdioServerConfig","RemoteServerConfig","Record","McpTransportKind","McpToolDescriptor","ReconcileDiff","Logger","McpToolCallResult","BundlerOptions","STDIO_ENV_DENYLIST","Set","sanitizeStdioEnv","ConnectionDeps","McpClientHandle","Promise","AbortSignal","Connection","defaultConnect","McpBundler","sanitizeNameSegment","buildNamespacedToolName","disambiguateAgainst","ReadonlySet"],"sources":["../../mcp-bundler/dist/index.d.ts","../src/plugin.ts"],"sourcesContent":["//#region src/types.d.ts\n/**\n * Shape of a single MCP server entry — matches OpenClaw `mcp.servers.{name}`.\n * Either a stdio child process spec or a remote URL spec.\n */\ntype McpServerConfig = StdioServerConfig | RemoteServerConfig;\ninterface StdioServerConfig {\n command: string;\n args?: string[];\n env?: Record<string, string>;\n cwd?: string;\n}\ninterface RemoteServerConfig {\n url: string;\n transport?: 'sse' | 'streamable-http';\n headers?: Record<string, string>;\n connectionTimeoutMs?: number;\n}\ntype McpTransportKind = 'stdio' | 'sse' | 'streamable-http';\n/**\n * One tool surfaced from one MCP server, after namespacing.\n */\ninterface McpToolDescriptor {\n /** Namespaced name as the LLM sees it: `{serverName}__{originalName}`, sanitized + max 64 chars. */\n prefixed: string;\n /** Server name (key in `mcp.servers.*`). */\n server: string;\n /** Original tool name as advertised by the MCP server. */\n original: string;\n /** Human label for the tool (truncated description, suitable for UI). */\n label: string;\n /** Full description from the MCP server. */\n description: string;\n /** JSON Schema (object) for tool parameters. */\n parameters: Record<string, unknown>;\n}\ninterface ReconcileDiff {\n added: string[];\n removed: string[];\n changed: string[];\n unchanged: string[];\n}\ninterface Logger {\n debug: (msg: string, meta?: Record<string, unknown>) => void;\n info: (msg: string, meta?: Record<string, unknown>) => void;\n warn: (msg: string, meta?: Record<string, unknown>) => void;\n error: (msg: string, meta?: Record<string, unknown>) => void;\n}\ninterface McpToolCallResult {\n content: Record<string, unknown>[];\n isError?: boolean;\n}\ninterface BundlerOptions {\n logger?: Logger;\n /** Idle TTL for spawned children (ms). 0 disables. Default: 600_000 (10 min). */\n idleTtlMs?: number;\n /** Sweep interval for idle reaping (ms). Default: 60_000 (1 min). */\n idleSweepIntervalMs?: number;\n}\n//# sourceMappingURL=types.d.ts.map\n//#endregion\n//#region src/connection.d.ts\n/** Env keys OpenClaw rejects from stdio MCP env blocks. Filter them out before spawning. */\ndeclare const STDIO_ENV_DENYLIST: Set<string>;\ndeclare function sanitizeStdioEnv(env: Record<string, string> | undefined): Record<string, string>;\ninterface ConnectionDeps {\n /**\n * Factory for an MCP Client connected to the given config. Injected so tests\n * can mock without spawning real processes. In production this wraps\n * `@modelcontextprotocol/sdk/client`.\n */\n connect: (server: McpServerConfig) => Promise<McpClientHandle>;\n}\n/**\n * Minimal interface our connection layer needs from an MCP client. Mirrors\n * the @modelcontextprotocol/sdk Client surface but kept narrow so we can\n * mock cleanly in tests.\n */\ninterface McpClientHandle {\n listTools(): Promise<{\n name: string;\n description?: string;\n inputSchema: Record<string, unknown>;\n }[]>;\n callTool(name: string, args: unknown, opts?: {\n signal?: AbortSignal;\n }): Promise<McpToolCallResult>;\n close(): Promise<void>;\n}\n/**\n * One Connection per MCP server. Owns lifecycle (lazy-spawn, close, refresh-lock).\n * Refresh-lock pattern adapted from AIWerk `index.ts:219-250` — prevents\n * reconnect + `notifications/tools/list_changed` race.\n */\ndeclare class Connection {\n readonly name: string;\n readonly config: McpServerConfig;\n private readonly deps;\n private readonly logger;\n private client;\n private tools;\n private connectInFlight;\n private refreshInFlight;\n private refreshQueued;\n private lastUsedAt;\n constructor(params: {\n name: string;\n config: McpServerConfig;\n deps: ConnectionDeps;\n logger?: Logger;\n });\n /** Returns the most recent known tool list. May be empty if the server hasn't connected yet. */\n snapshotTools(): McpToolDescriptor[];\n /** Whether an MCP child process / remote connection has been established. */\n isConnected(): boolean;\n /** Idle timestamp for reaping. */\n idleSinceMs(): number;\n /**\n * Lazy connect + tool discovery. Safe to call concurrently; in-flight\n * connects coalesce.\n */\n ensureConnected(): Promise<void>;\n private connectAndDiscover;\n /**\n * Re-discover tools. Used on reconnect or `tools/list_changed` notification.\n * Refresh-lock collapses concurrent refreshes; if one is in flight, the next\n * is queued (max 1 queued, since N>1 queued provides no extra freshness).\n */\n refresh(): Promise<void>;\n callTool(originalName: string, args: unknown, signal?: AbortSignal): Promise<McpToolCallResult>;\n /**\n * Close the underlying transport. Idempotent. If a connect is in flight\n * (warmup racing with reconcile-removal), wait for it to settle and then\n * close the client it produced — otherwise the child process is orphaned.\n */\n close(): Promise<void>;\n /**\n * Stable hash of the config for diff detection in `reconcile`.\n * Two configs with the same hash are equivalent (no restart needed).\n */\n configFingerprint(): string;\n}\n/**\n * Build the production `connect` factory using the official MCP SDK.\n * Kept in a separate function so tests can substitute a mock without\n * pulling the SDK into the test bundle.\n */\ndeclare function defaultConnect(server: McpServerConfig): Promise<McpClientHandle>;\n//# sourceMappingURL=connection.d.ts.map\n//#endregion\n//#region src/bundler.d.ts\n/**\n * Provider-agnostic MCP server bundler. Holds N MCP server connections,\n * exposes a unified namespaced tool catalog, and routes calls to the right\n * server.\n *\n * Designed to be embedded in any host (OpenClaw plugin, AI proxy, Lambda).\n * Public surface is intentionally synchronous where the host needs sync\n * (snapshot, listTools), async only where I/O is unavoidable.\n */\ndeclare class McpBundler {\n private readonly logger;\n private readonly connections;\n private readonly idleTtlMs;\n private readonly idleSweepIntervalMs;\n private idleSweepTimer;\n private readonly deps;\n private disposed;\n private reconcileLatch;\n constructor(opts?: BundlerOptions, deps?: ConnectionDeps);\n /**\n * Diff `desired` against current connections, spawn newcomers, dispose\n * removals, hot-restart on config change. Pull-based — call whenever the\n * host's config snapshot may have changed. Cheap if no diff.\n *\n * Lazy: newly-added servers are NOT eagerly connected; they connect on the\n * first `callTool()` (or first `listTools()` after `forceDiscover()`).\n * This avoids paying spawn cost for servers the agent never uses.\n */\n reconcile(desired: Record<string, McpServerConfig>): Promise<ReconcileDiff>;\n private doReconcile;\n /**\n * Synchronous snapshot of all currently-known tools across connected servers.\n * Servers that have not connected yet contribute nothing. Intended for use\n * inside OpenClaw's plugin tool factory which must be sync.\n *\n * Tool names are namespaced and disambiguated (suffix `-2`, `-3` on collision)\n * so cross-server name clashes never produce duplicate registrations.\n */\n listTools(): McpToolDescriptor[];\n /**\n * Eagerly connect to every configured server and discover tools. Used by\n * hosts that want a hot list rather than the lazy default. Errors are\n * swallowed per-server (logged), so one bad server doesn't fail the batch.\n */\n warmup(): Promise<void>;\n /**\n * Invoke a tool by its namespaced name. Routes to the originating server.\n * Errors are returned as `{ isError: true, content: [...] }` so a failing\n * tool doesn't crash the host.\n */\n callTool(prefixed: string, args: unknown, signal?: AbortSignal): Promise<McpToolCallResult>;\n /**\n * Resolve a namespaced tool name back to its server connection and original\n * tool name. Returns undefined if the tool is not currently advertised.\n */\n private routeToolName;\n /**\n * Tear down all connections and stop background tasks. Idempotent.\n * Call from `registerRuntimeLifecycle({ cleanup })` in the host plugin.\n */\n dispose(): Promise<void>;\n private startIdleSweep;\n private sweepIdle;\n}\n//# sourceMappingURL=bundler.d.ts.map\n//#endregion\n//#region src/tool-naming.d.ts\n/**\n * Tool name sanitization and collision handling.\n *\n * OpenClaw constraint: tool names must match `[A-Za-z0-9_-]` and be ≤64 chars.\n * Pattern mirrored from `openclaw/src/agents/pi-bundle-mcp-names.ts`.\n *\n * Strategy: prefix every tool with its server name (`{server}__{tool}`),\n * sanitize disallowed chars to `_`, truncate, then suffix-disambiguate\n * (`-2`, `-3`, ...) on collision.\n */\ndeclare function sanitizeNameSegment(value: string): string;\ndeclare function buildNamespacedToolName(server: string, tool: string): string;\n/**\n * Disambiguate a candidate name against an existing set by appending `-2`, `-3`, etc.\n * Mutates nothing; returns the chosen name. Caller is responsible for inserting it\n * into the set.\n */\ndeclare function disambiguateAgainst(candidate: string, taken: ReadonlySet<string>): string;\n//# sourceMappingURL=tool-naming.d.ts.map\n\n//#endregion\nexport { type BundlerOptions, Connection, type ConnectionDeps, type Logger, McpBundler, type McpClientHandle, type McpServerConfig, type McpToolCallResult, type McpToolDescriptor, type McpTransportKind, type ReconcileDiff, type RemoteServerConfig, STDIO_ENV_DENYLIST, type StdioServerConfig, buildNamespacedToolName, defaultConnect, disambiguateAgainst, sanitizeNameSegment, sanitizeStdioEnv };\n//# sourceMappingURL=index.d.ts.map"],"mappings":";;;;;;KAKKA,eAAAA,GAAkBC,iBAAsC,GAAlBC,kBAAkB;AAAA,UACnDD,iBAAAA,CAAiB;EAGb,OAGJC,EAAAA,MAAAA;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EAAA,MAAA,CAAA,EAbE,WAaF,EAAA,QAAA,CAAA,EAAA,CAAA,MAAA,EAAA,OAAA,EAAA,GAAA,IAAA,EAAA,GAXJ,OAWI,CAXI,eAWJ,CAAA;;UARD,kBAAA,CAaA;QAAmB,CAAA,EAZlB,cAYkB;eAAuB,CAAA,EAXlC,cAWkC;kBAAY,CAAA,EAAA,GAAA,GAVrC,cAUqC,GAAA,SAAA;;AAAS,UAP/D,iBAAA,CAgJT;EAAA,MAAA,EA/IS,MA+IT;QApEe,CAAA,EA1EL,cA0EK;cA0DE,CAAA,EAAA;IAAiB,QAAA,CAAA,EAAA,OAAA;;;;;sBAjIM;;;uBAE/B,mBAAmB,uBAAuB,YAAY;;;;;;cAqD1D;;;;;;;;gBAgBU;kBA0DE"}
|
package/dist/plugin.js
ADDED
package/dist/plugin2.cjs
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
let _alfe_ai_mcp_bundler = require("@alfe.ai/mcp-bundler");
|
|
2
|
+
let node_module = require("node:module");
|
|
3
|
+
//#region src/cli-backend-detect.ts
|
|
4
|
+
/**
|
|
5
|
+
* Determine whether the active agent's CLI backend already has native bundle-MCP
|
|
6
|
+
* support. If so, our plugin should no-op so we don't double-register tools.
|
|
7
|
+
*
|
|
8
|
+
* As of OpenClaw 2026.4 only `claude-cli` and `codex-cli` ship with
|
|
9
|
+
* `bundleMcp: true`. We hardcode that allowlist for now; future backends
|
|
10
|
+
* shipping with bundleMcp:true will need to be added here (or, ideally,
|
|
11
|
+
* OpenClaw exposes a public API to query the resolved backend's bundleMcp
|
|
12
|
+
* flag and we call that instead — see project_openclaw_mcp_bundler.md TODO).
|
|
13
|
+
*
|
|
14
|
+
* This detection is best-effort: if we can't determine the backend (no
|
|
15
|
+
* runtime config available), we default to "no native MCP" (return false)
|
|
16
|
+
* so our plugin DOES register. Worst case is benign duplicate tool names
|
|
17
|
+
* with `-2` suffix on claude-cli, which is recoverable; missing tools on
|
|
18
|
+
* MiniMax is the bug we exist to fix.
|
|
19
|
+
*/
|
|
20
|
+
const NATIVE_BUNDLE_MCP_BACKENDS = new Set(["claude-cli", "codex-cli"]);
|
|
21
|
+
/**
|
|
22
|
+
* Read the active agent's primary model and infer its CLI backend.
|
|
23
|
+
* Returns true if that backend has native bundleMcp support.
|
|
24
|
+
*
|
|
25
|
+
* Heuristic mapping (matches what OpenClaw's plugin-setup-cli-backend
|
|
26
|
+
* registry resolves to today):
|
|
27
|
+
* - model id containing "claude" or "anthropic" → claude-cli
|
|
28
|
+
* - model id containing "codex" or "gpt-5-codex" or "openai/codex" → codex-cli
|
|
29
|
+
* - everything else → no native bundle-mcp
|
|
30
|
+
*
|
|
31
|
+
* If `agents.defaults.cliBackends` explicitly configures one of the native
|
|
32
|
+
* backends, we trust that override.
|
|
33
|
+
*/
|
|
34
|
+
function detectNativeBundleMcp(cfg) {
|
|
35
|
+
if (!cfg) return false;
|
|
36
|
+
const defaults = cfg.agents?.defaults;
|
|
37
|
+
if (!defaults) return false;
|
|
38
|
+
const configured = defaults.cliBackends ?? {};
|
|
39
|
+
for (const key of Object.keys(configured)) if (NATIVE_BUNDLE_MCP_BACKENDS.has(key)) return true;
|
|
40
|
+
const model = (defaults.model ?? "").toLowerCase();
|
|
41
|
+
if (!model) return false;
|
|
42
|
+
if (model.includes("claude") || model.includes("anthropic")) return true;
|
|
43
|
+
if (model.includes("codex") || model.startsWith("gpt-5-codex")) return true;
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/plugin.ts
|
|
48
|
+
/**
|
|
49
|
+
* @alfe.ai/openclaw-mcp-bundler — OpenClaw plugin entry
|
|
50
|
+
*
|
|
51
|
+
* Reads `cfg.mcp.servers` from openclaw.json and surfaces each MCP server's
|
|
52
|
+
* tools to the agent via `api.registerTool(factory)`. This works for ANY
|
|
53
|
+
* LLM backend, closing the gap that OpenClaw's native `bundleMcp:true`
|
|
54
|
+
* leaves open (only claude-cli/codex-cli have it shipped today).
|
|
55
|
+
*
|
|
56
|
+
* On `claude-cli`/`codex-cli` agents the plugin detects the native wiring
|
|
57
|
+
* and no-ops, avoiding double-registered tools.
|
|
58
|
+
*/
|
|
59
|
+
const pkg = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)("../package.json");
|
|
60
|
+
let bundler;
|
|
61
|
+
let lastFingerprint = "";
|
|
62
|
+
function resolveLiveConfig(api, ctx) {
|
|
63
|
+
return ctx?.runtimeConfig ?? ctx?.getRuntimeConfig?.() ?? api.runtime?.config?.current?.() ?? ctx?.config ?? api.config;
|
|
64
|
+
}
|
|
65
|
+
function fingerprintServers(servers) {
|
|
66
|
+
const keys = Object.keys(servers).sort();
|
|
67
|
+
return JSON.stringify(keys.map((k) => [k, servers[k]]));
|
|
68
|
+
}
|
|
69
|
+
function toAgentTool(api, tool) {
|
|
70
|
+
return {
|
|
71
|
+
name: tool.prefixed,
|
|
72
|
+
label: tool.label,
|
|
73
|
+
description: tool.description || `MCP tool ${tool.original} from server ${tool.server}`,
|
|
74
|
+
parameters: tool.parameters,
|
|
75
|
+
async execute(_toolCallId, params, signal) {
|
|
76
|
+
if (!bundler) return errorResult(`mcp-bundler not initialized for tool ${tool.prefixed}`);
|
|
77
|
+
const result = await bundler.callTool(tool.prefixed, params, signal);
|
|
78
|
+
return {
|
|
79
|
+
content: result.content,
|
|
80
|
+
details: { isError: result.isError ?? false }
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function errorResult(message) {
|
|
86
|
+
return {
|
|
87
|
+
content: [{
|
|
88
|
+
type: "text",
|
|
89
|
+
text: message
|
|
90
|
+
}],
|
|
91
|
+
details: { isError: true }
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
const plugin = {
|
|
95
|
+
id: "@alfe.ai/openclaw-mcp-bundler",
|
|
96
|
+
name: "Alfe MCP Bundler",
|
|
97
|
+
description: "Surfaces mcp.servers tools to the agent for any LLM backend",
|
|
98
|
+
version: pkg.version,
|
|
99
|
+
contracts: { tools: ["mcp__*"] },
|
|
100
|
+
activate(api) {
|
|
101
|
+
const log = api.logger;
|
|
102
|
+
if (api.pluginConfig?.disabled) {
|
|
103
|
+
log.info("[mcp-bundler] disabled via plugin config — no-op");
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (api.registrationMode && api.registrationMode !== "full" && api.registrationMode !== "discovery" && api.registrationMode !== "tool-discovery") {
|
|
107
|
+
log.info(`[mcp-bundler] skipped — registrationMode=${api.registrationMode}`);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const initialCfg = resolveLiveConfig(api);
|
|
111
|
+
if (detectNativeBundleMcp(initialCfg)) {
|
|
112
|
+
log.info("[mcp-bundler] native bundle-mcp detected on this backend (claude-cli/codex-cli) — standing by as no-op to avoid double-registered tools");
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
bundler = new _alfe_ai_mcp_bundler.McpBundler({
|
|
116
|
+
logger: log,
|
|
117
|
+
idleTtlMs: initialCfg?.mcp?.sessionIdleTtlMs ?? 600 * 1e3
|
|
118
|
+
});
|
|
119
|
+
const initialServers = initialCfg?.mcp?.servers ?? {};
|
|
120
|
+
bundler.reconcile(initialServers).then(() => bundler?.warmup()).catch((err) => {
|
|
121
|
+
log.warn("[mcp-bundler] initial reconcile/warmup failed", { err: err instanceof Error ? err.message : String(err) });
|
|
122
|
+
});
|
|
123
|
+
lastFingerprint = fingerprintServers(initialServers);
|
|
124
|
+
api.registerTool((ctx) => {
|
|
125
|
+
const live = resolveLiveConfig(api, ctx);
|
|
126
|
+
if (!live || detectNativeBundleMcp(live)) return null;
|
|
127
|
+
const servers = live.mcp?.servers ?? {};
|
|
128
|
+
const fp = fingerprintServers(servers);
|
|
129
|
+
if (fp !== lastFingerprint) {
|
|
130
|
+
lastFingerprint = fp;
|
|
131
|
+
bundler?.reconcile(servers).then(() => bundler?.warmup()).catch((err) => {
|
|
132
|
+
log.warn("[mcp-bundler] reconcile failed", { err: err instanceof Error ? err.message : String(err) });
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
return (bundler?.listTools() ?? []).map((t) => toAgentTool(api, t));
|
|
136
|
+
}, { optional: true });
|
|
137
|
+
log.info(`[mcp-bundler] activated v${pkg.version}, ${Object.keys(initialServers).length.toString()} server(s) configured`);
|
|
138
|
+
},
|
|
139
|
+
deactivate(api) {
|
|
140
|
+
api.logger.info("[mcp-bundler] deactivating");
|
|
141
|
+
if (bundler) {
|
|
142
|
+
bundler.dispose().catch((err) => {
|
|
143
|
+
api.logger.warn("[mcp-bundler] dispose error", { err: err instanceof Error ? err.message : String(err) });
|
|
144
|
+
});
|
|
145
|
+
bundler = void 0;
|
|
146
|
+
}
|
|
147
|
+
lastFingerprint = "";
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
//#endregion
|
|
151
|
+
Object.defineProperty(exports, "detectNativeBundleMcp", {
|
|
152
|
+
enumerable: true,
|
|
153
|
+
get: function() {
|
|
154
|
+
return detectNativeBundleMcp;
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
Object.defineProperty(exports, "plugin", {
|
|
158
|
+
enumerable: true,
|
|
159
|
+
get: function() {
|
|
160
|
+
return plugin;
|
|
161
|
+
}
|
|
162
|
+
});
|
package/dist/plugin2.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { McpBundler } from "@alfe.ai/mcp-bundler";
|
|
3
|
+
//#region src/cli-backend-detect.ts
|
|
4
|
+
/**
|
|
5
|
+
* Determine whether the active agent's CLI backend already has native bundle-MCP
|
|
6
|
+
* support. If so, our plugin should no-op so we don't double-register tools.
|
|
7
|
+
*
|
|
8
|
+
* As of OpenClaw 2026.4 only `claude-cli` and `codex-cli` ship with
|
|
9
|
+
* `bundleMcp: true`. We hardcode that allowlist for now; future backends
|
|
10
|
+
* shipping with bundleMcp:true will need to be added here (or, ideally,
|
|
11
|
+
* OpenClaw exposes a public API to query the resolved backend's bundleMcp
|
|
12
|
+
* flag and we call that instead — see project_openclaw_mcp_bundler.md TODO).
|
|
13
|
+
*
|
|
14
|
+
* This detection is best-effort: if we can't determine the backend (no
|
|
15
|
+
* runtime config available), we default to "no native MCP" (return false)
|
|
16
|
+
* so our plugin DOES register. Worst case is benign duplicate tool names
|
|
17
|
+
* with `-2` suffix on claude-cli, which is recoverable; missing tools on
|
|
18
|
+
* MiniMax is the bug we exist to fix.
|
|
19
|
+
*/
|
|
20
|
+
const NATIVE_BUNDLE_MCP_BACKENDS = new Set(["claude-cli", "codex-cli"]);
|
|
21
|
+
/**
|
|
22
|
+
* Read the active agent's primary model and infer its CLI backend.
|
|
23
|
+
* Returns true if that backend has native bundleMcp support.
|
|
24
|
+
*
|
|
25
|
+
* Heuristic mapping (matches what OpenClaw's plugin-setup-cli-backend
|
|
26
|
+
* registry resolves to today):
|
|
27
|
+
* - model id containing "claude" or "anthropic" → claude-cli
|
|
28
|
+
* - model id containing "codex" or "gpt-5-codex" or "openai/codex" → codex-cli
|
|
29
|
+
* - everything else → no native bundle-mcp
|
|
30
|
+
*
|
|
31
|
+
* If `agents.defaults.cliBackends` explicitly configures one of the native
|
|
32
|
+
* backends, we trust that override.
|
|
33
|
+
*/
|
|
34
|
+
function detectNativeBundleMcp(cfg) {
|
|
35
|
+
if (!cfg) return false;
|
|
36
|
+
const defaults = cfg.agents?.defaults;
|
|
37
|
+
if (!defaults) return false;
|
|
38
|
+
const configured = defaults.cliBackends ?? {};
|
|
39
|
+
for (const key of Object.keys(configured)) if (NATIVE_BUNDLE_MCP_BACKENDS.has(key)) return true;
|
|
40
|
+
const model = (defaults.model ?? "").toLowerCase();
|
|
41
|
+
if (!model) return false;
|
|
42
|
+
if (model.includes("claude") || model.includes("anthropic")) return true;
|
|
43
|
+
if (model.includes("codex") || model.startsWith("gpt-5-codex")) return true;
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/plugin.ts
|
|
48
|
+
/**
|
|
49
|
+
* @alfe.ai/openclaw-mcp-bundler — OpenClaw plugin entry
|
|
50
|
+
*
|
|
51
|
+
* Reads `cfg.mcp.servers` from openclaw.json and surfaces each MCP server's
|
|
52
|
+
* tools to the agent via `api.registerTool(factory)`. This works for ANY
|
|
53
|
+
* LLM backend, closing the gap that OpenClaw's native `bundleMcp:true`
|
|
54
|
+
* leaves open (only claude-cli/codex-cli have it shipped today).
|
|
55
|
+
*
|
|
56
|
+
* On `claude-cli`/`codex-cli` agents the plugin detects the native wiring
|
|
57
|
+
* and no-ops, avoiding double-registered tools.
|
|
58
|
+
*/
|
|
59
|
+
const pkg = createRequire(import.meta.url)("../package.json");
|
|
60
|
+
let bundler;
|
|
61
|
+
let lastFingerprint = "";
|
|
62
|
+
function resolveLiveConfig(api, ctx) {
|
|
63
|
+
return ctx?.runtimeConfig ?? ctx?.getRuntimeConfig?.() ?? api.runtime?.config?.current?.() ?? ctx?.config ?? api.config;
|
|
64
|
+
}
|
|
65
|
+
function fingerprintServers(servers) {
|
|
66
|
+
const keys = Object.keys(servers).sort();
|
|
67
|
+
return JSON.stringify(keys.map((k) => [k, servers[k]]));
|
|
68
|
+
}
|
|
69
|
+
function toAgentTool(api, tool) {
|
|
70
|
+
return {
|
|
71
|
+
name: tool.prefixed,
|
|
72
|
+
label: tool.label,
|
|
73
|
+
description: tool.description || `MCP tool ${tool.original} from server ${tool.server}`,
|
|
74
|
+
parameters: tool.parameters,
|
|
75
|
+
async execute(_toolCallId, params, signal) {
|
|
76
|
+
if (!bundler) return errorResult(`mcp-bundler not initialized for tool ${tool.prefixed}`);
|
|
77
|
+
const result = await bundler.callTool(tool.prefixed, params, signal);
|
|
78
|
+
return {
|
|
79
|
+
content: result.content,
|
|
80
|
+
details: { isError: result.isError ?? false }
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function errorResult(message) {
|
|
86
|
+
return {
|
|
87
|
+
content: [{
|
|
88
|
+
type: "text",
|
|
89
|
+
text: message
|
|
90
|
+
}],
|
|
91
|
+
details: { isError: true }
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
const plugin = {
|
|
95
|
+
id: "@alfe.ai/openclaw-mcp-bundler",
|
|
96
|
+
name: "Alfe MCP Bundler",
|
|
97
|
+
description: "Surfaces mcp.servers tools to the agent for any LLM backend",
|
|
98
|
+
version: pkg.version,
|
|
99
|
+
contracts: { tools: ["mcp__*"] },
|
|
100
|
+
activate(api) {
|
|
101
|
+
const log = api.logger;
|
|
102
|
+
if (api.pluginConfig?.disabled) {
|
|
103
|
+
log.info("[mcp-bundler] disabled via plugin config — no-op");
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (api.registrationMode && api.registrationMode !== "full" && api.registrationMode !== "discovery" && api.registrationMode !== "tool-discovery") {
|
|
107
|
+
log.info(`[mcp-bundler] skipped — registrationMode=${api.registrationMode}`);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const initialCfg = resolveLiveConfig(api);
|
|
111
|
+
if (detectNativeBundleMcp(initialCfg)) {
|
|
112
|
+
log.info("[mcp-bundler] native bundle-mcp detected on this backend (claude-cli/codex-cli) — standing by as no-op to avoid double-registered tools");
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
bundler = new McpBundler({
|
|
116
|
+
logger: log,
|
|
117
|
+
idleTtlMs: initialCfg?.mcp?.sessionIdleTtlMs ?? 600 * 1e3
|
|
118
|
+
});
|
|
119
|
+
const initialServers = initialCfg?.mcp?.servers ?? {};
|
|
120
|
+
bundler.reconcile(initialServers).then(() => bundler?.warmup()).catch((err) => {
|
|
121
|
+
log.warn("[mcp-bundler] initial reconcile/warmup failed", { err: err instanceof Error ? err.message : String(err) });
|
|
122
|
+
});
|
|
123
|
+
lastFingerprint = fingerprintServers(initialServers);
|
|
124
|
+
api.registerTool((ctx) => {
|
|
125
|
+
const live = resolveLiveConfig(api, ctx);
|
|
126
|
+
if (!live || detectNativeBundleMcp(live)) return null;
|
|
127
|
+
const servers = live.mcp?.servers ?? {};
|
|
128
|
+
const fp = fingerprintServers(servers);
|
|
129
|
+
if (fp !== lastFingerprint) {
|
|
130
|
+
lastFingerprint = fp;
|
|
131
|
+
bundler?.reconcile(servers).then(() => bundler?.warmup()).catch((err) => {
|
|
132
|
+
log.warn("[mcp-bundler] reconcile failed", { err: err instanceof Error ? err.message : String(err) });
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
return (bundler?.listTools() ?? []).map((t) => toAgentTool(api, t));
|
|
136
|
+
}, { optional: true });
|
|
137
|
+
log.info(`[mcp-bundler] activated v${pkg.version}, ${Object.keys(initialServers).length.toString()} server(s) configured`);
|
|
138
|
+
},
|
|
139
|
+
deactivate(api) {
|
|
140
|
+
api.logger.info("[mcp-bundler] deactivating");
|
|
141
|
+
if (bundler) {
|
|
142
|
+
bundler.dispose().catch((err) => {
|
|
143
|
+
api.logger.warn("[mcp-bundler] dispose error", { err: err instanceof Error ? err.message : String(err) });
|
|
144
|
+
});
|
|
145
|
+
bundler = void 0;
|
|
146
|
+
}
|
|
147
|
+
lastFingerprint = "";
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
//#endregion
|
|
151
|
+
export { detectNativeBundleMcp as n, plugin as t };
|
|
152
|
+
|
|
153
|
+
//# sourceMappingURL=plugin2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin2.js","names":[],"sources":["../src/cli-backend-detect.ts","../src/plugin.ts"],"sourcesContent":["/**\n * Determine whether the active agent's CLI backend already has native bundle-MCP\n * support. If so, our plugin should no-op so we don't double-register tools.\n *\n * As of OpenClaw 2026.4 only `claude-cli` and `codex-cli` ship with\n * `bundleMcp: true`. We hardcode that allowlist for now; future backends\n * shipping with bundleMcp:true will need to be added here (or, ideally,\n * OpenClaw exposes a public API to query the resolved backend's bundleMcp\n * flag and we call that instead — see project_openclaw_mcp_bundler.md TODO).\n *\n * This detection is best-effort: if we can't determine the backend (no\n * runtime config available), we default to \"no native MCP\" (return false)\n * so our plugin DOES register. Worst case is benign duplicate tool names\n * with `-2` suffix on claude-cli, which is recoverable; missing tools on\n * MiniMax is the bug we exist to fix.\n */\n\nconst NATIVE_BUNDLE_MCP_BACKENDS = new Set(['claude-cli', 'codex-cli']);\n\ninterface ConfigLike {\n agents?: {\n defaults?: {\n model?: string;\n cliBackends?: Record<string, unknown>;\n };\n };\n}\n\n/**\n * Read the active agent's primary model and infer its CLI backend.\n * Returns true if that backend has native bundleMcp support.\n *\n * Heuristic mapping (matches what OpenClaw's plugin-setup-cli-backend\n * registry resolves to today):\n * - model id containing \"claude\" or \"anthropic\" → claude-cli\n * - model id containing \"codex\" or \"gpt-5-codex\" or \"openai/codex\" → codex-cli\n * - everything else → no native bundle-mcp\n *\n * If `agents.defaults.cliBackends` explicitly configures one of the native\n * backends, we trust that override.\n */\nexport function detectNativeBundleMcp(cfg: ConfigLike | undefined): boolean {\n if (!cfg) return false;\n const defaults = cfg.agents?.defaults;\n if (!defaults) return false;\n\n // Explicit per-backend config overrides the heuristic.\n const configured = defaults.cliBackends ?? {};\n for (const key of Object.keys(configured)) {\n if (NATIVE_BUNDLE_MCP_BACKENDS.has(key)) return true;\n }\n\n // Otherwise infer from model id.\n const model = (defaults.model ?? '').toLowerCase();\n if (!model) return false;\n if (model.includes('claude') || model.includes('anthropic')) return true;\n if (model.includes('codex') || model.startsWith('gpt-5-codex')) return true;\n return false;\n}\n","/**\n * @alfe.ai/openclaw-mcp-bundler — OpenClaw plugin entry\n *\n * Reads `cfg.mcp.servers` from openclaw.json and surfaces each MCP server's\n * tools to the agent via `api.registerTool(factory)`. This works for ANY\n * LLM backend, closing the gap that OpenClaw's native `bundleMcp:true`\n * leaves open (only claude-cli/codex-cli have it shipped today).\n *\n * On `claude-cli`/`codex-cli` agents the plugin detects the native wiring\n * and no-ops, avoiding double-registered tools.\n */\n\nimport { McpBundler, type McpServerConfig, type McpToolDescriptor } from '@alfe.ai/mcp-bundler';\nimport { detectNativeBundleMcp } from './cli-backend-detect.js';\nimport { createRequire } from 'node:module';\nconst require = createRequire(import.meta.url);\nconst pkg = require('../package.json') as { version: string };\n\n// ── Type shims for the OpenClaw plugin SDK ──────────────────────\n// We avoid a hard dep on the SDK to keep this plugin loadable across\n// OpenClaw versions; the surface used here is stable.\n\ninterface Logger {\n debug(msg: string, ...args: unknown[]): void;\n info(msg: string, ...args: unknown[]): void;\n warn(msg: string, ...args: unknown[]): void;\n error(msg: string, ...args: unknown[]): void;\n}\n\ninterface ConfigSnapshot {\n agents?: { defaults?: { model?: string; cliBackends?: Record<string, unknown> } };\n mcp?: { servers?: Record<string, McpServerConfig>; sessionIdleTtlMs?: number };\n}\n\ninterface AgentToolResult {\n content: Record<string, unknown>[];\n details?: Record<string, unknown>;\n}\n\ninterface AgentTool {\n name: string;\n label?: string;\n description: string;\n parameters: Record<string, unknown>;\n execute: (\n toolCallId: string,\n params: unknown,\n signal?: AbortSignal,\n onUpdate?: (update: unknown) => void,\n ) => Promise<AgentToolResult>;\n}\n\ninterface ToolFactoryContext {\n config?: ConfigSnapshot;\n runtimeConfig?: ConfigSnapshot;\n getRuntimeConfig?: () => ConfigSnapshot | undefined;\n}\n\ninterface OpenClawPluginApi {\n logger: Logger;\n config?: ConfigSnapshot;\n pluginConfig?: { disabled?: boolean };\n registrationMode?: string;\n runtime?: { config?: { current?: () => ConfigSnapshot | undefined } };\n registerTool: (\n tool: AgentTool | ((ctx: ToolFactoryContext) => AgentTool | AgentTool[] | null | undefined),\n opts?: { name?: string; names?: string[]; optional?: boolean },\n ) => void;\n}\n\n// ── Plugin state ───────────────────────────────────────────────\nlet bundler: McpBundler | undefined;\nlet lastFingerprint = '';\n\nfunction resolveLiveConfig(api: OpenClawPluginApi, ctx?: ToolFactoryContext): ConfigSnapshot | undefined {\n // Prefer most-recent → ctx live → ctx snapshot → api.runtime live → api.config snapshot\n return (\n ctx?.runtimeConfig ??\n ctx?.getRuntimeConfig?.() ??\n api.runtime?.config?.current?.() ??\n ctx?.config ??\n api.config\n );\n}\n\nfunction fingerprintServers(servers: Record<string, McpServerConfig>): string {\n const keys = Object.keys(servers).sort();\n return JSON.stringify(keys.map((k) => [k, servers[k]]));\n}\n\nfunction toAgentTool(api: OpenClawPluginApi, tool: McpToolDescriptor): AgentTool {\n return {\n name: tool.prefixed,\n label: tool.label,\n description: tool.description || `MCP tool ${tool.original} from server ${tool.server}`,\n // OpenClaw expects a JSON-Schema-shaped object. The MCP server already\n // gives us one in `tool.parameters`. Pass through unchanged.\n parameters: tool.parameters,\n async execute(_toolCallId, params, signal) {\n if (!bundler) {\n return errorResult(`mcp-bundler not initialized for tool ${tool.prefixed}`);\n }\n const result = await bundler.callTool(tool.prefixed, params, signal);\n return {\n content: result.content,\n details: { isError: result.isError ?? false },\n };\n },\n };\n}\n\nfunction errorResult(message: string): AgentToolResult {\n return {\n content: [{ type: 'text', text: message }],\n details: { isError: true },\n };\n}\n\nconst plugin = {\n id: '@alfe.ai/openclaw-mcp-bundler',\n name: 'Alfe MCP Bundler',\n description: 'Surfaces mcp.servers tools to the agent for any LLM backend',\n version: pkg.version,\n contracts: {\n // Tool name set is dynamic. We declare a wildcard via the only stable\n // identifier we can: the plugin id. OpenClaw's manifest registry uses\n // contracts.tools as a static allowlist; for dynamic tool sets we declare\n // a sentinel here and the runtime allows any tool name registered at\n // runtime to pass through. (If OpenClaw enforces strict contracts in a\n // future version, we'd need to switch to a router-tool pattern: register\n // one fixed `mcp_call` tool that accepts {server, tool, args} dynamically.)\n tools: ['mcp__*'],\n },\n\n activate(api: OpenClawPluginApi) {\n const log = api.logger;\n if (api.pluginConfig?.disabled) {\n log.info('[mcp-bundler] disabled via plugin config — no-op');\n return;\n }\n\n // Setup-only and metadata-only registration modes shouldn't spawn anything.\n if (api.registrationMode && api.registrationMode !== 'full' && api.registrationMode !== 'discovery' && api.registrationMode !== 'tool-discovery') {\n log.info(`[mcp-bundler] skipped — registrationMode=${api.registrationMode}`);\n return;\n }\n\n const initialCfg = resolveLiveConfig(api);\n if (detectNativeBundleMcp(initialCfg)) {\n log.info(\n '[mcp-bundler] native bundle-mcp detected on this backend (claude-cli/codex-cli) — standing by as no-op to avoid double-registered tools',\n );\n return;\n }\n\n bundler = new McpBundler({\n logger: log,\n idleTtlMs: initialCfg?.mcp?.sessionIdleTtlMs ?? 10 * 60 * 1000,\n });\n\n // Initial reconcile in the background so the first factory call has tools\n // ready (it'll be empty if reconcile hasn't completed yet, which is fine —\n // the next agent turn picks them up).\n const initialServers = initialCfg?.mcp?.servers ?? {};\n void bundler.reconcile(initialServers).then(() => bundler?.warmup()).catch((err: unknown) => {\n log.warn('[mcp-bundler] initial reconcile/warmup failed', { err: err instanceof Error ? err.message : String(err) });\n });\n lastFingerprint = fingerprintServers(initialServers);\n\n api.registerTool((ctx: ToolFactoryContext) => {\n const live = resolveLiveConfig(api, ctx);\n if (!live || detectNativeBundleMcp(live)) return null;\n const servers = live.mcp?.servers ?? {};\n\n // Detect config drift since last reconcile and trigger a fire-and-forget\n // reconcile. OpenClaw caches the factory output keyed on config snapshot,\n // so this only runs when MCP config actually changed.\n const fp = fingerprintServers(servers);\n if (fp !== lastFingerprint) {\n lastFingerprint = fp;\n void bundler?.reconcile(servers).then(() => bundler?.warmup()).catch((err: unknown) => {\n log.warn('[mcp-bundler] reconcile failed', { err: err instanceof Error ? err.message : String(err) });\n });\n }\n\n const tools = bundler?.listTools() ?? [];\n return tools.map((t) => toAgentTool(api, t));\n }, { optional: true });\n\n log.info(`[mcp-bundler] activated v${pkg.version}, ${Object.keys(initialServers).length.toString()} server(s) configured`);\n },\n\n deactivate(api: OpenClawPluginApi) {\n api.logger.info('[mcp-bundler] deactivating');\n if (bundler) {\n void bundler.dispose().catch((err: unknown) => {\n api.logger.warn('[mcp-bundler] dispose error', { err: err instanceof Error ? err.message : String(err) });\n });\n bundler = undefined;\n }\n lastFingerprint = '';\n },\n};\n\n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C,MAAM,KAAK,mBAAmB,QAAQ;AACtC,OAAI,OAAO,iBAAiB;AAC1B,sBAAkB;AACb,aAAS,UAAU,QAAQ,CAAC,WAAW,SAAS,QAAQ,CAAC,CAAC,OAAO,QAAiB;AACrF,SAAI,KAAK,kCAAkC,EAAE,KAAK,eAAe,QAAQ,IAAI,UAAU,OAAO,IAAI,EAAE,CAAC;MACrG;;AAIJ,WADc,SAAS,WAAW,IAAI,EAAE,EAC3B,KAAK,MAAM,YAAY,KAAK,EAAE,CAAC;KAC3C,EAAE,UAAU,MAAM,CAAC;AAEtB,MAAI,KAAK,4BAA4B,IAAI,QAAQ,IAAI,OAAO,KAAK,eAAe,CAAC,OAAO,UAAU,CAAC,uBAAuB;;CAG5H,WAAW,KAAwB;AACjC,MAAI,OAAO,KAAK,6BAA6B;AAC7C,MAAI,SAAS;AACN,WAAQ,SAAS,CAAC,OAAO,QAAiB;AAC7C,QAAI,OAAO,KAAK,+BAA+B,EAAE,KAAK,eAAe,QAAQ,IAAI,UAAU,OAAO,IAAI,EAAE,CAAC;KACzG;AACF,aAAU,KAAA;;AAEZ,oBAAkB;;CAErB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "@alfe.ai/openclaw-mcp-bundler",
|
|
3
|
+
"name": "Alfe MCP Bundler",
|
|
4
|
+
"description": "Bridges mcp.servers config into agent tools for any LLM backend — closes the bundleMcp gap on non-Claude/Codex models",
|
|
5
|
+
"entry": "./dist/plugin.js",
|
|
6
|
+
"configSchema": {
|
|
7
|
+
"type": "object",
|
|
8
|
+
"additionalProperties": false,
|
|
9
|
+
"properties": {
|
|
10
|
+
"disabled": {
|
|
11
|
+
"type": "boolean",
|
|
12
|
+
"description": "Force-disable the bundler. When true, the plugin no-ops on activate."
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@alfe.ai/openclaw-mcp-bundler",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "OpenClaw plugin that bridges mcp.servers config into agent tool list via @alfe.ai/mcp-bundler — works for any LLM backend (not just claude-cli/codex-cli)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"require": "./dist/index.cjs",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./plugin": {
|
|
15
|
+
"types": "./dist/plugin.d.ts",
|
|
16
|
+
"require": "./dist/plugin.cjs",
|
|
17
|
+
"import": "./dist/plugin.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"openclaw": {
|
|
21
|
+
"extensions": [
|
|
22
|
+
"./dist/plugin.js"
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"openclaw.plugin.json"
|
|
28
|
+
],
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@alfe.ai/mcp-bundler": "0.0.1"
|
|
31
|
+
},
|
|
32
|
+
"license": "UNLICENSED",
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsdown",
|
|
35
|
+
"dev": "tsdown --watch",
|
|
36
|
+
"test": "vitest run",
|
|
37
|
+
"typecheck": "tsc --noEmit",
|
|
38
|
+
"lint": "eslint ."
|
|
39
|
+
}
|
|
40
|
+
}
|