Navigation
MCP-Haskell (hs-mcp): Type-Safe, Robust Client-Server Solutions - MCP Implementation

MCP-Haskell (hs-mcp): Type-Safe, Robust Client-Server Solutions

Efficient, type-safe MCP protocol implementation in Haskell: robust client-server solutions for scalable, mission-critical systems.

Developer Tools
4.1(161 reviews)
241 saves
112 comments

This tool saved users approximately 12773 hours last month!

About MCP-Haskell (hs-mcp)

What is MCP-Haskell (hs-mcp): Type-Safe, Robust Client-Server Solutions?

MCP-Haskell is a Haskell implementation of the Model Context Protocol (MCP), enabling seamless integration of tools, resources, and prompts between Haskell applications and MCP-compliant clients. Designed for type-safe and fault-tolerant communication, it provides a structured framework for building client-server systems that adhere rigorously to the MCP specification. Whether you're building AI tooling integrations or cross-process resource managers, this library ensures reliability through its robust architecture and thorough testing.

How to Use MCP-Haskell: Step-by-Step Implementation

Getting started involves three core steps: setup, configuration, and execution. Begin by cloning the repository and configuring your Nix environment:

# Setup
git clone https://github.com/buecking/hs-mcp.git
cd hs-mcp
nix develop

Create servers using the provided API, defining capabilities like resource handling or tool execution. Here's a simplified server snippet:

main :: IO ()
main = do
  let serverInfo = Implementation "my-server" "1.0.0"
  server <- createServer serverInfo serverCapabilities
  registerResourceReadHandler server $ \request -> do
    -- Your implementation logic
    pure $ Success "Read successful"
  runServerWithSTDIO server

Test with the included echo server or the MCP Inspector tool.

MCP-Haskell (hs-mcp) Features

Key Features of MCP-Haskell: Beyond Standard Capabilities

  • Protocol Integrity: Full MCP compliance with precise type definitions
  • Transport Flexibility: Built-in support for StdIO and JSON-RPC communication
  • Modular Components: Separate handlers for resources, tools, and prompts
  • Test-Driven Reliability: Extensive test suite ensuring production readiness

Use Cases: Where MCP-Haskell Shines

Primarily used for:

  • Building AI tooling integrations for platforms like Claude Desktop
  • Creating cross-language server workflows via standardized JSON-RPC messaging
  • Local development environments with fast resource sharing over StdIO
  • Automated testing frameworks requiring protocol validation

MCP-Haskell (hs-mcp) FAQ

FAQ: Common Questions Answered

Does this support other clients besides Claude?

Yes! Works with any MCP-compliant client, including the MCP Inspector and custom implementations.

How do I extend existing servers?

Use the modular API to incrementally add capabilities - start with basic resource handling and progressively include tools/prompt systems.

What's the contribution process?

Submit pull requests targeting the main branch. All contributions are reviewed for protocol compliance and type safety.

Content

MCP-Haskell (hs-mcp)

A Haskell implementation of the Model Context Protocol (MCP).

Overview

MCP-Haskell (hs-mcp) provides a Haskell implementation of the Model Context Protocol, allowing Haskell applications to expose tools, resources, and prompts to MCP-compatible clients like Claude.

Key features:

  • Full implementation of MCP protocol
  • StdIO transport for local process communication
  • JSON-RPC messaging
  • Support for resources, tools, and prompts
  • Comprehensive test suite

Installation

# Clone the repository
git clone github.com:buecking/hs-mcp.git
cd hs-mcp

# direnv
# echo 'use flake' > .envrc
direnv allow

# nix
nix develop

# Build the project
cabal build

Usage

Creating a simple server

import Network.MCP.Server
import Network.MCP.Types
import Network.MCP.Server.StdIO

main :: IO ()
main = do
  -- Create server
  let serverInfo = Implementation "my-server" "1.0.0"
      serverCapabilities = ServerCapabilities
        { resourcesCapability = Just $ ResourcesCapability True
        , toolsCapability = Just $ ToolsCapability True
        , promptsCapability = Nothing
        }
  
  server <- createServer serverInfo serverCapabilities
  
  -- Register resources (optional)
  let resource = Resource 
        { resourceUri = "my://resource"
        , resourceName = "My Resource"
        , resourceDescription = Just "Description"
        , resourceMimeType = Just "text/plain"
        , resourceTemplate = Nothing
        }
  
  registerResources server [resource]
  
  -- Register resource read handler
  registerResourceReadHandler server $ \request -> do
    -- Implement resource reading logic
    ...

  -- Register tools (optional)
  let tool = Tool 
        { toolName = "my-tool"
        , toolDescription = Just "My tool"
        , toolInputSchema = "{...}" -- JSON schema
        }
  
  registerTools server [tool]
  
  -- Register tool call handler
  registerToolCallHandler server $ \request -> do
    -- Implement tool execution logic
    ...
  
  -- Start the server with StdIO transport
  runServerWithSTDIO server

Example Server

The project includes an example echo server that demonstrates the MCP functionality:

# Build and run the example server
cabal run mcp-echo-server

You can test it with the MCP Inspector or Claude Desktop.

Testing

Run the test suite:

cabal test

Protocol Compatibility

This implementation follows the Model Context Protocol specification and is compatible with:

  • Claude Desktop
  • MCP Inspector
  • Other MCP clients following the specification

Project Structure

  • src/Network/MCP/Types.hs - Core MCP types
  • src/Network/MCP/Transport/ - Transport implementations
  • src/Network/MCP/Server/ - Server implementation
  • Examples/ - Example implementations
  • Test/ - Test suite

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the BSD-3-Clause License - see the LICENSE file for details.

Related MCP Servers & Clients