角色上下文管理服务器

一个基于角色的上下文管理服务器,用于定义和管理AI代理的上下文边界,支持角色创建、记忆管理和动态风格调整。

  • by Chris-June
  • TypeScript
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 Chris-June/MCP-Server

使用说明

角色特定上下文MCP服务器

模型上下文协议(MCP)服务器,根据系统中的代理角色定义和管理上下文边界。

概述

此MCP服务器为AI代理启用基于角色的上下文管理,允许您:

  • 为每个人工智能代理(营销专家、歌曲作者、行政助理等)制定明确的指示、目标和领域知识
  • 保持与角色相关的内存分区和作用域,防止不同代理角色之间的交叉污染
  • 根据角色动态调整语调和风格(严肃、诙谐、讽刺),并在提示中加入语调特征

特性

角色管理

  • 创建、更新和删除自定义角色
  • 具有特定专业领域的预定义角色
  • 特定角色的系统提示和说明
  • 可定制的音调配置文件

内存管理

  • 特定角色的内存存储
  • 基于与当前查询相关性的记忆检索
  • 记忆的生存时间(TTL)
  • 每个角色的内存限制

MCP集成

  • 将角色作为MCP资源公开
  • 提供角色管理和查询处理工具
  • 提供基于角色的交互提示

入门指南

先决条件

  • Node.js 18+
  • OpenAI API密钥

安装

# Clone the repository
git clone https://github.com/yourusername/role-context-mcp.git
cd role-context-mcp

# Install dependencies
npm install

# Set up environment variables
echo "OPENAI_API_KEY=your_api_key_here" > .env

# Build the project
npm run build

运行服务器

# Run the MCP server
npm start

# Run the HTTP server for testing
npm run start:http

配置

可以通过修改来配置服务器 src/config.ts.关键配置选项包括:

  • 默认角色及其属性
  • 可用音调配置文件
  • 内存管理设置
  • OpenAI模型选择

MCP集成

资源

服务器公开以下资源:

  • role://{roleId} -关于特定角色的信息
  • role://tones -可用音调配置文件

工具

服务器提供以下工具:

  • process-with-role -使用特定角色处理查询
  • create-role -创建新角色
  • update-role -更新现有角色
  • delete-role -删除自定义角色
  • change-role-tone -改变角色的基调
  • store-memory -为特定角色存储内存
  • clear-role-memories -清除角色的所有记忆

鼓励

服务器提供以下提示:

  • role-{roleId} -使用特定角色处理请求
  • create-custom-role -创建新的自定义角色

示例用法

使用角色处理查询(MCP)

// Example of using the process-with-role tool
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)

// Example of using the 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);

创建自定义角色

// Example of using the create-role tool
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.'
  }
});

许可证

麻省理工学院