Dart LSP MCP服务器
Claude Code的Dart Language Server MCP实现。
🚀 安装
远程安装(建议)
curl -fsSL https://raw.githubusercontent.com/coco-de/dart-lsp/main/install.sh | bash自动执行以下操作:
- 下载适用于OS/体系结构的二进制文件
~/.local/bin/dart-lsp-mcp在中安装- 在Claude Code设置中注册MCP服务器
支持平台: 平台架构状态 |--------|----------|------| |macOS | arm64(苹果硅)|✅ | |Linux | x64 |✅ | | macOS | x64 (Intel) | 🚧 (需要构建源代码)| | Windows | x64 | 🚧 (需要构建源代码)|
验证安装
# 바이너리 확인
~/.local/bin/dart-lsp-mcp --version
# MCP 도구 목록 확인
echo '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' | ~/.local/bin/dart-lsp-mcp更新
重新运行安装脚本将更新到最新版本:
curl -fsSL https://raw.githubusercontent.com/coco-de/dart-lsp/main/install.sh | bash从源构建
git clone https://github.com/coco-de/dart-lsp.git
cd dart-lsp
make install要求:Dart SDK 3.10.3+
🎯 特点
- 实时错误检测:在编写代码时立即发现问题
- 智能自动完成:按框架定制建议
- 文档管理器:立即查看API文档
- 代码格式化:自动应用Dart官方样式
- 框架支持:Flutter、Serverpod、Jaspr、Riverpod
🛠️ MCP工具
| 工具 | 说明 |
|---|---|
dart_analyze | 代码分析和错误/警告返回 |
dart_complete | 自动完成建议 |
dart_hover | 元件文档/类型信息 |
dart_definition | 转到定义 |
dart_format | 代码格式化 |
dart_symbols | 文档结构(大纲) |
dart_code_actions | 快速修复/重新构建 |
dart_add_workspace | 添加工作空间 |
📋 工作流
1. 프로젝트 열기
→ dart_add_workspace로 워크스페이스 등록
2. 코드 작성 중
→ dart_complete로 정확한 API 확인
→ dart_hover로 문서 확인
3. 작성 완료
→ dart_analyze로 에러 검증
→ dart_format으로 포맷팅
4. 문제 발견 시
→ dart_code_actions로 빠른 수정🎨 特定于框架的支持
服务器吊舱
class BookEndpoint extends Endpoint {
// 'endpoint-method' 입력 시 템플릿 제안
Future getBook(Session session, int id) async {
// 'db-find' 입력 시 쿼리 템플릿 제안
return await Book.db.findById(session, id);
}
}碧玉
class HomePage extends StatelessComponent {
@override
Iterable build(BuildContext context) sync* {
yield div(classes: 'container', [
// HTML 요소 자동완성
]);
}
}Flutter+Riverpod
class MyWidget extends ConsumerWidget {
// 'provider', 'futureprovider' 템플릿 제안
@override
Widget build(BuildContext context, WidgetRef ref) {
final state = ref.watch(myProvider);
return Container();
}
}📁 项目结构
dart-lsp/
├── bin/
│ ├── mcp_server.dart # MCP 서버 진입점
│ └── server.dart # LSP 서버 (독립 실행용)
├── lib/src/
│ ├── analyzer_service.dart
│ ├── document_manager.dart
│ ├── completions/ # 자동완성
│ ├── diagnostics/ # 진단
│ ├── navigation/ # 코드 탐색
│ ├── formatting/ # 포맷팅
│ ├── serverpod/ # Serverpod 지원
│ ├── jaspr/ # Jaspr 지원
│ ├── flutter/ # Flutter 지원
│ └── dcm/ # DCM 규칙
├── .github/workflows/
│ └── release.yml # 자동 빌드/릴리스
├── install.sh # 원격 설치 스크립트
├── build.sh # 로컬 빌드 스크립트
└── Makefile # 빌드 자동화🐛 故障排除
MCP服务器未响应
# 바이너리 위치 확인
which dart-lsp-mcp
# 수동 테스트
echo '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' | ~/.local/bin/dart-lsp-mcp检查Claude Code设置
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json Linux: ~/.config/claude/claude_desktop_config.json
{
"mcpServers": {
"dart-lsp": {
"command": "/Users/yourname/.local/bin/dart-lsp-mcp",
"args": [],
"env": {}
}
}
}更改设置后重新启动
# Claude Code 재시작 필요📄 许可证
BSD-3条款
______________________________________________________________________
由以下材料制成❤️ 通过 科科德
