-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli-server.ts
More file actions
49 lines (44 loc) · 1.75 KB
/
Copy pathcli-server.ts
File metadata and controls
49 lines (44 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* cli-server.ts — stdio entry point for a CLI-backed MCP server.
*
* Use this variant when your MCP server wraps a local CLI binary (git,
* kubectl, terraform, your own tool) instead of a remote HTTP API. Replace
* the bundled `cli_echo` smoke-test tool with your own domain tools.
*
* Required env vars:
* CLI_PATH Absolute or PATH-resolvable path to the CLI binary.
*
* Optional env vars:
* CLI_BASE_ARGS Fixed arguments prepended to every invocation.
* CLI_CWD Working directory for spawned processes (default: process.cwd()).
* CLI_TIMEOUT_MS Per-invocation timeout in ms (default: 30000).
*/
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { CliClient } from "./cli-client/cli-client.js";
import { loadCliConfig } from "./config/config.loader.js";
import { createMcpServer } from "./server-factory.js";
import { echoTools, handleEchoTool } from "./tools/echo.tools.js";
import { ToolRegistry } from "./tools/tool-registry.js";
export async function startCliServer(): Promise<void> {
const config = loadCliConfig();
const client = new CliClient(config);
const registry = new ToolRegistry<CliClient>();
registry.register({
tools: echoTools,
handler: handleEchoTool
});
const server = createMcpServer({
name: "mcp-template-cli-server",
version: "0.1.0",
description: "CLI-backed MCP template server with atomic tools and structured outputs.",
registry,
client
});
const transport = new StdioServerTransport();
await server.connect(transport);
}
startCliServer().catch((error) => {
const details = error instanceof Error ? `${error.name}: ${error.message}` : String(error);
console.error(`Failed to start CLI MCP server: ${details}`);
process.exit(1);
});