MCP标量
用Scala 3编写的模型上下文协议服务器
开发阶段
此软件当前处于ALPHA状态。
- \[x\] JSON模式的自动推导
- \[x\] 定义您的工具
- \[x\] 文本内容部分
- \[\]其他内容部分
- \[\]通知处理
- \[\]能力处理
- \[x\] stdio传输
- \[\]HTTP传输
- \[\]授权功能
这一实施需要您的关注和贡献。
欢迎打开Issue/PR来贡献这个项目。
演示
首先,将服务器构建到JS中:
sbt example/fastLinkJS然后,在MCP客户端中使用服务器:
// Example for Cline
{
"mcpServers": {
"mcpscala": {
"disabled": false,
"timeout": 30,
"command": "sh",
"args": ["/path/to/run.sh"],
"transportType": "stdio"
}
}
}你可以运行一些工具:
randomNumber
- 在以下之间生成随机数 min 向 max.
iota
- 生成一个数字序列 min 向 max.
sum
- 计算一系列数字的总和。
实施您的工具
看 Main.scala 了解详情。
//> using scala 3
//> using toolkit typelevel:default
//> using dep dev.capslock::mcpscala:0.1.0
package dev.capslock.mcpscala
import cats.effect.IO
import cats.effect.IOApp
import dev.capslock.mcpscala.transport.StdioServer
import dev.capslock.mcpscala.mcp.ContentPart
import sttp.tapir.Schema.annotations.description
case class RandomNumberInput(
@description("Minimum value (inclusive)") min: Int,
@description("Maximum value (exclusive)") max: Int
) derives io.circe.Decoder,
sttp.tapir.Schema
def randomNumber(input: RandomNumberInput): IO[Seq[ContentPart]] = IO {
val random = scala.util.Random.between(input.min, input.max)
Seq(ContentPart.TextContentPart(random.toString))
}
/** Entry point for the Stdio server.
*/
object StdioMain extends McpIOApp(
name = "random-number",
header = "Generate a random number",
):
val handlers = Handler.methodHandlers(
Map(
"randomNumber" -> server.Tool(randomNumber),
)
)
