MCPStdioServer

org.llm4s.mcp.MCPStdioServer
See theMCPStdioServer companion object
final class MCPStdioServer

An llm4s tool set served over stdio (#3403), so a desktop MCP client can launch it as a subprocess: the client writes newline-delimited JSON-RPC to the process's standard input and reads the replies from its standard output. It speaks what MCPServer speaks over HTTP - initialize, ping, tools/list and tools/call, with notifications/cancelled interrupting a running call - with no session and no authentication: the client that started the process is the only one that can reach it.

object WeatherServer {
 def main(args: Array[String]): Unit =
   MCPStdioServer("weather", "1.0.0", Seq(forecastTool)).serve()
}

'''Standard output is the protocol.''' serve points System.out, and Scala's Console.out for the thread it runs on and the threads it starts, at standard error while it runs, so a stray println or a logger writing to the console cannot corrupt the stream; configure logging to standard error (or a file) so nothing else does.

When standard input ends - the client closed it, or exited - the session is over: calls still running are cancelled, as when an HTTP session ends, and serve returns once they finish or drain has passed.

Value parameters

drain

the longest serve waits, after the input ends, for cancelled calls to finish

Attributes

Companion
object
Source
MCPStdioServer.scala
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def serve(): Unit

Serves the client on this process's standard input and output until the input ends. System.out writes to standard error meanwhile, and is restored when it returns.

Serves the client on this process's standard input and output until the input ends. System.out writes to standard error meanwhile, and is restored when it returns.

Attributes

Source
MCPStdioServer.scala

Serves one client over in and out until in ends; for a test, or a process with streams of its own.

Serves one client over in and out until in ends; for a test, or a process with streams of its own.

Attributes

Source
MCPStdioServer.scala