Skip to content

Commit 4eba0b8

Browse files
committed
Add some documentation.
1 parent 87d8fc3 commit 4eba0b8

File tree

15 files changed

+204
-4
lines changed

15 files changed

+204
-4
lines changed

.github/workflows/cljdoc.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: CljDoc
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
11+
check-cljdoc:
12+
13+
name: Check source code
14+
15+
timeout-minutes: 60
16+
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: Setup Clojure
23+
uses: DeLaGuardo/setup-clojure@master
24+
with:
25+
cli: latest
26+
27+
- name: Build the jar and update pom.xml's version
28+
run: clojure -X:jar && mkdir target && mv *.jar target/
29+
30+
- name: CljDoc Check
31+
uses: cljdoc/[email protected]

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5+
6+
Versions prior to v0.1.0 are considered experimental, their API may change.
7+
8+
## [Unreleased]

deps.edn

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,13 @@
2222
:nrepl {:extra-paths ["test"]
2323
:extra-deps {nrepl/nrepl {:mvn/version "1.3.1"}}
2424
:jvm-opts ["-Djdk.attach.allowAttachSelf"]
25-
:main-opts ["-m" "nrepl.cmdline" "--port" "7888"]}}}
25+
:main-opts ["-m" "nrepl.cmdline" "--port" "7888"]}
26+
27+
:jar {:replace-deps {com.github.seancorfield/depstar {:mvn/version "2.1.303"}}
28+
:exec-fn hf.depstar/jar
29+
:exec-args {:sync-pom true
30+
:group-id "fi.metosin"
31+
:artifact-id "mcp-toolkit"
32+
:version "0.0.1"
33+
:jar "mcp-toolkit.jar"}}}}
34+

doc/SUMMARY.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Summary
2+
3+
[Introduction](introduction.md)
4+
[API Design](api-design.md)
5+
[The session atom](session.md)
6+
[The context hashmap](context.md)
7+
[Using the library](using-the-library.md)
8+
[REPL story](repl-story.md)

doc/api-design.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## API Design
2+
3+
MCP-toolkit is used in a client-server architecture, the client typically being an agentic AI,
4+
and the server typically being an MCP server in Clojure.
5+
6+
The namespace `mcp-toolkit.client` is for implementing a MCP client, it is designed to communicate with a MCP server.
7+
The namespace `mcp-toolkit.server` is for implementing a MCP server, it is designed to communicate with a MCP client.
8+
If you want to implement a MCP proxy, you can use both.
9+
10+
The API design is the same in both namespaces:
11+
- The state representing the communication with the remote site is in an atom called `session`.
12+
- A hashmap `context` contains the `session` and a few other things related to interfacing with the transport layout.
13+
- The `context` is passed as the first parameter of most of functions in the API.
14+
- The `session` contains some callbacks which are called when receiving certain kind of messages from the MCP protocol.
15+
By default some of the callbacks are pointing to provided function which implement a default behavior.
16+
If the user wants to customize the behavior, s/he can do it at the creation of the session value.
17+
- All the message handlers are assumed to either return a value to be immediately sent as `:result` to the caller, or
18+
to return a Promesa promise which will resolve to that value later, asynchronously.

doc/cljdoc.edn

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{:cljdoc.doc/tree [["Readme" {:file "README.md"}]
2+
["Changes" {:file "CHANGELOG.md"}]
3+
["Introduction" {:file "doc/introduction.md"}]
4+
["API design" {:file "doc/api-design.md"}]
5+
["Session" {:file "doc/session.md"}]
6+
["Context" {:file "doc/context.md"}]
7+
["Using the library" {:file "doc/using-the-library.md"}]
8+
["REPL story" {:file "doc/repl-story.md"}]]}

doc/context.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## The context hashmap
2+
3+
The context hashmap contains:
4+
- The session atom
5+
- Some I/O related functions which are use-case specific and that the user has to provide.
6+
- The `:send-message` function
7+
- The `:close-connection` function
8+
9+
The context hashmap is also used for passing the current message to be processed to the event handlers.
10+
11+
### Context vs. session
12+
13+
The difference between the `context` and the `session` is that the `session` is a mutable state (an atom) being shared by all the event handlers,
14+
while the `context` is an immutable Clojure value contains contextual information, like the current message being processed.
15+
16+
You can add your own data in either the `context` or the `session` if it makes sense for you,
17+
all the message handlers and the user callbacks are called with the context as their first (and only) argument.

doc/introduction.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## Introduction
2+
3+
MCP-toolkit is a library for interfacing Clojure code with the MCP protocol.
4+
5+
It provides a structure for:
6+
- registering and unregistering your prompts, resources, tools, roots, etc ...
7+
- making them discoverable and invocable to the remote site
8+
- updating their presence or lack of
9+
- sending notifications to the remote site when they are updated
10+
- experimenting and developing MCP tools from a REPL session while a they are being served

doc/repl-story.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## REPL story
2+
3+
When your client or your server is running, connect to it via a REPL using the method of your choice.
4+
5+
On the server side, you can register or unregister resources using:
6+
- `add-prompt`, `remove-prompt`, `add-resource`, `remove-resource`, `add-tool`, `remove-tool`, `set-resource-templates` and `set-resource-uri-complete-fn`
7+
which will mutate the session atom and notify the client about the changes.
8+
9+
On the client side, you can do the same using `add-root` and `remove-root`.
10+
11+
For all of those above functions, you need to pass the context as the first argument.
12+
To make it accessible from the root level in your Clojure program, depending on your setup, it may be handing to have a root-level atom referring to it.

doc/session.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## The session atom
2+
3+
A session is typically created using the function `mcp-toolkit.client/create-session` or `mcp-toolkit.client/create-session`.
4+
5+
It contains:
6+
- The `:initialized` boolean, becomes true after the initial handshake between the client and server.
7+
- The `:protocol-version` used, initialized after the initial handshake.
8+
- `:client-capabilities` / `:server-capabilities` listing what features the remote site supports.
9+
- Some data about the ongoing Remote Method Calls, waiting for a response.
10+
- The locally registered resources and a maintained collection of the resources available on the remote site.
11+
- The callbacks starting with `:on-`, triggered on events, some of them directly being some types of messages.
12+
Some of them are defaulting to a built-in behavior which maintain the collection of resources available on the remote site.
13+
14+
The session atom can be modified from the message handlers.

0 commit comments

Comments
 (0)