Skip to main content

An MCP server exposing Apache Kafka admin and data-plane operations as tools for AI agents.

Project description

๐ŸฆŠ kafka-mcp

An MCP server that gives your AI agents eyes into Apache Kafka.

kafka-mcp exposes Kafka administration operations as Model Context Protocol tools, so assistants like Claude Desktop, Claude Code, or any MCP-compatible client can inspect and operate your cluster in plain language โ€” "list all my topics with their replication factor" โ€” instead of you reaching for the CLI.

It ships with a batteries-included docker-compose.yml that spins up a complete local Kafka lab (KRaft broker + Schema Registry + Web UI) so you can try it end-to-end in minutes.

Python MCP Apache Kafka uv


โœจ Features

  • ๐Ÿ”Œ Drop-in MCP server โ€” runs over stdio, so any MCP client can launch it as a subprocess.
  • ๐Ÿ“‹ Topic management โ€” list & describe topics, create / delete, add partitions, and read or alter configs.
  • ๐Ÿ‘ฅ Consumer group insight โ€” list & describe groups, inspect members & assignments, and compute per-partition lag.
  • ๐Ÿ“จ Produce & peek โ€” send a message to a topic, or read recent records back without committing offsets.
  • ๐Ÿฉบ Cluster & offset views โ€” describe brokers / controller and fetch earliest / latest watermarks per partition.
  • โšก Async-friendly โ€” blocking Kafka admin calls are offloaded to worker threads so the event loop stays snappy.
  • ๐Ÿณ Self-contained local lab โ€” one docker compose up gives you Kafka (KRaft, no ZooKeeper), Schema Registry, and a Web UI.
  • ๐Ÿ› ๏ธ Tiny & hackable โ€” a single main.py you can read in one sitting and extend with new tools.

๐Ÿงญ How it works

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   MCP over stdio   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   Kafka Admin API   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   AI Agent       โ”‚ โ—€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ถ  โ”‚   kafka-mcp      โ”‚ โ—€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ถ  โ”‚   Kafka broker   โ”‚
โ”‚ (Claude, etc.)   โ”‚   tool calls       โ”‚  (FastMCP server)โ”‚   confluent-kafka   โ”‚  (localhost:9092)โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

The agent never talks to Kafka directly โ€” it calls a tool, kafka-mcp translates that into a confluent-kafka admin or client request, and returns structured JSON the model can reason about.


๐Ÿ“ฆ Prerequisites

  • Python 3.12+
  • uv for dependency management (recommended)
  • Docker + Docker Compose (only if you want the local Kafka lab)

๐Ÿš€ Quick start

1. Clone & install

git clone <your-repo-url> kafka-mcp
cd kafka-mcp
uv sync

2. Start a local Kafka (optional, but handy)

docker compose up -d

This brings up three services:

Service URL / Port What it's for
Kafka broker localhost:9092 The broker your MCP server connects to
Schema Registry http://localhost:8081 Avro/Protobuf/JSON schema management
Kafka UI http://localhost:8080 Browse topics, messages, and consumer groups

๐Ÿ’ก Auto-create topics is enabled, so you can produce to a new topic and watch it appear via the MCP list_topics tool.

3. Run the MCP server

uv run main.py

You should see:

Kafka MCP for you agents!

The server is now listening on stdio, ready for an MCP client to connect.


๐Ÿค– Connecting an MCP client

Most clients (Claude Desktop, Claude Code, โ€ฆ) launch MCP servers from a JSON config. Point them at this project like so:

{
  "mcpServers": {
    "kafka-zaksway": {
      "command": "uv",
      "args": ["--directory", "/absolute/path/to/kafka-mcp", "run", "main.py"],
      "env": {
        "BOOTSTRAP_SERVER": "localhost:9092"
      }
    }
  }
}
  • Claude Desktop โ†’ add the block to claude_desktop_config.json.
  • Claude Code โ†’ claude mcp add kafka-zaksway -- uv --directory /absolute/path/to/kafka-mcp run main.py

Restart the client, and kafka-zaksway will appear among your available tools.


๐Ÿงฐ Available tools

kafka-mcp exposes 14 tools spanning topic management, consumer groups, the cluster, and the data plane. Tools marked โš ๏ธ are destructive (they delete data) โ€” agents should confirm before calling them.

Category Tool Parameters Description
Topics list_topics withInternal: bool List topics with partition count & replication factor.
Topics describe_topic topic: str Per-partition leader / replicas / ISR + non-default config overrides.
Topics create_topic topic: str, partitions: int = 1, replication_factor: int = 1, config: dict = {} Create a new topic.
Topics delete_topic โš ๏ธ topic: str Permanently delete a topic and all of its data.
Topics add_partitions topic: str, new_total_count: int Increase a topic's partition count (cannot shrink).
Topics alter_topic_config topic: str, config: dict Set / update topic configuration entries.
Topics get_topic_offsets topic: str Earliest & latest offsets (watermarks) per partition.
Cluster describe_cluster โ€” Cluster id, controller broker, and broker list.
Groups list_consumer_groups โ€” All consumer groups with their state.
Groups describe_consumer_group group_id: str State, coordinator, members & their partition assignments.
Groups consumer_group_lag group_id: str Committed offset, end offset, and lag per partition.
Groups delete_consumer_group โš ๏ธ group_id: str Permanently delete a consumer group.
Data produce_message topic: str, value: str, key: str = null, partition: int = null Produce a single message and await delivery.
Data consume_messages topic: str, max_messages: int = 10, timeout_seconds: float = 5.0, from_beginning: bool = true Peek recent messages without committing offsets.

๐Ÿ’ก The registered MCP tool names are full descriptive sentences (e.g. Show committed offsets and lag for a Kafka consumer group); the short identifiers above mirror the Python functions in main.py and are used here for brevity.

Example โ€” list_topics response:

[
  { "name": "orders",   "partitions": 6, "replication-factor": 1 },
  { "name": "payments", "partitions": 3, "replication-factor": 1 }
]

โš™๏ธ Configuration

The server is configured entirely through environment variables.

Variable Default Description
BOOTSTRAP_SERVER localhost:9092 Kafka bootstrap server(s) to connect to.

๐Ÿ“ฆ Releasing to PyPI

The package is published to PyPI as zaksway-kafka-mcp by a GitHub Actions workflow (.github/workflows/publish.yml) that triggers on v* version tags and authenticates via Trusted Publishing (OIDC) โ€” no API tokens stored anywhere.

One-time setup โ€” register a Trusted Publisher on PyPI:

Field Value
Owner zakariahere
Repository zaksway-kafka-mcp
Workflow filename publish.yml
Environment pypi

To cut a release:

# 1. Bump `version` in pyproject.toml (e.g. 0.1.0 -> 0.2.0), then:
git commit -am "release: v0.2.0"
git tag v0.2.0
git push origin master --tags

The workflow verifies the tag matches pyproject.toml, builds the wheel + sdist, smoke-tests both, and publishes. Once published, anyone can run it with zero install:

uvx zaksway-kafka-mcp           # run the server directly
# or
pip install zaksway-kafka-mcp   # then run: kafka-zaksway

๐Ÿ—‚๏ธ Project structure

kafka-mcp/
โ”œโ”€โ”€ src/zaksway_kafka_mcp/
โ”‚   โ”œโ”€โ”€ __init__.py     # The MCP server + all 14 tool definitions
โ”‚   โ””โ”€โ”€ __main__.py     # `python -m zaksway_kafka_mcp` entry point
โ”œโ”€โ”€ tests/
โ”‚   โ””โ”€โ”€ smoke_test.py   # Import/packaging check run in CI before publish
โ”œโ”€โ”€ .github/workflows/
โ”‚   โ””โ”€โ”€ publish.yml     # Build + publish to PyPI on `v*` tags (Trusted Publishing)
โ”œโ”€โ”€ main.py             # Backward-compat shim (keeps `uv run main.py` working)
โ”œโ”€โ”€ docker-compose.yml  # Local Kafka lab (broker + schema registry + UI)
โ”œโ”€โ”€ pyproject.toml      # Project metadata, dependencies & build backend
โ”œโ”€โ”€ uv.lock             # Pinned dependency lockfile
โ””โ”€โ”€ README.md           # You are here

๐Ÿ›ฃ๏ธ Roadmap

Recently shipped โœ…

  • create_topic / delete_topic
  • add_partitions & alter_topic_config
  • Describe consumer groups & their lag
  • Peek at the latest messages on a topic

Ideas for what's next:

  • Reset / set consumer group offsets
  • ACL management (list / create / delete)
  • Broker config inspection
  • Schema Registry integration (list subjects & schemas)

๐Ÿง‘โ€๐Ÿ’ป Author

Zakaria BOUAZZA : https://zakaria.lu

๐Ÿ“„ License

No license has been specified yet. Add one (e.g. MIT) before sharing publicly.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zaksway_kafka_mcp-0.1.0.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zaksway_kafka_mcp-0.1.0-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file zaksway_kafka_mcp-0.1.0.tar.gz.

File metadata

  • Download URL: zaksway_kafka_mcp-0.1.0.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for zaksway_kafka_mcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d954156859976e85b67402a4e44dd4d2addd1a6638be05603b7ff1c7d0d20fc8
MD5 1845191504a6ad1b8a9b47630fd91f8a
BLAKE2b-256 590ea87c56c829ddcdee72aa8507906bed368272723de9986699c95ac3d49b6d

See more details on using hashes here.

File details

Details for the file zaksway_kafka_mcp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: zaksway_kafka_mcp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for zaksway_kafka_mcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fc4523c598ab88d933fc9acfe968a32d86695a1f71954636966b0d7d58ef1961
MD5 f8e70a3ed08916a280c82f1c98390162
BLAKE2b-256 c3f9bc4b8d1caf55969d48153de6377c3b78e90589c19f92c8efd9cb81380a1e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page