A generic, reusable Model Context Protocol (MCP) Server.
Exposes a list of llm4s ToolFunctions via two transport protocols:
- MCP 2025-06-18 Streamable HTTP — POST / DELETE
{path} - MCP 2024-11-05 HTTP+SSE — GET
{path}/sse+ POST{path}/messages?sessionId=…(required by Claude Desktop and other legacy MCP clients)
=== Authentication === Set MCPServerOptions.apiKey to enable Bearer-token authentication. When set, every HTTP request must include Authorization: Bearer <key>; unauthenticated requests receive HTTP 401. Without an API key the server logs a development-only security warning, and start() refuses to bind to a non-loopback host (returning a Left) so an unauthenticated server is never exposed to the network.
=== Concurrency === Connections are served by an elastic, bounded thread pool capped at MCPServer.MaxServerThreads threads (shared across long-lived SSE streams and short Streamable HTTP requests). Beyond that ceiling new connections are rejected until capacity frees up, providing backpressure under load.
val tools = Seq(myTool1, myTool2)
val options = MCPServerOptions(8080, "/mcp", "MyServer", "1.0", apiKey = Some("secret"))
val server = new MCPServer(options, tools)
server.start()
Value parameters
- options
-
Server configuration.
- tools
-
List of tools to expose.
Attributes
- Companion
- object
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any