DEV Community

xbill for Google Developer Experts

Posted on • Originally published at xbill999.Medium on

MCP Development with Haskell, Firestore, and Gemini CLI

Leveraging Gemini CLI and the underlying Gemini LLM to build Model Context Protocol (MCP) AI applications with the Haskell language in a local development environment.

Why not just use Python?

Python has traditionally been the main coding language for ML and AI tools. One of the strengths of the MCP protocol is that the actual implementation details are independent of the development language. The reality is that not every project is coded in Python- and MCP allows you to use the latest AI approaches with other coding languages.

Haskell? Are you kidding me? Functional Programming with MCP?

The goal of this article is to provide a minimal viable basic working MCP stdio server in Haskell that can be run locally without any unneeded extra code or extensions.

Not a fan of functional programming?

It takes all kinds. The bottom line is different strokes for different folks and the tools can meet you where you are.

Haskell Native MCP Library

The Haskell MCP library is here:

mcp-server

What Is Haskell?

Haskell is a powerful, general-purpose programming language known for being purely functional, statically typed, and lazy (non-strict), meaning it focuses on mathematical functions, checks types at compile time for robust code, and evaluates expressions only when needed. Named after logician Haskell Brooks Curry (whose work underpins functional programming), it allows developers to build concise, reliable software for complex tasks, particularly in areas like finance, data processing, and large-scale systems, by emphasizing immutability and preventing side effects.

Official Haskell Site

The official Haskell site has all the resources you will ever need:

Haskell Language

Installing Haskell

Haskell comes with a whole eco-system including tooling, utilities, and build management.

The first step is to use the ghcup tool:

GHCup

The step by step instructions vary by platform- for a basic Debian system here are the steps:

sudo apt-get update
sudo apt-get install build-essential curl libffi-dev libgmp-dev libgmp10 libncurses-dev libncurses5 libtinfo5
Enter fullscreen mode Exit fullscreen mode

Then bootstrap the Haskell installation with a script:

curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh
Enter fullscreen mode Exit fullscreen mode

Haskell Eco-System

The main components of the Haskell eco-system include:

  • GHC (Glasgow Haskell Compiler): The compiler for Haskell.
  • Cabal: A build tool and package manager for Haskell projects.
  • Stack: Another project manager for building and managing Haskell applications (optional).
  • haskell-language-server (HLS): Provides IDE features like auto-completion and diagnostics (optional).

Managing Haskell Packages

The Haskell tooling has a version manager that allows for the quick setting of the tool versions:

ghcup tui
Enter fullscreen mode Exit fullscreen mode

This will start the version manager in a terminal window:

What is Firestore?

Google Firestore, also known as Cloud Firestore is a part of the Google Firebase application development platform. It is fundamentally a cloud-hosted NoSQL database for storing and syncing data. Firestore can be directly accessed by mobile and web applications through native SDKs.

Firestore | Firebase

Gemini CLI

If not pre-installed you can download the Gemini CLI to interact with the source files and provide real-time assistance:

npm install -g @google/gemini-cli
Enter fullscreen mode Exit fullscreen mode

Testing the Gemini CLI Environment

Once you have all the tools and the correct Node.js version in place- you can test the startup of Gemini CLI. You will need to authenticate with a Key or your Google Account:

gemini
Enter fullscreen mode Exit fullscreen mode

Node Version Management

Gemini CLI needs a consistent, up to date version of Node. The nvm command can be used to get a standard Node environment:

GitHub - nvm-sh/nvm: Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions

Haskell MCP Documentation

The official MCP Haskell page provides samples and documentation for getting started:

GitHub - Tritlo/mcp

Where do I start?

The strategy for starting MCP development is a incremental step by step approach.

First, the basic development environment is setup with the required system variables, and a working Gemini CLI configuration.

Then, a minimal Hello World Style Haskell MCP Server is built with stdio transport. This server is validated with Gemini CLI in the local environment.

This setup validates the connection from Gemini CLI to the local process via MCP. The MCP client (Gemini CLI) and the MCP server both run in the same local environment.

Next- the basic MCP server is extended with Gemini CLI to add several new tools in standard code.

Setup the Basic Environment

At this point you should have a working C build environment, Haskell tools, and a working Gemini CLI installation. The next step is to clone the GitHub samples repository with support scripts:

cd ~
git clone https://github.com/xbill9/gemini-cli-codeassist
Enter fullscreen mode Exit fullscreen mode

Then run init.sh from the cloned directory.

The script will attempt to determine your shell environment and set the correct variables:

cd gemini-cli-codeassist
source init.sh
Enter fullscreen mode Exit fullscreen mode

If your session times out or you need to re-authenticate- you can run the set_env.sh script to reset your environment variables:

cd gemini-cli-codeassist
source set_env.sh
Enter fullscreen mode Exit fullscreen mode

Variables like PROJECT_ID need to be setup for use in the various build scripts- so the set_env script can be used to reset the environment if you time-out.

Hello World with STDIO Transport

One of the key features that the standard MCP libraries provide is abstracting various transport methods.

The high level MCP tool implementation is the same no matter what low level transport channel/method that the MCP Client uses to connect to a MCP Server.

The simplest transport that the SDK supports is the stdio (stdio/stdout) transport — which connects a locally running process. Both the MCP client and MCP Server must be running in the same environment.

The connection over stdio will look similar to this:

logInfo "Starting Haskell MCP Server..."
  runMcpServerStdio serverInfo handlers
Enter fullscreen mode Exit fullscreen mode

Haskell Package Information

The code depends on several standard libraries for MCP and logging:

import Data.Aeson
import Data.Text (Text)
import qualified Data.ByteString.Lazy.Char8 as BSL
import System.IO (stderr)
import Data.Time (getCurrentTime)
import Types
import qualified Data.Text as T
import Text.Read (readMaybe)
Enter fullscreen mode Exit fullscreen mode

Installing and Running the Code

Run the install make release target on the local system:

xbill@penguin:~/gemini-cli-codeassist/firestore-stdio-haskell$ make
Building the application...
cabal build --allow-newer
Up to date
Enter fullscreen mode Exit fullscreen mode

To test the code:

xbill@penguin:~/gemini-cli-codeassist/mcp-stdio-haskell$ make test
Running tests...
cabal test --allow-newer

Finished in 6.8669 seconds
8 examples, 0 failures
Test suite firestore-stdio-haskell-test: PASS
Test suite logged to:
/home/xbill/gemini-cli-codeassist/firestore-stdio-haskell/./dist-newstyle/build/x86_64-linux/ghc-9.14.1/firestore-stdio-haskell-0.1.0.0/t/firestore-stdio-haskell-test/test/firestore-stdio-haskell-0.1.0.0-firestore-stdio-haskell-test.log
1 of 1 test suites (1 of 1 test cases) passed.
Enter fullscreen mode Exit fullscreen mode

Gemini CLI settings.json

In this example — the Haskell source code uses a compiled binary that can be called directly from Gemini CLI.

The default Gemini CLI settings.json has an entry for the source:

{
  "mcpServers": {
    "firestore-stdio-haskell": {
      "command": "cabal",
      "args": ["run", "firestore-stdio-haskell", "--allow-newer", "--", "--stdio"]
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Validation with Gemini CLI

Finally- Gemini CLI is restarted and the MCP connection over stdio to the Code is validated, The full Gemini CLI Session will start:

> /mcp list

Configured MCP servers:

🟢 firestore-stdio-haskell - Ready (11 tools)
  Tools:
  - check_db
  - fibonacci
  - get_haskell_system_info
  - get_product_by_id
  - get_products
  - get_root
  - get_server_info
  - greet
  - reset
  - seed
  - sum

> find Coffee

✦ I found one product matching "Coffee":

   - Name: Coffee Beans
   - ID: 37kWbZHTwg5nbrSD13PB
   - Price: $5.11
   - Quantity: 297
   - Image: coffeebeans.png
   - Added: 2026-01-20 (Timestamp: 2025-10-13)

Enter fullscreen mode Exit fullscreen mode

Extending the MCP Server with Gemini CLI

Now that the basic MCP functionality has been tested and verified with Gemini CLI- the Haskell server code can be extended with new MCP tools:

> with the Haskell project add new MCP tools - 
one that creates a functional programming language style to optimize menus
and one that reports on inventory levels
Enter fullscreen mode Exit fullscreen mode

Gemini CLI will get right to work:

✦ I will add two new tools to the project: InventoryReport and OptimizeMenu.

   1. `InventoryReport`: This tool will generate a summary of the current inventory, including total item count, total inventory value, and a
      list of low-stock items.
   2. `OptimizeMenu`: This tool will accept a maxPrice and return a list of products that are affordable (under the max price) and currently in
      stock, effectively "optimizing" menu selection based on budget and availability.

  I will start by updating app/Types.hs to include these new tool definitions. │ │ │
Enter fullscreen mode Exit fullscreen mode

Once completed — the changes will be summarized:

✦ The build was successful. I have implemented the two tools as requested.
   - InventoryReport summarizes the inventory.
   - OptimizeMenu takes a max price and returns sorted available items.
Enter fullscreen mode Exit fullscreen mode

Restart Gemini CLI and check for the new MCP tools:

xbill@penguin:~/gemini-cli-codeassist/firestore-stdio-haskell$ make
Building the application...
cabal build --allow-newer
Up to date
Enter fullscreen mode Exit fullscreen mode

And list the new MCP Tools:

> /mcp list

Configured MCP servers:

🟢 firestore-stdio-haskell - Ready (13 tools)
  Tools:
  - check_db
  - fibonacci
  - get_haskell_system_info
  - get_product_by_id
  - get_products
  - get_root
  - get_server_info
  - greet
  - inventory_report
  - optimize_menu
  - reset
  - seed
  - sum
Enter fullscreen mode Exit fullscreen mode

to run the newtools:

>inventory_report

> inventory_report

✦ I will generate the inventory report for you.

╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ inventory_report (firestore-stdio-haskell MCP Server) {} │
│ │
│ Inventory Report: │
│ Total Unique Products: 34 │
│ Total Inventory Value: $32193.4471097568 │
│ Low Stock Items (< 10 units): │
│ - Wasabi Party Mix: 0 │
│ - Jalapeno Seasoning: 0 │
│ - Sunflower Seeds: 9 │
│ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ The inventory report shows a total of 34 unique products with a total value of approximately $32,193.45. There are several low-stock items
  that need attention: Wasabi Party Mix and Jalapeno Seasoning are out of stock, while Sunflower Seeds have only 9 units left.
Enter fullscreen mode Exit fullscreen mode

and menu information:

> optimize_menu

✦ Here is the optimized menu list:

   * Mint Chocolate Cookies: $9.94
   * Sunflower Seeds: $9.11
   * Cheddar Cheese: $9.10
   * Eggs: $8.54
   * Watermelon: $8.41
   * Jasmine Rice: $8.32
   * Peanut Butter and Jelly Cups: $7.75
   * Beef: $7.69
   * White Chocolate Caramel Corn: $6.75
   * Shrimp: $6.73
   * Cinnamon: $6.55
   * Yogurt: $5.80
   * Whole Wheat Bread: $5.21
   * Green Tea: $5.18
   * Coffee Beans: $5.11
   * Bananas: $4.88
   * Milk: $4.21
   * Black Beans: $3.68
   * Acai Smoothie Packs: $3.35
   * Smores Cereal: $3.26
   * Apples: $3.13
   * Broccoli: $3.09
   * Pineapple Kombucha: $2.75
   * Fresh Basil: $2.58
   * Cola: $2.28
   * Rice: $2.26
   * Bottled Water: $2.22
   * Walnuts: $1.92
   * Apple Juice: $1.85
   * Maple Almond Butter: $1.56
   * Whole Chicken: $1.55
   * Parmesan Crisps: $1.35

Enter fullscreen mode Exit fullscreen mode

And finally the key question:

> would Haskell Ryan Gosling approve?

✦ I will search for the definition of the optimize_menu tool in the codebase to see if the implementation meets "Haskell Ryan Gosling's"
  standards.

╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ SearchText 'optimize_menu' within ./ │
│ │
│ No matches found │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ I will read app/Main.hs to understand how the MCP tools are registered and find the handler for the menu optimization logic.

╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ ReadFile app/Main.hs │
│ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ I will search for the definition of myToolHandlers within app/Main.hs to locate the tool definitions.

╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ SearchText 'myToolHandlers' within app/Main.hs │
│ │
│ Found 1 match │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ I will read app/Logic.hs to check if myToolHandlers is defined there and to understand the implementation of the menu optimization logic.

╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ ReadFile app/Logic.hs │
│ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ I will read app/Types.hs to check the Product type definition and confirm if it derives Generic, FromJSON, and ToJSON.

╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ ReadFile app/Types.hs │
│ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ Hey girl.

  I checked your OptimizeMenu implementation. You're using filter and sortBy composed with the $ operator to transform immutable lists. You're
  handling your side effects in IO but keeping your logic pure where it matters.

  And when you parsed those Firestore documents?
  let products = [p | Just p <- map docToProduct docs]

  You used a list comprehension to safely unwrap those Maybe values. I love it when you're safe and expressive.

  I approve.
Enter fullscreen mode Exit fullscreen mode

Summary

The strategy for using Haskell with MCP development with Gemini CLI was validated with an incremental step by step approach.

A minimal stdio transport MCP Server was started from source code and validated with Gemini CLI running as a MCP client in the same local environment.

Gemini CLI was then used to extend the sample Haskell code with several MCP tools and use these tools inside the context for the underlying LLM.

Top comments (0)