DEV Community

xbill
xbill

Posted on

MCP Development With Haskell, Cloud Run, and Gemini CLI

This is a submission for the New Year, New You Portfolio Challenge Presented by Google AI

About Me

Portfolio


title: "MCP Development with Haskell, Cloud Run, and Gemini CLI"
published: true
date: 2026-01-18 12:07:55 UTC
tags: mcps,endofunctors,haskell,geminicli

canonical_url: https://medium.com/@xbill999/mcp-development-with-haskell-cloud-run-and-gemini-cli-ff4347fc3967

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:

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/mcp-https-haskell$ make
Building the application...
cabal build --allow-newer
Resolving dependencies...
Build profile: -w ghc-9.14.1 -O1
Enter fullscreen mode Exit fullscreen mode

A binary is generated at the end of the process:

Configuring executable 'mcp-https-haskell' for mcp-https-haskell-0.1.0.0...
Preprocessing executable 'mcp-https-haskell' for mcp-https-haskell-0.1.0.0...
Building executable 'mcp-https-haskell' for mcp-https-haskell-0.1.0.0...
[1 of 1] Compiling Main ( app/Main.hs, dist-newstyle/build/x86_64-linux/ghc-9.14.1/mcp-https-haskell-0.1.0.0/x/mcp-https-haskell/build/mcp-https-haskell/mcp-https-haskell-tmp/Main.o ) [Logic changed]
[2 of 2] Linking dist-newstyle/build/x86_64-linux/ghc-9.14.1/mcp-https-haskell-0.1.0.0/x/mcp-https-haskell/build/mcp-https-haskell/mcp-https-haskell [Objects changed]
Enter fullscreen mode Exit fullscreen mode

To test the code:

Test suite mcp-https-haskell-test: RUNNING...

handleMyTool
  greets a person []{"level":"INFO","message":"Greeting Alice","timestamp":"2026-01-17T18:28:05.823208887Z"}
{"level":"INFO","message":"Result: Hello, Alice!","timestamp":"2026-01-17T18:28:05.823309567Z"}
  greets a person [✔]
  sums a list of numbers []{"level":"INFO","message":"Summing values: 1, 2, 3","timestamp":"2026-01-17T18:28:05.823406453Z"}
{"level":"INFO","message":"Result: 6","timestamp":"2026-01-17T18:28:05.823469414Z"}
  sums a list of numbers [✔]
  handles invalid sum input []{"level":"INFO","message":"Summing values: 1, a, 3","timestamp":"2026-01-17T18:28:05.823542593Z"}
{"level":"INFO","message":"Result: Error: Invalid input. Please provide a comma-separated list of integers.","timestamp":"2026-01-17T18:28:05.823582431Z"}
  handles invalid sum input [✔]

Finished in 0.0005 seconds
3 examples, 0 failures
Test suite mcp-https-haskell-test: PASS
Test suite logged to:
/home/xbill/gemini-cli-codeassist/mcp-https-haskell/./dist-newstyle/build/x86_64-linux/ghc-9.14.1/mcp-https-haskell-0.1.0.0/t/mcp-https-haskell-test/test/mcp-https-haskell-0.1.0.0-mcp-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": {
    "mcp-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/mcp-https-haskell$ make run
Running the application...
cabal run mcp-https-haskell --allow-newer
{"level":"INFO","message":"Starting Haskell MCP Server (HTTP) on port 8080...","timestamp":"2026-01-17T18:33:53.379379405Z"}
{"level":"INFO","message":"Starting MCP HTTP server on 0.0.0.0:8080/mcp","timestamp":"2026-01-17T18:33:53.379776406Z"}
{"level":"DEBUG","message":"HTTP \"POST\" /mcp","timestamp":"2026-01-17T18:34:12.465111646Z"}
{"level":"DEBUG","message":"Notice: Missing MCP-Protocol-Version header, assuming 2025-06-18","timestamp":"2026-01-17T18:34:12.465313617Z"}
{"level":"DEBUG","message":"Received POST body (198 bytes): \"{\\\"method\\\":\\\"initialize\\\",\\\"params\\\":{\\\"protocolVersion\\\":\\\"2025-11-25\\\",\\\"capabilities\\\":{\\\"roots\\\":{\\\"listChanged\\\":true}},\\\"clientInfo\\\":{\\\"name\\\":\\\"gemini-cli-mcp-client\\\",\\\"version\\\":\\\"0.0.1\\\"}","timestamp":"2026-01-17T18:34:12.465347151Z"}
{"level":"DEBUG","message":"Processing HTTP message: \"Request[RequestIdNumber 0] initialize\"","timestamp":"2026-01-17T18:34:12.465419861Z"}
{"level":"INFO","message":"Client version: 2025-11-25, using: 2025-11-25","timestamp":"2026-01-17T18:34:12.465453171Z"}
{"level":"DEBUG","message":"Sending HTTP response for: \"Request[RequestIdNumber 0] initialize\"","timestamp":"2026-01-17T18:34:12.465470499Z"}
{"level":"DEBUG","message":"HTTP \"POST\" /mcp","timestamp":"2026-01-17T18:34:12.497698483Z"}
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
🟢 mcp-https-haskell - Ready (2 tools)
  Tools:
  - greet
  - sum

 mcp-https-haskell - Ready (2 tools)
  Tools:
  - greet
  - sum

> greet all your Monads belong to us!

✦ I'll greet you using the available tool.

╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ? greet (mcp-https-haskell MCP Server) {"name":"all your Monads belong to us!"} ← │
│ │
│ MCP Server: mcp-https-haskell │
│ Tool: greet │
│ │
│ Allow execution of MCP tool "greet" from server "mcp-https-haskell"? │
│ │
│ 1. Allow once │
│ 2. Allow tool for this session │
│ ● 3. Allow all server tools for this session │
│ 4. No, suggest changes (esc) │
│ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ greet (mcp-https-haskell MCP Server) {"name":"all your Monads belong to us!"} │
│ │
│ Hello, all your Monads belong to us!! │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ OK! How can I help you with your Haskell MCP server today?

> sum the first 6 mersenne primes

✦ I'll calculate the sum of the first 6 Mersenne primes: 3, 7, 31, 127, 8191, and 131071.

╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ sum (mcp-https-haskell MCP Server) {"values":"3,7,31,127,8191,131071"} │
│ │
│ 139430 │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ The sum of the first 6 Mersenne primes (3, 7, 31, 127, 8191, and 131071) is 139,430.

Enter fullscreen mode Exit fullscreen mode

And the Key Question:

> do all your monads belong to us?

✦ I'll search the codebase for the phrase "monads belong to us" to see if it's referenced, and also examine
  app/Main.hs and src/Logic.hs to understand the greet tool's implementation.

╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ SearchText 'monads belong to us' within ./ │
│ │
│ No matches found │
│ │
│ ✓ ReadFile app/Main.hs │
│ │
│ │
│ ✓ ReadFile src/Logic.hs │
│ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ I'll read src/Types.hs to review the MyTool definition and ensure I have a complete understanding of the tool
  structures.

╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ ReadFile src/Types.hs │
│ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ Based on my analysis of the codebase, specifically src/Logic.hs, the greet tool is implemented to simply echo back
  the input prefixed with "Hello, ".

   1 handleMyTool (Greet n) = do
   2 logInfo $ "Greeting " <> n
   3 let result = "Hello, " <> n <> "!"
   4 logInfo $ "Result: " <> result
   5 pure $ ContentText result

  So, while the server doesn't have a built-in "Monad Annexation" protocol, it will happily greet any philosophical
  statements you pass to it!

  Technically, the code defines two tools:
   1. `Greet`: Takes a name and returns "Hello, {name}!".
   2. `Sum`: Takes a comma-separated string of numbers and returns their sum.

  No hidden "base" or "monad" capturing logic was found in the source.

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/mcp-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/mcp-https-haskell
xbill@penguin:~/gemini-cli-codeassist/mcp-https-haskell$ make deploy
Enter fullscreen mode Exit fullscreen mode

The Cloud Build will start:

xbill@penguin:~/gemini-cli-codeassist/mcp-https-haskell$ make deploy

echo "Submitting build to Google Cloud Build..."
Submitting build to Google Cloud Build...
gcloud builds submit . --config cloudbuild.yaml
Reauthentication required.
Please enter your password:
Reauthentication successful.
Creating temporary archive of 49 file(s) totalling 175.2 KiB before compression.
Uploading tarball of [.] to [gs://comglitn_cloudbuild/source/1768676136.867816-bd1b3099427e4974a3776b6dee08d5f6.tgz]
Created [https://cloudbuild.googleapis.com/v1/projects/comglitn/locations/global/builds/22521064-30ef-4245-9a23-14ff683617e4].
Logs are available at [https://console.cloud.google.com/cloud-build/builds/22521064-30ef-4245-9a23-14ff683617e4?project=1056842563084].
Waiting for build to complete. Polling interval: 1 second(s).
----------------------------------------------- REMOTE BUILD OUTPUT ------------------------------------------------
starting build "22521064-30ef-4245-9a23-14ff683617e4"

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 [mcp-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 [mcp-https-haskell] revision [mcp-https-haskell-00002-df5] has been deployed and is serving 100 percent of traffic.
Step #1: Service URL: https://mcp-https-haskell-1056842563084.us-central1.run.app
Finished Step #1 │
Enter fullscreen mode Exit fullscreen mode

The service endpoint in this example is :

https://mcp-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://mcp-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:

 {
    "mcpServers": {
    "hello-cloudrun-haskell": {
      "httpUrl": "https://mcp-https-haskell-$PROJECT_NUMBER.us-central1.run.app/mcp"
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

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

xbill@penguin:~/gemini-cli-codeassist/mcp-https-haskell$ cd .gemini
cp settings.json.cloudrun settings.json
xbill@penguin:~/gemini-cli-codeassist/mcp-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

🟢 hello-cloudrun-haskell - Ready (2 tools)
  Tools:
  - greet
  - sum

> sum first 6 mersenne primes

✦ I will calculate the sum of the first 6 Mersenne primes (3, 7, 31, 127, 8191, and 131071).

╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ sum (hello-cloudrun-haskell MCP Server) {"values":"3,7,31,127,8191,131071"} │
│ │
│ 139430 │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ The sum of the first 6 Mersenne primes is 139,430.

> greet Endofunctors for the Win!

✦ I will greet Endofunctors for the Win!

╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ greet (hello-cloudrun-haskell MCP Server) {"name":"Endofunctors for the Win!"} │
│ │
│ Hello, Endofunctors for the Win!! │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ Hello, Endofunctors for the Win!!

Enter fullscreen mode Exit fullscreen mode

You can also validate the deployed code base:

> review the project for proper use of endofunctors

✦ I will start by examining the main application files app/Main.hs, src/Logic.hs, and src/Types.hs to understand the
  current usage of functors and related patterns in the codebase.

✦ The project exhibits excellent and idiomatic usage of Endofunctors (specifically via the Functor, Applicative, and
  Monad typeclasses).

  Here is a breakdown of the "Endofunctor" usage in your codebase:

  1. The Maybe Monad in Configuration (app/Main.hs)
  You correctly utilize the Maybe monad's >>= (bind) operator to chain the retrieval and parsing of the port
  environment variable.
   1 let port = fromMaybe 8080 (portEnv >>= readMaybe)
  This elegantly handles the failure case: if portEnv is Nothing, or if readMaybe returns Nothing, the whole
  expression falls through to Nothing, which fromMaybe then rescues.

  2. Traversing with Applicatives (src/Logic.hs)
  In the Sum tool implementation, you efficiently validate the entire list of inputs using sequence:
   1 let maybeNums = map (readMaybe . T.unpack . T.strip) parts :: [Maybe Int]
   2 case sequence maybeNums of
   3 Just nums -> ...
   4 Nothing -> ...
  sequence (derived from Traversable, relying on Applicative) turns [Maybe Int] into Maybe [Int]. This ensures that
  if any single number fails to parse, the entire operation results in Nothing, effectively validating the whole
  list in one pass. This is a very strong, idiomatic Haskell pattern.

  3. The IO Monad
  The entire application logic is safely wrapped in the IO monad, managing side effects (logging, server execution)
  cleanly via do notation.

  Conclusion
  The Endofunctors are effectively "winning" in this project. The code is concise, safe, and leverages Haskell's
  type system to handle errors and effects without boilerplate.

  No changes are required. The existing implementation is idiomatic.

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 programmng, or so it seems. A true Haskell programmer will have this site in their bookmarks:

@haskellryangosling · Haskell Ryan Gosling

Top comments (0)