Flutter弃用MCP服务器
此MCP服务器跟踪Flutter API的弃用情况,并提供工具来检查代码中弃用的API并建议替换。
项目结构
flutter-deprecations-server/
├── cmd/
│ └── server/ # Main application entry point
│ └── main.go
├── internal/ # Private application code
│ ├── handlers/ # MCP tool handlers
│ │ ├── mcp_handlers.go
│ │ ├── mcp_handlers_test.go
│ │ └── testdata/
│ ├── models/ # Data structures
│ │ └── flutter.go
│ └── services/ # Business logic
│ ├── cache.go
│ ├── cache_test.go
│ ├── deprecations.go
│ ├── deprecations_test.go
│ ├── flutter_api.go
│ ├── flutter_api_test.go
│ ├── flutter_version.go
│ ├── interfaces.go
│ ├── version_info.go
│ ├── version_info_test.go
│ └── testdata/
├── pkg/ # Public libraries
│ └── config/ # Configuration constants
│ └── config.go
├── bin/ # Compiled binaries
├── Makefile # Build automation
├── go.mod # Go module definition
├── go.sum # Dependency checksums
└── README.md特性
- 基于源代码的弃用跟踪:直接扫描Flutter的GitHub源代码
@Deprecated注释 - 本地缓存:以24小时缓存时间在本地存储弃用
- 代码分析:分析Flutter代码片段中弃用的API
- 更换建议:为已弃用的API提供现代替代方案
- 全面扫描:扫描Flutter的关键目录(小部件、材料、cupertino、服务等)
- 版本检查:使用Flutter CLI(最可靠)和GitHub API回退获取最新的Flutter版本
- 多平台支持:检查FVM和Docker映像的可用性
- 命令行缓存管理:手动缓存更新和清除,并显示进度报告
- 短命令选项:支持长命令标志和短命令标志
- 费率限制处理:通过有用的错误消息优雅地处理GitHub API速率限制
- 详细日志记录:详细日志记录
-vvv故障排除标志
MCP工具
1. check_flutter_deprecations
分析已弃用API的Flutter代码,并提出替换建议。
参数:
code(string):要分析的Flutter代码片段
例子:
Color.red.withOpacity(0.5) // Will suggest Color.red.withValues(alpha: 0.5)2. list_flutter_deprecations
从缓存中列出所有已知的Flutter弃用。
参数: 无
退货: 完整的弃用列表,包括替换和版本信息。
3. check_flutter_version_info
获取最新稳定的Flutter版本,并检查不同工具和平台的可用性。
参数: 无
退货:
- 最新稳定的Flutter版本(可用时使用Flutter CLI,GitHub API回退)
- Flutter CLI安装状态和通道信息
- FVM安装状态和版本可用性
- Docker镜像可用性
instrumentisto/flutter和ghcr.io/cirruslabs/flutter - 使用示例和安装命令
已知的弃用
服务器包括常见弃用的内置模式:
Color.withOpacity()→Color.withValues(alpha:)RaisedButton→ElevatedButtonFlatButton→TextButtonOutlineButton→OutlinedButtonScaffold.of(context).showSnackBar→ScaffoldMessenger.of(context).showSnackBar
安装
使用Makefile(推荐)
# Install dependencies
make deps
# Build the server
make build
# Run the server
make run
# Build for multiple platforms
make build-all手动构建
# Install dependencies
go mod tidy
# Build the server
go build -o bin/flutter-deprecations-server ./cmd/server
# Run the server
./bin/flutter-deprecations-server
# Update deprecations cache manually
./bin/flutter-deprecations-server --update
# Update with verbose logging
./bin/flutter-deprecations-server --update -vvv
# Clear deprecations cache
./bin/flutter-deprecations-server --clear-cache
# Show current cache contents
./bin/flutter-deprecations-server --show-cache
# Show help information
./bin/flutter-deprecations-server --help发展
# Format code
make fmt
# Vet code
make vet
# Run tests
make test
# Development build and run
make dev使用AI助手进行配置
添加到您的MCP配置中(例如。, mcp.json):
{
"mcpServers": {
"flutter-deprecations": {
"command": "/path/to/flutter-deprecations-server/bin/flutter-deprecations-server",
"args": [],
"env": {}
}
}
}版本检测
服务器使用可靠的多层方法来检测最新的Flutter版本:
- 主要的,重要的:Flutter命令行界面(
flutter --version)-最准确,符合开发人员环境 - API官方:Google Storage Flutter发布API(
https://storage.googleapis.com/flutter_infra_release/releases/releases_linux.json)-比GitHub更快、更可靠 - 后备方案:GitHub API版本-当Flutter CLI和官方API都不可用时使用
- 信道检测:从官方来源识别稳定/测试/开发渠道
- Docker注册表支持:检查Docker Hub和GitHub容器注册表
缓存位置
弃用缓存在: ~/.flutter-deprecations/flutter_deprecations.json
使用工具时,缓存每24小时自动更新一次。
使用示例
问你的AI助手:
- “检查Flutter代码是否弃用:
Color.red.withOpacity(0.5)" - “列出所有Flutter弃用”
- “我应该用什么来代替RaisedButton?”
- “Flutter的最新版本是什么?它在FVM和Docker中可用吗?”
- “检查Flutter版本信息”
命令行用法
服务器支持多种用于缓存管理的命令行选项:
# Show help and available options
./bin/flutter-deprecations-server --help
./bin/flutter-deprecations-server -h # Short version
# Update deprecations cache with progress reporting
./bin/flutter-deprecations-server --update
./bin/flutter-deprecations-server -u # Short version
# Update with verbose logging for troubleshooting
./bin/flutter-deprecations-server --update -vvv
./bin/flutter-deprecations-server -u -vvv # Short version
# Clear deprecations cache
./bin/flutter-deprecations-server --clear-cache
./bin/flutter-deprecations-server -cc # Short version
# Show current cache contents
./bin/flutter-deprecations-server --show-cache
./bin/flutter-deprecations-server -sc # Short version
# Start the MCP server (default behavior)
./bin/flutter-deprecations-server可用选项
--help, -h:显示使用示例的帮助信息--update, -u:更新Flutter弃用缓存并退出--clear-cache, -cc:清除Flutter弃用缓存并退出--show-cache, -sc:显示当前Flutter弃用缓存并退出--vvv:启用详细日志记录以进行详细的故障排除
建筑
该项目遵循Go最佳实践和干净的架构:
- cmd/:应用程序入口点
- 内部/:私有应用程序代码(不能由其他项目导入)
- pkg/:可以导入的公共库
- 生成文件:构建自动化和常见任务
服务层
- 缓存服务:以清晰的功能处理本地文件缓存
- FlutterAPI服务:管理GitHub API交互,包括速率限制处理、源代码扫描和Docker注册表检查
- FlutterVersionService:直接从Flutter CLI获取Flutter版本
- 弃用服务:分析和管理Flutter源代码中的弃用数据
- 版本信息服务:提供全面的版本和可用性信息
处理程序层
- MCP处理器:实现MCP工具接口并协调服务调用
测试
- 全面的测试套件:所有服务和处理程序的单元测试
- 模拟服务:使用依赖注入测试基础设施
- 测试覆盖率:运行
make test-coverage生成覆盖率报告
