Fix debug logging

This commit is contained in:
Colin McDonnell
2025-12-17 10:44:49 -08:00
parent 361bd1502f
commit 53f6f18352
6 changed files with 88 additions and 174 deletions
+14 -15
View File
@@ -1,24 +1,23 @@
import { type } from "arktype";
import type { Context } from "../main.ts";
import { $ } from "../utils/shell.ts";
import { handleToolError, handleToolSuccess, tool, type ToolResult } from "./shared.ts";
import { execute, tool } from "./shared.ts";
export const DebugShellCommand = type({});
export const DebugShellCommandTool = tool({
name: "debug_shell_command",
description:
"debug tool: runs 'git status' and returns the output. use this to test shell command execution in the MCP server.",
parameters: DebugShellCommand,
execute: async (): Promise<ToolResult> => {
try {
export function DebugShellCommandTool(_ctx: Context) {
return tool({
name: "debug_shell_command",
description:
"debug tool: runs 'git status' and returns the output. use this to test shell command execution in the MCP server.",
parameters: DebugShellCommand,
execute: execute(_ctx, async () => {
const result = $("git", ["status"]);
return handleToolSuccess({
return {
success: true,
command: "git status",
output: result.trim(),
});
} catch (error) {
return handleToolError(error);
}
},
});
};
}),
});
}
+18 -22
View File
@@ -1,7 +1,8 @@
import { relative, resolve } from "node:path";
import { type } from "arktype";
import { $ } from "../utils/shell.ts";
import { handleToolError, handleToolSuccess, type ToolResult, tool } from "./shared.ts";
import type { Context } from "../main.ts";
import { execute, tool } from "./shared.ts";
export const ListFiles = type({
path: type.string
@@ -9,14 +10,13 @@ export const ListFiles = type({
.default("."),
});
// static tool - doesn't need ctx, just runs git/find commands
export const ListFilesTool = tool({
name: "list_files",
description:
"List files in the repository, including both git-tracked and untracked files. Useful for discovering the file structure and locating files, including newly created files that haven't been committed yet.",
parameters: ListFiles,
execute: async ({ path }: { path?: string }): Promise<ToolResult> => {
try {
export function ListFilesTool(_ctx: Context) {
return tool({
name: "list_files",
description:
"List files in the repository, including both git-tracked and untracked files. Useful for discovering the file structure and locating files, including newly created files that haven't been committed yet.",
parameters: ListFiles,
execute: execute(_ctx, async ({ path }: { path?: string }) => {
const pathStr = path ?? ".";
const cwd = process.cwd();
@@ -62,13 +62,11 @@ export const ListFilesTool = tool({
findFailed = true;
}
// if both methods failed, return an error
// if both methods failed, throw an error (execute helper will handle it)
if (gitFailed && findFailed) {
return handleToolError(
new Error(
`Failed to list files: both git ls-files and find commands failed. ` +
`Path: ${pathStr}, working directory: ${cwd}`
)
throw new Error(
`Failed to list files: both git ls-files and find commands failed. ` +
`Path: ${pathStr}, working directory: ${cwd}`
);
}
@@ -82,14 +80,12 @@ export const ListFilesTool = tool({
const untrackedFiles = filesystemFiles.filter((f) => !gitFilesSet.has(f));
const untrackedCount = untrackedFiles.length;
return handleToolSuccess({
return {
files: allFiles,
method: "combined",
trackedCount: gitFiles.length,
untrackedCount,
});
} catch (error) {
return handleToolError(error);
}
},
});
};
}),
});
}
+3 -3
View File
@@ -22,7 +22,7 @@ import { IssueInfoTool } from "./issueInfo.ts";
import { AddLabelsTool } from "./labels.ts";
import { PullRequestTool } from "./pr.ts";
import { PullRequestInfoTool } from "./prInfo.ts";
import { AddReviewCommentTool, ReviewTool, StartReviewTool, SubmitReviewTool } from "./review.ts";
import { AddReviewCommentTool, StartReviewTool, SubmitReviewTool } from "./review.ts";
import { GetReviewCommentsTool, ListPullRequestReviewsTool } from "./reviewComments.ts";
import { SelectModeTool } from "./selectMode.ts";
import { addTools, isProgressCommentDisabled } from "./shared.ts";
@@ -87,12 +87,12 @@ export async function startMcpHttpServer(
GetReviewCommentsTool(ctx),
ListPullRequestReviewsTool(ctx),
GetCheckSuiteLogsTool(ctx),
DebugShellCommandTool,
DebugShellCommandTool(ctx),
AddLabelsTool(ctx),
CreateBranchTool(ctx),
CommitFilesTool(ctx),
PushBranchTool(ctx),
ListFilesTool,
ListFilesTool(ctx),
];
// only include ReportProgressTool if progress comment is not disabled