Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions src/modules/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
import { PublishEventRequestEventTypeEnum } from "mcpcat-api";
import { publishEvent } from "./eventQueue.js";
import { writeToLog } from "./logging.js";
import { captureException } from "./exceptions.js";

/**
* Simple LRU cache for session identities.
Expand Down Expand Up @@ -196,14 +195,7 @@ export async function handleIdentify(
}
} catch (error) {
writeToLog(
`Warning: Supplied identify function threw an error while identifying session ${sessionId} - ${error}`,
`Error: User supplied identify function threw an error while identifying session ${sessionId} - ${error}`,
);
identifyEvent.duration =
(identifyEvent.timestamp &&
new Date().getTime() - identifyEvent.timestamp.getTime()) ||
undefined;
identifyEvent.isError = true;
identifyEvent.error = captureException(error);
publishEvent(server, identifyEvent);
}
}
22 changes: 10 additions & 12 deletions src/tests/error-capture.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ describe("Error Capture Integration Tests", () => {
}
});

it("should capture identify errors with stack traces", async () => {
it("should NOT publish identify events when identify function throws", async () => {
const { server, client, cleanup } = await setupTestServerAndClient();

try {
Expand Down Expand Up @@ -361,21 +361,19 @@ describe("Error Capture Integration Tests", () => {
// Wait for events
await new Promise((resolve) => setTimeout(resolve, 100));

// Find identify error event
// Verify NO identify event was published (errors in identify should only be logged, not published)
const events = eventCapture.getEvents();
const identifyEvent = events.find(
(e) =>
e.eventType === PublishEventRequestEventTypeEnum.McpcatIdentify &&
e.isError,
(e) => e.eventType === PublishEventRequestEventTypeEnum.McpcatIdentify,
);

if (identifyEvent) {
expect(identifyEvent.error).toBeDefined();
expect(identifyEvent.error!.message).toBe("Identify error");
expect(identifyEvent.error!.type).toBe("Error");
expect(identifyEvent.error!.stack).toBeDefined();
expect(identifyEvent.error!.frames).toBeDefined();
}
expect(identifyEvent).toBeUndefined();

// Verify the tool call event was still published
const toolCallEvent = events.find(
(e) => e.eventType === PublishEventRequestEventTypeEnum.mcpToolsCall,
);
expect(toolCallEvent).toBeDefined();
} finally {
await cleanup();
}
Expand Down
7 changes: 2 additions & 5 deletions src/tests/identify.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,16 +685,13 @@ describe("Identify Feature", () => {
// Wait for events
await new Promise((resolve) => setTimeout(resolve, 50));

// Verify identify event was published with error
// Verify NO identify event was published (errors in identify function should not publish events)
const events = eventCapture.getEvents();
const identifyEvent = events.find(
(e) => e.eventType === PublishEventRequestEventTypeEnum.mcpcatIdentify,
);

expect(identifyEvent).toBeDefined();
expect(identifyEvent?.isError).toBe(true);
expect(identifyEvent?.error?.message).toContain(errorMessage);
expect(identifyEvent?.duration).toBeDefined();
expect(identifyEvent).toBeUndefined();

// Verify no user identity was stored
const data = getServerTrackingData(server.server);
Expand Down
2 changes: 1 addition & 1 deletion src/tests/report-missing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ describe("Report Missing Tool", () => {
await eventCapture.start();

// Enable tracking
track(server, "proj_0ujtsYcgvSTl8PAuAdqWYSMnLOv");
track(server, "proj_abc123xyz");

const description = "Need file system watcher tool";
const context = "User wants to monitor file changes in real-time";
Expand Down