Skip to content

Commit 5a0a4a1

Browse files
committed
split out tools registrations too
1 parent 84cb986 commit 5a0a4a1

File tree

2 files changed

+64
-49
lines changed

2 files changed

+64
-49
lines changed

src/index.ts

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { runCommand } from "./run-command.js";
1313
import { createRequire } from "module";
1414
import { verbose_log } from "./always_log.js";
1515
import { registerPrompts } from "./prompts.js";
16+
import { reisterTools } from "./tools.js";
1617
const require = createRequire(import.meta.url);
1718
const {
1819
name: package_name,
@@ -35,55 +36,7 @@ const server = new Server(
3536
}
3637
);
3738

38-
server.setRequestHandler(ListToolsRequestSchema, async () => {
39-
verbose_log("INFO: ListTools");
40-
return {
41-
tools: [
42-
{
43-
name: "run_command",
44-
description:
45-
"Run a command on this " + os.platform() + " machine",
46-
inputSchema: {
47-
type: "object",
48-
properties: {
49-
command: {
50-
type: "string",
51-
description: "Command with args",
52-
},
53-
workdir: {
54-
// previous run_command calls can probe the filesystem and find paths to change to
55-
type: "string",
56-
description: "Optional, current working directory",
57-
},
58-
stdin: {
59-
type: "string",
60-
description:
61-
"Optional, text to pipe into the command's STDIN. For example, pass a python script to python3. Or, pass text for a new file to the cat command to create it!",
62-
},
63-
// args to consider:
64-
// - env - obscure cases where command takes a param only via an env var?
65-
// - timeout - lets just hard code this for now
66-
},
67-
required: ["command"],
68-
},
69-
},
70-
],
71-
};
72-
});
73-
74-
server.setRequestHandler(
75-
CallToolRequestSchema,
76-
async (request): Promise<CallToolResult> => {
77-
verbose_log("INFO: ToolRequest", request);
78-
switch (request.params.name) {
79-
case "run_command": {
80-
return await runCommand(request.params.arguments);
81-
}
82-
default:
83-
throw new Error("Unknown tool");
84-
}
85-
}
86-
);
39+
reisterTools(server);
8740

8841
registerPrompts(server);
8942

src/tools.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import os from "os";
2+
import {
3+
CallToolRequestSchema,
4+
CallToolResult,
5+
ListToolsRequestSchema,
6+
} from "@modelcontextprotocol/sdk/types.js";
7+
import { verbose_log } from "./always_log.js";
8+
import { runCommand } from "./run-command.js";
9+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
10+
11+
export function reisterTools(server: Server) {
12+
server.setRequestHandler(ListToolsRequestSchema, async () => {
13+
verbose_log("INFO: ListTools");
14+
return {
15+
tools: [
16+
{
17+
name: "run_command",
18+
description:
19+
"Run a command on this " + os.platform() + " machine",
20+
inputSchema: {
21+
type: "object",
22+
properties: {
23+
command: {
24+
type: "string",
25+
description: "Command with args",
26+
},
27+
workdir: {
28+
// previous run_command calls can probe the filesystem and find paths to change to
29+
type: "string",
30+
description:
31+
"Optional, current working directory",
32+
},
33+
stdin: {
34+
type: "string",
35+
description:
36+
"Optional, text to pipe into the command's STDIN. For example, pass a python script to python3. Or, pass text for a new file to the cat command to create it!",
37+
},
38+
// args to consider:
39+
// - env - obscure cases where command takes a param only via an env var?
40+
// - timeout - lets just hard code this for now
41+
},
42+
required: ["command"],
43+
},
44+
},
45+
],
46+
};
47+
});
48+
49+
server.setRequestHandler(
50+
CallToolRequestSchema,
51+
async (request): Promise<CallToolResult> => {
52+
verbose_log("INFO: ToolRequest", request);
53+
switch (request.params.name) {
54+
case "run_command": {
55+
return await runCommand(request.params.arguments);
56+
}
57+
default:
58+
throw new Error("Unknown tool");
59+
}
60+
}
61+
);
62+
}

0 commit comments

Comments
 (0)