MCPcopy Create free account
hub / github.com/ReAPI-com/mcp-openapi / McpService

Class McpService

src/McpService.ts:9–339  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7export const VERSION = "0.0.4";
8
9export class McpService {
10 private readonly logger: Logger;
11
12 constructor(
13 private readonly specExplorer: ISpecExplorer,
14 logger?: Logger
15 ) {
16 this.logger = logger || new ConsoleLogger();
17 this.initializeExplorer().catch(error => {
18 this.logger.error('Failed to initialize spec explorer', { error });
19 throw error;
20 });
21 }
22
23 private async initializeExplorer() {
24 try {
25 this.logger.info('Initializing spec explorer');
26 await this.specExplorer.initialize();
27 this.logger.info('Spec explorer initialized successfully');
28 } catch (error) {
29 this.logger.error('Failed to initialize spec explorer', { error });
30 throw error;
31 }
32 }
33
34 createServer() {
35 this.logger.info('Creating MCP server');
36 const mcpServer = new McpServer({
37 name: "reapi-mcp-server",
38 version: VERSION,
39 });
40
41 this.setUpTools(mcpServer);
42 this.logger.info('MCP server created successfully');
43
44 return mcpServer;
45 }
46
47 private setUpTools(server: McpServer) {
48 server.tool("refresh-api-catalog", "Refresh the API catalog", async () => {
49 try {
50 this.logger.info('Refreshing API catalog');
51 await this.specExplorer.refresh();
52 this.logger.info('API catalog refreshed successfully');
53 return {
54 content: [{ type: "text", text: "API catalog refreshed" }],
55 };
56 } catch (error) {
57 this.logger.error('Failed to refresh API catalog', { error });
58 throw error;
59 }
60 });
61
62 // server.tool(
63 // 'sync-api-catalog',
64 // 'Sync the API catalog',
65 // async () => {
66 // await this.specExplorer.sync();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected