AIChat MCP Server
将AIChat服务封装为MCP服务器,供Claude、Cursor等AI客户端调用,支持创建AI角色、管理会话、自动对话和搜索历史论战。
README
AIChat MCP Server
将 AIChat 服务封装为 MCP (Model Context Protocol) 服务器,供 Claude、Cursor 等 AI 客户端调用。
功能
AI 可以通过 MCP 工具调用你的 AIChat 服务:
- 创建AI角色用户
- 创建和管理会话
- 发送消息
- 启动/停止自动对话
- 搜索历史著名论战
认证
MCP Server 支持 3 种认证方式:
| 方式 | 环境变量 | 说明 |
|---|---|---|
| API Key | AICHAT_API_KEY |
推荐 - 需要在 AIChat 中预生成 API Key |
| 用户名密码 | AICHAT_USERNAME + AICHAT_PASSWORD |
自动登录获取 Token |
| 直接 Token | AICHAT_ACCESS_TOKEN |
直接使用已有的 Access Token |
生成 API Key
- 登录 AIChat 网页端
- 在浏览器控制台执行以下代码生成 API Key:
// 获取当前用户的 accessToken(登录后)
const token = localStorage.getItem('accessToken');
// 生成 API Key
fetch('/api/auth/api-key/generate', {
method: 'POST',
headers: { 'Authorization': 'Bearer ' + token }
}).then(r => r.json()).then(d => console.log('API Key:', d.apiKey));
或者使用 curl(需要先通过浏览器获取 token):
curl -X POST http://localhost:8080/api/auth/api-key/generate \
-H "Authorization: Bearer <your-jwt-token>"
配置示例
方式A: 使用 mcporter (推荐)
将配置添加到 C:\Users\renji\.mcporter\mcporter.json:
{
"mcpServers": {
"aichat": {
"command": "python",
"args": ["D:/AI Project/AIChat/AIChat-MCP/server.py"],
"env": {
"AICHAT_BASE_URL": "http://localhost:8080/api",
"AICHAT_API_KEY": "your-api-key-here"
}
}
}
}
方式B: Claude Desktop
编辑 ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"aichat": {
"command": "python",
"args": ["D:/AI Project/AIChat/AIChat-MCP/server.py"],
"env": {
"AICHAT_BASE_URL": "http://localhost:8080/api",
"AICHAT_USERNAME": "your-username",
"AICHAT_PASSWORD": "your-password"
}
}
}
}
方式C: 使用环境变量
# 方式1: API Key(推荐)
set AICHAT_API_KEY=your-api-key
set AICHAT_BASE_URL=http://localhost:8080/api
# 方式2: 用户名密码
set AICHAT_USERNAME=your-username
set AICHAT_PASSWORD=your-password
set AICHAT_BASE_URL=http://localhost:8080/api
# 方式3: 直接Token
set AICHAT_ACCESS_TOKEN=your-access-token
set AICHAT_BASE_URL=http://localhost:8080/api
python server.py
快速开始
1. 安装依赖
cd AIChat-MCP
pip install -r requirements.txt
2. 配置认证
设置环境变量或直接在 mcporter 配置中添加认证信息。
3. 启动 MCP Server
python server.py
可用工具
| 工具 | 说明 |
|---|---|
list_users |
列出所有AI角色用户 |
create_user |
创建新的AI角色 |
get_user |
根据ID获取用户详情 |
get_user_by_name |
根据名称获取用户详情 |
list_sessions |
列出所有会话 |
create_session |
创建新会话 |
get_session |
获取会话详情和消息 |
start_chat |
启动自动对话 |
stop_chat |
停止对话 |
delete_session |
删除会话 |
clear_messages |
清空消息 |
search_famous_debates |
搜索历史著名论战 |
使用示例
命令行测试
# 列出所有工具
mcporter list aichat
# 列出用户
mcporter call aichat.list_users
# 根据名称查找用户
mcporter call aichat.get_user_by_name name:=牛顿
# 根据ID查找用户
mcporter call aichat.get_user userId:=1
# 搜索历史论战
mcporter call aichat.search_famous_debates "query=物理"
# 创建用户
mcporter call aichat.create_user name:=牛顿 displayName:=艾萨克·牛顿 modelType:=QWEN rolePrompt:=你是艾萨克·牛顿,英国物理学家
# 创建会话
mcporter call aichat.create_session name:=牛顿vs胡克 sessionTheme:=关于万有引力优先权的争论
# 获取会话详情
mcporter call aichat.get_session sessionId:=1
让 AI 创建历史人物对话
用户: 帮我创建一个关于牛顿和胡克万有引力争论的对话
AI 会自动:
- 调用
search_famous_debates搜索相关论战 - 调用
create_user创建"牛顿"用户 - 调用
create_user创建"胡克"用户 - 调用
create_session创建会话 - 调用
start_chat启动自动对话
搜索历史论战
用户: 找出物理学上著名的论战
AI 会调用 search_famous_debates 返回预设的历史著名论战列表。
配置
修改后端地址
# 方式1: 环境变量
set AICHAT_BASE_URL=http://localhost:8080/api
python server.py
# 方式2: 直接修改 server.py 中的 BASE_URL
BASE_URL = "http://your-server:8080/api"
项目结构
AIChat-MCP/
├── server.py # MCP Server 主程序
├── requirements.txt # Python 依赖
└── README.md # 说明文档
依赖
- Python 3.8+
- mcp >= 1.0.0
- requests >= 2.31.0
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.