prompt-mcp-server
Version:
提示词模板和Cursor规则的MCP服务器 - A Model Context Protocol server for managing prompt templates and cursor rules
132 lines • 4.64 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PromptService = void 0;
const connection_1 = require("../database/connection");
/**
* 提示词模板服务类
*/
class PromptService {
/**
* 获取所有提示词模板列表
* @param options 查询选项
*/
async getAllPromptTemplates(options = {}) {
const { category, 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);
}
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : '';
// 获取总数
const countQuery = `SELECT COUNT(*) as total FROM prompt_templates ${whereClause}`;
const countResult = await (0, connection_1.executeQueryOne)(countQuery, params);
const total = countResult?.total || 0;
// 获取数据
const dataQuery = `
SELECT id, name, title, description, content, category, tags, author, version,
is_active, created_at, updated_at
FROM prompt_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,
};
}
/**
* 根据名称获取提示词模板
* @param name 模板名称
*/
async getPromptTemplateByName(name) {
const query = `
SELECT id, name, title, description, content, category, tags, author, version,
is_active, created_at, updated_at
FROM prompt_templates
WHERE name = ? AND is_active = 1
`;
return await (0, connection_1.executeQueryOne)(query, [name]);
}
/**
* 根据ID获取提示词模板
* @param id 模板ID
*/
async getPromptTemplateById(id) {
const query = `
SELECT id, name, title, description, content, category, tags, author, version,
is_active, created_at, updated_at
FROM prompt_templates
WHERE id = ? AND is_active = 1
`;
return await (0, connection_1.executeQueryOne)(query, [id]);
}
/**
* 搜索提示词模板
* @param keyword 搜索关键词
* @param options 查询选项
*/
async searchPromptTemplates(keyword, options = {}) {
const { category, 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);
}
const whereClause = `WHERE ${conditions.join(' AND ')}`;
// 获取总数
const countQuery = `SELECT COUNT(*) as total FROM prompt_templates ${whereClause}`;
const countResult = await (0, connection_1.executeQueryOne)(countQuery, params);
const total = countResult?.total || 0;
// 获取数据
const dataQuery = `
SELECT id, name, title, description, content, category, tags, author, version,
is_active, created_at, updated_at
FROM prompt_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 getPromptCategories() {
const query = `
SELECT DISTINCT category
FROM prompt_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.PromptService = PromptService;
//# sourceMappingURL=prompt-service.js.map