@logspace/mcp-server
Version:
MCP server for Logspace log analysis integration with AI models.
76 lines • 2.77 kB
JavaScript
import { z } from 'zod';
import { getApiClient } from '../services/apiClient.js';
import { formatError, logError, logInfo, isAuthError } from '../utils/errorHandler.js';
import { validateBugId } from '../utils/validator.js';
export const FetchBugLogsSchema = z.object({
bugId: z.union([z.number(), z.string()]).describe('The ID of the bug to fetch logs for'),
});
export async function fetchBugLogs(args) {
try {
const bugId = validateBugId(args.bugId);
logInfo(`Fetching logs for bug ID: ${bugId}`);
const apiClient = getApiClient();
const logData = await apiClient.fetchLogData(bugId);
// Create a comprehensive summary
const summary = {
bugId,
username: logData.username,
assignee: logData.assignee_username,
videoUrl: logData.video_url,
session: {
timestamp: new Date(logData.log_json.session.timestamp).toISOString(),
duration: `${Math.floor(logData.log_json.session.duration / 1000)}s`,
},
logs: {
networkRequests: logData.log_json.logs.network?.length || 0,
consoleLogs: logData.log_json.logs.console?.length || 0,
errors: logData.log_json.logs.error?.length || 0,
performanceEntries: logData.log_json.logs.performance?.length || 0,
interactions: logData.log_json.logs.interaction?.length || 0,
annotations: logData.log_json.logs.annotation?.length || 0,
},
metadata: logData.log_json.metadata,
};
return {
content: [
{
type: 'text',
text: JSON.stringify({
success: true,
summary,
fullData: logData,
}, null, 2),
},
],
};
}
catch (error) {
logError('fetch_bug_logs', error);
// Check if this is an authentication error
const authErrorMessage = isAuthError(error);
if (authErrorMessage) {
return {
content: [
{
type: 'text',
text: authErrorMessage,
},
],
isError: true,
};
}
return {
content: [
{
type: 'text',
text: JSON.stringify({
success: false,
error: formatError(error),
}, null, 2),
},
],
isError: true,
};
}
}
//# sourceMappingURL=fetchBugLogs.js.map