Role-Specific Context MCP Server

Role-Specific Context MCP Server

site icon
2025.03.21 0
TypeScript角色管理内存管理MCP集成开发效率
MCP-Server 是一个基于角色定义和管理上下文的模型上下文协议(MCP)服务器。它通过角色管理、内存管理和MCP集成等功能,帮助用户为不同的AI代理(如市场营销专家、词曲作者、行政助理等)建立清晰的指令、目标和领域知识,同时确保不同角色之间的内存分区和范围隔离,避免交叉污染。
View on GitHub

Overview

基本能力

产品定位

MCP-Server 是一个用于管理AI代理角色上下文的服务器,通过角色定义和内存管理,确保不同角色的上下文隔离和动态风格适应。

核心功能

  1. 角色管理
  2. 创建、更新和删除自定义角色
  3. 预定义角色与特定领域知识
  4. 角色特定的系统提示和指令
  5. 可定制的风格配置

  6. 内存管理

  7. 角色特定的内存存储
  8. 基于查询相关性的内存检索
  9. 内存的生存时间(TTL)
  10. 每个角色的内存限制

  11. MCP集成

  12. 将角色作为MCP资源暴露
  13. 提供角色管理和查询处理的工具
  14. 提供基于角色的交互提示

适用场景

  • 需要为不同AI代理分配特定角色和上下文的场景
  • 需要动态调整AI代理风格和语气的场景
  • 需要隔离不同角色内存以避免交叉污染的场景

工具列表

  1. process-with-role - 使用特定角色处理查询
  2. create-role - 创建新角色
  3. update-role - 更新现有角色
  4. delete-role - 删除自定义角色
  5. change-role-tone - 更改角色的语气
  6. store-memory - 为特定角色存储内存
  7. clear-role-memories - 清除角色的所有内存

常见问题解答

  • 如何配置默认角色? 修改 src/config.ts 文件中的默认角色和属性。
  • 如何设置内存管理?src/config.ts 中调整内存管理设置。
  • 如何选择OpenAI模型?src/config.ts 中配置OpenAI模型选择。

使用教程

使用依赖

  • Node.js 18+
  • OpenAI API key

安装教程

# 克隆仓库
git clone https://github.com/yourusername/role-context-mcp.git
cd role-context-mcp

# 安装依赖
npm install

# 设置环境变量
echo "OPENAI_API_KEY=your_api_key_here" > .env

# 构建项目
npm run build

调试方式

# 运行MCP服务器
npm start

# 运行HTTP服务器进行测试
npm run start:http

示例用法

使用角色处理查询(MCP)

const result = await client.executeToolRequest({
  name: 'process-with-role',
  parameters: {
    roleId: 'marketing-expert',
    query: 'How can I improve my social media engagement?',
    customInstructions: 'Focus on B2B strategies'
  }
});

使用角色处理查询(HTTP API)

const response = await axios.post('http://localhost:3000/process', {
  roleId: 'marketing-expert',
  query: 'How can I improve my social media engagement?',
  customInstructions: 'Focus on B2B strategies'
});

console.log(response.data.response);

创建自定义角色

const result = await client.executeToolRequest({
  name: 'create-role',
  parameters: {
    id: 'tech-writer',
    name: 'Technical Writer',
    description: 'Specializes in clear, concise technical documentation',
    instructions: 'Create documentation that is accessible to both technical and non-technical audiences',
    domains: ['technical-writing', 'documentation', 'tutorials'],
    tone: 'technical',
    systemPrompt: 'You are an experienced technical writer with expertise in creating clear, concise documentation for complex systems.'
  }
});

许可证

该项目遵循 MIT 开源许可条款。