UNPKG

prompt-mcp-server

Version:

提示词模板和Cursor规则的MCP服务器 - A Model Context Protocol server for managing prompt templates and cursor rules

174 lines 6.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CursorRulesService = void 0; const connection_1 = require("../database/connection"); /** * Cursor规则模板服务类 */ class CursorRulesService { /** * 获取所有Cursor规则模板列表 * @param options 查询选项 */ async getAllCursorRulesTemplates(options = {}) { const { category, language, framework, is_active = true, limit = 50, offset = 0 } = options; // 构建查询条件 const conditions = []; const params = []; if (is_active !== undefined) { conditions.push('is_active = ?'); params.push(is_active ? 1 : 0); } if (category) { conditions.push('category = ?'); params.push(category); } if (language) { conditions.push('language = ?'); params.push(language); } if (framework) { conditions.push('framework = ?'); params.push(framework); } const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : ''; // 获取总数 const countQuery = `SELECT COUNT(*) as total FROM cursor_rules_templates ${whereClause}`; const countResult = await (0, connection_1.executeQueryOne)(countQuery, params); const total = countResult?.total || 0; // 获取数据 const dataQuery = ` SELECT id, name, title, description, content, language, framework, category, tags, author, version, is_active, created_at, updated_at FROM cursor_rules_templates ${whereClause} ORDER BY created_at DESC LIMIT ? OFFSET ? `; const data = await (0, connection_1.executeQuery)(dataQuery, [...params, limit, offset]); return { data, total, page: Math.floor(offset / limit) + 1, limit, }; } /** * 根据名称获取Cursor规则模板 * @param name 模板名称 */ async getCursorRulesTemplateByName(name) { const query = ` SELECT id, name, title, description, content, language, framework, category, tags, author, version, is_active, created_at, updated_at FROM cursor_rules_templates WHERE name = ? AND is_active = 1 `; return await (0, connection_1.executeQueryOne)(query, [name]); } /** * 根据ID获取Cursor规则模板 * @param id 模板ID */ async getCursorRulesTemplateById(id) { const query = ` SELECT id, name, title, description, content, language, framework, category, tags, author, version, is_active, created_at, updated_at FROM cursor_rules_templates WHERE id = ? AND is_active = 1 `; return await (0, connection_1.executeQueryOne)(query, [id]); } /** * 搜索Cursor规则模板 * @param keyword 搜索关键词 * @param options 查询选项 */ async searchCursorRulesTemplates(keyword, options = {}) { const { category, language, framework, is_active = true, limit = 50, offset = 0 } = options; const conditions = []; const params = []; // 添加搜索条件 conditions.push('(name LIKE ? OR title LIKE ? OR description LIKE ? OR content LIKE ?)'); const searchParam = `%${keyword}%`; params.push(searchParam, searchParam, searchParam, searchParam); if (is_active !== undefined) { conditions.push('is_active = ?'); params.push(is_active ? 1 : 0); } if (category) { conditions.push('category = ?'); params.push(category); } if (language) { conditions.push('language = ?'); params.push(language); } if (framework) { conditions.push('framework = ?'); params.push(framework); } const whereClause = `WHERE ${conditions.join(' AND ')}`; // 获取总数 const countQuery = `SELECT COUNT(*) as total FROM cursor_rules_templates ${whereClause}`; const countResult = await (0, connection_1.executeQueryOne)(countQuery, params); const total = countResult?.total || 0; // 获取数据 const dataQuery = ` SELECT id, name, title, description, content, language, framework, category, tags, author, version, is_active, created_at, updated_at FROM cursor_rules_templates ${whereClause} ORDER BY created_at DESC LIMIT ? OFFSET ? `; const data = await (0, connection_1.executeQuery)(dataQuery, [...params, limit, offset]); return { data, total, page: Math.floor(offset / limit) + 1, limit, }; } /** * 获取所有编程语言 */ async getProgrammingLanguages() { const query = ` SELECT DISTINCT language FROM cursor_rules_templates WHERE language IS NOT NULL AND is_active = 1 ORDER BY language `; const results = await (0, connection_1.executeQuery)(query); return results.map(row => row.language); } /** * 获取所有框架 */ async getFrameworks() { const query = ` SELECT DISTINCT framework FROM cursor_rules_templates WHERE framework IS NOT NULL AND is_active = 1 ORDER BY framework `; const results = await (0, connection_1.executeQuery)(query); return results.map(row => row.framework); } /** * 获取所有分类 */ async getCursorRulesCategories() { const query = ` SELECT DISTINCT category FROM cursor_rules_templates WHERE category IS NOT NULL AND is_active = 1 ORDER BY category `; const results = await (0, connection_1.executeQuery)(query); return results.map(row => row.category); } } exports.CursorRulesService = CursorRulesService; //# sourceMappingURL=cursor-rules-service.js.map