-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathembeddedBasicHttp.js
More file actions
56 lines (45 loc) · 1.4 KB
/
embeddedBasicHttp.js
File metadata and controls
56 lines (45 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* An embedded basic HTTP Transport example.
*
* This example demonstrates how to start the PatternFly MCP Server
* with HTTP transport and security configuration.
*/
import { start } from '@patternfly/patternfly-mcp';
const main = async () => {
console.warn('Embedding PatternFly MCP Server with HTTP transport...');
// Start server with HTTP transport
const server = await start({
http: {
port: 8080,
host: '127.0.0.1',
allowedOrigins: ['https://app.example.com'],
allowedHosts: ['localhost', '127.0.0.1']
},
logging: {
stderr: true,
level: 'info'
}
});
console.warn('Server started on http://127.0.0.1:8080');
console.warn(`Server is running: ${server.isRunning()}`);
// Optional: Listen to server logs
server.onLog(event => {
console.warn(`[${event.level.toUpperCase()}] ${event.msg || ''}`);
});
// Get server statistics
const stats = await server.getStats();
console.warn('Server stats:', stats);
// Graceful shutdown, Press Ctrl+C to stop.
process.on('SIGINT', async () => {
console.warn('\nShutting down server...');
await server.stop();
console.warn('Server stopped.');
process.exit(0);
});
console.warn('Server is running. Press Ctrl+C to stop.');
console.warn('Connect to: http://127.0.0.1:8080');
};
main().catch(error => {
console.error('Failed to start server:', error);
process.exit(1);
});