@agent-smith/cli 0.0.64 → 0.0.65
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/cmd/lib/tasks/cmd.js +23 -2
- package/dist/cmd/lib/tasks/mcp.d.ts +13 -0
- package/dist/cmd/lib/tasks/mcp.js +57 -0
- package/dist/db/db.js +1 -1
- package/dist/interfaces.d.ts +19 -1
- package/package.json +1 -1
|
@@ -13,6 +13,7 @@ import { formatStats, readPromptFile } from "../utils.js";
|
|
|
13
13
|
import { executeWorkflow } from "../workflows/cmd.js";
|
|
14
14
|
import { configureTaskModel, mergeInferParams } from "./conf.js";
|
|
15
15
|
import { openTaskSpec } from "./utils.js";
|
|
16
|
+
import { McpServer } from "./mcp.js";
|
|
16
17
|
async function executeTask(name, payload, options, quiet = false) {
|
|
17
18
|
await initAgent();
|
|
18
19
|
if (options.debug) {
|
|
@@ -41,8 +42,21 @@ async function executeTask(name, payload, options, quiet = false) {
|
|
|
41
42
|
vars[k] = options[k];
|
|
42
43
|
}
|
|
43
44
|
});
|
|
44
|
-
|
|
45
|
+
const mcpServers = new Array();
|
|
46
|
+
if (taskFileSpec?.mcp) {
|
|
45
47
|
taskSpec.tools = [];
|
|
48
|
+
for (const tool of Object.values(taskFileSpec.mcp)) {
|
|
49
|
+
const mcp = new McpServer(tool.command, tool.arguments, tool?.tools ?? null);
|
|
50
|
+
mcpServers.push(mcp);
|
|
51
|
+
await mcp.start();
|
|
52
|
+
const tools = await mcp.extractTools();
|
|
53
|
+
tools.forEach(t => taskSpec.tools?.push(t));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (taskSpec.toolsList) {
|
|
57
|
+
if (!taskSpec?.tools) {
|
|
58
|
+
taskSpec.tools = [];
|
|
59
|
+
}
|
|
46
60
|
for (const toolName of taskSpec.toolsList) {
|
|
47
61
|
const { found, tool, type } = readTool(toolName);
|
|
48
62
|
if (!found) {
|
|
@@ -117,7 +131,6 @@ async function executeTask(name, payload, options, quiet = false) {
|
|
|
117
131
|
if (i == 0) {
|
|
118
132
|
perfTimer.start();
|
|
119
133
|
}
|
|
120
|
-
++i;
|
|
121
134
|
spinner.text = formatTokenCount(i);
|
|
122
135
|
if (!options?.verbose) {
|
|
123
136
|
if (hasThink) {
|
|
@@ -136,6 +149,13 @@ async function executeTask(name, payload, options, quiet = false) {
|
|
|
136
149
|
}
|
|
137
150
|
}
|
|
138
151
|
}
|
|
152
|
+
else {
|
|
153
|
+
if (t == ex.template.tags.think?.end) {
|
|
154
|
+
let msg = color.dim("Thinking:") + ` ${i} ${color.dim("tokens")}`;
|
|
155
|
+
msg = msg + " " + color.dim(perfTimer.time());
|
|
156
|
+
console.log(msg);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
139
159
|
if (hasTools) {
|
|
140
160
|
if (t == ex.template.tags.toolCall?.start) {
|
|
141
161
|
continueWrite = false;
|
|
@@ -188,6 +208,7 @@ async function executeTask(name, payload, options, quiet = false) {
|
|
|
188
208
|
catch (err) {
|
|
189
209
|
throw new Error(`executing task: ${name} (${err})`);
|
|
190
210
|
}
|
|
211
|
+
mcpServers.forEach(async (s) => await s.stop());
|
|
191
212
|
if (isChatMode.value) {
|
|
192
213
|
if (brain.ex.name != ex.name) {
|
|
193
214
|
brain.setDefaultExpert(ex);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
|
+
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
3
|
+
import { LmTaskToolSpec } from "@agent-smith/lmtask/dist/interfaces.js";
|
|
4
|
+
declare class McpServer {
|
|
5
|
+
transport: StdioClientTransport;
|
|
6
|
+
client: Client;
|
|
7
|
+
authorizedTools: Array<string> | null;
|
|
8
|
+
constructor(command: string, args: Array<string>, authorizedTools?: string[]);
|
|
9
|
+
start(): Promise<void>;
|
|
10
|
+
stop(): Promise<void>;
|
|
11
|
+
extractTools(): Promise<Array<LmTaskToolSpec>>;
|
|
12
|
+
}
|
|
13
|
+
export { McpServer, };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
|
+
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
3
|
+
class McpServer {
|
|
4
|
+
transport;
|
|
5
|
+
client;
|
|
6
|
+
authorizedTools = null;
|
|
7
|
+
constructor(command, args, authorizedTools = new Array) {
|
|
8
|
+
this.transport = new StdioClientTransport({
|
|
9
|
+
command: command,
|
|
10
|
+
args: args
|
|
11
|
+
});
|
|
12
|
+
this.client = new Client({ name: "AgentSmith", version: "1.0.0" });
|
|
13
|
+
if (authorizedTools) {
|
|
14
|
+
this.authorizedTools = authorizedTools;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
async start() {
|
|
18
|
+
await this.client.connect(this.transport);
|
|
19
|
+
}
|
|
20
|
+
async stop() {
|
|
21
|
+
await this.client.close();
|
|
22
|
+
}
|
|
23
|
+
async extractTools() {
|
|
24
|
+
const toolSpecs = new Array();
|
|
25
|
+
const serverToolsList = await this.client.listTools();
|
|
26
|
+
for (const tool of serverToolsList.tools) {
|
|
27
|
+
if (this.authorizedTools) {
|
|
28
|
+
if (!this.authorizedTools.includes(tool.name)) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const args = {};
|
|
33
|
+
if (tool.inputSchema.properties) {
|
|
34
|
+
for (const [k, v] of Object.entries(tool.inputSchema.properties)) {
|
|
35
|
+
const vv = v;
|
|
36
|
+
args[k] = { description: vv.description + " (" + vv.type + ")" };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const exec = async (args) => {
|
|
40
|
+
const res = await this.client.callTool({
|
|
41
|
+
name: tool.name,
|
|
42
|
+
arguments: args,
|
|
43
|
+
});
|
|
44
|
+
return res;
|
|
45
|
+
};
|
|
46
|
+
const t = {
|
|
47
|
+
name: tool.name,
|
|
48
|
+
description: tool.description ?? "",
|
|
49
|
+
arguments: args,
|
|
50
|
+
execute: exec
|
|
51
|
+
};
|
|
52
|
+
toolSpecs.push(t);
|
|
53
|
+
}
|
|
54
|
+
return toolSpecs;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export { McpServer, };
|
package/dist/db/db.js
CHANGED
|
@@ -5,7 +5,7 @@ import { createDirectoryIfNotExists } from "../cmd/sys/dirs.js";
|
|
|
5
5
|
const confDir = path.join(process.env.HOME ?? "~/", ".config/agent-smith/cli");
|
|
6
6
|
const dbPath = path.join(confDir, "config.db");
|
|
7
7
|
let db;
|
|
8
|
-
const debugDb =
|
|
8
|
+
const debugDb = false;
|
|
9
9
|
function initDb(isVerbose, execSchema) {
|
|
10
10
|
if (execSchema) {
|
|
11
11
|
createDirectoryIfNotExists(confDir, true);
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -79,6 +79,7 @@ interface LmTaskFileSpec extends BaseLmTask {
|
|
|
79
79
|
ctx: number;
|
|
80
80
|
model?: ModelSpec;
|
|
81
81
|
modelpack?: ModelPack;
|
|
82
|
+
mcp?: McpServerSpec;
|
|
82
83
|
}
|
|
83
84
|
interface BaseLmTaskConfig {
|
|
84
85
|
templateName: string;
|
|
@@ -92,6 +93,23 @@ interface FinalLmTaskConfig {
|
|
|
92
93
|
model?: ModelSpec;
|
|
93
94
|
modelname?: string;
|
|
94
95
|
}
|
|
96
|
+
interface McpServerSpec {
|
|
97
|
+
command: string;
|
|
98
|
+
arguments: string[];
|
|
99
|
+
tools: string[];
|
|
100
|
+
}
|
|
101
|
+
interface McpServerTool {
|
|
102
|
+
name: string;
|
|
103
|
+
description: string;
|
|
104
|
+
inputSchema: {
|
|
105
|
+
type: string;
|
|
106
|
+
properties: Record<string, {
|
|
107
|
+
type: string;
|
|
108
|
+
description: string;
|
|
109
|
+
}>;
|
|
110
|
+
required: string[];
|
|
111
|
+
};
|
|
112
|
+
}
|
|
95
113
|
type InputMode = "manual" | "promptfile" | "clipboard";
|
|
96
114
|
type OutputMode = "txt" | "clipboard";
|
|
97
115
|
type RunMode = "cli" | "cmd";
|
|
@@ -107,4 +125,4 @@ type CmdExtension = "js";
|
|
|
107
125
|
type ModelFileExtension = "yml";
|
|
108
126
|
type FeatureExtension = TaskExtension | CmdExtension | ActionExtension | WorkflowExtension | ModelFileExtension;
|
|
109
127
|
type AliasType = "task" | "action" | "workflow";
|
|
110
|
-
export { InputMode, VerbosityMode, OutputMode, RunMode, FormatMode, FeatureType, ActionExtension, TaskExtension, WorkflowExtension, AdaptaterExtension, CmdExtension, ModelFileExtension, FeatureSpec, Features, ConfigFile, FeatureExtension, AliasType, ToolType, Settings, DbModelDef, ModelSpec, ModelfileSpec, ModelPack, LmTaskFileSpec, LmTaskConfig, FinalLmTaskConfig, };
|
|
128
|
+
export { InputMode, VerbosityMode, OutputMode, RunMode, FormatMode, FeatureType, ActionExtension, TaskExtension, WorkflowExtension, AdaptaterExtension, CmdExtension, ModelFileExtension, FeatureSpec, Features, ConfigFile, FeatureExtension, AliasType, ToolType, Settings, DbModelDef, ModelSpec, ModelfileSpec, ModelPack, LmTaskFileSpec, LmTaskConfig, FinalLmTaskConfig, McpServerSpec, McpServerTool, };
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@agent-smith/cli",
|
|
3
3
|
"description": "Agent Smith: terminal client for language model agents",
|
|
4
4
|
"repository": "https://github.com/synw/agent-smith",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.65",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"buildrl": "rm -rf dist/* && rollup -c",
|
|
8
8
|
"build": "rm -rf dist/* && tsc",
|