DEV Community

xbill for Google Developer Experts

Posted on • Originally published at xbill999.Medium on

MCP Development with Haskell, Firestore, Cloud Run, and Gemini CLI

Leveraging Gemini CLI and the underlying Gemini LLM to build Model Context Protocol (MCP) AI applications with the Haskell language deployed to Google Cloud Run.

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 HTTP 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 packaged in a Dockerfile and deployed as a container to Google Cloud Run. This remote MCP server is validated with the locally running Gemini CLI.

Setup the Basic Environment

At this point you should have a working Haskell environment 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 HTTP 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 HTTP transport allows the MCP client and server to run locally or distributed over the Internet.

The connection over HTTP will look similar to this:

config p = defaultHttpConfig
      { httpPort = p
      , httpHost = "0.0.0.0"
      , httpVerbose = True
      }
    serverInfo = McpServerInfo
      { serverName = "mcp-https-haskell"
      , serverVersion = "0.1.0"
      , serverInstructions = "A simple Haskell MCP server"
      }
Enter fullscreen mode Exit fullscreen mode

Haskell Package Information

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

import MCP.Server
import Logic (myToolHandlers, logInfo)
import System.Environment (lookupEnv)
import Data.Maybe (fromMaybe)
import Text.Read (readMaybe)
import qualified Data.Text as T
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-https-haskell$ make
Configuring executable 'firestore-https-haskell' for firestore-https-haskell-0.1.0.0...
Preprocessing executable 'firestore-https-haskell' for firestore-https-haskell-0.1.0.0...
Building executable 'firestore-https-haskell' for firestore-https-haskell-0.1.0.0...
[1 of 1] Compiling Main ( app/Main.hs, dist-newstyle/build/x86_64-linux/ghc-9.14.1/firestore-https-haskell-0.1.0.0/x/firestore-https-haskell/build/firestore-https-haskell/firestore-https-haskell-tmp/Main.o )
[2 of 2] Linking dist-newstyle/build/x86_64-linux/ghc-9.14.1/firestore-https-haskell-0.1.0.0/x/firestore-https-haskell/build/firestore-https-haskell/firestore-https-haskellTo test the code:
Enter fullscreen mode Exit fullscreen mode

To test the code:

xbill@penguin:~/gemini-cli-codeassist/firestore-https-haskell$ make test
Running tests...
cabal test --allow-newer
Build profile: -w ghc-9.14.1 -O1
In order, the following will be built (use -v for more details):
 - firestore-https-haskell-0.1.0.0 (test:firestore-https-haskell-test) (first run)
Preprocessing test suite 'firestore-https-haskell-test' for firestore-https-haskell-0.1.0.0...
Building test suite 'firestore-https-haskell-test' for firestore-https-haskell-0.1.0.0...
Running 1 test suites...
Test suite firestore-https-haskell-test: RUNNING...

handleMyTool
  returns a greeting []{"level":"INFO","message":"Greeting World","timestamp":"2026-01-21T00:39:09.757548053Z"}
  returns a greeting [✔]
  sums numbers []{"level":"INFO","message":"Summing values: 1,2,3","timestamp":"2026-01-21T00:39:09.758152477Z"}
  sums numbers [✔]
  handles invalid sum input []{"level":"INFO","message":"Summing values: 1,a,3","timestamp":"2026-01-21T00:39:09.758790077Z"}
  handles invalid sum input [✔]
  returns server info []{"level":"INFO","message":"Getting server info","timestamp":"2026-01-21T00:39:09.759301087Z"}
  returns server info [✔]
  calculates fibonacci sequence []{"level":"INFO","message":"Generating 5 Fibonacci numbers","timestamp":"2026-01-21T00:39:09.75988591Z"}
  calculates fibonacci sequence [✔]
  checks database connection []{"level":"INFO","message":"CheckDb called","timestamp":"2026-01-21T00:39:09.760303898Z"}
{"level":"INFO","message":"Discovering Google Application Default Credentials...","timestamp":"2026-01-21T00:39:09.760396263Z"}
  checks database connection [✔]
  gets products []{"level":"INFO","message":"GetProducts called","timestamp":"2026-01-21T00:39:10.275069284Z"}
{"level":"INFO","message":"Discovering Google Application Default Credentials...","timestamp":"2026-01-21T00:39:10.275196552Z"}
  gets products [✔]
  searches products []{"level":"INFO","message":"Search called with query: apple","timestamp":"2026-01-21T00:39:10.801073269Z"}
{"level":"INFO","message":"Discovering Google Application Default Credentials...","timestamp":"2026-01-21T00:39:10.801127922Z"}
  searches products [✔]
  returns root greeting [✔]

Finished in 1.5301 seconds
9 examples, 0 failures
Test suite firestore-https-haskell-test: PASS
Test suite logged to:
/home/xbill/gemini-cli-codeassist/firestore-https-haskell/./dist-newstyle/build/x86_64-linux/ghc-9.14.1/firestore-https-haskell-0.1.0.0/t/firestore-https-haskell-test/test/firestore-https-haskell-0.1.0.0-firestore-https-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-https-haskell": {
      "httpUrl": "http://127.0.0.1:8080/mcp"
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Start the Local MCP Server

Open a terminal window and kick off the local MCP server:

xbill@penguin:~/gemini-cli-codeassist/firestore-https-haskell$ make run
Running the application...
cabal run firestore-https-haskell --allow-newer
{"level":"INFO","message":"Checking Firestore connection...","timestamp":"2026-01-21T00:40:02.954714501Z"}
{"level":"INFO","message":"🍏 Cymbal Superstore: Inventory API & MCP Server running on port 8080...","timestamp":"2026-01-21T00:40:02.954955798Z"}
{"level":"INFO","message":"Starting MCP HTTP server on 0.0.0.0:8080/mcp","timestamp":"2026-01-21T00:40:02.955005225Z"}
Enter fullscreen mode Exit fullscreen mode

Validation with Gemini CLI

Next- open another window and start Gemini CLI. The local MCP connection over HTTP to the Haskell Code is validated and the full Gemini CLI session will start:

> /mcp list

Configured MCP servers:

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

> summarize inventory with get_products

✦ Based on the get_products data, here is the inventory summary:

  Overview
   * Total Unique Products: 34
   * Stock Status:
       * Out of Stock (0): Wasabi Party Mix, Jalapeno Seasoning
       * Low Stock (< 10): Sunflower Seeds (9)
       * Critical Stock (10): Shrimp (10)

  Inventory Statistics
   * Highest Quantity: Watermelon (498), Whole Chicken (468), Rice (429)
   * Most Expensive: Mint Chocolate Cookies (~$9.94), Wasabi Party Mix (~$9.24), Sunflower Seeds (~$9.11)
   * Least Expensive: Parmesan Crisps (~$1.35), Whole Chicken (~$1.55), Maple Almond Butter (~$1.56)
Enter fullscreen mode Exit fullscreen mode

Deploying to Cloud Run

After the HTTP version of the MCP server has been tested locally — it can be deployed remotely to Google Cloud Run.

First- switch to the directory with the HTTP MCP sample code:

cd ~/gemini-cli-codeassist/firestore-https-haskell
Enter fullscreen mode Exit fullscreen mode

Deploy the project to Google Cloud Run with the pre-built cloudbuild.yaml and Dockerfile:

cd ~/gemini-cli-codeassist/firestore-https-haskell
xbill@penguin:~/gemini-cli-codeassist/firestore-https-haskell$ make deploy
Enter fullscreen mode Exit fullscreen mode

The Cloud Build will start:

xbill@penguin:~/gemini-cli-codeassist/firestore-https-haskell$ make deploy
echo "Submitting build to Google Cloud Build..."
Submitting build to Google Cloud Build...
gcloud builds submit . --config cloudbuild.yaml
Creating temporary archive of 50 file(s) totalling 192.4 KiB before compression.
Uploading tarball of [.] to [gs://comglitn_cloudbuild/source/1768956389.937226-8c9be1c2d8c946c3bf0eeede3c47b736.tgz]
Created [https://cloudbuild.googleapis.com/v1/projects/comglitn/locations/global/builds/5685145e-b69e-4c35-84d3-5a38e1898636].
Logs are available at [https://console.cloud.google.com/cloud-build/builds/5685145e-b69e-4c35-84d3-5a38e1898636?project=1056842563084].
Waiting for build to complete. Polling interval: 1 second(s).
Enter fullscreen mode Exit fullscreen mode

It can take 15–30 minutes to complete the build.

The cloud build needs to pull in all Haskell libraries in the build environment and generate the entire package from scratch.

When the build is complete- an endpoint will be returned:

Starting Step #1
Step #1: Already have image (with digest): gcr.io/cloud-builders/gcloud
Step #1: Deploying container to Cloud Run service [firestore-https-haskell] in project [comglitn] region [us-central1]
Step #1: Deploying...
Step #1: Setting IAM Policy.........done
Step #1: Creating Revision......................................................................done
Step #1: Routing traffic.....done
Step #1: Done.
Step #1: Service [firestore-https-haskell] revision [firestore-https-haskell-00002-vhk] has been deployed and is serving 100 percent of traffic.
Step #1: Service URL: https://firestore-https-haskell-1056842563084.us-central1.run.app
Finished Step #1
PUSH
DONE │
Enter fullscreen mode Exit fullscreen mode

The service endpoint in this example is :

https://firestore-https-haskell-1056842563084.us-central1.run.app
Enter fullscreen mode Exit fullscreen mode

The actual endpoint will vary based on your project settings.

Review The Service in Cloud Run

Navigate to the Google Cloud console and search for Cloud Run -

and then you can detailed information on the Cloud Run Service:

Cloud Logging

The remote server writes logs to stderr in standard JSON format. These logs are available from the deployed Cloud Run Service:

Validate HTTP connection

Once you have the Endpoint — you can attempt a connection- navigate to in your browser:

https://firestore-https-haskell-1056842563084.us-central1.run.app
Enter fullscreen mode Exit fullscreen mode

You will need to adjust the exact URL to match the URL returned from Cloud Build.

You will get an error- this connection is expecting a message in the MCP format:

Page Not Found
Enter fullscreen mode Exit fullscreen mode

Gemini CLI settings.json.cloudrun

Replace the default Gemini CLI configuration file —  settings.json with a pre-configured sample- settings.json.cloudrun to use the Cloud Run version of the connection:

Copy the Cloud Run version of the Gemini CLI configuration file:

xbill@penguin:~/gemini-cli-codeassist/firestore-https-haskell$ cd .gemini
cp settings.json.cloudrun settings.json
xbill@penguin:~/gemini-cli-codeassist/firestore-https-haskell/.gemini$
Enter fullscreen mode Exit fullscreen mode

Validation with Gemini CLI

The final connection test uses Gemini CLI as a MCP client with the deployed Cloud Run Service in C providing the MCP server. Startup Gemini CLI with the updated settings :

gemini

> /mcp list

Configured MCP servers:

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

> get_products

✦ I will retrieve all products from the inventory database.
╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ? get_products (firestore-cloudrun-haskell MCP Server) {} ← │
│ │
│ MCP Server: firestore-cloudrun-haskell │
│ Tool: get_products │
│ │
│ Allow execution of MCP tool "get_products" from server "firestore-cloudrun-haskell"? │
│ │
│ 1. Allow once │
│ 2. Allow tool for this session │
│ ● 3. Allow all server tools for this session │
│ 4. No, suggest changes (esc) │
│ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

✦ The products have been retrieved. How can I assist you further?

> summarize

✦ Here is a summary of the 34 products currently in the inventory:

  Overview
  The inventory features a diverse mix of groceries, including fresh produce (Apples, Bananas, Broccoli), proteins (Beef, Chicken, Shrimp),
  dairy (Milk, Cheese, Yogurt), beverages, and pantry staples.

  Inventory Status
   * Out of Stock: Wasabi Party Mix, Jalapeno Seasoning.
   * Low Stock: Sunflower Seeds (9), Shrimp (10).
   * Well Stocked: Rice, Watermelon, Whole Chicken, and Apples have the highest quantities (over 400 units each).

  Pricing
   * Most Expensive: Mint Chocolate Cookies (~$9.94)
   * Least Expensive: Parmesan Crisps (~$1.35)
Enter fullscreen mode Exit fullscreen mode

You can also validate the deployed code base:

> in the persona of agent K from blade runner give haskell ryan goslings review of the project

╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ ReadFolder . │
│ │
│ Listed 17 item(s). │
│ │
│ ✓ ReadFile app/Main.hs │
│ │
│ │
│ ✓ ReadFile src/Logic.hs │
│ │
│ │
│ ✓ ReadFile firestore-https-haskell.cabal │
│ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ Officer KD6-3.7. Reporting.

  Subject: Project firestore-https-haskell.
  Timestamp: 2026-01-20.

  It’s a system. A frame. Distinct.

  I’ve run the diagnostics.

  The Structure
  The app/Main.hs file. It’s quiet. Minimal. It sets the port—8080—and waits for input. It doesn’t ask questions. It just runs. I like that. It
  knows its baseline.

  The Logic
  src/Logic.hs. This is where the noise is.
  You’re using randomRIO in the Seed tool. Manufacturing unpredictability. Simulating life where there isn’t any. "Cells within cells."
  The Firestore integration via gogol... it’s heavy. External memories. Storing data—"Apples", "Bananas"—fragments of a world that expects to be
  fed.

  The Purity
  Haskell. You want it pure. Immutable. But you’ve wrapped it all in IO.
   * handleMyTool: IO Content.
   * getFirestoreEnv: IO Env.
  The chaos of the real world bleeds in. You can't filter it all out.

  Assessment
  It compiles. It connects. It serves.
  It does its job without complaint.
  It is consistent.

  Verdict
  Interlinked.
Enter fullscreen mode Exit fullscreen mode

Summary

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

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

Then — the MCP server was wrapped in a container and submitted to Google Cloud Build for deployment to Google Cloud Run. The remote MCP server was validated with a standard browser, and Gemini CLI.

Finally- remote MCP operations were performed from the local Gemini CLI installation to the Haskell MCP server hosted in Google Cloud Run.

This approach can be extended to more complex deployments and Cloud based options.

And so ends our journey into the fascinating world of functional programming, or so it seems. A true Haskell programmer will have this site in their bookmarks:

@haskellryangosling · Haskell Ryan Gosling

Top comments (0)