mcp-0.1.0.0: A Haskell implementation of the Model Context Protocol (MCP)
Copyright(C) 2025 Matthias Pall Gissurarson
LicenseMIT
Maintainermpg@mpg.is
Stabilityexperimental
PortabilityGHC
Safe HaskellSafe-Inferred
LanguageGHC2021

MCP.Server

Description

This module provides a complete MCP server implementation, including message handling, state management, and JSON-RPC communication over standard input/output streams.

Synopsis

Server Interface

data ServerState Source #

Server state tracking initialization, capabilities, and subscriptions

Instances

Instances details
Show ServerState Source # 
Instance details

Defined in MCP.Server

type MCPServerM = ReaderT ServerConfig (StateT ServerState (ExceptT Text IO)) Source #

The monad stack for MCP server operations

runMCPServer :: ServerConfig -> ServerState -> MCPServerM a -> IO (Either Text (a, ServerState)) Source #

Run an MCPServerM computation with the given config and initial state

Message Handling

handleMessage :: MCPServer MCPServerM => ByteString -> MCPServerM (Maybe ()) Source #

Handle an incoming JSON-RPC message

handleRequest :: MCPServer MCPServerM => JSONRPCRequest -> MCPServerM () Source #

Handle a JSON-RPC request

handleNotification :: JSONRPCNotification -> MCPServerM () Source #

Handle a JSON-RPC notification

Server Runner

runServer :: MCPServer MCPServerM => ServerConfig -> IO () Source #

Run the MCP server with the given configuration

data ServerConfig Source #

Configuration for running an MCP server

Instances

Instances details
Show ServerConfig Source # 
Instance details

Defined in MCP.Server

Utilities

sendResponse :: (MonadIO m, ToJSON a) => Handle -> RequestId -> a -> m () Source #

Send a JSON-RPC response

sendNotification :: (MonadIO m, ToJSON a) => Handle -> Text -> a -> m () Source #

Send a JSON-RPC notification

sendError :: MonadIO m => Handle -> RequestId -> JSONRPCErrorInfo -> m () Source #

Send a JSON-RPC error response