mcp: A Servant-based Model Context Protocol (MCP) server for Haskell

[ ai, library, mpl, web ] [ Propose Tags ] [ Report a vulnerability ]

This library provides a complete server implementation of the Model Context Protocol (MCP) for Haskell, built on Servant. It re-exports the core protocol types from mcp-types for convenience.

MCP is a protocol that enables seamless communication between AI models and external tools, resources, and services. This implementation supports MCP protocol version 2025-06-18 with full compatibility for resources, tools, prompts, completions, elicitation, and all standard MCP message types.

Three transports are provided: HTTP with JWT authentication via servant-auth-server, a simple unauthenticated HTTP transport for local development or use behind a reverse proxy, and a stdio transport for subprocess-based integrations. All HTTP transports use streaming SSE responses at the /mcp endpoint. An extensible handler framework (ProcessHandlers, ToolHandler) allows implementing custom MCP servers with minimal boilerplate.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.0, 0.1.1.0, 0.2.0.0, 0.2.0.1, 0.3.0.1, 0.3.1.0
Change log CHANGELOG.md
Dependencies aeson (>=2.1 && <2.3), base (>=4.18 && <4.22), bytestring (>=0.11 && <0.13), containers (>=0.6 && <0.8), http-media (>=0.8 && <0.9), mcp-types (>=0.1.0 && <0.2), mtl (>=2.2 && <2.4), servant (>=0.19 && <0.21), servant-auth-server (>=0.4 && <0.5), servant-server (>=0.19 && <0.21), text (>=2.0 && <2.2), time (>=1.12 && <1.15), wai (>=3.2 && <3.3) [details]
Tested with ghc ==9.12.2
License MPL-2.0
Copyright (c) 2025 DPella AB
Author DPella AB
Maintainer matti@dpella.io, lobo@dpella.io
Uploaded by tritlo at 2026-02-19T12:47:35Z
Category Web, AI
Home page https://github.com/DPella/mcp
Bug tracker https://github.com/DPella/mcp/issues
Source repo head: git clone https://github.com/DPella/mcp.git
Distributions
Downloads 70 total (9 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for mcp-0.3.1.0

[back to package description]

mcp — MCP server for Haskell

mcp on Hackage

A complete server implementation of the Model Context Protocol (MCP) for Haskell, built on Servant.

Implements MCP protocol version 2025-06-18. Re-exports the core protocol types from mcp-types for convenience.

Modules

  • MCP.Server — Re-exports everything below for convenience.
  • MCP.Server.Common — Transport-agnostic core: types, state management, request routing, ProcessHandlers, ToolHandler framework.
  • MCP.Server.HTTP — Servant-based HTTP transports with streaming SSE responses at the /mcp endpoint. Provides both a JWT-authenticated API (MCPAPI / mcpAPI) and a simple unauthenticated API (SimpleHTTPAPI / simpleHttpApp) for local development or use behind a reverse proxy.
  • MCP.Server.Stdio — Stdio transport reading/writing JSON-RPC messages line-by-line, suitable for subprocess-based integrations.

Install

build-depends:
    base
  , servant
  , servant-server
  , servant-auth-server
  , aeson
  , mcp

If you only need the protocol types (e.g. for a client), depend on mcp-types instead.

Quick Start

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}

import Control.Concurrent.MVar (newMVar)
import MCP.Server

-- Define your handler state and user types
type instance MCPHandlerState = ()
type instance MCPHandlerUser  = MyUser

-- Create server state with capabilities
mkServerState :: IO (MVar MCPServerState)
mkServerState = do
  let impl = Implementation "my-server" "1.0.0" Nothing
      caps = ServerCapabilities
        { logging      = Nothing
        , prompts      = Nothing
        , resources    = Nothing
        , tools        = Just (ToolsCapability { listChanged = Just True })
        , completions  = Nothing
        , experimental = Nothing
        }
      handlers = withToolHandlers myTools defaultProcessHandlers
  newMVar $ initMCPServerState () Nothing Nothing caps impl Nothing handlers

-- Define tools using the ToolHandler framework
myTools :: [ToolHandler]
myTools =
  [ toolHandler "greet" (Just "Say hello") greetSchema $ \_args ->
      return $ ProcessSuccess $ toolTextResult ["Hello!"]
  ]

A fully documented example server lives in mcp-server/example/.

Features

  • Three transports: HTTP with JWT auth, simple unauthenticated HTTP, and stdio
  • JWT authentication via servant-auth-server (authenticated HTTP transport)
  • Simple HTTP for local development or behind a reverse proxy (simpleHttpApp)
  • Extensible handler framework: ProcessHandlers record with optional handlers for each MCP method
  • Tool helpers: ToolHandler, toolHandler, withToolHandlers, toolTextResult, toolTextError
  • Server-to-client requests: ProcessClientInput for sampling, elicitation, and other client callbacks on both transports
  • MCP 2025-06-18: Full protocol version support

License

MPL-2.0