《Crush 从入门到精通》第六、七章:LSP与MCP集成
第六章:LSP 集成
LSP 简介
LSP(Language Server Protocol) 是微软推出的语言服务器协议,用于为编程语言提供智能编辑功能。
┌─────────┐ ┌─────────────────┐ ┌─────────┐
│ Editor │◀──────▶│ LSP Client │◀──────▶│ LSP │
│ (Crush) │ │ (Crush 内置) │ │ Server │
└─────────┘ └─────────────────┘ └─────────┘
配置 LSP 服务器
全局配置
lsp:
# Go 语言服务器
gopls:
command: "gopls"
enabled: true
options:
gofumpt: true
# TypeScript/JavaScript
tsserver:
command: "typescript-language-server"
args: ["--stdio"]
file_types: ["typescript", "javascript"]
# Python
pyright:
command: "pyright-langserver"
args: ["--stdio"]
file_types: ["python"]
# Rust
rust_analyzer:
command: "rust-analyzer"
file_types: ["rust"]
代码诊断
# 请求诊断
crush> 检查当前文件的代码问题
# 诊断结果
src/main.go:15:2 - error: undefined: fmt.Println (using gopls)
src/utils.go:23:10 - warning: unused parameter 'ctx'
第七章:MCP 扩展
MCP 协议概述
MCP(Model Context Protocol) 是一个开放协议,允许 AI 模型与外部工具和数据源连接。
┌─────────────┐ ┌─────────────────┐
│ AI Model │◀──────▶│ MCP Client │
│ (Crush) │ │ (Crush 内置) │
└─────────────┘ └────────┬────────┘
│
│ JSON-RPC 2.0
▼
┌──────────────────────────────────────────────────────────────┐
│ MCP Server │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ filesystem │ │ github │ │ sqlite │ │
│ │ server │ │ server │ │ server │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
└──────────────────────────────────────────────────────────────┘
配置 MCP 服务器
STDIO 类型服务器
mcp:
servers:
filesystem:
command: "npx"
args:
- "-y"
- "@modelcontextprotocol/server-filesystem"
- "/home/user/projects"
github:
command: "npx"
args:
- "-y"
- "@modelcontextprotocol/server-github"
env:
GITHUB_TOKEN: "\({GITHUB_TOKEN}"
```
---
### MCP 工具使用
```bash
# 列出所有可用的 MCP 工具
crush> 列出所有可用的 MCP 工具
# 使用 GitHub MCP 工具
crush> 在 github 仓库 charmbracelet/crush 中创建一个 issue
# 使用 Filesystem MCP 工具
crush> 列出 /home/user/projects 目录下的所有 Go 文件
```
---
### 实战案例:GitHub 集成
```yaml
mcp:
servers:
github:
command: "npx"
args:
- "-y"
- "@modelcontextprotocol/server-github"
env:
GITHUB_TOKEN: "\){GITHUB_TOKEN}"
使用示例:
crush> 查看 crush 仓库的最新 5 个 closed issues
crush> 在当前项目创建一个 PR,标题为 "feat: 添加新功能"
crush> 搜索仓库中与 "authentication" 相关的代码
本文是《Crush 从入门到精通》系列的第六、七章
登录后可参与表态
讨论回复
0 条回复还没有人回复,快来发表你的看法吧!
推荐
推荐
智谱 GLM-5 已上线
我正在智谱大模型开放平台 BigModel.cn 上打造 AI 应用,智谱新一代旗舰模型 GLM-5 已上线,在推理、代码、智能体综合能力达到开源模型 SOTA 水平。
领取 2000万 Tokens
通过邀请链接注册即可获得大礼包,期待和你一起在 BigModel 上畅享卓越模型能力