Kafka MCP Server

1

Add it to Claude Code

Run this in a terminal.

Run in terminal
claude mcp add kafka-mcp-server -- uv run python -m app.main
README.md

An MCP server that enables interaction with Kafka clusters

Kafka MCP Server

Overview

FastMCP-based MCP server that connects to Kafka and exposes MCP tools for common broker, topic, consumer, and retention operations.

Features

  • List/create/delete topics and inspect topic configs.
  • Tail recent messages or collect a short live stream.
  • List consumer groups and compute group lag.
  • Inspect cluster broker metadata.
  • Store and manage named Kafka users locally.

Requirements

  • Python 3.10+ (Makefile defaults to 3.13).
  • uv (recommended) or any Python environment manager.
  • A Kafka broker (local via Podman or your own cluster).

Quick start (uv)

  1. Create and activate a virtual environment:
    • uv python install 3.13
    • uv venv .venv --python 3.13
    • source .venv/bin/activate
  2. Install dependencies:
    • uv sync
  3. Run the server:
    • uv run python -m app.main

Default MCP SSE endpoint: http://localhost:8000/mcp

Makefile shortcuts

  • Start server: make start
  • Start Kafka (Podman): make kafka-start
  • Stop Kafka: make kafka-stop
  • Kafka logs: make kafka-logs
  • Run smoke test: make test-smoke

Configuration

Server settings come from FastMCP ServerSettings. The defaults are:

  • Host: 0.0.0.0
  • Port: 8000

FastMCP supports environment overrides such as:

  • FASTMCP_SERVER_HOST
  • FASTMCP_SERVER_PORT

Smoke tests and clients can use:

  • MCP_URL (default http://localhost:8000/mcp)
  • KAFKA_BOOTSTRAP_SERVERS (default localhost:9092)
  • KAFKA_TEST_TOPIC (default mcp_smoke)
  • KAFKA_TEST_GROUP (default mcp_smoke_group)

Kafka connection payload

Most tools require a Kafka connection object with the following fields:

  • bootstrap_servers (required)
  • security_protocol (default PLAINTEXT)
  • sasl_mechanism, sasl_username, sasl_password (optional)
  • ssl_cafile, ssl_certfile, ssl_keyfile (optional)
  • oauth_token (required when sasl_mechanism is OAUTHBEARER)

MCP tool catalog

Each tool name below is the MCP command. Parameter shapes match the schemas in app/schemas.py.

  • health - Returns {"status":"ok"}.
    • Params: none
  • list_topics - Lists topics with partition and replication info.
    • Params: connection
  • create_topic - Creates a topic with optional configs.
    • Params: connection, payload (name, num_partitions, replication_factor, configs)
  • delete_topic - Deletes a topic by name.
    • Params: connection, name
  • topic_configs - Fetches topic configuration values.
    • Params: connection, name
  • topic_retention - Returns retention.ms for a topic.
    • Params: connection, name
  • tail_messages - Reads the most recent messages for a topic.
    • Params: connection, name, payload (limit)
  • live_messages - Collects a short live stream of messages.
    • Params: connection, name, payload (max_messages, duration_seconds, poll_interval_ms)
  • list_consumer_groups - Lists consumer groups with state and member count.
    • Params: connection
  • consumer_group_lag - Computes lag per partition for a group.
    • Params: connection, group_id
  • cluster_info - Returns broker and controller metadata.
    • Params: connection
  • list_kafka_users - Lists locally stored user entries.
    • Params: none
  • upsert_kafka_user - Creates or updates a local user entry.
    • Params: user (username, sasl_mechanism, note)
  • delete_kafka_user - Deletes a local user entry.
    • Params: username

MCP command examples (Python)

from mcp import ClientSession
from mcp.client.sse import sse_client

MCP_URL = "http://localhost:8000/mcp"

connection = {
      "bootstrap_servers": "localhost:9092",
      "security_protocol": "PLAINTEXT",
      "sasl_mechanism": None,
      "sasl_username": None,
      "sasl_password": None,
      "ssl_cafile": None,
      "ssl_certfile": None,
      "ssl_keyfile": None,
      "oauth_token": None,
}

async with sse_client(MCP_URL) as (read, write):
      async with ClientSession(read, write) as session:
            await session.initialize()

            await session.call_tool("list_topics", {"connection": connection})

            await session.call_tool(
                  "create_topic",
                  {
                        "connection": connection,
                        "payload": {
                              "name": "example-topic",
                              "num_partitions": 1,
                              "replication_factor": 1,
                              "configs": {},
                        },
                  },
            )

Local storage

Kafka user entries are stored at app/data/users.json.

Testing

Smoke test all MCP tools end-to-end:

  1. Start Kafka: make kafka-start
  2. Start the server: make start
  3. In a new terminal: make test-smoke

LocalAI (optional)

LocalAI is not required for Kafka MCP usage, but this repo includes helper targets for running models locally:

  1. Install LocalAI and a model: make localai-install && make localai-model
  2. Start LocalAI: make localai-start

Tools (14)

healthReturns the health status of the server.
list_topicsLists Kafka topics with partition and replication information.
create_topicCreates a new Kafka topic with optional configurations.
delete_topicDeletes a Kafka topic by name.
topic_configsFetches configuration values for a specific topic.
topic_retentionReturns the retention.ms setting for a topic.
tail_messagesReads the most recent messages for a topic.
live_messagesCollects a short live stream of messages from a topic.
list_consumer_groupsLists consumer groups with their state and member count.
consumer_group_lagComputes lag per partition for a specific consumer group.
cluster_infoReturns broker and controller metadata for the cluster.
list_kafka_usersLists locally stored Kafka user entries.
upsert_kafka_userCreates or updates a local Kafka user entry.
delete_kafka_userDeletes a local Kafka user entry.

Environment Variables

FASTMCP_SERVER_HOSTHost address for the MCP server
FASTMCP_SERVER_PORTPort for the MCP server
MCP_URLURL for the MCP SSE endpoint
KAFKA_BOOTSTRAP_SERVERSDefault bootstrap servers for Kafka connection

Configuration

claude_desktop_config.json
{"mcpServers": {"kafka": {"command": "uv", "args": ["run", "python", "-m", "app.main"]}}}

Try it

List all topics currently available on my Kafka cluster.
Check the consumer group lag for the group 'analytics-processor'.
Tail the last 10 messages from the 'user-events' topic.
Create a new topic named 'test-topic' with 3 partitions.
Show me the cluster metadata and broker information.

Frequently Asked Questions

What are the key features of Kafka MCP Server?

List, create, and delete Kafka topics with configuration inspection.. Tail recent messages or collect live streams from topics.. Monitor consumer groups and calculate partition lag.. Inspect cluster broker and controller metadata.. Manage Kafka user credentials locally..

What can I use Kafka MCP Server for?

Debugging message flow by tailing live topics directly from the chat interface.. Quickly checking consumer group health and lag during incident response.. Automating topic creation and configuration management for development environments.. Inspecting cluster metadata to verify broker connectivity and status..

How do I install Kafka MCP Server?

Install Kafka MCP Server by running: uv sync && uv run python -m app.main

What MCP clients work with Kafka MCP Server?

Kafka MCP Server works with any MCP-compatible client including Claude Desktop, Claude Code, Cursor, and other editors with MCP support.

Turn this server into reusable context

Keep Kafka MCP Server docs, env vars, and workflow notes in Conare so your agent carries them across sessions.

Need the old visual installer? Open Conare IDE.
Open Conare