@@ -13,7 +13,8 @@ import { Logger } from "@lighthouse-tooling/shared";
1313import { LIGHTHOUSE_MCP_TOOLS } from "@lighthouse-tooling/types" ;
1414
1515import { ToolRegistry } from "./registry/ToolRegistry.js" ;
16- import { MockLighthouseService } from "./services/MockLighthouseService.js" ;
16+ import { LighthouseService } from "./services/LighthouseService.js" ;
17+ import { ILighthouseService } from "./services/ILighthouseService.js" ;
1718import { MockDatasetService } from "./services/MockDatasetService.js" ;
1819import {
1920 ListToolsHandler ,
@@ -26,7 +27,7 @@ import { ServerConfig, DEFAULT_SERVER_CONFIG } from "./config/server-config.js";
2627export class LighthouseMCPServer {
2728 private server : Server ;
2829 private registry : ToolRegistry ;
29- private lighthouseService : MockLighthouseService ;
30+ private lighthouseService : ILighthouseService ;
3031 private datasetService : MockDatasetService ;
3132 private logger : Logger ;
3233 private config : ServerConfig ;
@@ -37,7 +38,13 @@ export class LighthouseMCPServer {
3738 private listResourcesHandler : ListResourcesHandler ;
3839 private initializeHandler : InitializeHandler ;
3940
40- constructor ( config : Partial < ServerConfig > = { } ) {
41+ constructor (
42+ config : Partial < ServerConfig > = { } ,
43+ services ?: {
44+ lighthouseService ?: ILighthouseService ;
45+ datasetService ?: MockDatasetService ;
46+ } ,
47+ ) {
4148 this . config = { ...DEFAULT_SERVER_CONFIG , ...config } ;
4249
4350 // Initialize logger
@@ -61,8 +68,20 @@ export class LighthouseMCPServer {
6168 ) ;
6269
6370 // Initialize services
64- this . lighthouseService = new MockLighthouseService ( this . config . maxStorageSize , this . logger ) ;
65- this . datasetService = new MockDatasetService ( this . lighthouseService , this . logger ) ;
71+ if ( services ?. lighthouseService ) {
72+ this . lighthouseService = services . lighthouseService ;
73+ } else {
74+ if ( ! this . config . lighthouseApiKey ) {
75+ throw new Error ( "LIGHTHOUSE_API_KEY environment variable is required" ) ;
76+ }
77+ this . lighthouseService = new LighthouseService ( this . config . lighthouseApiKey , this . logger ) ;
78+ }
79+
80+ if ( services ?. datasetService ) {
81+ this . datasetService = services . datasetService ;
82+ } else {
83+ this . datasetService = new MockDatasetService ( this . lighthouseService , this . logger ) ;
84+ }
6685
6786 // Initialize registry
6887 this . registry = new ToolRegistry ( this . logger ) ;
@@ -201,7 +220,7 @@ export class LighthouseMCPServer {
201220
202221 // Handle ListResources
203222 this . server . setRequestHandler ( ListResourcesRequestSchema , async ( ) => {
204- const files = this . lighthouseService . listFiles ( ) ;
223+ const files = await this . lighthouseService . listFiles ( ) ;
205224 const datasets = this . datasetService . listDatasets ( ) ;
206225
207226 const resources = [
@@ -237,6 +256,11 @@ export class LighthouseMCPServer {
237256 version : this . config . version ,
238257 } ) ;
239258
259+ // Initialize Lighthouse service
260+ if ( this . lighthouseService . initialize ) {
261+ await this . lighthouseService . initialize ( ) ;
262+ }
263+
240264 // Register tools
241265 await this . registerTools ( ) ;
242266
@@ -311,7 +335,7 @@ export class LighthouseMCPServer {
311335 getStats ( ) : {
312336 registry : any ;
313337 storage : any ;
314- datasets : any ;
338+ datasets : unknown ;
315339 } {
316340 return {
317341 registry : this . registry . getMetrics ( ) ,
@@ -330,7 +354,7 @@ export class LighthouseMCPServer {
330354 /**
331355 * Get lighthouse service instance (for testing)
332356 */
333- getLighthouseService ( ) : MockLighthouseService {
357+ getLighthouseService ( ) : ILighthouseService {
334358 return this . lighthouseService ;
335359 }
336360
0 commit comments