@logspace/mcp-server
Version:
MCP server for Logspace log analysis integration with AI models.
84 lines • 3.04 kB
JavaScript
import { z } from 'zod';
import { getApiClient } from '../services/apiClient.js';
import { getLogParser } from '../services/logParser.js';
import { formatError, logError, logInfo, isAuthError } from '../utils/errorHandler.js';
import { validateBugId } from '../utils/validator.js';
export const ListNetworkRequestsSchema = z.object({
bugId: z.union([z.number(), z.string()]).describe('The ID of the bug'),
method: z.string().optional().describe('Filter by HTTP method (GET, POST, etc.)'),
statusCode: z.number().optional().describe('Filter by status code'),
urlPattern: z.string().optional().describe('Filter by URL pattern (regex)'),
});
export async function listNetworkRequests(args) {
try {
let bugId = validateBugId(args.bugId);
if (typeof bugId !== 'number') {
// convert to number
bugId = Number(bugId);
}
logInfo(`Listing network requests for bug ID: ${bugId}`);
const apiClient = getApiClient();
const logData = await apiClient.fetchLogData(bugId);
const logParser = getLogParser();
const filters = {
method: args.method,
statusCode: args.statusCode,
urlPattern: args.urlPattern,
};
const requests = logParser.filterNetworkRequests(logData, filters);
// Format the requests
const formattedRequests = requests.map((req, idx) => ({
index: idx,
method: req.method,
url: req.url,
status: req.status,
duration: `${req.duration}ms`,
timestamp: new Date(req.timestamp).toISOString(),
requestBody: req.requestBody,
responseBody: req.responseBody,
headers: Object.fromEntries(req.headers),
}));
return {
content: [
{
type: 'text',
text: JSON.stringify({
success: true,
total: formattedRequests.length,
filters,
requests: formattedRequests,
}, null, 2),
},
],
};
}
catch (error) {
logError('list_network_requests', 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=listNetworkRequests.js.map