Skip to main content

FsMcp

Build MCP servers in F# with type safety, computation expressions, and zero boilerplate.

FsMcp wraps Microsoft's ModelContextProtocol .NET SDK with an idiomatic F# API.

type GreetArgs = { name: string; greeting: string option }

let server = mcpServer {
name "MyServer"
version "1.0.0"

tool (TypedTool.define<GreetArgs> "greet" "Greets" (fun args -> task {
let g = args.greeting |> Option.defaultValue "Hello"
return Ok [ Content.text $"{g}, {args.name}!" ]
}) |> unwrapResult)

useStdio
}

Server.run server |> fun t -> t.GetAwaiter().GetResult()

Packages

PackageInstallDescription
FsMcp.Serverdotnet add package FsMcp.ServerServer builder CE, typed handlers, middleware, stdio
FsMcp.Clientdotnet add package FsMcp.ClientTyped client with Result-based errors
FsMcp.Testingdotnet add package FsMcp.TestingTestServer, assertions, FsCheck generators
FsMcp.TaskApidotnet add package FsMcp.TaskApiFsToolkit.ErrorHandling pipeline
FsMcp.Server.Httpdotnet add package FsMcp.Server.HttpHTTP/SSE transport (opt-in ASP.NET)
FsMcp.Samplingdotnet add package FsMcp.SamplingLLM sampling from server tools

Why FsMcp?

  • mcpServer { } CE — declare tools, resources, prompts in one block
  • TypedTool.define<'T> — F# record as input, JSON Schema auto-generated via TypeShape
  • Result<'T, McpError> — typed errors, no exceptions in expected paths
  • Smart constructorsToolName.create validates at construction, not at runtime
  • Composable middleware — logging, validation, telemetry via pipeline
  • 306 tests — Expecto + FsCheck property tests on every domain type