内容
# Carrot Protocol MCP Server
一个 MCP(Model Context Protocol)服务器,支持通过 AI 与 Carrot Protocol 进行交互 - Carrot Protocol 是一个基于 Solana 的 DeFi 生息代币系统。
## 这是什么?
该项目提供了 Claude AI 和 Carrot Protocol 之间的桥梁,允许用户:
- **存入稳定币 (USDC)** 以铸造 CRT (Carrot Protocol Token)
- 将存款分配给借贷协议(Marginfi、Kamino、Mango)来**赚取收益**
- **赎回 CRT** 以提取本金和累计收益
- 通过 Claude 使用对话式 AI 进行**自然交互**
## 架构
```
┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ User │────▶│ CLI Client │────▶│ MCP Server │────▶│ Carrot │
│ (Natural │ │ + Claude │ │ (Express) │ │ Protocol │
│ Language) │◀────│ AI │◀────│ │◀────│ API │
└─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘
```
## 快速开始
### 前提条件
- Node.js 22+
- npm
- 用于签署交易的 Solana 密钥对(JSON 文件)
- Anthropic API 密钥
### 设置
```bash
cd client
npm install
npm run build
```
创建一个 `.env.local` 文件:
```env
MCP_SERVER_URL=https://mcp.deficarrot.com/mcp
ANTHROPIC_MODEL_API_KEY=your-anthropic-api-key
```
将您的 Solana 密钥对文件作为 `user1.json` 放置在客户端目录中。
运行客户端:
```bash
npm run local
```
## 客户端命令
客户端运行后,您可以使用以下命令:
| Command | Description |
|---------|-------------|
| `send <query>` | 向 Claude 发送自然语言查询 |
| `list-tools` | 显示可用的 MCP 工具 |
| `list-resources` | 显示可用的 MCP 资源 |
| `list-prompts` | 显示可用的 MCP 提示词 |
| `get-prompt <name>` | 执行预定义的流程 |
| `read-resource <uri>` | 阅读协议文档 |
| `help` | 显示所有命令 |
| `exit` | 退出客户端 |
### 示例互动
```
> send What is the current APY for CRT?
> send I want to deposit 100 USDC
> send Redeem all my CRT tokens
> get-prompt check_yield
```
## 可用的 MCP 工具
| Tool | Description |
|------|-------------|
| `get_crt_apy` | 获取当前收益 (APY) |
| `issue_crt` | 通过指定 CRT 数量来铸造 CRT |
| `issue_crt_with_usdc` | 通过指定 USDC 数量来铸造 CRT |
| `issue_all_crt` | 使用全部 USDC 余额来铸造 CRT |
| `redeem_crt` | 按数量赎回 CRT |
| `redeem_crt_for_usdc` | 赎回以获得特定的 USDC 数量 |
| `redeem_all_crt` | 赎回全部 CRT 余额 |
## 配置
### MCP Server
生产环境 MCP 服务器托管在:
```
https://mcp.deficarrot.com/mcp
```
### 区块链地址
| Token | Address |
|-------|---------|
| CRT | `CRTx1JouZhzSU6XytsE42UQraoGqiHgxabocVfARTy2s` |
| USDC | `EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v` |
## 测试 MCP Server
验证服务器是否正在运行:
```bash
# Health check - returns server info
curl https://mcp.deficarrot.com/
# Initialize an MCP session
curl -X POST https://mcp.deficarrot.com/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {"name": "test", "version": "1.0.0"}
},
"id": 1
}'
# List available tools (use mcp-session-id from initialize response)
curl -X POST https://mcp.deficarrot.com/mcp \
-H "Content-Type: application/json" \
-H "mcp-session-id: <SESSION_ID>" \
-d '{"jsonrpc": "2.0", "method": "tools/list", "id": 2}'
```
## 安全
- 交易签名仅在客户端进行
- 私钥永远不会离开客户端
- 生产环境中强制使用 HTTPS
- 基于会话的身份验证,超时时间为 24 小时
## 开发
对于从事服务器或基础设施的贡献者:
### 仓库结构
```
mcp-server/
├── server/ # MCP Server - Express.js 后端
├── client/ # 带有 Claude AI 的交互式 CLI
├── infra/ # AWS CDK 基础设施
└── llm/ # LLM 配置文件
```
### 本地服务器开发
```bash
cd server
npm install
npm run build
npm start # Starts on http://localhost:8080
```
### 格式化
```bash
make fmt # Format code
make fmt_check # Check formatting
```
## 许可证
MIT