
indoorvivants/mcp 是从 https://github.com/indoorvivants/mcp. 导入的 MCP 服务器候选
概览
indoorvivants/mcp 是从 https://github.com/indoorvivants/mcp. 导入的 MCP 服务器候选
概述(AI 翻译)
这是一个实现模型上下文协议的进行中库。
目前图书馆由三个部分组成:
- 使用 MCP 的 JSON 模式实现协议子集的代码生成器
- 最小运行时间以帮助 JSON 结构序列化
- 实现 JSONRPC 2.0 协议的最小 jsonrpc 运行时
请注意,jsonrpc 实现不支持取消,通常也不是为严肃使用设计的——但快速启动总是很棒!未来,这个库将在 jsonrpclib 发布 Scala Native 0.5 版本后提供集成(或者如果有人参与该集成,可能会更早发布)。
开始
请注意,该库使用的是Scala 3.7——这对应用程序来说通常没问题,因为你可以使用3.7以上的任何版本
将其保存在 mcp.scala 文件中,并用 MCP Inspector 运行:
关于更复杂的示例,包含工具使用和双向通信,请参见示例。
看它实际行动
只要你安装了 Scala CLI 和 npx,就可以使用 MCP Inspector 运行提供的示例:
样品在MCP检测器中加载并工作:
本页由 AI 翻译,技术细节请以原文为准。
README
Model Context Protocol for Scala 3
This is a WIP library implementing the Model Context Protocol.
At the moment the library consists of three parts:
- Code generator that uses JSON schema from MCP to implement a subset of the protocol
- Minimal runtime to help serialising structures in JSON
- Minimal jsonrpc runtime implementing JSONRPC 2.0 protocol
Note that the jsonrpc implementation does not support cancellation, and is generally not designed for serious usage – but it’s great to get things off the ground quickly! In the future, this library will provide an integration with jsonrpclib, once that library is published for Scala Native 0.5 (or may be earlier, if someone works on that integration).
Getting Started
Note that the library is using Scala 3.7 – which is generally fine for apps, as you can use any version of Scala above 3.7
//> using scala 3.7.0
//> using dep com.indoorvivants::mcp-quick::latest.release
import mcp.*
@main def hello =
val mcp = MCPBuilder
.create()
.handle(initialize): req =>
InitializeResult(
capabilities =
ServerCapabilities(tools = Some(ServerCapabilities.Tools())),
protocolVersion = req.protocolVersion,
serverInfo = Implementation("scala-mcp", "0.0.1")
)
.run(SyncTransport.default)
end hello
Save it in a mcp.scala file and run it with MCP Inspector:
npx @modelcontextprotocol/inspector scala-cli run mcp.scala
For a more involved example, containing tool usage and bi-directional communication, see the sample.
See it in action
You can run the provided sample using MCP inspector as long as you have Scala CLI and npx installed:
npx @modelcontextprotocol/inspector make run-sample
The sample loads and works in the MCP inspector:
And can be configured in Claude desktop:
安装
npx @modelcontextprotocol/inspector scala-cli run mcp.scala