mcp
MCP Server library
claude mcp add --transport stdio roklenarcic-mcp-server clojure -M -m org.clojars.roklenarcic.mcp-server.core
How to use
This MCP server library provides a framework for building Model Context Protocol (MCP) servers in Clojure without forcing a particular transport, JSON library, or web framework. It exposes a set of core abstractions for sessions, routing of JSON-RPC-like calls to handlers, and a pluggable serialization layer. Typical usage involves choosing a JSON serializer, defining a session with a server-info descriptor and one or more tools/handlers, and then starting a STDIO-based server or integrating with your preferred transport. The README demonstrates creating a server with a weather example tool that receives a location and returns a generated weather description, illustrating how you can define input schemas, handler functions, and dispatch tables to route commands from clients.
To use this server, you would:
- Pick a JSON serializer (choices include Charred, Cheshire, clj-data, and others) and wire it into the session via the serde abstraction.
- Define a server-info map with a name, version, and instructions to describe your service.
- Create tools by specifying a name, description, an input schema, and a handler function that processes incoming RPC calls.
- Build a session (optionally starting from the provided helpers) and start the server over STDIO or your chosen transport by supplying the session to start-server-on-streams or a custom transport layer. The design emphasizes flexibility so you can swap in your own HTTP/WebSocket layer, logging, or data stores without changing core server logic.
How to install
Prerequisites:
- Java runtime (recommended: Java 11+)
- Clojure tooling installed (deps.edn and clojure command via clj/boot or babashka as desired)
Installation steps:
- Install Clojure tooling (if not already installed):
- macOS/Linux: curl -O https://download.clojure.org/install/linux-install-1.11.1.1151.sh && sh linux-install-1.11.1.1151.sh
- Windows: follow the instructions at https://clojure.org/guides/install_clj
- Clone the repository or add the MCP server as a dependency in your project using your preferred Clojure tooling (deps.edn or leiningen).
- Add a dependency on the MCP server library in your deps.edn, for example (if published coordinates match): {:deps { org.clojars.roklenarcic/mcp-server {:mvn/version "<latest-version>"} }}
- Create a small application that requires the MCP server namespaces and builds a session as shown in the README examples (weather service etc.).
- Run your application with your normal Clojure startup flow (deps.edn + clojure -M:your-uber-jar or -X:your-main).
Note: The project is alpha and may require adapting to evolving APIs as features are added.
Additional notes
Tips and considerations:
- The library supports both synchronous and asynchronous handlers; handlers may return plain values or Java CompletableFuture-like objects. Plan your tools accordingly.
- You can mix JSON serializers by plugging in different serde implementations; youβre not locked into a single serializer.
- Sessions are the central abstraction. They are maps stored in atoms and can hold per-connection state such as authentication data, database connections, or resource handles.
- The README shows a complete STDIO-based server setup, but you can swap to other transports by implementing the client communication functions used by the exchange and handlers.
- This project is in alpha; APIs and recommended patterns may change. Keep an eye on documentation and release notes for breaking changes.
Related MCP Servers
modex
Modex is a Clojure MCP Library to augment your AI models with Tools, Resources & Prompts using Clojure (Model Context Protocol). Implements MCP Server & Client.
repl
Model Context Protocol Clojure support including REPL integration with development tools.
datascript
π Datascript MCP Server
mcp-toolkit
a lib to build MCP clients and MCP servers in Clojure(script)
datomic
π Datomic MCP Server
clj -starter
Starter template to build MCP tools in Clojure (using Modex) (Model Context Protocol)