server.ts•2.31 kB
/**
* Forensics Connection MCP Server implementation
*/
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import {
CallToolRequestSchema,
ListToolsRequestSchema,
} from '@modelcontextprotocol/sdk/types.js';
import { AnalyzeConnectionsTool } from './tools/index.js';
import { AnalysisRequest } from './types.js';
import { Config } from './config.js';
/**
* Forensics Connection MCP Server
*/
export class ForensicsServer {
private server: Server;
private analyzeConnectionsTool: AnalyzeConnectionsTool;
private config: Config;
constructor(config: Config) {
this.config = config;
this.server = new Server(
{
name: 'forensics-connections',
version: '0.1.0',
},
{
capabilities: {
tools: {},
},
}
);
this.analyzeConnectionsTool = new AnalyzeConnectionsTool(config);
this.setupToolHandlers();
}
/**
* Get the underlying MCP Server instance
*/
getServer(): Server {
return this.server;
}
/**
* Setup tool request handlers
*/
private setupToolHandlers(): void {
// List available tools
this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
tools: [
this.analyzeConnectionsTool.getDefinition(),
],
}));
// Handle tool calls
this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
switch (request.params.name) {
case 'analyze_connections':
return this.analyzeConnectionsTool.execute(
request.params.arguments as unknown as AnalysisRequest
);
default:
throw new Error(`Unknown tool: ${request.params.name}`);
}
});
}
/**
* Test server health
*/
async healthCheck(): Promise<boolean> {
try {
// Test OpenAI connection through the tool
const testRequest: AnalysisRequest = {
evidence: 'Test evidence with John Smith and Jane Doe mentioned together.',
options: {
includeVisualization: false,
minimumConnectionStrength: 1,
}
};
const result = await this.analyzeConnectionsTool.execute(testRequest);
return !result.isError;
} catch (error) {
console.error('Health check failed:', error);
return false;
}
}
}