内容
# Warpcast MCP Server
一个用于Warpcast集成的模型上下文协议(Model Context Protocol,MCP)服务器,允许您使用Claude与您的Warpcast账户进行交互。
## 特性
- 向您的Warpcast账户发布内容
- 从Warpcast读取内容
- 按关键字或标签搜索内容
- 浏览和互动频道
- 关注/取消关注频道
- 获取热门内容
## 设置
1. 克隆此仓库
```bash
git clone https://github.com/zhangzhongnan928/mcp-warpcast-server.git
cd mcp-warpcast-server
```
2. 安装依赖
```bash
npm install
```
3. 生成API密钥并配置身份验证
此MCP服务器提供了一个辅助脚本来生成所需的Ed25519密钥对:
```bash
npm run generate-keys
```
按照提示操作:
- 生成一个随机的Ed25519密钥对
- 将密钥保存到您的`.env`文件中
- 获取有关如何在Warpcast中注册密钥的说明
或者,如果您更喜欢手动设置:
### 选项1:使用签名密钥请求
1. 生成一个Ed25519密钥对
2. 使用Warpcast签名密钥请求API请求权限,以代表您的账户签名消息
3. 在Warpcast应用中完成授权
下面是一个示例实现:
```typescript
import * as ed from '@noble/ed25519';
import { mnemonicToAccount, signTypedData } from 'viem/accounts';
import axios from 'axios';
// 生成密钥对
const privateKey = ed.utils.randomPrivateKey();
const publicKeyBytes = await ed.getPublicKey(privateKey);
const key = '0x' + Buffer.from(publicKeyBytes).toString('hex');
// EIP-712域和类型用于SignedKeyRequest
const SIGNED_KEY_REQUEST_VALIDATOR_EIP_712_DOMAIN = {
name: 'Farcaster SignedKeyRequestValidator',
version: '1',
chainId: 10,
verifyingContract: '0x00000000fc700472606ed4fa22623acf62c60553',
};
const SIGNED_KEY_REQUEST_TYPE = [
{ name: 'requestFid', type: 'uint256' },
{ name: 'key', type: 'bytes' },
{ name: 'deadline', type: 'uint256' },
];
// 生成签名密钥请求签名
const appFid = process.env.APP_FID;
const account = mnemonicToAccount(process.env.APP_MNEMONIC);
const deadline = Math.floor(Date.now() / 1000) + 86400; // 签名有效期为1天
const signature = await account.signTypedData({
domain: SIGNED_KEY_REQUEST_VALIDATOR_EIP_712_DOMAIN,
types: {
SignedKeyRequest: SIGNED_KEY_REQUEST_TYPE,
},
primaryType: 'SignedKeyRequest',
message: {
requestFid: BigInt(appFid),
key,
deadline: BigInt(deadline),
},
});
// 创建签名密钥请求
const warpcastApi = 'https://api.warpcast.com';
const { token, deeplinkUrl } = await axios
.post(`${warpcastApi}/v2/signed-key-requests`, {
key,
requestFid: appFid,
signature,
deadline,
})
.then((response) => response.data.result.signedKeyRequest);
console.log('深度链接URL:', deeplinkUrl);
console.log('在安装了Warpcast的移动设备上打开此URL以授权此密钥');
```
### 选项2:使用现有的应用密钥
如果您已经为您的Farcaster账户设置了应用密钥,您可以直接使用FID、私钥和公钥。
4. 构建服务器
```bash
npm run build
```
5. 配置Claude for Desktop以使用此服务器
## 与Claude for Desktop的配置
将以下内容添加到您的`claude_desktop_config.json`中:
```json
{
"mcpServers": {
"warpcast": {
"command": "node",
"args": [
"/absolute/path/to/mcp-warpcast-server/build/index.js"
],
"env": {
"WARPCAST_FID": "your_fid_here",
"WARPCAST_PRIVATE_KEY": "your_private_key_here",
"WARPCAST_PUBLIC_KEY": "your_public_key_here"
}
}
}
}
```
将`/absolute/path/to/mcp-warpcast-server`替换为您克隆此仓库的实际绝对路径,并用您的实际凭据更新环境变量。
## 使用
配置完成后,您可以要求Claude:
- “发布关于[主题]的内容”
- “读取[用户名]的最新内容”
- “搜索关于[主题]的内容”
- “向我展示Warpcast上的热门内容”
- “向我展示Warpcast上的热门频道”
- “从[channel]频道获取内容”
- “为我关注[channel]频道”
## 可用工具
此MCP服务器提供了几个Claude可以使用的工具:
1. **post-cast**:在Warpcast上创建新帖子(最多320个字符)
2. **get-user-casts**:检索特定用户的最近内容
3. **search-casts**:按关键字或短语搜索内容
4. **get-trending-casts**:获取当前在Warpcast上热门的内容
5. **get-all-channels**:列出Warpcast上可用的频道
6. **get-channel**:获取特定频道的信息
7. **get-channel-casts**:获取特定频道的内容
8. **follow-channel**:关注一个频道
9. **unfollow-channel**:取消关注一个频道
## 身份验证说明
此服务器使用Warpcast的应用密钥身份验证方法,需要与您的Farcaster账户注册的Ed25519密钥对。身份验证流程如下:
1. 创建一个包含您的FID和公钥的头部
2. 创建一个带有过期时间的有效负载
3. 使用您的私钥签名头部和有效负载
4. 使用生成的令牌进行API调用
在生产应用中,建议使用官方的Farcaster SDK来生成身份验证令牌。
## 安全考虑
- 保持您的私钥安全,绝不要分享
- 考虑定期更换您的密钥
- 服务器记录身份验证错误以帮助调试
## 故障排除
如果您遇到问题:
1. 检查您的环境变量是否设置正确
2. 确保您的密钥已正确注册到您的Farcaster账户
3. 检查Claude for Desktop日志以获取任何错误
4. 验证您的Warpcast账户是否具有必要的权限
## 许可证
MIT