Cover image
Try Now
2025-03-25

WIP: Haskell server/client for MCP (Model Context Protocol)

3 years

Works with Finder

1

Github Watches

0

Github Forks

0

Github Stars

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.

相关推荐

  • NiKole Maxwell
  • I craft unique cereal names, stories, and ridiculously cute Cereal Baby images.

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • Yasir Eryilmaz
  • AI scriptwriting assistant for short, engaging video content.

  • Daren White
  • A supportive coach for mastering all Spanish tenses.

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://zenepic.net
  • Embark on a thrilling diplomatic quest across a galaxy on the brink of war. Navigate complex politics and alien cultures to forge peace and avert catastrophe in this immersive interstellar adventure.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • huahuayu
  • A unified API gateway for integrating multiple etherscan-like blockchain explorer APIs with Model Context Protocol (MCP) support for AI assistants.

  • deemkeen
  • control your mbot2 with a power combo: mqtt+mcp+llm

  • zhaoyunxing92
  • 本项目是一个钉钉MCP(Message Connector Protocol)服务,提供了与钉钉企业应用交互的API接口。项目基于Go语言开发,支持员工信息查询和消息发送等功能。

  • justmywyw
  • Short and sweet example MCP server / client implementation for Tools, Resources and Prompts.

  • sligter
  • Lite-MCP-Client是一个基于命令行的轻量级MCP客户端工具

    Reviews

    2 (1)
    Avatar
    user_2dElmKBE
    2025-04-16

    I have been using hs-mcp by buecking, and it's truly impressive! This handy tool simplifies tasks with great efficiency and robust functionality. Whether you're a beginner or a seasoned pro, hs-mcp offers a seamless experience. Its intuitive design and powerful features make it a must-have for any engineering toolbox. Highly recommend checking it out at https://github.com/buecking/hs-mcp!