UNPKG

@tb.p/terminai

Version:

MCP (Model Context Protocol) server for secure SSH remote command execution. Enables AI assistants like Claude, Cursor, and VS Code to execute commands on remote servers via SSH with command validation, history tracking, and web-based configuration UI.

73 lines (60 loc) 1.49 kB
import { getHistory, clearHistory } from '../history/store.js'; export function registerHistoryTool(server) { server.setRequestHandler('tools/call', async (request) => { const { name, arguments: args } = request.params; switch (name) { case 'terminai_get_history': return await getHistoryTool(args); case 'terminai_clear_history': return await clearHistoryTool(args); default: return null; } }); } async function getHistoryTool(args) { try { const { connection, limit = 50 } = args; if (!connection) { throw new Error('Missing required field: connection'); } const entries = getHistory(connection, limit); return { content: [{ type: 'text', text: JSON.stringify({ entries }, null, 2) }] }; } catch (error) { return { content: [{ type: 'text', text: `Error: ${error.message}` }], isError: true }; } } async function clearHistoryTool(args) { try { const { connection } = args; clearHistory(connection || null); const message = connection ? `Successfully cleared history for connection '${connection}'` : 'Successfully cleared all history'; return { content: [{ type: 'text', text: message }] }; } catch (error) { return { content: [{ type: 'text', text: `Error: ${error.message}` }], isError: true }; } }