使用说明
一个Clojure库,用于轻松构建兼容的模型上下文协议(MCP)服务器。它实现了 这是通过包装 官方Java SDK 作为戒指 该处理程序可以嵌入到Clojure应用程序中,同时仍然利用Clojure中间件和 路由。这使得使用最推荐的传输(Streamable Http)变得容易,而不是 需要挂载多个servlet,使Clojure应用程序复杂化。
安装
com.latacora/mcp-sdk {:git/url "https://github.com/latacora/mcp-sdk"
:git/sha "<latest-commit-sha>"}
用法
(require '[com.latacora.mcp.core :as mcp])
; for tools, this library provides a convenient way to construct
; tool specifications using malli schemas for input and output
; validation (as well as json-schema generation)
(def tool
(mcp/create-tool-specification
{:name "add"
:title "Add two numbers"
:description "Adds two numbers together"
:input-schema [:map [:a int?] [:b int?]]
:output-schema [:map [:result int?]]
:handler (fn [_exchange {:keys [a b]}]
{:result (+ a b)})}))
; when you construct the mcp handler you provide java objects
; like the underlying modelcontextprotocol requests. this means
; you're free to build any of the other mcp server features using
; interop. at a future date we might provide clojure wrappers to
; make constructing them easier, but for now we only provide one for
; tools since they're the most common and tedious to construct with interop.
(def handler (mcp/create-ring-handler {:name "hello-world" :version "1.0.0" :tools [tool]}))
; note that this is a custom run-jetty function that preserves
; the original servlet request/response objects in metadata so
; they can be passed to the embedded mcp servlet. it is a drop-in
; replacement for ring.adapter.jetty/run-jetty. here we perform no
; routing and so the mcp server is mounted at the root path, but you
; can embed the handler anywhere in your routing tree.
(def server (mcp/run-jetty handler {:port 3000 :join? false}))
测试
您可以使用 mcp检查员 测试您的MCP服务器。
npx @modelcontextprotocol/inspector --server-url http://localhost:3000
许可证
版权所有©Latacora
在Eclipse公共许可证2.0版本下分发。