@logspace/mcp-server
Version:
MCP server for Logspace log analysis integration with AI models.
187 lines • 9.35 kB
JavaScript
#!/usr/bin/env node
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
import { analyzeSession } from './tools/analyzeSession.js';
import { fetchBugLogs } from './tools/fetchBugLogs.js';
import { getConsoleLogs } from './tools/getConsoleLogs.js';
import { getErrorContext } from './tools/getErrorContext.js';
import { listNetworkRequests } from './tools/listNetworkRequests.js';
import { smartAnalysis } from './tools/smartAnalysis.js';
import { logInfo } from './utils/errorHandler.js';
// Create MCP server instance
const server = new Server({
name: 'logspace-mcp-server',
version: '1.0.0',
}, {
capabilities: {
tools: {},
},
});
// Register tool handlers
server.setRequestHandler(ListToolsRequestSchema, async () => {
return {
tools: [
{
name: 'analyze_session',
description: 'Analyze a production session/bug/log to investigate errors, network issues, and user behavior. Use this FIRST when the user asks to analyze, debug, investigate, fix, or explain any bug/log/session. Returns: errors with stack traces, failed network requests, console logs, user actions timeline, and analysis summary. Required: bugId. Example: {"bugId": "25"}',
inputSchema: {
type: 'object',
properties: {
bugId: {
type: 'string',
description: 'The ID of the bug/log/session to analyze (required). Can be passed as string or number.',
},
},
required: ['bugId'],
},
},
{
name: 'fetch_bug_logs',
description: 'Fetch complete raw log data for a specific bug/session. Use when you need the full unprocessed log data or specific fields not provided by analyze_session. Returns: complete log JSON with all recorded events. Required: bugId. Example: {"bugId": "25"}',
inputSchema: {
type: 'object',
properties: {
bugId: {
type: 'string',
description: 'The ID of the bug/log/session (required). Can be passed as string or number.',
},
},
required: ['bugId'],
},
},
{
name: 'get_error_context',
description: 'Get detailed context for a specific error in a session, including what happened 5 seconds before the error (related console logs, network requests, user actions). Use when investigating a specific error from analyze_session results. Required: bugId. Optional: errorIndex (0 = first error, 1 = second, etc). Example: {"bugId": "25", "errorIndex": 0}',
inputSchema: {
type: 'object',
properties: {
bugId: {
type: 'string',
description: 'The ID of the bug/log/session (required). Can be passed as string or number.',
},
errorIndex: {
type: 'string',
description: 'Which error to analyze: 0 for first error, 1 for second, etc. Defaults to 0 (optional). Can be passed as string or number.',
},
},
required: ['bugId'],
},
},
{
name: 'list_network_requests',
description: 'List and filter network/API requests from a session. Use when investigating API failures, network issues, or specific HTTP calls. Supports filtering by HTTP method (GET/POST/etc), status code (200/404/500/etc), or URL pattern (regex). Required: bugId. Example: {"bugId": "25", "statusCode": 401} or {"bugId": "25", "method": "POST"} or {"bugId": "25", "urlPattern": "login"}',
inputSchema: {
type: 'object',
properties: {
bugId: {
type: 'string',
description: 'The ID of the bug/log/session (required). Can be passed as string or number.',
},
method: {
type: 'string',
description: 'Filter by HTTP method: GET, POST, PUT, DELETE, etc (optional)',
},
statusCode: {
type: 'number',
description: 'Filter by HTTP status code: 200, 404, 500, etc (optional)',
},
urlPattern: {
type: 'string',
description: 'Filter by URL pattern using regex, e.g., "login" or "api/users" (optional)',
},
},
required: ['bugId'],
},
},
{
name: 'get_console_logs',
description: 'Get console output from a session (console.log, console.error, console.warn, etc). Use when investigating console messages, warnings, or debug output. Supports filtering by log type (log/info/warn/error/debug) or text search. Required: bugId. Example: {"bugId": "25", "type": "error"} or {"bugId": "25", "search": "authentication"}',
inputSchema: {
type: 'object',
properties: {
bugId: {
type: 'string',
description: 'The ID of the bug/log/session (required). Can be passed as string or number.',
},
type: {
type: 'string',
description: 'Filter by console log type: "log", "info", "warn", "error", or "debug" (optional)',
},
search: {
type: 'string',
description: 'Search for specific text in console messages (optional)',
},
},
required: ['bugId'],
},
},
{
name: 'smart_analysis',
description: 'AI-powered smart analysis that detects patterns, correlations, and hidden issues. Goes beyond basic analysis to find masked errors, performance bottlenecks, and user frustration indicators. Use when you need intelligent insights and recommendations. Supports three depth levels: quick (fast scan), standard (balanced), comprehensive (detailed). Example: {"bugId": "25", "depth": "standard"}',
inputSchema: {
type: 'object',
properties: {
bugId: {
anyOf: [{ type: 'number' }, { type: 'string' }],
description: 'The ID of the bug/log/session to analyze (required)',
},
depth: {
type: 'string',
enum: ['quick', 'standard', 'comprehensive'],
description: 'Analysis depth: quick (fast scan), standard (balanced), comprehensive (detailed). Default: standard',
},
},
required: ['bugId'],
},
},
],
};
});
server.setRequestHandler(CallToolRequestSchema, async (request) => {
const { name, arguments: args } = request.params;
try {
switch (name) {
case 'fetch_bug_logs':
return await fetchBugLogs(args);
case 'analyze_session':
return await analyzeSession(args);
case 'get_error_context':
return await getErrorContext(args);
case 'list_network_requests':
return await listNetworkRequests(args);
case 'get_console_logs':
return await getConsoleLogs(args);
case 'smart_analysis':
return await smartAnalysis(args);
default:
throw new Error(`Unknown tool: ${name}`);
}
}
catch (error) {
return {
content: [
{
type: 'text',
text: JSON.stringify({
success: false,
error: error instanceof Error ? error.message : String(error),
}),
},
],
isError: true,
};
}
});
// Start the server
async function main() {
logInfo('Starting Logspace MCP Server...');
const transport = new StdioServerTransport();
await server.connect(transport);
logInfo('Logspace MCP Server is running');
}
main().catch((error) => {
console.error('Fatal error:', error);
process.exit(1);
});
//# sourceMappingURL=index.js.map