march-cli 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/march.mjs +13 -0
- package/package.json +36 -0
- package/src/agent/command-exec-tool.mjs +91 -0
- package/src/agent/context-stats-tool.mjs +57 -0
- package/src/agent/editing/diff-apply.mjs +28 -0
- package/src/agent/editing/diff-format.mjs +57 -0
- package/src/agent/file-edit-tool.mjs +276 -0
- package/src/agent/find-tool.mjs +112 -0
- package/src/agent/model-payload-dumper.mjs +201 -0
- package/src/agent/pi-session/pi-session-sidecar-failure.mjs +10 -0
- package/src/agent/provider/payload-messages.mjs +138 -0
- package/src/agent/read-file-tool.mjs +112 -0
- package/src/agent/runner/fast-model.mjs +36 -0
- package/src/agent/runner/runner-cleanup.mjs +12 -0
- package/src/agent/runner/runner-init.mjs +15 -0
- package/src/agent/runner/runner-session-state.mjs +40 -0
- package/src/agent/runner.mjs +266 -0
- package/src/agent/runtime/runner-runtime-host.mjs +73 -0
- package/src/agent/runtime/runtime-factory.mjs +42 -0
- package/src/agent/runtime/runtime-host.mjs +34 -0
- package/src/agent/session/session-auto-name.mjs +41 -0
- package/src/agent/session/session-binding.mjs +12 -0
- package/src/agent/session/session-options.mjs +46 -0
- package/src/agent/tool-names.mjs +1 -0
- package/src/agent/tool-result.mjs +3 -0
- package/src/agent/tools.mjs +54 -0
- package/src/agent/turn/turn-events.mjs +64 -0
- package/src/agent/turn/turn-runner.mjs +103 -0
- package/src/auth/login-command.mjs +90 -0
- package/src/auth/storage.mjs +33 -0
- package/src/cli/args.mjs +71 -0
- package/src/cli/commands/copy-command.mjs +73 -0
- package/src/cli/commands/export-command.mjs +206 -0
- package/src/cli/commands/extensions-command.mjs +53 -0
- package/src/cli/commands/help-command.mjs +7 -0
- package/src/cli/commands/model-command.mjs +110 -0
- package/src/cli/commands/paste-image-command.mjs +43 -0
- package/src/cli/commands/provider-command.mjs +55 -0
- package/src/cli/commands/status-command.mjs +157 -0
- package/src/cli/commands/thinking-command.mjs +80 -0
- package/src/cli/fallback-ui.mjs +156 -0
- package/src/cli/input/attachment-tokens.mjs +20 -0
- package/src/cli/input/autocomplete.mjs +106 -0
- package/src/cli/input/external-editor.mjs +39 -0
- package/src/cli/input/history-store.mjs +35 -0
- package/src/cli/input/image-clipboard.mjs +55 -0
- package/src/cli/input/keybinding-dispatch.mjs +76 -0
- package/src/cli/input/keybindings.mjs +96 -0
- package/src/cli/input/mode-state.mjs +43 -0
- package/src/cli/input/prompt-templates.mjs +84 -0
- package/src/cli/input/select-with-keyboard.mjs +67 -0
- package/src/cli/permissions.mjs +103 -0
- package/src/cli/repl-commands.mjs +86 -0
- package/src/cli/repl-loop.mjs +157 -0
- package/src/cli/selector-list.mjs +21 -0
- package/src/cli/session/pi-session-switch-command.mjs +41 -0
- package/src/cli/session/session-command.mjs +23 -0
- package/src/cli/session/session-list-command.mjs +68 -0
- package/src/cli/session/session-name-command.mjs +26 -0
- package/src/cli/session/session-source-command.mjs +89 -0
- package/src/cli/session/session-switch-command.mjs +1 -0
- package/src/cli/shell/shell-command.mjs +55 -0
- package/src/cli/shell/shell-drawer-controls.mjs +33 -0
- package/src/cli/shell/shell-drawer.mjs +192 -0
- package/src/cli/shell/shell-split-layout.mjs +70 -0
- package/src/cli/slash-commands.mjs +176 -0
- package/src/cli/startup/startup-banner.mjs +17 -0
- package/src/cli/startup/startup-session.mjs +51 -0
- package/src/cli/status-line-updater.mjs +74 -0
- package/src/cli/tool-output.mjs +9 -0
- package/src/cli/tui/editor/external-editor-runner.mjs +24 -0
- package/src/cli/tui/input/mouse-selection-controller.mjs +89 -0
- package/src/cli/tui/input/mouse-tracking.mjs +20 -0
- package/src/cli/tui/layout/main-pane-layout.mjs +38 -0
- package/src/cli/tui/layout/safe-render-boundary.mjs +46 -0
- package/src/cli/tui/markdown-renderer.mjs +279 -0
- package/src/cli/tui/output/scroll-state.mjs +79 -0
- package/src/cli/tui/output/tool-card-renderer.mjs +59 -0
- package/src/cli/tui/output-buffer.mjs +297 -0
- package/src/cli/tui/permission-request-ui.mjs +18 -0
- package/src/cli/tui/recall-rendering.mjs +25 -0
- package/src/cli/tui/select/editor-select-list.mjs +111 -0
- package/src/cli/tui/selection-screen.mjs +212 -0
- package/src/cli/tui/status/retry-status.mjs +72 -0
- package/src/cli/tui/status/spinner-status.mjs +42 -0
- package/src/cli/tui/status/status-bar.mjs +88 -0
- package/src/cli/tui/syntax/highlighting.mjs +277 -0
- package/src/cli/tui/syntax/languages.mjs +91 -0
- package/src/cli/tui/syntax/tree-sitter/bash.highlights.scm +261 -0
- package/src/cli/tui/syntax/tree-sitter/c.highlights.scm +341 -0
- package/src/cli/tui/syntax/tree-sitter/cpp.highlights.scm +268 -0
- package/src/cli/tui/syntax/tree-sitter/csharp.highlights.scm +577 -0
- package/src/cli/tui/syntax/tree-sitter/css.highlights.scm +109 -0
- package/src/cli/tui/syntax/tree-sitter/diff.highlights.scm +49 -0
- package/src/cli/tui/syntax/tree-sitter/go.highlights.scm +254 -0
- package/src/cli/tui/syntax/tree-sitter/html.highlights.scm +13 -0
- package/src/cli/tui/syntax/tree-sitter/java.highlights.scm +330 -0
- package/src/cli/tui/syntax/tree-sitter/json.highlights.scm +38 -0
- package/src/cli/tui/syntax/tree-sitter/php.highlights.scm +203 -0
- package/src/cli/tui/syntax/tree-sitter/python.highlights.scm +137 -0
- package/src/cli/tui/syntax/tree-sitter/ruby.highlights.scm +309 -0
- package/src/cli/tui/syntax/tree-sitter/rust.highlights.scm +531 -0
- package/src/cli/tui/syntax/tree-sitter/toml.highlights.scm +39 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-bash.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-c-sharp.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-c.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-cpp.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-css.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-diff.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-go.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-html.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-java.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-json.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-php.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-python.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-ruby.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-rust.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-toml.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-tsx.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-typescript.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-yaml.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tsx.highlights.scm +35 -0
- package/src/cli/tui/syntax/tree-sitter/typescript.highlights.scm +35 -0
- package/src/cli/tui/syntax/tree-sitter/yaml.highlights.scm +99 -0
- package/src/cli/tui/tool-rendering.mjs +194 -0
- package/src/cli/tui/tui-diff-rendering.mjs +157 -0
- package/src/cli/tui/tui-handlers.mjs +110 -0
- package/src/cli/tui/tui-input-controller.mjs +61 -0
- package/src/cli/tui/ui-theme.mjs +148 -0
- package/src/cli/ui.mjs +299 -0
- package/src/config/config-json.mjs +73 -0
- package/src/config/dotenv.mjs +20 -0
- package/src/config/features.mjs +75 -0
- package/src/config/loader.mjs +109 -0
- package/src/config/settings-command.mjs +97 -0
- package/src/context/diagnostics.mjs +70 -0
- package/src/context/engine.mjs +148 -0
- package/src/context/injections.mjs +26 -0
- package/src/context/project-context.mjs +20 -0
- package/src/context/session-status.mjs +15 -0
- package/src/context/shell-layers.mjs +23 -0
- package/src/context/system-core/base.md +60 -0
- package/src/context/system-core/prompts/deepseek-v4-pro.md +3 -0
- package/src/context/system-core/prompts/default.md +3 -0
- package/src/context/system-core.mjs +35 -0
- package/src/debug/model-context-dumper.mjs +52 -0
- package/src/extensions/discovery.mjs +40 -0
- package/src/extensions/lifecycle-adapter.mjs +210 -0
- package/src/extensions/lifecycle-manifest.mjs +69 -0
- package/src/image-gen/index.mjs +7 -0
- package/src/image-gen/provider.mjs +231 -0
- package/src/image-gen/tool.mjs +84 -0
- package/src/lsp/client.mjs +204 -0
- package/src/lsp/diagnostic-store.mjs +39 -0
- package/src/lsp/servers.mjs +212 -0
- package/src/lsp/service.mjs +65 -0
- package/src/main.mjs +294 -0
- package/src/mcp/client.mjs +195 -0
- package/src/mcp/config.mjs +130 -0
- package/src/mcp/index.mjs +48 -0
- package/src/mcp/tools.mjs +98 -0
- package/src/memory/database.mjs +219 -0
- package/src/memory/glossary.mjs +124 -0
- package/src/memory/graph/graph-cascades.mjs +109 -0
- package/src/memory/graph/graph-diagnostics.mjs +73 -0
- package/src/memory/graph/graph-path-removal.mjs +50 -0
- package/src/memory/graph/graph-path-utils.mjs +17 -0
- package/src/memory/graph/graph-primitives.mjs +103 -0
- package/src/memory/graph/graph-read.mjs +159 -0
- package/src/memory/graph.mjs +282 -0
- package/src/memory/markdown/markdown-delete.mjs +23 -0
- package/src/memory/markdown/markdown-format.mjs +128 -0
- package/src/memory/markdown/markdown-recall.mjs +28 -0
- package/src/memory/markdown/ripgrep.mjs +16 -0
- package/src/memory/markdown/sqlite-index.mjs +87 -0
- package/src/memory/markdown-store.mjs +286 -0
- package/src/memory/markdown-tools.mjs +103 -0
- package/src/memory/search.mjs +142 -0
- package/src/memory/snapshot.mjs +86 -0
- package/src/memory/system-views.mjs +120 -0
- package/src/memory/tools.mjs +282 -0
- package/src/notification/desktop-notifier.mjs +85 -0
- package/src/platform/open-file.mjs +28 -0
- package/src/provider/config-command.mjs +129 -0
- package/src/provider/presets.mjs +72 -0
- package/src/session/attachment-display.mjs +16 -0
- package/src/session/attachment-references.mjs +65 -0
- package/src/session/attachments.mjs +140 -0
- package/src/session/persist.mjs +1 -0
- package/src/session/pi-manager.mjs +34 -0
- package/src/session/session-utils.mjs +16 -0
- package/src/session/sidecar-sync.mjs +19 -0
- package/src/session/sidecar.mjs +68 -0
- package/src/session/transcript.mjs +83 -0
- package/src/session/tree.mjs +42 -0
- package/src/shell/cli-runtime.mjs +11 -0
- package/src/shell/hints.mjs +12 -0
- package/src/shell/node-pty-adapter.mjs +81 -0
- package/src/shell/runtime-state.mjs +126 -0
- package/src/shell/runtime.mjs +244 -0
- package/src/shell/screen-buffer.mjs +136 -0
- package/src/shell/tool-read.mjs +74 -0
- package/src/shell/tools.mjs +299 -0
- package/src/supergrok/actions/image-generate.mjs +60 -0
- package/src/supergrok/actions/search.mjs +78 -0
- package/src/supergrok/auth.mjs +36 -0
- package/src/supergrok/constants.mjs +18 -0
- package/src/supergrok/oauth-provider.mjs +278 -0
- package/src/supergrok/provider.mjs +36 -0
- package/src/supergrok/response.mjs +76 -0
- package/src/supergrok/tool.mjs +61 -0
- package/src/text/ansi.mjs +3 -0
- package/src/web/config-command.mjs +43 -0
- package/src/web/fetch.mjs +78 -0
- package/src/web/presets.mjs +16 -0
- package/src/web/search.mjs +83 -0
- package/src/web/tools.mjs +107 -0
package/src/main.mjs
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import { homedir } from "node:os";
|
|
2
|
+
import { join, resolve, basename, relative } from "node:path";
|
|
3
|
+
import { existsSync, mkdirSync } from "node:fs";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { parseCliArgs, showHelp } from "./cli/args.mjs";
|
|
6
|
+
import { createUI } from "./cli/ui.mjs";
|
|
7
|
+
import { createPermissionController, MODE } from "./cli/permissions.mjs";
|
|
8
|
+
import { loadKeybindings } from "./cli/input/keybindings.mjs";
|
|
9
|
+
import { createInputHistoryStore } from "./cli/input/history-store.mjs";
|
|
10
|
+
import { createModeState } from "./cli/input/mode-state.mjs";
|
|
11
|
+
import { loadPromptTemplates } from "./cli/input/prompt-templates.mjs";
|
|
12
|
+
import { runInteractiveRepl, runSingleShotPrompt } from "./cli/repl-loop.mjs";
|
|
13
|
+
import { createStatusLineUpdater } from "./cli/status-line-updater.mjs";
|
|
14
|
+
import { wireTuiHandlers } from "./cli/tui/tui-handlers.mjs";
|
|
15
|
+
import { createMarchAuthStorage } from "./auth/storage.mjs";
|
|
16
|
+
import { runLoginCommand } from "./auth/login-command.mjs";
|
|
17
|
+
import { createRunner } from "./agent/runner.mjs";
|
|
18
|
+
import { createCliShellRuntime } from "./shell/cli-runtime.mjs";
|
|
19
|
+
import { MarkdownMemoryStore } from "./memory/markdown-store.mjs";
|
|
20
|
+
import { createMarkdownMemoryTools } from "./memory/markdown-tools.mjs";
|
|
21
|
+
import { loadDotEnv } from "./config/dotenv.mjs";
|
|
22
|
+
import { loadConfig } from "./config/loader.mjs";
|
|
23
|
+
import { discoverProjectExtensionPaths } from "./extensions/discovery.mjs";
|
|
24
|
+
import { loadProjectLifecycleHookManifests } from "./extensions/lifecycle-manifest.mjs";
|
|
25
|
+
import { resolvePiSessionManager } from "./session/pi-manager.mjs";
|
|
26
|
+
import { loadOrCreateProjectId, resumeStartupSession } from "./cli/startup/startup-session.mjs";
|
|
27
|
+
import { formatStartupBanner } from "./cli/startup/startup-banner.mjs";
|
|
28
|
+
import { initializeMcp } from "./mcp/index.mjs";
|
|
29
|
+
import { createWebToolsFromConfig } from "./web/tools.mjs";
|
|
30
|
+
import { createModelContextDumper } from "./debug/model-context-dumper.mjs";
|
|
31
|
+
import { runProviderConfigCommand } from "./provider/config-command.mjs";
|
|
32
|
+
import { runWebSearchConfigCommand } from "./web/config-command.mjs";
|
|
33
|
+
import { createDesktopTurnNotifier } from "./notification/desktop-notifier.mjs";
|
|
34
|
+
import { registerSuperGrokOAuthProvider } from "./supergrok/oauth-provider.mjs";
|
|
35
|
+
|
|
36
|
+
export async function run(argv) {
|
|
37
|
+
const cwd = process.cwd();
|
|
38
|
+
loadDotEnv(cwd);
|
|
39
|
+
registerSuperGrokOAuthProvider();
|
|
40
|
+
|
|
41
|
+
const args = parseCliArgs(argv);
|
|
42
|
+
|
|
43
|
+
if (args.help) {
|
|
44
|
+
showHelp();
|
|
45
|
+
return 0;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (args.command?.name === "login") {
|
|
49
|
+
try {
|
|
50
|
+
return await runLoginCommand({
|
|
51
|
+
providerId: args.command.args[0] ?? args.provider,
|
|
52
|
+
});
|
|
53
|
+
} catch (err) {
|
|
54
|
+
process.stderr.write(`Error: ${err.message}\n`);
|
|
55
|
+
return 1;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (args.command?.name === "provider" || args.command?.name === "websearch") {
|
|
60
|
+
const command = args.command.name === "provider" ? runProviderConfigCommand : runWebSearchConfigCommand;
|
|
61
|
+
if (args.providerConfig) return await command({ homeDir: homedir() });
|
|
62
|
+
process.stderr.write(`Usage: march ${args.command.name} --config\n`);
|
|
63
|
+
return 1;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const stateRoot = join(homedir(), ".march");
|
|
67
|
+
if (!existsSync(stateRoot)) mkdirSync(stateRoot, { recursive: true });
|
|
68
|
+
|
|
69
|
+
// Load config (CLI args override config file values)
|
|
70
|
+
const config = loadConfig(cwd);
|
|
71
|
+
const provider = args.provider ?? config.provider ?? null;
|
|
72
|
+
const serviceTier = config.serviceTier ?? null;
|
|
73
|
+
const model = args.model ?? config.model ?? null;
|
|
74
|
+
const extensionPaths = [
|
|
75
|
+
...discoverProjectExtensionPaths(cwd),
|
|
76
|
+
...args.extensions.map((extensionPath) => resolve(cwd, extensionPath)),
|
|
77
|
+
];
|
|
78
|
+
const lifecycleManifests = loadProjectLifecycleHookManifests(cwd);
|
|
79
|
+
const keybindingConfig = loadKeybindings(cwd);
|
|
80
|
+
const promptTemplateConfig = loadPromptTemplates(cwd);
|
|
81
|
+
const authConfig = createMarchAuthStorage({ provider: provider ?? "deepseek", providers: config.providers, cwd });
|
|
82
|
+
|
|
83
|
+
if (!authConfig.hasAuth) {
|
|
84
|
+
process.stderr.write("Error: no providers configured. Run: march provider --config\n");
|
|
85
|
+
return 1;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const projectMarchDir = resolve(cwd, ".march");
|
|
89
|
+
if (!existsSync(projectMarchDir)) mkdirSync(projectMarchDir, { recursive: true });
|
|
90
|
+
const inputHistoryStore = createInputHistoryStore({ path: join(projectMarchDir, "input-history.json") });
|
|
91
|
+
const modeState = createModeState();
|
|
92
|
+
const namespace = loadOrCreateProjectId(projectMarchDir);
|
|
93
|
+
const memoryRoot = resolveMemoryRoot(config.memoryRoot, stateRoot);
|
|
94
|
+
const memoryStore = new MarkdownMemoryStore({ root: memoryRoot });
|
|
95
|
+
const memoryTools = createMarkdownMemoryTools(memoryStore);
|
|
96
|
+
const currentProject = basename(cwd);
|
|
97
|
+
|
|
98
|
+
const shellRuntime = args.shellRuntime ? createCliShellRuntime({ cwd }) : null;
|
|
99
|
+
|
|
100
|
+
// MCP: connect to configured MCP servers
|
|
101
|
+
const mcpInit = await initializeMcp({ projectDir: cwd });
|
|
102
|
+
const { clientManager: mcpClientManager, mcpTools, mcpInjections } = mcpInit;
|
|
103
|
+
for (const { server, error } of mcpInit.errors) {
|
|
104
|
+
if (args.json) {
|
|
105
|
+
// errors will be surfaced in diagnostics via runner status
|
|
106
|
+
} else {
|
|
107
|
+
process.stderr.write(`[mcp] ${server}: ${error}\n`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const webTools = createWebToolsFromConfig(config);
|
|
112
|
+
const turnNotifier = createDesktopTurnNotifier({
|
|
113
|
+
enabled: Boolean(config.notifications?.turnEnd),
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// Permission controller
|
|
117
|
+
const permissionMode = args.permissionMode ?? MODE.BYPASS;
|
|
118
|
+
const permissionController = createPermissionController({ mode: permissionMode });
|
|
119
|
+
|
|
120
|
+
// Session persistence — always pi mode
|
|
121
|
+
const usePiSessions = true;
|
|
122
|
+
const usePiRuntimeHost = true;
|
|
123
|
+
const sessionSource = "pi";
|
|
124
|
+
const sessionsRoot = join(projectMarchDir, "sessions");
|
|
125
|
+
const sessionState = {
|
|
126
|
+
sessionId: args.resume ?? Date.now().toString(36),
|
|
127
|
+
sessionDir: null,
|
|
128
|
+
};
|
|
129
|
+
sessionState.sessionDir = join(sessionsRoot, sessionState.sessionId);
|
|
130
|
+
const contextDumpRoot = resolve(projectMarchDir, "context-dumps", sessionState.sessionId);
|
|
131
|
+
const modelContextDumper = createModelContextDumper({
|
|
132
|
+
enabled: args.dumpContext,
|
|
133
|
+
rootDir: contextDumpRoot,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const ui = createUI({
|
|
137
|
+
json: args.json,
|
|
138
|
+
cwd,
|
|
139
|
+
keybindings: keybindingConfig.keybindings,
|
|
140
|
+
promptTemplates: promptTemplateConfig.templates,
|
|
141
|
+
shellRuntime,
|
|
142
|
+
historyStore: inputHistoryStore,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// Esc to abort current turn
|
|
146
|
+
let turnRunning = false;
|
|
147
|
+
let refreshStatusBar = null;
|
|
148
|
+
|
|
149
|
+
const runner = await createRunner({
|
|
150
|
+
cwd,
|
|
151
|
+
modelId: model,
|
|
152
|
+
provider,
|
|
153
|
+
serviceTier,
|
|
154
|
+
|
|
155
|
+
providers: config.providers,
|
|
156
|
+
stateRoot,
|
|
157
|
+
ui,
|
|
158
|
+
memoryStore,
|
|
159
|
+
memoryTools,
|
|
160
|
+
shellRuntime,
|
|
161
|
+
mcpTools,
|
|
162
|
+
mcpInjections,
|
|
163
|
+
mcpClientManager,
|
|
164
|
+
webTools,
|
|
165
|
+
namespace,
|
|
166
|
+
projectMarchDir,
|
|
167
|
+
extensionPaths,
|
|
168
|
+
sessionManager: resolvePiSessionManager({
|
|
169
|
+
cwd,
|
|
170
|
+
projectMarchDir,
|
|
171
|
+
enabled: usePiSessions,
|
|
172
|
+
}),
|
|
173
|
+
useRuntimeHost: usePiRuntimeHost,
|
|
174
|
+
syncPiSidecar: usePiSessions || usePiRuntimeHost,
|
|
175
|
+
lifecycleHooks: lifecycleManifests.hooks,
|
|
176
|
+
lifecycleDiagnostics: lifecycleManifests.diagnostics,
|
|
177
|
+
authStorage: authConfig.authStorage,
|
|
178
|
+
maxTurns: config.maxTurns ?? undefined,
|
|
179
|
+
trimBatch: config.trimBatch ?? undefined,
|
|
180
|
+
permissionController,
|
|
181
|
+
modelContextDumper,
|
|
182
|
+
turnNotifier,
|
|
183
|
+
onModelPayload: ({ estimatedTokens }) => {
|
|
184
|
+
refreshStatusBar?.({ contextTokens: estimatedTokens });
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
refreshStatusBar = createStatusLineUpdater({
|
|
189
|
+
ui,
|
|
190
|
+
runner,
|
|
191
|
+
sessionState,
|
|
192
|
+
sessionSource,
|
|
193
|
+
getMode: () => modeState.get(),
|
|
194
|
+
});
|
|
195
|
+
refreshStatusBar();
|
|
196
|
+
|
|
197
|
+
wireTuiHandlers({
|
|
198
|
+
ui,
|
|
199
|
+
runner,
|
|
200
|
+
sessionState,
|
|
201
|
+
projectMarchDir,
|
|
202
|
+
refreshStatusBar,
|
|
203
|
+
isTurnRunning: () => turnRunning,
|
|
204
|
+
modeState,
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
// Resume session
|
|
208
|
+
const startupResume = await resumeStartupSession({
|
|
209
|
+
resumeId: args.resume,
|
|
210
|
+
runner,
|
|
211
|
+
sessionState,
|
|
212
|
+
projectMarchDir,
|
|
213
|
+
ui,
|
|
214
|
+
});
|
|
215
|
+
refreshStatusBar();
|
|
216
|
+
|
|
217
|
+
// Single-shot mode
|
|
218
|
+
if (args.prompt) {
|
|
219
|
+
turnRunning = true;
|
|
220
|
+
try {
|
|
221
|
+
await runSingleShotPrompt({
|
|
222
|
+
prompt: args.prompt,
|
|
223
|
+
runner,
|
|
224
|
+
memoryStore,
|
|
225
|
+
currentProject,
|
|
226
|
+
ui,
|
|
227
|
+
sessionState,
|
|
228
|
+
refreshStatusBar,
|
|
229
|
+
modeState,
|
|
230
|
+
});
|
|
231
|
+
} finally {
|
|
232
|
+
turnRunning = false;
|
|
233
|
+
await closeMarchRuntime({ runner, memoryStore, ui, blankLine: true });
|
|
234
|
+
}
|
|
235
|
+
return 0;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const dumpContextPath = args.dumpContext ? relative(cwd, contextDumpRoot) : null;
|
|
239
|
+
if (startupResume.transcriptTurns?.length > 0) ui.restoreTranscript?.(startupResume.transcriptTurns);
|
|
240
|
+
for (const line of formatStartupBanner({ cwd, modelId: runner.engine.modelId, thinkingLevel: runner.engine.thinkingLevel, mode: modeState.get(), dumpContextPath })) ui.writeln(line);
|
|
241
|
+
try {
|
|
242
|
+
await runInteractiveRepl({
|
|
243
|
+
cwd,
|
|
244
|
+
args,
|
|
245
|
+
ui,
|
|
246
|
+
runner,
|
|
247
|
+
memoryStore,
|
|
248
|
+
currentProject,
|
|
249
|
+
sessionState,
|
|
250
|
+
sessionsRoot,
|
|
251
|
+
projectMarchDir,
|
|
252
|
+
sessionSource,
|
|
253
|
+
extensionPaths,
|
|
254
|
+
keybindingConfig,
|
|
255
|
+
promptTemplateConfig,
|
|
256
|
+
renderStartupBanner: () => formatStartupBanner({ cwd, modelId: runner.engine.modelId, thinkingLevel: runner.engine.thinkingLevel, mode: modeState.get(), dumpContextPath }),
|
|
257
|
+
refreshStatusBar,
|
|
258
|
+
setTurnRunning: (value) => { turnRunning = value; },
|
|
259
|
+
modeState,
|
|
260
|
+
});
|
|
261
|
+
} finally {
|
|
262
|
+
await closeMarchRuntime({ runner, memoryStore, ui });
|
|
263
|
+
}
|
|
264
|
+
return 0;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
async function closeMarchRuntime({ runner, memoryStore, ui, blankLine = false }) {
|
|
268
|
+
let firstError = null;
|
|
269
|
+
try {
|
|
270
|
+
await runner.dispose();
|
|
271
|
+
} catch (err) {
|
|
272
|
+
firstError ??= err;
|
|
273
|
+
}
|
|
274
|
+
try {
|
|
275
|
+
memoryStore.close();
|
|
276
|
+
} catch (err) {
|
|
277
|
+
firstError ??= err;
|
|
278
|
+
}
|
|
279
|
+
try {
|
|
280
|
+
if (blankLine) ui.writeln("");
|
|
281
|
+
await ui.close();
|
|
282
|
+
} catch (err) {
|
|
283
|
+
firstError ??= err;
|
|
284
|
+
}
|
|
285
|
+
if (firstError) throw firstError;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function resolveMemoryRoot(configured, stateRoot) {
|
|
289
|
+
if (configured) return resolve(String(configured));
|
|
290
|
+
if (process.env.MARCH_MEMORY_ROOT) return resolve(process.env.MARCH_MEMORY_ROOT);
|
|
291
|
+
return resolve(stateRoot, "March Memories");
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (process.argv[1] === fileURLToPath(import.meta.url)) process.exitCode = await run(process.argv.slice(2));
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
|
+
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
3
|
+
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
4
|
+
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
5
|
+
import { CallToolResultSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
6
|
+
import { detectTransport } from "./config.mjs";
|
|
7
|
+
|
|
8
|
+
const DEFAULT_TIMEOUT = 30_000;
|
|
9
|
+
|
|
10
|
+
export class McpClientManager {
|
|
11
|
+
constructor() {
|
|
12
|
+
this._clients = new Map(); // name -> { client, transport, config, status, tools }
|
|
13
|
+
this._abortController = new AbortController();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// ── Connection ─────────────────────────────────────────────────────
|
|
17
|
+
|
|
18
|
+
async connect(name, config) {
|
|
19
|
+
if (this._clients.has(name)) {
|
|
20
|
+
await this.disconnect(name);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const transportType = detectTransport(config);
|
|
24
|
+
const transport = transportType === "stdio"
|
|
25
|
+
? this._createStdioTransport(config)
|
|
26
|
+
: await this._createHttpTransport(config);
|
|
27
|
+
|
|
28
|
+
const client = new Client(
|
|
29
|
+
{ name: "march", version: "0.1.0" },
|
|
30
|
+
{ capabilities: { tools: {} } },
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
await client.connect(transport, { timeout: config.timeout ?? DEFAULT_TIMEOUT });
|
|
35
|
+
} catch (err) {
|
|
36
|
+
transport.close?.();
|
|
37
|
+
throw new Error(`Failed to connect to MCP server "${name}": ${err.message}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
this._clients.set(name, {
|
|
41
|
+
client,
|
|
42
|
+
transport,
|
|
43
|
+
config,
|
|
44
|
+
status: "connected",
|
|
45
|
+
tools: [],
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
return client;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async disconnect(name) {
|
|
52
|
+
const entry = this._clients.get(name);
|
|
53
|
+
if (!entry) return;
|
|
54
|
+
try {
|
|
55
|
+
await entry.client.close();
|
|
56
|
+
} catch {
|
|
57
|
+
// best-effort
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
entry.transport.close?.();
|
|
61
|
+
} catch {
|
|
62
|
+
// best-effort
|
|
63
|
+
}
|
|
64
|
+
this._clients.delete(name);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async disconnectAll() {
|
|
68
|
+
const names = [...this._clients.keys()];
|
|
69
|
+
await Promise.all(names.map((n) => this.disconnect(n)));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// ── Transport factories ────────────────────────────────────────────
|
|
73
|
+
|
|
74
|
+
_createStdioTransport(config) {
|
|
75
|
+
return new StdioClientTransport({
|
|
76
|
+
command: config.command,
|
|
77
|
+
args: config.args ?? [],
|
|
78
|
+
env: config.env ?? {},
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async _createHttpTransport(config) {
|
|
83
|
+
// Try streamable HTTP first, SSE as fallback
|
|
84
|
+
try {
|
|
85
|
+
const transport = new StreamableHTTPClientTransport(new URL(config.url), {
|
|
86
|
+
requestInit: config.headers ? { headers: config.headers } : undefined,
|
|
87
|
+
});
|
|
88
|
+
return transport;
|
|
89
|
+
} catch {
|
|
90
|
+
const transport = new SSEClientTransport(new URL(config.url), {
|
|
91
|
+
requestInit: config.headers ? { headers: config.headers } : undefined,
|
|
92
|
+
});
|
|
93
|
+
return transport;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// ── Tool discovery ─────────────────────────────────────────────────
|
|
98
|
+
|
|
99
|
+
async discoverTools(name) {
|
|
100
|
+
const entry = this._clients.get(name);
|
|
101
|
+
if (!entry) throw new Error(`MCP server "${name}" not connected`);
|
|
102
|
+
|
|
103
|
+
try {
|
|
104
|
+
const result = await entry.client.listTools();
|
|
105
|
+
entry.tools = result.tools ?? [];
|
|
106
|
+
return entry.tools;
|
|
107
|
+
} catch (err) {
|
|
108
|
+
entry.status = "failed";
|
|
109
|
+
throw new Error(`Failed to list tools from "${name}": ${err.message}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
getTools(name) {
|
|
114
|
+
const entry = this._clients.get(name);
|
|
115
|
+
return entry?.tools ?? [];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
getAllTools() {
|
|
119
|
+
const all = [];
|
|
120
|
+
for (const [name, entry] of this._clients) {
|
|
121
|
+
for (const tool of entry.tools) {
|
|
122
|
+
all.push({ server: name, tool });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return all;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// ── Tool call ──────────────────────────────────────────────────────
|
|
129
|
+
|
|
130
|
+
async callTool(serverName, toolName, args, timeout) {
|
|
131
|
+
const entry = this._clients.get(serverName);
|
|
132
|
+
if (!entry) throw new Error(`MCP server "${serverName}" not connected`);
|
|
133
|
+
|
|
134
|
+
try {
|
|
135
|
+
const result = await entry.client.callTool(
|
|
136
|
+
{ name: toolName, arguments: args ?? {} },
|
|
137
|
+
CallToolResultSchema,
|
|
138
|
+
{ resetTimeoutOnProgress: true, timeout: timeout ?? entry.config.timeout ?? DEFAULT_TIMEOUT },
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
// Flatten content into a readable text block
|
|
142
|
+
return this._formatResult(result);
|
|
143
|
+
} catch (err) {
|
|
144
|
+
throw new Error(`MCP tool "${serverName}/${toolName}" failed: ${err.message}`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
_formatResult(result) {
|
|
149
|
+
const parts = [];
|
|
150
|
+
for (const item of result.content ?? []) {
|
|
151
|
+
if (item.type === "text") {
|
|
152
|
+
parts.push(item.text);
|
|
153
|
+
} else if (item.type === "image") {
|
|
154
|
+
parts.push(`[image: ${item.mimeType ?? "unknown"} (${item.data?.length ?? 0} bytes)]`);
|
|
155
|
+
} else if (item.type === "resource") {
|
|
156
|
+
parts.push(`[resource: ${item.resource?.uri ?? item.resource?.text ?? "unknown"}]`);
|
|
157
|
+
} else {
|
|
158
|
+
parts.push(JSON.stringify(item));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return {
|
|
162
|
+
content: parts.join("\n"),
|
|
163
|
+
details: { serverName, isError: result.isError },
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// ── Status ─────────────────────────────────────────────────────────
|
|
168
|
+
|
|
169
|
+
getStatus(name) {
|
|
170
|
+
const entry = this._clients.get(name);
|
|
171
|
+
if (!entry) return { status: "disconnected" };
|
|
172
|
+
return {
|
|
173
|
+
status: entry.status,
|
|
174
|
+
toolCount: entry.tools.length,
|
|
175
|
+
transport: detectTransport(entry.config),
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
getAllStatuses() {
|
|
180
|
+
const result = {};
|
|
181
|
+
for (const [name] of this._clients) {
|
|
182
|
+
result[name] = this.getStatus(name);
|
|
183
|
+
}
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
isConnected(name) {
|
|
188
|
+
const entry = this._clients.get(name);
|
|
189
|
+
return entry?.status === "connected";
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
serverNames() {
|
|
193
|
+
return [...this._clients.keys()];
|
|
194
|
+
}
|
|
195
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
2
|
+
import { join, dirname } from "node:path";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Load MCP server configurations from .march/mcp.json (project) and
|
|
7
|
+
* ~/.march/mcp.json (user). Project config takes precedence over user config
|
|
8
|
+
* for servers with the same name.
|
|
9
|
+
*
|
|
10
|
+
* Config format (standard MCP):
|
|
11
|
+
* {
|
|
12
|
+
* "mcpServers": {
|
|
13
|
+
* "server-name": {
|
|
14
|
+
* "command": "npx", // stdio transport
|
|
15
|
+
* "args": ["-y", "server"],
|
|
16
|
+
* "env": { "KEY": "value" }, // optional
|
|
17
|
+
* "instructions": "..." // optional prompt injection
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* Remote servers use "url" instead of "command"/"args".
|
|
23
|
+
*/
|
|
24
|
+
export function loadMcpConfig(projectDir) {
|
|
25
|
+
const servers = new Map();
|
|
26
|
+
|
|
27
|
+
// User-level config (lower priority)
|
|
28
|
+
const userPath = join(homedir(), ".march", "mcp.json");
|
|
29
|
+
if (existsSync(userPath)) {
|
|
30
|
+
try {
|
|
31
|
+
const raw = JSON.parse(readFileSync(userPath, "utf-8"));
|
|
32
|
+
for (const [name, cfg] of Object.entries(raw.mcpServers ?? {})) {
|
|
33
|
+
servers.set(name, { ...cfg, _scope: "user" });
|
|
34
|
+
}
|
|
35
|
+
} catch (err) {
|
|
36
|
+
console.error(`[mcp] Failed to parse ${userPath}: ${err.message}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Project-level config (higher priority — overrides user)
|
|
41
|
+
const projectPath = join(projectDir, ".march", "mcp.json");
|
|
42
|
+
if (existsSync(projectPath)) {
|
|
43
|
+
try {
|
|
44
|
+
const raw = JSON.parse(readFileSync(projectPath, "utf-8"));
|
|
45
|
+
for (const [name, cfg] of Object.entries(raw.mcpServers ?? {})) {
|
|
46
|
+
servers.set(name, { ...cfg, _scope: "project" });
|
|
47
|
+
}
|
|
48
|
+
} catch (err) {
|
|
49
|
+
console.error(`[mcp] Failed to parse ${projectPath}: ${err.message}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return servers;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Walk up from startDir to find all .march/mcp.json files (hierarchical merge).
|
|
58
|
+
* Closest to startDir wins. Stops at root or when git root boundary is hit.
|
|
59
|
+
*/
|
|
60
|
+
export function loadMcpConfigHierarchical(startDir) {
|
|
61
|
+
const chain = [];
|
|
62
|
+
let dir = startDir;
|
|
63
|
+
const root = dirname(dir) === dir ? dir : null;
|
|
64
|
+
|
|
65
|
+
while (dir && dir !== root) {
|
|
66
|
+
const cfgPath = join(dir, ".march", "mcp.json");
|
|
67
|
+
if (existsSync(cfgPath)) {
|
|
68
|
+
try {
|
|
69
|
+
chain.unshift(JSON.parse(readFileSync(cfgPath, "utf-8")));
|
|
70
|
+
} catch (err) {
|
|
71
|
+
console.error(`[mcp] Failed to parse ${cfgPath}: ${err.message}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const parent = dirname(dir);
|
|
75
|
+
if (parent === dir) break;
|
|
76
|
+
dir = parent;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// User-level as base
|
|
80
|
+
const userPath = join(homedir(), ".march", "mcp.json");
|
|
81
|
+
if (existsSync(userPath)) {
|
|
82
|
+
try {
|
|
83
|
+
chain.unshift(JSON.parse(readFileSync(userPath, "utf-8")));
|
|
84
|
+
} catch (err) {
|
|
85
|
+
console.error(`[mcp] Failed to parse ${userPath}: ${err.message}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Merge: later entries override earlier
|
|
90
|
+
const servers = new Map();
|
|
91
|
+
for (const cfg of chain) {
|
|
92
|
+
for (const [name, serverCfg] of Object.entries(cfg.mcpServers ?? {})) {
|
|
93
|
+
servers.set(name, serverCfg);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return servers;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Determine transport type from server config.
|
|
102
|
+
* Returns "stdio" if config has "command", "http" if it has "url".
|
|
103
|
+
*/
|
|
104
|
+
export function detectTransport(config) {
|
|
105
|
+
if (config.command) return "stdio";
|
|
106
|
+
if (config.url) return "http";
|
|
107
|
+
return "stdio"; // default
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Build a display name for a server.
|
|
112
|
+
*/
|
|
113
|
+
export function serverDisplayName(name, config) {
|
|
114
|
+
const source = config._scope ?? "unknown";
|
|
115
|
+
return `${name} [${detectTransport(config)} · ${source}]`;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Validate server config returns human-readable errors, or null if valid.
|
|
120
|
+
*/
|
|
121
|
+
export function validateMcpConfig(name, config) {
|
|
122
|
+
const transport = detectTransport(config);
|
|
123
|
+
if (transport === "stdio" && !config.command) {
|
|
124
|
+
return `Server "${name}": stdio transport requires "command"`;
|
|
125
|
+
}
|
|
126
|
+
if (transport === "http" && !config.url) {
|
|
127
|
+
return `Server "${name}": http transport requires "url"`;
|
|
128
|
+
}
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export { loadMcpConfig, loadMcpConfigHierarchical, detectTransport, validateMcpConfig, serverDisplayName } from "./config.mjs";
|
|
2
|
+
export { McpClientManager } from "./client.mjs";
|
|
3
|
+
export { buildMcpToolName, parseMcpToolName, convertMcpTool, convertAllMcpTools } from "./tools.mjs";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Initialize MCP: load config, connect to servers, discover tools.
|
|
7
|
+
* Returns { clientManager, mcpTools, mcpInjections, errors }.
|
|
8
|
+
*/
|
|
9
|
+
export async function initializeMcp({ projectDir }) {
|
|
10
|
+
const { loadMcpConfig } = await import("./config.mjs");
|
|
11
|
+
const { McpClientManager } = await import("./client.mjs");
|
|
12
|
+
const { convertAllMcpTools } = await import("./tools.mjs");
|
|
13
|
+
|
|
14
|
+
const servers = loadMcpConfig(projectDir);
|
|
15
|
+
if (servers.size === 0) {
|
|
16
|
+
return { clientManager: null, mcpTools: [], mcpInjections: [], errors: [] };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const clientManager = new McpClientManager();
|
|
20
|
+
const errors = [];
|
|
21
|
+
const mcpInjections = [];
|
|
22
|
+
|
|
23
|
+
for (const [name, config] of servers) {
|
|
24
|
+
if (config.enabled === false) continue;
|
|
25
|
+
try {
|
|
26
|
+
await clientManager.connect(name, config);
|
|
27
|
+
await clientManager.discoverTools(name);
|
|
28
|
+
const injection = buildMcpInstructionsInjection(name, config);
|
|
29
|
+
if (injection) mcpInjections.push(injection);
|
|
30
|
+
} catch (err) {
|
|
31
|
+
errors.push({ server: name, error: err.message });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const mcpTools = convertAllMcpTools(clientManager);
|
|
36
|
+
return { clientManager, mcpTools, mcpInjections, errors };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function buildMcpInstructionsInjection(serverName, config) {
|
|
40
|
+
if (typeof config?.instructions !== "string") return null;
|
|
41
|
+
const content = config.instructions.trim();
|
|
42
|
+
if (!content) return null;
|
|
43
|
+
return {
|
|
44
|
+
type: "mcp_server",
|
|
45
|
+
source: serverName,
|
|
46
|
+
content,
|
|
47
|
+
};
|
|
48
|
+
}
|