这是一个独立客户端,用于启动支持 MCP(模型上下文协议)的 Metals 语言服务器,使AI助手能够与Scala项目进行交互。使用scala-cli构建,以实现快速编译和简单分发。
此工具提供了一种无头方式来运行具有MCP功能的Metals语言服务器,允许像Claude这样的AI代码助手理解并处理您的Scala代码库。它会自动发现Metals安装,配置语言服务器,并监控MCP服务器的健康状况。
Linux:
wget https://github.com/jpablo/metals-standalone-client/releases/latest/download/metals-standalone-client-linux-executable
chmod +x metals-standalone-client-linux-executable
./metals-standalone-client-linux-executable --help
macOS:
wget https
://github.com/jpablo/metals-standalone-client/releases/latest/download/metals-standalone-client-macos-executable
chmod +x metals-standalone-client-macos-executable
./metals-standalone-client-macos-executable --help
Windows:
REM 将两个文件下载到同一目录中:
REM - metals-standalone-client-windows-executable.bat
REM - metals-standalone-client-windows-executable.jar
metals-standalone-client-windows-executable.bat --help
# 构建装配JAR包
scala-cli --power package . --assembly -f -o metals-standalone-client
# 或者构建独立可执行文件
scala-cli --power package . --standalone -f -o metals-standalone-client
# 使用当前目录
scala-cli run .
# 指定项目路径和选项
scala-cli run . -- --verbose /path/to/scala/project
-v, --verbose: 启用详细日志记录-h, --help: 显示帮助信息一旦Metals独立客户端正在运行,您可以配置Claude Code使用MCP服务器:
claude mcp add --transport sse metals http://localhost:60013/sse
这将使Claude Code能够通过Metals语言服务器与您的Scala项目进行交互。
该工具会自动查找以下位置的MCP配置文件:
.metals/mcp.json.cursor/mcp.json.vscode/mcp.jsonbuild.sbt的Scala项目build.sbt、project.scala或.scala文件的Scala项目该项目使用scala-cli进行构建管理。配置在project.scala中定义,使用scala-cli的“使用指令”:
//> 使用 scala "3.7.1"
//> 使用 dep "io.circe::circe-core:0.14.14"
//> 使用 dep "io.circe::circe-parser:0.14.14"
// ... 其他依赖项
这种方法提供了:
# 编译
scala-cli compile .
# 运行应用程序
scala-cli run . -- [--verbose] [PROJECT_PATH]
# 测试
scala-cli test .
# 构建装配JAR包
scala-cli --power package . --assembly -f -o metals-standalone-client
# 构建独立可执行文件
scala-cli --power package . --standalone -f -o metals-standalone-client
# 快速构建测试(编译+测试+打包)
./test-build.sh
该项目使用GitHub Actions在每次向主分支推送时自动构建和发布适用于Linux、macOS和Windows的可执行文件。发布的包括单个可执行文件,无需编译即可使用。