mcp-clojure-sdk
by: unravel-team
A Clojure SDK to create MCP servers (and eventually clients)
📌Overview
Purpose: The clojure-sdk
is designed to facilitate the creation of Model Context Protocol (MCP) servers through a robust and user-friendly interface.
Overview: This framework provides developers with the necessary tools to quickly set up MCP servers, showcasing various functionalities through built-in examples like calculators and data visualizers. The SDK is built on top of lsp4clj
, ensuring efficient handling of JSON-RPC based communications while simplifying development tasks.
Key Features:
-
Calculator Server: Offers a variety of basic arithmetic operations, allowing users to perform tasks such as addition, subtraction, or calculating averages directly through the MCP interface.
-
Vega-lite Server: Enables the generation of sophisticated visualizations using Vega-lite. It includes features like data visualization and chart generation, requiring a pre-installed
vl-convert
CLI for operation.
io.modelcontext/clojure-sdk
A clojure-sdk
for creating Model Context Protocol servers!
Usage
The examples contain full working code for defining MCP servers including:
- calculator_server
- vegalite_server
- code_analysis_server
The examples
is a deps-new
app project. Instructions for compiling and running the example servers are available in the examples README.
The dependencies for clojure-sdk
are:
{io.modelcontextprotocol/mcp-clojure-sdk
{:git/url "https://github.com/unravel-team/mcp-clojure-sdk.git"
:git/sha "039cf220ac6bb3858f71e823016035e257a5380d"}}
Examples
Building the Examples Jar
$ make clean && make examples-jar
The examples jar contains the following servers:
- Calculator:
calculator_server
- Vega-lite:
vegalite_server
- Code Analysis:
code_analysis_server
Calculator: calculator_server
Provides basic arithmetic tools: add
, subtract
, multiply
, divide
, power
, square-root
, average
, factorial
.
Example commands:
- What's the average of [1, 2, 3, 4, 5]?
- What's the factorial of 15?
- What's 2 to the power of 1000?
- What's the square-root of 64?
Before running the calculator MCP server:
- Use the full-path to the examples JAR on your system.
In Claude Desktop
{
"calculator": {
"command": "java",
"args": [
"-Dclojure.tools.logging.factory=clojure.tools.logging.impl/log4j2-factory",
"-Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.Slf4jLog",
"-Dlog4j2.contextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector",
"-Dlog4j2.configurationFile=log4j2-mcp.xml",
"-Dbabashka.json.provider=metosin/jsonista",
"-Dlogging.level=INFO",
"-cp",
"/Users/vedang/mcp-clojure-sdk/examples/target/io.modelcontextprotocol.clojure-sdk/examples-1.2.0.jar",
"calculator_server"
]
}
}
In MCP Inspector
npx @modelcontextprotocol/inspector java -Dclojure.tools.logging.factory=clojure.tools.logging.impl/log4j2-factory -Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.Slf4jLog -Dlog4j2.contextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector -Dlog4j2.configurationFile=log4j2-mcp.xml -Dbabashka.json.provider=metosin/jsonista -Dlogging.level=INFO -cp examples/target/io.modelcontextprotocol.clojure-sdk/examples-1.2.0.jar calculator_server
Vega-lite: vegalite_server
Provides tools for generating Vega-lite charts: save-data
, visualize-data
.
Pre-requisite: Needs vl-convert CLI to be installed.
Example data sample:
[
{ "year": 2011, "value": 14.6, "growth_type": "Market Cap Growth" },
{ "year": 2011, "value": 11.4, "growth_type": "Revenue Growth" },
{ "year": 2011, "value": 26.6, "growth_type": "Net Income Growth" },
{ "year": 2012, "value": 40.1, "growth_type": "Market Cap Growth" },
{ "year": 2012, "value": 42.7, "growth_type": "Revenue Growth" },
{ "year": 2012, "value": 36.9, "growth_type": "Net Income Growth" },
{ "year": 2013, "value": 16.9, "growth_type": "Market Cap Growth" },
{ "year": 2013, "value": 14.6, "growth_type": "Revenue Growth" },
{ "year": 2013, "value": 15.3, "growth_type": "Net Income Growth" },
{ "year": 2014, "value": 9.6, "growth_type": "Market Cap Growth" },
{ "year": 2014, "value": 7.9, "growth_type": "Revenue Growth" },
{ "year": 2014, "value": 10.9, "growth_type": "Net Income Growth" },
{ "year": 2015, "value": 5.8, "growth_type": "Market Cap Growth" },
{ "year": 2015, "value": 6.7, "growth_type": "Revenue Growth" },
{ "year": 2015, "value": 6.2, "growth_type": "Net Income Growth" },
{ "year": 2016, "value": -12.4, "growth_type": "Market Cap Growth" },
{ "year": 2016, "value": -3.9, "growth_type": "Revenue Growth" },
{ "year": 2016, "value": -32.2, "growth_type": "Net Income Growth" },
{ "year": 2017, "value": 25.3, "growth_type": "Market Cap Growth" },
{ "year": 2017, "value": 5.9, "growth_type": "Revenue Growth" },
{ "year": 2017, "value": 43.9, "growth_type": "Net Income Growth" }
]
Visualize this data using Vega-lite.
Before running the vegalite MCP server
- Replace the full-path to the examples JAR with the correct path on your system.
- Specify the full-path to
vl-convert
on your system.
In Claude Desktop
{
"vegalite": {
"command": "java",
"args": [
"-Dclojure.tools.logging.factory=clojure.tools.logging.impl/log4j2-factory",
"-Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.Slf4jLog",
"-Dlog4j2.contextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector",
"-Dlog4j2.configurationFile=log4j2-mcp.xml",
"-Dbabashka.json.provider=metosin/jsonista",
"-Dlogging.level=INFO",
"-Dmcp.vegalite.vl_convert_executable=/Users/vedang/.cargo/bin/vl-convert",
"-cp",
"/Users/vedang/mcp-clojure-sdk/examples/target/io.modelcontextprotocol.clojure-sdk/examples-1.2.0.jar",
"vegalite_server"
]
}
}
In MCP Inspector
npx @modelcontextprotocol/inspector java -Dclojure.tools.logging.factory=clojure.tools.logging.impl/log4j2-factory -Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.Slf4jLog -Dlog4j2.contextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector -Dlog4j2.configurationFile=log4j2-mcp.xml -Dbabashka.json.provider=metosin/jsonista -Dlogging.level=INFO -Dmcp.vegalite.vl_convert_executable=/Users/vedang/.cargo/bin/vl-convert -cp examples/target/io.modelcontextprotocol.clojure-sdk/examples-1.2.0.jar vegalite_server
Code Analysis: code_analysis_server
Provides prompts: analyse-code
and poem-about-code
.
You can try the prompts in Claude Desktop or Inspector as a demonstration of exposing powerful prompts.
Before running the code-analysis MCP server
- Replace the full-path to the examples JAR with the correct path on your system.
In Claude Desktop
{
"code-analysis": {
"command": "java",
"args": [
"-Dclojure.tools.logging.factory=clojure.tools.logging.impl/log4j2-factory",
"-Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.Slf4jLog",
"-Dlog4j2.contextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector",
"-Dlog4j2.configurationFile=log4j2-mcp.xml",
"-Dbabashka.json.provider=metosin/jsonista",
"-Dlogging.level=INFO",
"-cp",
"/Users/vedang/mcp-clojure-sdk/examples/target/io.modelcontextprotocol.clojure-sdk/examples-1.2.0.jar",
"code_analysis_server"
]
}
}
In MCP Inspector
npx @modelcontextprotocol/inspector java -Dclojure.tools.logging.factory=clojure.tools.logging.impl/log4j2-factory -Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.Slf4jLog -Dlog4j2.contextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector -Dlog4j2.configurationFile=log4j2-mcp.xml -Dbabashka.json.provider=metosin/jsonista -Dlogging.level=INFO -cp examples/target/io.modelcontextprotocol.clojure-sdk/examples-1.2.0.jar code_analysis_server
Pending Work
You can see the list of pending changes in the todo.org file.
Development of the SDK
The clojure-sdk
is a standard deps-new
project. Expected commands:
Run tests:
$ make test
# or
clojure -T:build test
Run CI and build JAR:
$ make build
# or
clojure -T:build ci
This produces an updated pom.xml
inside target/classes/META-INF
and the JAR in target
. Update version and SCM tag information in build.clj
.
Install locally:
$ make install
# or
clojure -T:build install
Deploy to Clojars (requires CLOJARS_USERNAME
and CLOJARS_PASSWORD
environment variables and building first):
$ make deploy
# or
clojure -T:build deploy
The library will be deployed to io.modelcontext/clojure-sdk on clojars.org.
Inspiration
This SDK is built on top of lsp4clj, which handles the edge-cases of JSON-RPC servers. It provides a smart and easy-to-modify foundation.
License
Copyright © 2025 Unravel.tech
Distributed under the MIT License