API 文档

REST API 概览

Memory Bank MCP 服务器提供了一套完整的 REST API,用于管理项目、文档和规则。所有 API 都返回 JSON 格式的响应,遵循一致的响应格式。

响应格式

{
  "status": "success", // 或 "error"
  "data": {
    // 返回的数据
  },
  "message": "操作成功" // 或错误信息
}

错误处理

当 API 请求失败时,返回的响应将包含错误信息:

{
  "status": "error",
  "message": "详细的错误信息",
  "code": "ERROR_CODE" // 错误代码
}

项目管理接口

GET /api/projects

获取所有项目列表

请求参数

请求示例
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"
    }
  ]
}

POST /api/projects

创建新项目

请求参数
  • 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"
    ]
  }
}

GET /api/projects/:id

获取项目详情

路径参数
  • id - 项目ID
请求示例
fetch('/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"
  }
}

PUT /api/projects/:id

更新项目

路径参数
  • id - 项目ID
请求参数
  • name (可选) - 新项目名称
  • 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"
  }
}

DELETE /api/projects/:id

删除项目

路径参数
  • id - 项目ID
请求示例
fetch('/api/projects/project-123', {
  method: 'DELETE'
})
  .then(response => response.json())
  .then(data => console.log(data));
响应示例
{
  "status": "success",
  "data": {
    "success": true,
    "message": "项目删除成功"
  }
}

文档管理接口

GET /api/projects/:projectId/documents

获取项目文档列表

路径参数
  • projectId - 项目ID
请求示例
fetch('/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"
    }
  ]
}

GET /api/projects/:projectId/documents/:type

获取文档内容

路径参数
  • projectId - 项目ID
  • type - 文档类型
请求示例
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": "

任务列表

..." } }

PUT /api/projects/:projectId/documents/:type

更新文档内容

路径参数
  • projectId - 项目ID
  • type - 文档类型
请求参数
  • 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": "文档更新成功"
  }
}

规则管理接口

规则管理接口用于创建、查询、更新和删除项目规则,包括全局规则和项目特定规则。

GET /api/projects/:projectId/rules

获取项目规则列表

路径参数
  • projectId - 项目ID
请求示例
fetch('/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"
    }
  ]
}

GET /api/rules/:id

获取规则详情

路径参数
  • id - 规则ID
请求示例
fetch('/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"
  }
}

POST /api/rules

创建新规则

请求参数
  • name (必填) - 规则名称
  • description (可选) - 规则描述
  • content (必填) - 规则内容
  • type (必填) - 规则类型(如coding, workflow, documentation等)
  • scope (必填) - 规则范围(global或project)
  • projectId (当scope为project时必填) - 项目ID
  • priority (可选) - 规则优先级(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"
  }
}

PUT /api/rules/:id

更新规则

路径参数
  • id - 规则ID
请求参数
  • name (可选) - 规则名称
  • 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"
  }
}

DELETE /api/rules/:id

删除规则

路径参数
  • id - 规则ID
请求示例
fetch('/api/rules/rule-001', {
  method: 'DELETE'
})
  .then(response => response.json())
  .then(data => console.log(data));
响应示例
{
  "success": true,
  "data": {
    "success": true,
    "message": "规则删除成功"
  }
}

MCP 工具接口

Memory Bank MCP 服务器提供了一套符合 Model Context Protocol 协议的工具接口,可被大模型直接调用。

VAN 模式接口

VAN 模式接口用于项目验证与初始化,确保项目基础设施完备,验证关键文件存在性和完整性。