Skip to content

Commit 303a263

Browse files
committed
refactor(mcp): 迁移至官方SDK并增强可靠性
- 使用@modelcontextprotocol/sdk替换自定义传输实现 - 实现错误分类与自动重连机制 - 添加指数退避重试策略 - 支持OAuth 2.0认证 - 引入健康监控系统 - 改进模式验证与错误恢复 docs: 更新MCP改进文档记录变更
1 parent fb3c8e5 commit 303a263

20 files changed

Lines changed: 686 additions & 236 deletions

File tree

README.en.md

Lines changed: 35 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ English | [简体中文](README.md)
2121
<tr>
2222
<td width="50%" valign="top">
2323
<h3>🤖 Intelligent Conversations</h3>
24-
<p>Natural language interactions powered by LLMs with context understanding and multi-turn dialogues. Simply run <code>blade "task"</code> to launch the UI and auto-send your first message.</p>
24+
<p>Natural language interactions powered by LLMs with context understanding and multi-turn dialogues. Simply run <code>blade</code> to launch the interactive UI.</p>
2525
</td>
2626
<td width="50%" valign="top">
2727
<h3>🛠️ Rich Toolset</h3>
@@ -100,16 +100,27 @@ blade --print "Hello, introduce yourself"
100100

101101
Blade Code supports multiple LLM providers. You need to configure the appropriate API key:
102102

103-
### Method 1: Environment Variables (Recommended)
103+
### Method 1: Configuration File (Recommended)
104104

105105
```bash
106-
# Qwen (Alibaba Cloud)
107-
export QWEN_API_KEY="your-qwen-api-key"
108-
export BLADE_BASE_URL="https://dashscope.aliyuncs.com/compatible-mode/v1"
109-
110-
# VolcEngine
111-
export VOLCENGINE_API_KEY="your-volcengine-api-key"
112-
export BLADE_BASE_URL="https://ark.cn-beijing.volces.com/api/v3"
106+
# Create user-level configuration file
107+
mkdir -p ~/.blade
108+
cat > ~/.blade/config.json << 'EOF'
109+
{
110+
"provider": "openai-compatible",
111+
"apiKey": "your-api-key",
112+
"baseUrl": "https://dashscope.aliyuncs.com/compatible-mode/v1",
113+
"model": "qwen-max"
114+
}
115+
EOF
116+
117+
# Or use environment variable interpolation in config file
118+
cat > ~/.blade/config.json << 'EOF'
119+
{
120+
"apiKey": "${BLADE_API_KEY}",
121+
"baseUrl": "${BLADE_BASE_URL:-https://apis.iflow.cn/v1}"
122+
}
123+
EOF
113124
```
114125

115126
### Method 2: First-Run Setup Wizard (Recommended Experience)
@@ -119,23 +130,13 @@ blade
119130
# If no API key is configured, an interactive wizard will guide you through Provider, Base URL, API Key, and model setup.
120131
```
121132

122-
### Method 3: Command Line Arguments
133+
### Method 3: Config Command
123134

124135
```bash
125-
blade --api-key your-api-key --base-url https://api.example.com "Hello"
136+
# Use config command to manage configuration
137+
blade config
126138
```
127139

128-
### Method 4: Configuration File
129-
130-
```bash
131-
# User-level configuration
132-
mkdir -p ~/.blade
133-
nano ~/.blade/config.json
134-
135-
# Project-level configuration
136-
mkdir -p .blade
137-
nano .blade/config.json
138-
```
139140

140141
### Get API Keys
141142

@@ -152,38 +153,33 @@ nano .blade/config.json
152153
# Interactive mode (default)
153154
blade
154155

155-
# Direct message (automatically sent once the UI is ready)
156-
blade "What is artificial intelligence?"
157-
158-
# Code generation
159-
blade "Write a debounce function in JavaScript"
156+
# Non-interactive quick answer (print mode)
157+
blade --print "What is artificial intelligence?"
160158

161-
# Non-interactive quick answer
162-
blade --print "Summarize the repo in one sentence"
159+
# Code generation (print mode)
160+
blade --print "Write a debounce function in JavaScript"
163161
```
164162

165-
> Any message passed as `blade "..."` is automatically injected and executed once the interactive UI finishes initializing—no extra keystrokes required.
166-
167163
### Smart Tool Invocation
168164

169165
Blade Code automatically selects appropriate tools based on your needs:
170166

171167
```bash
172-
# File operations
173-
blade "List all TypeScript files in the current directory"
168+
# File operations (print mode)
169+
blade --print "List all TypeScript files in the current directory"
174170

175-
# Git operations
176-
blade "Show the last 5 commit logs"
171+
# Git operations (print mode)
172+
blade --print "Show the last 5 commit logs"
177173

178-
# Code review (non-interactive example)
174+
# Code review (print mode)
179175
blade --print "Review code quality in src/utils directory"
180176
```
181177

182178
### Session Management
183179

184180
```bash
185-
# Create or use named session
186-
blade --session-id "project-alpha" "Start new project"
181+
# Create or use named session (print mode)
182+
blade --session-id "project-alpha" --print "Start new project"
187183

188184
# Continue recent session
189185
blade --continue
@@ -253,9 +249,6 @@ blade doctor
253249

254250
# Check for updates
255251
blade update
256-
257-
# Set up authentication token
258-
blade setup-token
259252
```
260253

261254
### AI Model Options
@@ -322,21 +315,18 @@ blade --setting-sources "global,user,local"
322315

323316
| Command | Description | Example |
324317
|---------|-------------|---------|
325-
| `blade [message..]` | Send message or launch interactive mode (default) | `blade "Hello"` |
318+
| `blade` | Start interactive AI assistant (default) | `blade` |
326319
| `blade config` | Configuration management | `blade config` |
327320
| `blade mcp` | Configure and manage MCP servers | `blade mcp` |
328321
| `blade doctor` | System health check | `blade doctor` |
329322
| `blade update` | Check and install updates | `blade update` |
330323
| `blade install [target]` | Install specific version (stable/latest/version) | `blade install latest` |
331-
| `blade setup-token` | Set up authentication token | `blade setup-token` |
332-
| `blade completion` | Generate shell completion script | `blade completion` |
333324

334325
### Debug Options
335326

336327
| Option | Short | Description |
337328
|--------|-------|-------------|
338329
| `--debug [category]` | `-d` | Enable debug mode with optional category filtering |
339-
| `--verbose` | | Enable verbose output mode |
340330

341331
### Output Options
342332

README.md

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,27 @@ blade --print "你好,介绍一下自己"
109109

110110
Blade Code 支持多种 LLM 提供商,您需要配置相应的 API 密钥:
111111

112-
### 方式一:环境变量(推荐)
112+
### 方式一:配置文件(推荐)
113113

114114
```bash
115-
# 千问(阿里云)
116-
export QWEN_API_KEY="your-qwen-api-key"
117-
export BLADE_BASE_URL="https://dashscope.aliyuncs.com/compatible-mode/v1"
115+
# 创建用户级配置文件
116+
mkdir -p ~/.blade
117+
cat > ~/.blade/config.json << 'EOF'
118+
{
119+
"provider": "openai-compatible",
120+
"apiKey": "your-api-key",
121+
"baseUrl": "https://dashscope.aliyuncs.com/compatible-mode/v1",
122+
"model": "qwen-max"
123+
}
124+
EOF
118125

119-
# 火山引擎
120-
export VOLCENGINE_API_KEY="your-volcengine-api-key"
121-
export BLADE_BASE_URL="https://ark.cn-beijing.volces.com/api/v3"
126+
# 或在配置文件中使用环境变量插值
127+
cat > ~/.blade/config.json << 'EOF'
128+
{
129+
"apiKey": "${BLADE_API_KEY}",
130+
"baseUrl": "${BLADE_BASE_URL:-https://apis.iflow.cn/v1}"
131+
}
132+
EOF
122133
```
123134

124135
### 方式二:首启设置向导(推荐体验)
@@ -128,24 +139,11 @@ blade
128139
# 若未配置 API Key,将自动引导完成 Provider、Base URL、API Key、模型的填写
129140
```
130141

131-
### 方式三:命令行参数
142+
### 方式三:配置命令
132143

133144
```bash
134-
blade --api-key your-api-key --base-url https://api.example.com "你好"
135-
```
136-
137-
### 方式四:配置文件
138-
139-
```bash
140-
# 用户级配置
141-
mkdir -p ~/.blade
142-
nano ~/.blade/config.json
143-
144-
# 项目级配置(提交到仓库)
145-
mkdir -p .blade
146-
nano .blade/config.json
147-
# 或者为当前机器准备不提交的设置
148-
nano .blade/settings.local.json
145+
# 使用 config 命令管理配置
146+
blade config
149147
```
150148

151149
### 获取 API 密钥
@@ -259,9 +257,6 @@ blade doctor
259257

260258
# 检查更新
261259
blade update
262-
263-
# 设置认证令牌
264-
blade setup-token
265260
```
266261

267262
### AI 模型选项
@@ -352,21 +347,18 @@ blade --setting-sources "global,user,local"
352347

353348
| 命令 | 说明 | 示例 |
354349
|------|------|------|
355-
| `blade [message..]` | 发送消息或启动交互式界面(默认) | `blade "你好"` |
350+
| `blade` | 启动交互式 AI 助手(默认) | `blade` |
356351
| `blade config` | 配置管理 | `blade config` |
357352
| `blade mcp` | 配置和管理 MCP 服务器 | `blade mcp` |
358353
| `blade doctor` | 系统健康检查 | `blade doctor` |
359354
| `blade update` | 检查更新并安装 | `blade update` |
360355
| `blade install [target]` | 安装指定版本(stable/latest/版本号) | `blade install latest` |
361-
| `blade setup-token` | 设置认证令牌 | `blade setup-token` |
362-
| `blade completion` | 生成 shell 补全脚本 | `blade completion` |
363356

364357
### 调试选项
365358

366359
| 选项 | 简写 | 说明 |
367360
|------|------|------|
368361
| `--debug [category]` | `-d` | 启用调试模式,可选分类过滤 |
369-
| `--verbose` | | 启用详细输出模式 |
370362

371363
### 输出选项
372364

0 commit comments

Comments
 (0)