modex bb
Babashka MCP服务器框架。构建 模型上下文协议 在上运行的服务器 巴巴什卡 JVM启动时间为零。
特性
- 标准JSON-RPC传输 --从stdin读取,写入stdout
- 工具DSL --陈述性
(tools ...)用于定义具有类型化参数、文档、默认值和验证的MCP工具的宏 - MCP 2024-11-05协议 --初始化、工具/列表、工具/调用、提示/列表、资源/列表
- 线程安全 --锁定stdout,通过future进行异步请求处理
- 轻量级 --单一依赖项(JSON为cheshire)
快速开始
添加到您的 bb.edn:
{:deps {io.github.hive-agi/modex-bb {:git/tag "v0.1.0"
:git/sha "439ff17ea854dce14a3e3963d6c86c5400c72962"}}}定义工具并启动服务器:
(ns my-server
(:require [modex-bb.mcp.server :as mcp-server]
[modex-bb.mcp.tools :refer [tools]]))
(def my-tools
(tools
(greet "Say hello to someone"
[{:keys [name]
:type {:name :string}
:doc {:name "Person to greet"}}]
[{:message (str "Hello, " name "!")}])
(add "Add two numbers"
[{:keys [a b]
:type {:a :number :b :number}
:doc {:a "First number" :b "Second number"}}]
[{:result (+ a b)}])))
(def server
(mcp-server/->server
{:name "my-server"
:version "0.1.0"
:tools my-tools}))
(defn -main [& _]
(mcp-server/start-server! server))运行它:
bb --config bb.edn -m my-server工具DSL
这 tools 宏支持映射解构参数 :type, :doc,以及 :or (默认值):
(tools
(my_tool "Description of my tool"
[{:keys [required_param optional_param]
:type {:required_param :string :optional_param :number}
:doc {:required_param "This is required"
:optional_param "This has a default"}
:or {optional_param 42}}]
;; Body — return a vector of result maps
[{:output (str required_param " = " optional_param)}]))参数无 :or 默认值在MCP模式中标记为必需。类型有 :string 或 :number.
建筑
modex_bb/mcp/
server.clj — JSON-RPC stdio loop, request routing, AServer reify
tools.clj — Tool DSL macros, parameter validation, invocation
protocols.clj — AServer protocol definition
schema.clj — MCP protocol version, error codes
json_rpc.clj — JSON-RPC message constructors
log.clj — Logging shim (stderr)使用modex bb的项目
许可证
麻省理工学院
