server.ts•1.03 kB
import { MCPServer, MCPServerOptions } from '@browsermcp/mcp';
export interface ServerConfig {
port: number;
host: string;
debug?: boolean;
}
export class TestMCPServer {
private server: MCPServer;
private config: ServerConfig;
constructor(config: ServerConfig) {
this.config = config;
const options: MCPServerOptions = {
port: config.port,
host: config.host
};
this.server = new MCPServer(options);
}
async start(): Promise<void> {
try {
await this.server.start();
if (this.config.debug) {
console.log(`MCP Server started on ${this.config.host}:${this.config.port}`);
}
} catch (error) {
console.error('Failed to start MCP server:', error);
throw error;
}
}
async stop(): Promise<void> {
try {
await this.server.stop();
if (this.config.debug) {
console.log('MCP Server stopped');
}
} catch (error) {
console.error('Failed to stop MCP server:', error);
throw error;
}
}
}