WM

windymelt/mcp-scala

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

37 stars 4 forks 质量 66 趋势 20MIT

用 Scala 编写的模型上下文协议服务器

概览

用 Scala 3 编写的模型上下文协议服务器 - [x] 自动推导JSON模式 - [x] 定义你的工具 - [x] 文本内容部分 - [ ] 其他内容部分 - [ ] 通知处理 - [ ] 能力处理 - [x] 标准传输 - [ ] HTTP 传输 - [ ] 授权功能 这项实施需要你的关注和贡献。 欢迎打开“议题/公关”来贡献这个项目。 然后,利用MCP客户端中的服务器功能: - randomNumber - 生成最小到最大值之间的随机数。- iota - 生成从最小到最大值的数字序列。- sum - 计算一串数字的和。

概述(AI 翻译)

用 Scala 3 编写的模型上下文协议服务器

发展阶段

该软件目前处于ALPHA状态。

  • [x] JSON模式的自动推导
  • [x] 定义你的工具
  • [x] 文本内容部分
  • [ ] 其他内容部分
  • [ ] 通知处理
  • [ ] 能力处理
  • [x] 标准交通
  • [ ] HTTP 传输
  • [ ] 授权功能

这项实施需要你的关注和贡献。

欢迎打开“议题/公关”来贡献这个项目。

演示

首先,把服务器写进JS:

然后,利用MCP客户端中的服务器功能:

你可以运行一些工具:

  • randomNumber
  • 生成介于min到max之间的随机数。
  • iota
  • 生成从 min 到 max 的数字序列。
  • sum
  • 计算一列数字的和。

实施你的工具

详情请参见Main.scala。

本页由 AI 翻译,技术细节请以原文为准。

README

MCP-scala

Model Context Protocol server written in Scala 3

Development stage

This software is currently ALPHA state.

  • [x] Automatic derivation of JSON Schema
  • [x] Define your tool
  • [x] Text content part
  • [ ] Other content parts
  • [ ] Notification handling
  • [ ] Capability handling
  • [x] stdio transport
  • [ ] HTTP transport
  • [ ] Authorization feature

This implementation needs your attention and contribution.

Feel free to open Issue / PR to contribute this project.

Demo

First, build server into JS:

sbt example/fastLinkJS

Then, utilize server in your MCP client:

// Example for Cline
{
  "mcpServers": {
    "mcpscala": {
      "disabled": false,
      "timeout": 30,
      "command": "sh",
      "args": ["/path/to/run.sh"],
      "transportType": "stdio"
    }
  }
}

You can run some tool:

  • randomNumber
    • generate random number between min to max.
  • iota
    • generate a sequence of numbers from min to max.
  • sum
    • calculate the sum of a sequence of numbers.

Implement your tool

See Main.scala for details.

//> 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),
    )
  )

在 GitHub 查看完整 README

安装

This server does not publish a one-line install command.

Open the repository installation guide 新手?先看 mcpskill.org 教程 →

配置

// Example for Cline { "mcpServers": { "mcpscala": { "disabled": false, "timeout": 30, "command": "sh", "args": ["/path/to/run.sh"], "transportType": "stdio" } } }