Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(mcp): harden project update/auth timeout/install chmod

Tinb18dfa8e635d
diff --git a/packages/mcp/src/auth/auth-service.test.ts b/packages/mcp/src/auth/auth-service.test.ts
index e0fe10bea..97873307f 100644
--- a/packages/mcp/src/auth/auth-service.test.ts
+++ b/packages/mcp/src/auth/auth-service.test.ts
@@ -50,17 +50,19 @@ describe("AuthService", () => {
});
it("reuses the cached token when validation succeeds", async () => {
+ const timeoutSpy = vi.spyOn(AbortSignal, "timeout");
loadCredentialsMock.mockResolvedValue({
version: 1,
baseUrl: "https://api.example.com",
clientId: "kaneo-mcp",
accessToken: "cached-token",
});
- globalThis.fetch = vi.fn().mockResolvedValue(
+ const fetchMock = vi.fn().mockResolvedValue(
new Response(JSON.stringify({ user: { id: "user-1" } }), {
status: 200,
}),
- ) as typeof fetch;
+ );
+ globalThis.fetch = fetchMock as typeof fetch;
const service = new AuthService({
baseUrl: "https://api.example.com",
@@ -68,6 +70,12 @@ describe("AuthService", () => {
});
await expect(service.getAccessToken()).resolves.toBe("cached-token");
+ expect(timeoutSpy).toHaveBeenCalledWith(10_000);
+ expect(fetchMock).toHaveBeenCalledTimes(1);
+ const requestInit = fetchMock.mock.calls[0]?.[1] as
+ | { signal?: AbortSignal }
+ | undefined;
+ expect(requestInit?.signal).toBeInstanceOf(AbortSignal);
expect(clearCredentialsMock).not.toHaveBeenCalled();
expect(requestDeviceCodeMock).not.toHaveBeenCalled();
});
diff --git a/packages/mcp/src/auth/auth-service.ts b/packages/mcp/src/auth/auth-service.ts
index fffd1b99d..084e36f10 100644
--- a/packages/mcp/src/auth/auth-service.ts
+++ b/packages/mcp/src/auth/auth-service.ts
@@ -32,8 +32,10 @@ export class AuthService {
token: string,
): Promise<TokenValidationResult> {
try {
+ const signal = AbortSignal.timeout(10_000);
const res = await fetch(`${this.baseUrl}/api/auth/get-session`, {
headers: { Authorization: `Bearer ${token}` },
+ signal,
});
if (res.status === 401) {
return "invalid";
diff --git a/packages/mcp/src/install/index.ts b/packages/mcp/src/install/index.ts
index 7a539d5ec..bfb623355 100644
--- a/packages/mcp/src/install/index.ts
+++ b/packages/mcp/src/install/index.ts
@@ -303,7 +303,11 @@ export async function runInstall(argv: string[]): Promise<void> {
for (const w of mergedWrites) {
await mkdir(dirname(w.configPath), { recursive: true });
await writeFile(w.configPath, w.merged, { encoding: "utf8", mode: 0o600 });
- await chmod(w.configPath, 0o600);
+ try {
+ await chmod(w.configPath, 0o600);
+ } catch {
+ /* ignore chmod failures on some FS */
+ }
writtenPaths.push(w.configPath);
}
diff --git a/packages/mcp/src/tools/register.test.ts b/packages/mcp/src/tools/register.test.ts
index e81d450c8..60b4820f3 100644
--- a/packages/mcp/src/tools/register.test.ts
+++ b/packages/mcp/src/tools/register.test.ts
@@ -123,6 +123,43 @@ describe("registerTools", () => {
expect(result?.isError).toBe(false);
});
+ it("fetches the current project and sends a full body for update_project", async () => {
+ const { server, tools } = createServerMock();
+ const client = {
+ json: vi
+ .fn()
+ .mockResolvedValueOnce({
+ name: "Roadmap",
+ slug: "roadmap",
+ })
+ .mockResolvedValueOnce({ id: "project-1", name: "Roadmap v2" }),
+ };
+
+ registerTools(server as never, { client: client as never });
+
+ const result = await tools.get("update_project")?.handler({
+ id: "project-1",
+ name: "Roadmap v2",
+ });
+
+ expect(client.json).toHaveBeenNthCalledWith(1, "/api/project/project-1", {
+ method: "GET",
+ });
+ const putCall = client.json.mock.calls[1];
+ expect(putCall?.[0]).toBe("/api/project/project-1");
+ const putBody = JSON.parse(
+ String((putCall?.[1] as { body?: string })?.body ?? "{}"),
+ );
+ expect(putBody).toEqual({
+ name: "Roadmap v2",
+ icon: "Layout",
+ slug: "roadmap",
+ description: "",
+ isPublic: false,
+ });
+ expect(result?.isError).toBe(false);
+ });
+
it("returns an MCP error result when the client request fails", async () => {
const { server, tools } = createServerMock();
const client = {
diff --git a/packages/mcp/src/tools/register.ts b/packages/mcp/src/tools/register.ts
index 3a92737a7..c7bf77a58 100644
--- a/packages/mcp/src/tools/register.ts
+++ b/packages/mcp/src/tools/register.ts
@@ -155,7 +155,7 @@ export function registerTools(
? patch.icon
: typeof existing.icon === "string"
? existing.icon
- : undefined;
+ : "Layout";
const slug =
patch.slug ??
(typeof existing.slug === "string" ? existing.slug : "");
@@ -167,24 +167,15 @@ export function registerTools(
? patch.description
: typeof existing.description === "string"
? existing.description
- : undefined;
+ : "";
const isPublic =
patch.isPublic !== undefined
? patch.isPublic
: typeof existing.isPublic === "boolean"
? existing.isPublic
- : undefined;
+ : false;
- const body: Record<string, unknown> = { name, slug };
- if (icon !== undefined) {
- body.icon = icon;
- }
- if (description !== undefined) {
- body.description = description;
- }
- if (isPublic !== undefined) {
- body.isPublic = isPublic;
- }
+ const body = { name, icon, slug, description, isPublic };
return client.json(`/api/project/${encodeURIComponent(id)}`, {
method: "PUT",