Back to MCP directory
publicPublicdnsLocal runtime

mcp-clojure-sdk

这是一个用于创建Model Context Protocol服务器的Clojure SDK,提供了核心组件、通信流程和示例实现,支持工具调用、资源读取和提示获取等功能。

article

README

🚀 io 模型 SDK 文档

本 SDK 为构建支持模型的应用程序提供了丰富的工具、资源和提示接口,能帮助开发者更高效地进行开发。

✨ 主要特性

  • 统一协议:借助 JSON - RPC 2.0 协议,实现标准化交互。
  • 多语言支持:当前以 Clojure 实现,未来计划支持更多语言。
  • 可扩展性:方便添加新的工具、资源和提示。

🚀 快速开始

📦 安装

若要在项目中使用该 SDK,需将以下依赖添加到 deps.edn

io.model.context {:mvn/version "0.1.0"}

💻 使用示例

基础用法

创建一个基本的上下文实例:

(require [io.model.context :as ctx])

(let [context (ctx/create-context)]
  (with-retry context))

📚 详细文档

核心概念

上下文

上下文是工具、资源和提示的容器。可通过以下方式创建一个空上下文:

(empty-context)

之后可添加工具、资源或提示。

工具

工具是能够执行命令的函数,例如计算器。注册工具的方法如下:

(add-tool context :name tool-fn & args)
资源

资源是提供内容的函数,比如从文件读取内容。注册资源的方式为:

(add-resource context :uri resource-fn)
提示

提示是生成回复消息的函数,常用于对话系统。注册提示的方法是:

(add-prompt context :name prompt-fn & args)

传输层

若要实现自定义传输协议,只需继承 Transport 接口并实现以下方法:

  • initialize
  • read-message
  • write-message

客户端 API

通过客户端 API 可与服务器进行交互,主要包含以下方法:

初始化

(init context)

工具交互

(call-tool context tool-name args)
(list-tools context)

资源管理

(read-resource context uri)
(subscribe-resource context uri callback)
(unsubscribe-resource context subscription-id)
(list-resources context)

提示系统

(get-prompt context prompt-name args)
(list-prompts context)

健康检查

(ping context)

示例代码

高级用法

创建上下文:

(let [context (empty-context)]
  (add-tool context :calculate #(apply + %&))
  (add-resource context "file.txt" #(slurp %))
  (add-prompt context :greeting #(str "Hello, " %))
)

使用客户端:

(let [client (create-client transport)]
  (init client)
  (ping client)
  (call-tool client :calculate [1 2 3])
  (read-resource client "file.txt")
  (subscribe-resource client "file.txt" #(println %))
)

更多信息

如需深入了解如何在项目中使用该 SDK,请参考以下链接:

待办事项

查看 todo.org 文件 了解待完成的工作,按计划顺序处理。

开发指南

这是一个标准的 deps-new 项目,所有 deps-new 命令均可正常运行。

  • 运行项目测试:
$ make test ## 或 clojure -T:build test
  • 构建 JAR 包并运行 CI 管道:
$ make build ## 或 clojure -T:build ci
  • 本地安装:
$ make install ## 或 clojure -T:build install
  • 部署到 Clojars 需要设置 CLOJARS_USERNAMECLOJARS_PASSWORD 环境变量(需先运行 ci 任务):
$ make deploy ## 或 clojure -T:build deploy

致谢

此 SDK 基于 lsp4clj 构建,它解决了处理所有 JSON - RPC 边缘情况的难题。在意识到 lsp4clj 的智能方法之前,开发者是手动构建了这一层,并发现了所有的边缘情况。

📄 许可证

版权 © 2025 Unravel.tech

根据 MIT 许可证分发

help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client