内容
# solana-onchain-mcp
[](https://crates.io/crates/solana-onchain-mcp)
[](https://opensource.org/licenses/MIT)
[](CHANGELOG.md)
Solana区块链操作的MCP服务器。
## 演示

## 安装
### 方法1:预编译二进制文件(推荐)
**警告:** 在执行脚本之前,请确保您了解bash脚本的作用
```bash
curl -fsSL https://raw.githubusercontent.com/widnyana/solana-onchain-mcp/refs/heads/main/install.sh | bash
```
这将下载适用于您平台的最新版本并安装到 `~/.local/bin`。
### 方法2:从crates.io安装
```bash
cargo install solana-onchain-mcp
```
### 方法3:从源代码构建
```bash
cargo install --git https://github.com/widnyana/solana-onchain-mcp
```
需要Rust 1.85+。
## 设置
首先启动服务器:
```bash
SOLANA_NETWORK=devnet solana-onchain-mcp --port 3000
```
### Claude 代码
`.mcp.json`:
```json
{
"mcpServers": {
"solana": {
"url": "http://localhost:3000/mcp"
}
}
}
```
### Cursor
`.cursor/mcp.json`:
```json
{
"mcpServers": {
"solana": {
"url": "http://localhost:3000/mcp"
}
}
}
```
### VS Code
`.vscode/mcp.json` (参见 [MCP Server 文档](https://code.visualstudio.com/docs/copilot/customization/mcp-servers)):
```json
{
"servers": {
"solana": {
"type": "http",
"url": "http://localhost:3000/mcp"
}
}
}
```
### 使用密钥对(用于转账)
使用密钥对支持启动服务器(仅限本地):
```bash
SOLANA_NETWORK=devnet SOLANA_KEYPAIR_PATH=/path/to/keypair.json \
solana-onchain-mcp --http-allow-keypair --accept-risk --host 127.0.0.1 --port 3000
```
然后将您的客户端连接到 `http://localhost:3000/mcp`。
## 工具(19)
### 读取(不需要密钥对)
| 工具 | 描述 |
|------|-------------|
| `get_balance` | 地址的SOL余额 |
| `get_account_info` | 账户数据和元数据 |
| `get_multiple_accounts` | 批量获取最多100个账户 |
| `get_token_accounts_by_owner` | 钱包的SPL代币账户 |
| `get_program_accounts` | 程序拥有的账户 |
| `get_transaction` | 交易签名 |
| `get_signatures_for_address` | 地址交易历史 |
| `get_signature_status` | 交易确认状态 |
| `get_slot` | 当前槽/区块高度 |
| `simulate_transaction` | 测试交易而不签名 |
| `inspect_transaction_raw` | 原始交易与程序名称 |
| `inspect_transaction_humanized` | 人类可读的交易摘要 |
| `get_server_info` | 服务器配置和网络信息 |
### 写入(需要密钥对)
| 工具 | 描述 |
|------|-------------|
| `transfer_sol` | 转账SOL |
| `transfer_token` | 转账SPL代币 |
| `create_associated_token_account` | 创建代币账户 |
| `approve_token` | 批准代币委托人 |
| `revoke_token` | 撤销代币委托人 |
| `close_token_account` | 关闭未使用的代币账户 |
### 主网使用
⚠️ **警告:** 主网操作涉及真实资产。请始终:
1. 在devnet上进行彻底测试
2. 使用具有最小资金的专用钱包
3. 验证所有交易参数
4. 设置 `SOLANA_ACCEPT_RISK=true` 或使用 `--accept-risk` 标志
有关详细信息,请参见 [主网使用](USAGE.md#mainnet-usage)。
## 文档
有关配置、参数和安全性的详细信息,请参见 [USAGE.md](USAGE.md)。
## 要求
- Rust 1.85+(版本2024)
- Solana RPC访问
## 许可证
MIT