Memory Bank MCP 服务器提供了一套完整的 REST API,用于管理项目、文档和规则。所有 API 都返回 JSON 格式的响应,遵循一致的响应格式。
{
"status": "success", // 或 "error"
"data": {
// 返回的数据
},
"message": "操作成功" // 或错误信息
}
当 API 请求失败时,返回的响应将包含错误信息:
{
"status": "error",
"message": "详细的错误信息",
"code": "ERROR_CODE" // 错误代码
}
获取所有项目列表
无
fetch('/api/projects')
.then(response => response.json())
.then(data => console.log(data));
{
"status": "success",
"data": [
{
"id": "project-123",
"name": "示例项目",
"description": "这是一个示例项目",
"createdAt": "2023-11-30T08:15:30Z",
"updatedAt": "2023-11-30T10:22:45Z"
},
{
"id": "project-456",
"name": "测试项目",
"description": "用于测试的项目",
"createdAt": "2023-11-29T14:25:10Z",
"updatedAt": "2023-11-29T16:30:22Z"
}
]
}
创建新项目
name (必填) - 项目名称description (可选) - 项目描述fetch('/api/projects', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: '新项目',
description: '这是一个新项目'
})
})
.then(response => response.json())
.then(data => console.log(data));
{
"status": "success",
"data": {
"id": "project-789",
"name": "新项目",
"description": "这是一个新项目",
"createdAt": "2023-12-01T09:45:12Z",
"updatedAt": "2023-12-01T09:45:12Z",
"documents": [
"projectbrief.md",
"tasks.md",
"activeContext.md"
]
}
}
获取项目详情
id - 项目IDfetch('/api/projects/project-123')
.then(response => response.json())
.then(data => console.log(data));
{
"status": "success",
"data": {
"id": "project-123",
"name": "示例项目",
"description": "这是一个示例项目",
"createdAt": "2023-11-30T08:15:30Z",
"updatedAt": "2023-11-30T10:22:45Z"
}
}
更新项目
id - 项目IDname (可选) - 新项目名称description (可选) - 新项目描述fetch('/api/projects/project-123', {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: '更新的项目名称',
description: '更新的项目描述'
})
})
.then(response => response.json())
.then(data => console.log(data));
{
"status": "success",
"data": {
"id": "project-123",
"name": "更新的项目名称",
"description": "更新的项目描述",
"updatedAt": "2023-12-01T11:30:25Z"
}
}
删除项目
id - 项目IDfetch('/api/projects/project-123', {
method: 'DELETE'
})
.then(response => response.json())
.then(data => console.log(data));
{
"status": "success",
"data": {
"success": true,
"message": "项目删除成功"
}
}
获取项目文档列表
projectId - 项目IDfetch('/api/projects/project-123/documents')
.then(response => response.json())
.then(data => console.log(data));
{
"status": "success",
"data": [
{
"id": "doc-001",
"name": "projectbrief.md",
"type": "projectbrief",
"updatedAt": "2023-11-30T09:20:15Z"
},
{
"id": "doc-002",
"name": "tasks.md",
"type": "tasks",
"updatedAt": "2023-11-30T10:15:30Z"
},
{
"id": "doc-003",
"name": "activeContext.md",
"type": "activeContext",
"updatedAt": "2023-11-30T11:05:45Z"
}
]
}
获取文档内容
projectId - 项目IDtype - 文档类型fetch('/api/projects/project-123/documents/tasks')
.then(response => response.json())
.then(data => console.log(data));
{
"status": "success",
"data": {
"id": "doc-002",
"name": "tasks.md",
"content": "# 任务列表\n\n## 待办任务\n- [ ] [高] 实现用户认证\n- [ ] [中] 添加日志记录\n\n## 进行中任务\n- [-] 完善错误处理 (60%)\n\n## 已完成任务\n- [x] 设计数据模型\n- [x] 创建项目结构",
"type": "tasks",
"updatedAt": "2023-11-30T10:15:30Z",
"html": "任务列表
..."
}
}
更新文档内容
projectId - 项目IDtype - 文档类型content (必填) - 文档内容fetch('/api/projects/project-123/documents/tasks', {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
content: "# 任务列表\n\n## 待办任务\n- [ ] [高] 实现用户认证\n- [ ] [中] 添加日志记录\n- [ ] [低] 优化性能\n\n## 进行中任务\n- [-] 完善错误处理 (60%)\n\n## 已完成任务\n- [x] 设计数据模型\n- [x] 创建项目结构"
})
})
.then(response => response.json())
.then(data => console.log(data));
{
"status": "success",
"data": {
"id": "doc-002",
"name": "tasks.md",
"type": "tasks",
"updatedAt": "2023-12-01T14:25:45Z",
"message": "文档更新成功"
}
}
规则管理接口用于创建、查询、更新和删除项目规则,包括全局规则和项目特定规则。
获取项目规则列表
projectId - 项目IDfetch('/api/projects/project-123/rules')
.then(response => response.json())
.then(data => console.log(data));
{
"success": true,
"data": [
{
"id": "rule-001",
"name": "命名规范",
"description": "项目命名规范",
"content": "所有类名使用PascalCase,变量和方法使用camelCase",
"type": "coding",
"scope": "project",
"priority": "high",
"createdAt": "2023-11-30T09:15:30Z",
"updatedAt": "2023-11-30T09:15:30Z"
},
{
"id": "rule-002",
"name": "提交规范",
"description": "Git提交规范",
"content": "提交信息格式:[类型] 描述,类型包括feat, fix, docs, style等",
"type": "workflow",
"scope": "project",
"priority": "medium",
"createdAt": "2023-11-30T10:20:15Z",
"updatedAt": "2023-11-30T10:20:15Z"
}
]
}
获取规则详情
id - 规则IDfetch('/api/rules/rule-001')
.then(response => response.json())
.then(data => console.log(data));
{
"success": true,
"data": {
"id": "rule-001",
"name": "命名规范",
"description": "项目命名规范",
"content": "所有类名使用PascalCase,变量和方法使用camelCase",
"type": "coding",
"scope": "project",
"projectId": "project-123",
"priority": "high",
"createdAt": "2023-11-30T09:15:30Z",
"updatedAt": "2023-11-30T09:15:30Z"
}
}
创建新规则
name (必填) - 规则名称description (可选) - 规则描述content (必填) - 规则内容type (必填) - 规则类型(如coding, workflow, documentation等)scope (必填) - 规则范围(global或project)projectId (当scope为project时必填) - 项目IDpriority (可选) - 规则优先级(high, medium, low)fetch('/api/rules', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: "代码审查规则",
description: "代码审查标准和流程",
content: "每个PR必须至少有一名审查者审核通过才能合并",
type: "workflow",
scope: "project",
projectId: "project-123",
priority: "high"
})
})
.then(response => response.json())
.then(data => console.log(data));
{
"success": true,
"data": {
"id": "rule-003",
"name": "代码审查规则",
"description": "代码审查标准和流程",
"content": "每个PR必须至少有一名审查者审核通过才能合并",
"type": "workflow",
"scope": "project",
"projectId": "project-123",
"priority": "high",
"createdAt": "2023-12-01T14:30:25Z",
"updatedAt": "2023-12-01T14:30:25Z"
}
}
更新规则
id - 规则IDname (可选) - 规则名称description (可选) - 规则描述content (可选) - 规则内容type (可选) - 规则类型priority (可选) - 规则优先级fetch('/api/rules/rule-001', {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: "更新的命名规范",
content: "所有类名使用PascalCase,变量和方法使用camelCase,常量使用UPPER_SNAKE_CASE",
priority: "high"
})
})
.then(response => response.json())
.then(data => console.log(data));
{
"success": true,
"data": {
"id": "rule-001",
"name": "更新的命名规范",
"description": "项目命名规范",
"content": "所有类名使用PascalCase,变量和方法使用camelCase,常量使用UPPER_SNAKE_CASE",
"type": "coding",
"scope": "project",
"projectId": "project-123",
"priority": "high",
"updatedAt": "2023-12-01T15:45:10Z"
}
}
删除规则
id - 规则IDfetch('/api/rules/rule-001', {
method: 'DELETE'
})
.then(response => response.json())
.then(data => console.log(data));
{
"success": true,
"data": {
"success": true,
"message": "规则删除成功"
}
}
Memory Bank MCP 服务器提供了一套符合 Model Context Protocol 协议的工具接口,可被大模型直接调用。
VAN 模式接口用于项目验证与初始化,确保项目基础设施完备,验证关键文件存在性和完整性。