40ants-mcp - The framework for building MCP servers and clients in Common Lisp.

40ANTS-MCP ASDF System Details

About

A comprehensive framework for building Model Context Protocol (MCP) servers in Common Lisp. This library provides a complete implementation of the MCP specification with an easy-to-use API for creating servers that can interact with AI assistants like Claude Desktop.

Active development is ongoing and the interface is likely to change.

Features

Roadmap

Installation

You can install this library from Quicklisp, but you want to receive updates quickly, then install it from Ultralisp.org:

(ql-dist:install-dist "http://dist.ultralisp.org/"
                      :prompt nil)
(ql:quickload :40ants-mcp)

Usage

Here's a quick example of how to create an MCP server with custom tools:

(defpackage #:my-mcp-server
  (:use #:cl)
  (:import-from #:40ants-mcp/content/text
                #:text-content)
  (:import-from #:openrpc-server))

(in-package #:my-mcp-server)

;; Define your API
(openrpc-server:define-api (my-tools :title "My Custom Tools"))

;; Define a tool that adds two numbers
(openrpc-server:define-rpc-method (my-tools add) (a b)
  (:summary "Adds two numbers and returns the result.")
  (:param a integer "First number to add.")
  (:param b integer "Second number to add.")
  (:result (soft-list-of text-content))
  (list (make-instance 'text-content
                      :text (format nil "The sum of ~A and ~A is: ~A"
                                  a b (+ a b)))))

;; Start the server
(40ants-mcp/server/definition:start-server my-tools)

Running as a Script

For production use, you can create a Roswell script. Create a file my-mcp.ros:

#!/bin/sh
#|-*- mode:lisp -*-|#
#|
exec ros -Q -- $0 \"$@\"
|#

(ql:quickload '(:40ants-mcp :alexandria) :silent t)

;; Your package and tool definitions here...

(defun main (&rest argv)
  (declare (ignore argv))
  (40ants-mcp/server/definition:start-server my-tools))

Build and run the script:

# Build the script
ros build my-mcp.ros

# Run the server
./my-mcp

# With remote debugging support
SLYNK_PORT=4005 ./my-mcp

Each tool you define should return a list of content items. The most common content type is text-content, but you can also return other types defined in the MCP specification.

For more examples, check the examples/ directory in the source code.

API

40ANTS-MCP/CONTENT/BASE

Classes

CONTENT

Readers

40ANTS-MCP/CONTENT/TEXT

Classes

TEXT-CONTENT

Readers

40ANTS-MCP/SERVER/DEFINITION

Classes

MCP-SERVER

Readers

Functions

Start the MCP server

40ANTS-MCP/SERVER/ERRORS

Classes

TOOL-ERROR

You should signal this error in case if the tool can't accomplish it's job.

Readers

40ANTS-MCP/STDIO-TRANSPORT

Classes

STDIO-TRANSPORT

STDIO transport implementation for MCP (Model Context Protocol) communication. This class handles JSON-RPC message exchange via standard input/output streams. It is designed to work with the MCP protocol specification for AI model communication.

Readers

reader
(:input-stream = \*standard-input\*)

Input stream for reading JSON-RPC messages. Defaults to standard-input.

reader
(:output-stream = \*standard-output\*)

Output stream for writing JSON-RPC responses. Defaults to standard-output.

Flag indicating if transport is active and processing messages.

Accessors

accessor
(:input-stream = \*standard-input\*)

Input stream for reading JSON-RPC messages. Defaults to standard-input.

accessor
(:output-stream = \*standard-output\*)

Output stream for writing JSON-RPC responses. Defaults to standard-output.

Flag indicating if transport is active and processing messages.

Generics

Receive a JSON-RPC message, returns a message or NIL.

Send a JSON-RPC message, returns no values.

40ANTS-MCP/TRANSPORT/BASE

Generics

Receive a JSON-RPC message, returns a message or NIL.

Send a JSON-RPC message, returns no values.

Starts message processing using given transport.

Stops message processing using given transport.