本 MCP 服务器为 AI 代理提供基于角色的上下文管理,能为不同角色的 AI 代理设定清晰指示、目标和领域知识,对角色相关记忆进行分区管理,还可根据角色动态调整语气风格,有效提升 AI 交互的专业性和针对性。
# 克隆仓库
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
通过修改 src/config.ts 可以配置服务器。关键配置选项包括:
# 克隆仓库
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
通过修改 src/config.ts 可以配置服务器。关键配置选项包括:
// 使用 process-with-role 工具的示例
const result = await client.executeToolRequest({
name: 'process-with-role',
parameters: {
roleId: 'marketing-expert',
query: '如何提高我的社交媒体参与度?',
customInstructions: '专注于 B2B 策略'
}
});
// 使用 HTTP API 的示例
const response = await axios.post('http://localhost:3000/process', {
roleId: 'marketing-expert',
query: '如何提高我的社交媒体参与度?',
customInstructions: '专注于 B2B 策略'
});
// 使用 create-role 工具的示例
const result = await client.executeToolRequest({
name: 'create-role',
parameters: {
roleId: 'creative-writer',
instructions: '生成有创意的故事点子'
}
});
服务器公开以下资源:
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 - 创建新自定义角色[此处插入许可证信息]