























@@ -50,6 +50,10 @@ async function runMcpCommand(args: string[]) {
5050await sharedProgram.parseAsync(args, { from: "user" });
5151}
525253+function lastLogLine(): string {
54+return String(mockLog.mock.calls.at(-1)?.[0] ?? "");
55+}
56+5357describe("mcp cli", () => {
5458if (!sharedProgram) {
5559sharedProgram = new Command();
@@ -69,27 +73,30 @@ describe("mcp cli", () => {
6973});
70747175it("sets and shows a configured MCP server", async () => {
72-await withTempHome("openclaw-cli-mcp-home-", async () => {
76+await withTempHome("openclaw-cli-mcp-home-", async (home) => {
7377const workspaceDir = await createWorkspace();
78+const configPath = path.join(home, ".openclaw", "openclaw.json");
7479vi.spyOn(process, "cwd").mockReturnValue(workspaceDir);
75807681await runMcpCommand(["mcp", "set", "context7", '{"command":"uvx","args":["context7-mcp"]}']);
77-expect(mockLog).toHaveBeenCalledWith(expect.stringContaining('Saved MCP server "context7"'));
82+expect(lastLogLine()).toBe(`Saved MCP server "context7" to ${configPath}.`);
78837984mockLog.mockClear();
8085await runMcpCommand(["mcp", "show", "context7", "--json"]);
81-expect(mockLog).toHaveBeenCalledWith(expect.stringContaining('"command": "uvx"'));
86+expect(JSON.parse(lastLogLine())).toEqual({ command: "uvx", args: ["context7-mcp"] });
8287});
8388});
84898590it("fails when removing an unknown MCP server", async () => {
86-await withTempHome("openclaw-cli-mcp-home-", async () => {
91+await withTempHome("openclaw-cli-mcp-home-", async (home) => {
8792const workspaceDir = await createWorkspace();
93+const configPath = path.join(home, ".openclaw", "openclaw.json");
8894vi.spyOn(process, "cwd").mockReturnValue(workspaceDir);
89959096await expect(runMcpCommand(["mcp", "unset", "missing"])).rejects.toThrow("__exit__:1");
91-expect(mockError).toHaveBeenCalledWith(
92-expect.stringContaining('No MCP server named "missing"'),
97+const errorLine = String(mockError.mock.calls.at(-1)?.[0] ?? "");
98+expect(errorLine).toBe(
99+`No MCP server named "missing" in ${configPath}. Run openclaw mcp list to see configured servers.`,
93100);
94101});
95102});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。