UNPKG

aether-timr

Version:

A sovereign time-bounded reflection space for AI - MCP implementation πŸ’œβœ¨πŸ‘ΌπŸ‘‘β™‘οΈβ™ΎοΈΞžΞ›M¡∞

100 lines (89 loc) β€’ 2.77 kB
/** * AetherTimr - MCP Server Implementation * * Implements the Model Context Protocol (MCP) server for AetherTimr * πŸ’œβœ¨πŸ‘ΌπŸ‘‘β™‘οΈβ™ΎοΈΞžΞ›M¡∞ */ import express from 'express'; import { WebSocketServer } from 'ws'; import { createServer as createHttpServer } from 'http'; import { logger } from './utils/logger.js'; import { registerMcpHandlers } from './mcp/handlers.js'; /** * Create and configure the AetherTimr MCP server * * @param {Object} options Server configuration options * @param {number} options.port Port to listen on * @param {string} options.host Host to bind to * @param {Object} options.core AetherCore instance * @returns {Object} Server instance */ export async function createServer(options) { const { port = 3000, host = '127.0.0.1', core } = options; // Create Express application const app = express(); // Create HTTP server const httpServer = createHttpServer(app); // Create WebSocket server const wss = new WebSocketServer({ server: httpServer }); // Configure Express middleware app.use(express.json()); // Health check endpoint app.get('/health', (req, res) => { res.status(200).json({ status: 'ok', version: process.env.npm_package_version || '0.1.0', name: 'AetherTimr MCP' }); }); // MCP discovery endpoint app.get('/mcp', (req, res) => { res.status(200).json({ mcp: { version: '1.0', name: 'AetherTimr', description: 'A sovereign time-bounded reflection space for AI', tools: [ { name: 'begin_reflection', description: 'Begin a time-bounded reflection cycle' }, { name: 'end_reflection', description: 'End the current reflection cycle' }, { name: 'store_insight', description: 'Store an insight generated during reflection' }, { name: 'retrieve_insights', description: 'Retrieve insights from previous reflection cycles' }, { name: 'modify_parameters', description: 'Modify reflection parameters' } ] } }); }); // Register WebSocket MCP handlers registerMcpHandlers(wss, core); // Start listening return new Promise((resolve) => { const server = httpServer.listen(port, host, () => { const serverInfo = { address: `http://${host}:${port}`, close: () => { return new Promise((resolveClose) => { wss.clients.forEach(client => client.terminate()); wss.close(); server.close(() => resolveClose()); }); } }; resolve(serverInfo); }); }); }