DH

drshade/haskell-mcp-server

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

51 stars 17 forks 质量 76 趋势 20BSD-3-Clause

drshade/haskell-mcp-server 是从 https://github.com/drshade/haskell-mcp-server. 导入的 MCP 服务器候选

概览

drshade/haskell-mcp-server 是从 https://github.com/drshade/haskell-mcp-server. 导入的 MCP 服务器候选

概述(AI 翻译)

构建模型上下文协议服务器 Haskell 来自纯数据类型。声明你的工具、提示和资源为 ADT,每个类型写一个处理程序,库派生 JSON 模式, 为你提供参数解码、验证和线路协议——然后将其传递 stdio 或可流式 HTTP 到 Claude Code、Codex、Claude Desktop、Cursor 及任何 其他MCP客户端。

这是一个完整且可运行的MCP服务器,暴露了两个工具,current_weather 以及forecast,每个都带有由其构造子字段派生的JSON模式。

你免费得到的东西

推导读取你的类型,所以线路上的模式总是与 接收参数的处理器。给定该构造子来自 examples/Complete:

tools/list 返回恰好如此(从运行示例中捕获;a 没有描述的字段以其名称描述:

并且一个参数匹配的tools/call作为完全进入你的处理器 解码 Checkout Express (Address "1 Main St" "Springfield" Nothing)。 错误的论点永远不会传到你那里;图书馆会用适当的方式回应 JSON-RPC 错误。同样的机制反向用于类型化结果(参见 结构化输出)。

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

mcp-server

Build Model Context Protocol servers in Haskell from plain data types. Declare your tools, prompts and resources as ADTs, write one handler per type, and the library derives the JSON schemas, argument decoding, validation and wire protocol for you — then serves it over stdio or Streamable HTTP to Claude Code, Codex, Claude Desktop, Cursor and any other MCP client.

{-# LANGUAGE OverloadedStrings, TemplateHaskell #-}

import Data.Text (Text)
import MCP.Server
import MCP.Server.Derive

data Units = Celsius | Fahrenheit

data WeatherTool
    = CurrentWeather { city :: Text, units :: Maybe Units }
    | Forecast       { city :: Text, days :: Int }

handleTool :: ClientContext -> WeatherTool -> IO Content
handleTool _ (CurrentWeather c _) = pure $ ContentText $ "Sunny in " <> c
handleTool _ (Forecast c n)       = pure $ ContentText $ "Forecast for " <> c

$(pure [])  -- end the declaration group so the splice below can see the types

main :: IO ()
main = runMcpServerStdio serverInfo noHandlers
    { tools = Just $(deriveToolHandler ''WeatherTool 'handleTool) }
  where
    serverInfo = McpServerInfo
      { serverName = "weather", serverVersion = "1.0.0"
      , serverInstructions = "Weather lookups" }

That is a complete, working MCP server exposing two tools, current_weather and forecast, each with a JSON schema derived from its constructor’s fields.

What you get for free

The derivation reads your types, so the schema on the wire always matches the handler that receives the arguments. Given this constructor from examples/Complete:

data ShippingSpeed = Standard | Express | Overnight

data Address = Address
    { street  :: Text
    , city    :: Text
    , zipCode :: Maybe Text
    }

data MyTool
    = Checkout { speed :: ShippingSpeed, shipTo :: Address }
    | ...

tools/list returns exactly this (captured from the running example; a field without a description is described by its name):

{
  "name": "checkout",
  "description": "Checkout",
  "annotations": { "destructiveHint": true },
  "inputSchema": {
    "type": "object",
    "required": ["speed", "shipTo"],
    "properties": {
      "speed":  { "type": "string", "enum": ["standard", "express", "overnight"],
                  "description": "speed" },
      "shipTo": {
        "type": "object",
        "description": "shipTo",
        "required": ["street", "city"],
        "properties": {
          "street":  { "type": "string", "description": "street" },
          "city":    { "type": "string", "description": "city" },
在 GitHub 查看完整 README

安装

docker run -i --entrypoint=/usr/local/bin/simple-example haskell-mcp-server
新手?先看 mcpskill.org 教程 →

配置

{ "mcpServers": { "my-server": { "type": "stdio", "command": "/path/to/my-server", "env": { "API_KEY": "${API_KEY}" } } } }