@fcannizzaro/exocommand 1.0.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/LICENSE +21 -0
- package/README.md +108 -0
- package/dist/config.js +46 -0
- package/dist/executor.js +53 -0
- package/dist/index.js +100 -0
- package/dist/logger.js +31 -0
- package/dist/server.js +140 -0
- package/package.json +52 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Francesco Saverio Cannizzaro
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="media/animation.webp" width="256" alt="exocommand" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">@fcannizzaro/exocommand</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
An MCP server that exposes user-defined shell commands as tools for AI coding assistants.
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
[](https://github.com/fcannizzaro/exocommand/actions/workflows/publish.yaml)
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
Exocommand lets you define a curated set of shell commands in a simple YAML file and makes them available to any [MCP](https://modelcontextprotocol.io)-compatible AI client. Instead of giving an AI agent unrestricted terminal access, you control exactly which commands it can discover and execute.
|
|
16
|
+
|
|
17
|
+
## Features
|
|
18
|
+
|
|
19
|
+
- **YAML configuration** -- Define commands in a `.exocommand` file with a name, description, and shell command.
|
|
20
|
+
- **Live reload** -- The server watches the config file for changes and notifies connected clients automatically.
|
|
21
|
+
- **Streaming output** -- stdout and stderr are streamed line-by-line back to the client in real time.
|
|
22
|
+
- **Cancellation** -- Long-running commands can be cancelled by the client; the spawned process is killed immediately.
|
|
23
|
+
- **Multi-session** -- Uses the Streamable HTTP transport, supporting multiple concurrent MCP sessions.
|
|
24
|
+
- **Configurable port** -- Set via the config file, the `EXO_PORT` environment variable, or defaults to `3000`.
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
Run the server in your project directory:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
bunx @fcannizzaro/exocommand
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
The server starts on `http://127.0.0.1:5555/mcp` by default.
|
|
35
|
+
|
|
36
|
+
## Configuration
|
|
37
|
+
|
|
38
|
+
Create a `.exocommand` file in the project root (or set a custom path with the `EXO_COMMAND_FILE` env var):
|
|
39
|
+
|
|
40
|
+
```yaml
|
|
41
|
+
# Optional: override the default port
|
|
42
|
+
port: 4444
|
|
43
|
+
|
|
44
|
+
build:
|
|
45
|
+
description: "Run the production build"
|
|
46
|
+
command: "cargo build --release"
|
|
47
|
+
|
|
48
|
+
run:
|
|
49
|
+
description: "Run the application"
|
|
50
|
+
command: "cargo run"
|
|
51
|
+
|
|
52
|
+
clippy:
|
|
53
|
+
description: "Run clippy linter"
|
|
54
|
+
command: "cargo clippy"
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Each top-level key (except `port`) is a command. Commands must have a `description` and a `command` field. Names may contain letters, numbers, hyphens, and underscores.
|
|
58
|
+
|
|
59
|
+
## Safety
|
|
60
|
+
|
|
61
|
+
Remember to mount the `.exocommand` as read-only volume on Docker, to prevent the agent from modifying it.
|
|
62
|
+
|
|
63
|
+
If you have already use a script to start containerized agents, you can modify it to automatically mount the `.exocommand` file when present in the launch directory:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
extra_mounts=()
|
|
67
|
+
|
|
68
|
+
[ -f "$PWD/.exocommand" ] && extra_mounts+=(-v "$PWD/.exocommand:$PWD/.exocommand:ro")
|
|
69
|
+
|
|
70
|
+
docker run \
|
|
71
|
+
# ...
|
|
72
|
+
"${extra_mounts[@]}" \
|
|
73
|
+
# ...
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Environment Variables
|
|
77
|
+
|
|
78
|
+
| Variable | Description | Default |
|
|
79
|
+
| --- | --- | --- |
|
|
80
|
+
| `EXO_COMMAND_FILE` | Path to the `.exocommand` config file | `./.exocommand` |
|
|
81
|
+
| `EXO_PORT` | Server port (overrides config file) | `3000` |
|
|
82
|
+
|
|
83
|
+
## Connecting an AI Client
|
|
84
|
+
|
|
85
|
+
Point any MCP-compatible client at the server's `/mcp` endpoint. For example, with [OpenCode](https://opencode.ai):
|
|
86
|
+
|
|
87
|
+
```json
|
|
88
|
+
{
|
|
89
|
+
"mcp": {
|
|
90
|
+
"exocommand": {
|
|
91
|
+
"enabled": true,
|
|
92
|
+
"type": "remote",
|
|
93
|
+
"url": "http://host.docker.internal:5555/mcp"
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
The server exposes two tools:
|
|
100
|
+
|
|
101
|
+
| Tool | Description |
|
|
102
|
+
| --- | --- |
|
|
103
|
+
| `listCommands()` | Returns all available commands from the config file. |
|
|
104
|
+
| `execute(name)` | Executes a command by name, streaming output back to the client. |
|
|
105
|
+
|
|
106
|
+
## License
|
|
107
|
+
|
|
108
|
+
[MIT](LICENSE)
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { parse as parseYaml } from "yaml";
|
|
2
|
+
const NAME_PATTERN = /^[a-zA-Z0-9_-]+$/;
|
|
3
|
+
const RESERVED_KEYS = new Set(["port"]);
|
|
4
|
+
export async function loadConfig(filePath) {
|
|
5
|
+
const file = Bun.file(filePath);
|
|
6
|
+
if (!(await file.exists())) {
|
|
7
|
+
throw new Error(`Config file not found: ${filePath}`);
|
|
8
|
+
}
|
|
9
|
+
const content = await file.text();
|
|
10
|
+
const parsed = parseYaml(content);
|
|
11
|
+
if (parsed === null || parsed === undefined || typeof parsed !== "object") {
|
|
12
|
+
throw new Error(`Invalid config: expected a YAML mapping, got ${typeof parsed}`);
|
|
13
|
+
}
|
|
14
|
+
const config = { commands: [] };
|
|
15
|
+
// Parse port
|
|
16
|
+
const rawPort = parsed.port;
|
|
17
|
+
if (rawPort !== undefined) {
|
|
18
|
+
const port = Number(rawPort);
|
|
19
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
20
|
+
throw new Error(`Invalid port "${rawPort}": must be an integer between 1 and 65535`);
|
|
21
|
+
}
|
|
22
|
+
config.port = port;
|
|
23
|
+
}
|
|
24
|
+
// Parse commands
|
|
25
|
+
for (const [name, value] of Object.entries(parsed)) {
|
|
26
|
+
if (RESERVED_KEYS.has(name)) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (!NAME_PATTERN.test(name)) {
|
|
30
|
+
throw new Error(`Invalid command name "${name}": must match ${NAME_PATTERN}`);
|
|
31
|
+
}
|
|
32
|
+
if (typeof value !== "object" ||
|
|
33
|
+
value === null ||
|
|
34
|
+
typeof value.description !== "string" ||
|
|
35
|
+
typeof value.command !== "string") {
|
|
36
|
+
throw new Error(`Invalid command "${name}": must have "description" (string) and "command" (string)`);
|
|
37
|
+
}
|
|
38
|
+
const { description, command } = value;
|
|
39
|
+
config.commands.push({ name, description, command: command.trim() });
|
|
40
|
+
}
|
|
41
|
+
return config;
|
|
42
|
+
}
|
|
43
|
+
export async function loadCommands(filePath) {
|
|
44
|
+
const config = await loadConfig(filePath);
|
|
45
|
+
return config.commands;
|
|
46
|
+
}
|
package/dist/executor.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export async function executeCommand(command, log, signal) {
|
|
2
|
+
if (signal.aborted) {
|
|
3
|
+
return { exitCode: -1, killed: true };
|
|
4
|
+
}
|
|
5
|
+
const proc = Bun.spawn(["sh", "-c", command], {
|
|
6
|
+
stdout: "pipe",
|
|
7
|
+
stderr: "pipe",
|
|
8
|
+
});
|
|
9
|
+
const onAbort = () => {
|
|
10
|
+
proc.kill();
|
|
11
|
+
};
|
|
12
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
13
|
+
const streamLines = async (stream, logger) => {
|
|
14
|
+
const reader = stream.getReader();
|
|
15
|
+
const decoder = new TextDecoder();
|
|
16
|
+
let buffer = "";
|
|
17
|
+
try {
|
|
18
|
+
while (true) {
|
|
19
|
+
const { done, value } = await reader.read();
|
|
20
|
+
if (done)
|
|
21
|
+
break;
|
|
22
|
+
buffer += decoder.decode(value, { stream: true });
|
|
23
|
+
const lines = buffer.split("\n");
|
|
24
|
+
buffer = lines.pop();
|
|
25
|
+
for (const line of lines) {
|
|
26
|
+
if (line.length > 0) {
|
|
27
|
+
await log(logger === "stderr" ? "error" : "info", logger, line);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
// flush remaining buffer
|
|
32
|
+
if (buffer.length > 0) {
|
|
33
|
+
await log(logger === "stderr" ? "error" : "info", logger, buffer);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
// stream may error if process is killed; ignore when aborted
|
|
38
|
+
if (!signal.aborted) {
|
|
39
|
+
throw new Error(`Error reading ${logger} stream`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
await Promise.all([
|
|
44
|
+
streamLines(proc.stdout, "stdout"),
|
|
45
|
+
streamLines(proc.stderr, "stderr"),
|
|
46
|
+
]);
|
|
47
|
+
const exitCode = await proc.exited;
|
|
48
|
+
signal.removeEventListener("abort", onAbort);
|
|
49
|
+
return {
|
|
50
|
+
exitCode,
|
|
51
|
+
killed: signal.aborted,
|
|
52
|
+
};
|
|
53
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { watch } from "fs";
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { WebStandardStreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js";
|
|
4
|
+
import { isInitializeRequest } from "@modelcontextprotocol/sdk/types.js";
|
|
5
|
+
import { createServer } from "./server.js";
|
|
6
|
+
import { loadConfig } from "./config.js";
|
|
7
|
+
import { logger } from "./logger.js";
|
|
8
|
+
const CONFIG_PATH = process.env.EXO_COMMAND_FILE || "./.exocommand";
|
|
9
|
+
// Load config to get port
|
|
10
|
+
const config = await loadConfig(CONFIG_PATH);
|
|
11
|
+
const PORT = parseInt(process.env.EXO_PORT || String(config.port ?? 3000), 10);
|
|
12
|
+
const transports = new Map();
|
|
13
|
+
const servers = new Set();
|
|
14
|
+
async function handleMcp(req) {
|
|
15
|
+
const url = new URL(req.url);
|
|
16
|
+
if (url.pathname !== "/mcp") {
|
|
17
|
+
return new Response("Not Found", { status: 404 });
|
|
18
|
+
}
|
|
19
|
+
const sessionId = req.headers.get("mcp-session-id") ?? undefined;
|
|
20
|
+
if (req.method === "GET") {
|
|
21
|
+
if (!sessionId || !transports.has(sessionId)) {
|
|
22
|
+
return new Response("Invalid or missing session ID", { status: 400 });
|
|
23
|
+
}
|
|
24
|
+
return transports.get(sessionId).handleRequest(req);
|
|
25
|
+
}
|
|
26
|
+
if (req.method === "DELETE") {
|
|
27
|
+
if (!sessionId || !transports.has(sessionId)) {
|
|
28
|
+
return new Response("Invalid or missing session ID", { status: 400 });
|
|
29
|
+
}
|
|
30
|
+
return transports.get(sessionId).handleRequest(req);
|
|
31
|
+
}
|
|
32
|
+
if (req.method === "POST") {
|
|
33
|
+
// reuse existing session
|
|
34
|
+
if (sessionId && transports.has(sessionId)) {
|
|
35
|
+
return transports.get(sessionId).handleRequest(req);
|
|
36
|
+
}
|
|
37
|
+
// parse body to check if it's an initialize request
|
|
38
|
+
const body = await req.json();
|
|
39
|
+
if (!sessionId && isInitializeRequest(body)) {
|
|
40
|
+
const transport = new WebStandardStreamableHTTPServerTransport({
|
|
41
|
+
sessionIdGenerator: () => crypto.randomUUID(),
|
|
42
|
+
onsessioninitialized: (sid) => {
|
|
43
|
+
transports.set(sid, transport);
|
|
44
|
+
logger.info("session", `created ${sid}`);
|
|
45
|
+
},
|
|
46
|
+
onsessionclosed: (sid) => {
|
|
47
|
+
transports.delete(sid);
|
|
48
|
+
logger.warn("session", `closed ${sid}`);
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
const server = createServer();
|
|
52
|
+
servers.add(server);
|
|
53
|
+
transport.onclose = () => {
|
|
54
|
+
if (transport.sessionId) {
|
|
55
|
+
transports.delete(transport.sessionId);
|
|
56
|
+
}
|
|
57
|
+
servers.delete(server);
|
|
58
|
+
};
|
|
59
|
+
await server.connect(transport);
|
|
60
|
+
return transport.handleRequest(req, { parsedBody: body });
|
|
61
|
+
}
|
|
62
|
+
return Response.json({
|
|
63
|
+
jsonrpc: "2.0",
|
|
64
|
+
error: {
|
|
65
|
+
code: -32000,
|
|
66
|
+
message: "Bad Request: no valid session ID",
|
|
67
|
+
},
|
|
68
|
+
id: null,
|
|
69
|
+
}, { status: 400 });
|
|
70
|
+
}
|
|
71
|
+
return new Response("Method Not Allowed", { status: 405 });
|
|
72
|
+
}
|
|
73
|
+
Bun.serve({
|
|
74
|
+
port: PORT,
|
|
75
|
+
hostname: "127.0.0.1",
|
|
76
|
+
idleTimeout: 0,
|
|
77
|
+
fetch: handleMcp,
|
|
78
|
+
});
|
|
79
|
+
logger.info("server", `listening on http://127.0.0.1:${PORT}/mcp`);
|
|
80
|
+
// Watch .exocommand for changes and notify connected clients
|
|
81
|
+
let debounceTimer = null;
|
|
82
|
+
watch(CONFIG_PATH, (eventType) => {
|
|
83
|
+
if (eventType !== "change")
|
|
84
|
+
return;
|
|
85
|
+
if (debounceTimer)
|
|
86
|
+
clearTimeout(debounceTimer);
|
|
87
|
+
debounceTimer = setTimeout(() => {
|
|
88
|
+
debounceTimer = null;
|
|
89
|
+
logger.info("watcher", ".exocommand changed, notifying clients");
|
|
90
|
+
for (const server of servers) {
|
|
91
|
+
try {
|
|
92
|
+
server.sendToolListChanged();
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
// client may have disconnected
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}, 200);
|
|
99
|
+
});
|
|
100
|
+
logger.info("watcher", `watching ${CONFIG_PATH} for changes`);
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const RESET = "\x1b[0m";
|
|
2
|
+
const BOLD = "\x1b[1m";
|
|
3
|
+
const DIM = "\x1b[2m";
|
|
4
|
+
const CYAN = "\x1b[36m";
|
|
5
|
+
const GREEN = "\x1b[32m";
|
|
6
|
+
const YELLOW = "\x1b[33m";
|
|
7
|
+
const RED = "\x1b[31m";
|
|
8
|
+
function timestamp() {
|
|
9
|
+
const now = new Date();
|
|
10
|
+
const h = String(now.getHours()).padStart(2, "0");
|
|
11
|
+
const m = String(now.getMinutes()).padStart(2, "0");
|
|
12
|
+
const s = String(now.getSeconds()).padStart(2, "0");
|
|
13
|
+
return `${h}:${m}:${s}`;
|
|
14
|
+
}
|
|
15
|
+
function format(color, event, message) {
|
|
16
|
+
return `${DIM}${timestamp()}${RESET} ${color}${BOLD}[${event}]${RESET} ${message}`;
|
|
17
|
+
}
|
|
18
|
+
export const logger = {
|
|
19
|
+
info(event, message) {
|
|
20
|
+
console.log(format(CYAN, event, message));
|
|
21
|
+
},
|
|
22
|
+
success(event, message) {
|
|
23
|
+
console.log(format(GREEN, event, message));
|
|
24
|
+
},
|
|
25
|
+
warn(event, message) {
|
|
26
|
+
console.log(format(YELLOW, event, message));
|
|
27
|
+
},
|
|
28
|
+
error(event, message) {
|
|
29
|
+
console.log(format(RED, event, message));
|
|
30
|
+
},
|
|
31
|
+
};
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { z } from "zod/v4";
|
|
3
|
+
import { loadCommands } from "./config.js";
|
|
4
|
+
import { executeCommand } from "./executor.js";
|
|
5
|
+
import { logger } from "./logger.js";
|
|
6
|
+
const CONFIG_PATH = process.env.EXO_COMMAND_FILE || "./.exocommand";
|
|
7
|
+
export function createServer() {
|
|
8
|
+
const server = new McpServer({
|
|
9
|
+
name: "exocommand",
|
|
10
|
+
version: "1.0.0",
|
|
11
|
+
}, {
|
|
12
|
+
capabilities: {
|
|
13
|
+
logging: {},
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
server.registerTool("listCommands", {
|
|
17
|
+
title: "List Commands",
|
|
18
|
+
description: "List all available commands defined in the .exocommand config file",
|
|
19
|
+
}, async () => {
|
|
20
|
+
try {
|
|
21
|
+
const commands = await loadCommands(CONFIG_PATH);
|
|
22
|
+
logger.info("listCommands", `found ${commands.length} command(s)`);
|
|
23
|
+
return {
|
|
24
|
+
content: [
|
|
25
|
+
{
|
|
26
|
+
type: "text",
|
|
27
|
+
text: JSON.stringify(commands.map((c) => ({
|
|
28
|
+
name: c.name,
|
|
29
|
+
description: c.description,
|
|
30
|
+
command: c.command,
|
|
31
|
+
})), null, 2),
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
return {
|
|
38
|
+
content: [
|
|
39
|
+
{
|
|
40
|
+
type: "text",
|
|
41
|
+
text: `Error loading commands: ${err.message}`,
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
isError: true,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
server.registerTool("execute", {
|
|
49
|
+
title: "Execute Command",
|
|
50
|
+
description: "Execute a predefined command by name. Streams stdout and stderr via logging notifications.",
|
|
51
|
+
inputSchema: {
|
|
52
|
+
name: z.string().describe("The command name/id to execute"),
|
|
53
|
+
},
|
|
54
|
+
}, async ({ name: commandName }, extra) => {
|
|
55
|
+
logger.warn("execute", `running "${commandName}"`);
|
|
56
|
+
let commands;
|
|
57
|
+
try {
|
|
58
|
+
commands = await loadCommands(CONFIG_PATH);
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
return {
|
|
62
|
+
content: [
|
|
63
|
+
{
|
|
64
|
+
type: "text",
|
|
65
|
+
text: `Error loading config: ${err.message}`,
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
isError: true,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const cmd = commands.find((c) => c.name === commandName);
|
|
72
|
+
if (!cmd) {
|
|
73
|
+
const available = commands.map((c) => c.name).join(", ");
|
|
74
|
+
return {
|
|
75
|
+
content: [
|
|
76
|
+
{
|
|
77
|
+
type: "text",
|
|
78
|
+
text: `Command "${commandName}" not found. Available commands: ${available}`,
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
isError: true,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
const log = async (level, logger, data) => {
|
|
85
|
+
await extra.sendNotification({
|
|
86
|
+
method: "notifications/message",
|
|
87
|
+
params: { level, logger, data },
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
try {
|
|
91
|
+
const result = await executeCommand(cmd.command, log, extra.signal);
|
|
92
|
+
if (result.killed) {
|
|
93
|
+
logger.warn("execute", `"${commandName}" was cancelled`);
|
|
94
|
+
return {
|
|
95
|
+
content: [
|
|
96
|
+
{
|
|
97
|
+
type: "text",
|
|
98
|
+
text: `Command "${commandName}" was cancelled.`,
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
isError: true,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
if (result.exitCode !== 0) {
|
|
105
|
+
logger.error("execute", `"${commandName}" exited with code ${result.exitCode}`);
|
|
106
|
+
return {
|
|
107
|
+
content: [
|
|
108
|
+
{
|
|
109
|
+
type: "text",
|
|
110
|
+
text: `Command "${commandName}" exited with code ${result.exitCode}`,
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
isError: true,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
logger.success("execute", `"${commandName}" completed (exit code 0)`);
|
|
117
|
+
return {
|
|
118
|
+
content: [
|
|
119
|
+
{
|
|
120
|
+
type: "text",
|
|
121
|
+
text: `Command "${commandName}" completed successfully (exit code 0)`,
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
catch (err) {
|
|
127
|
+
logger.error("execute", `"${commandName}" failed: ${err.message}`);
|
|
128
|
+
return {
|
|
129
|
+
content: [
|
|
130
|
+
{
|
|
131
|
+
type: "text",
|
|
132
|
+
text: `Command "${commandName}" failed: ${err.message}`,
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
isError: true,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
return server;
|
|
140
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fcannizzaro/exocommand",
|
|
3
|
+
"module": "index.ts",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"author": {
|
|
8
|
+
"name": "Francesco Saverio Cannizzaro (fcannizzaro)",
|
|
9
|
+
"url": "https://fcannizzaro.com"
|
|
10
|
+
},
|
|
11
|
+
"funding": [
|
|
12
|
+
{
|
|
13
|
+
"type": "patreon",
|
|
14
|
+
"url": "https://www.patreon.com/fcannizzaro"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/fcannizzaro/exocommand/issues"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/fcannizzaro/exocommand"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"README.md",
|
|
27
|
+
"LICENSE"
|
|
28
|
+
],
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsc"
|
|
31
|
+
},
|
|
32
|
+
"bin": {
|
|
33
|
+
"exocommand": "./index.js"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/bun": "latest"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"typescript": "^5"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@modelcontextprotocol/sdk": "^1.26.0",
|
|
43
|
+
"yaml": "^2.8.2"
|
|
44
|
+
},
|
|
45
|
+
"keywords": [
|
|
46
|
+
"exocommand",
|
|
47
|
+
"mcp",
|
|
48
|
+
"agentic-programming",
|
|
49
|
+
"mcp",
|
|
50
|
+
"model-context-protocol"
|
|
51
|
+
]
|
|
52
|
+
}
|