Dart语言服务器

为Claude Code提供的Dart语言服务器MCP实现,具备实时错误检测、智能代码补全和文档查看等功能。

  • by coco-de
  • Dart
  • 本地部署
  • 2 星标
  • 更新于
在 GitHub 查看 coco-de/dart-lsp

使用说明

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<Book> getBook(Session session, int id) async {
    // 'db-find' 입력 시 쿼리 템플릿 제안
    return await Book.db.findById(session, id);
  }
}

碧玉

class HomePage extends StatelessComponent {
  @override
  Iterable<Component> 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条款


由以下材料制成❤️ 通过 科科德