Kafka Streaming MCP server

Enables seamless Kafka message streaming for AI models by providing publish and consume functionalities through a configurable Python server with stdio and SSE transport support.
Back to servers
Setup instructions
Provider
Pavan Java
Release date
Mar 17, 2025
Language
Python
Stats
14 stars

This MCP server integrates with Apache Kafka to provide publish and consume functionalities for LLM and Agentic applications, allowing AI models to interact with Kafka topics through a standardized interface.

Prerequisites

  • Python 3.8+
  • Apache Kafka instance
  • Python dependencies

Installation

  1. Clone the repository:

    git clone <repository-url>
    cd <repository-directory>
    
  2. Create and activate a virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows, use: venv\Scripts\activate
    
  3. Install dependencies:

    pip install -r requirements.txt
    

    If requirements.txt is missing, install these packages:

    pip install aiokafka python-dotenv pydantic-settings mcp-server
    

Configuration

Create a .env file in the project root:

# Kafka Configuration
KAFKA_BOOTSTRAP_SERVERS=localhost:9092
TOPIC_NAME=your-topic-name
IS_TOPIC_READ_FROM_BEGINNING=False
DEFAULT_GROUP_ID_FOR_CONSUMER=kafka-mcp-group

# Optional: Custom Tool Descriptions
# TOOL_PUBLISH_DESCRIPTION="Custom description for the publish tool"
# TOOL_CONSUME_DESCRIPTION="Custom description for the consume tool"

Running the Server

Start the server using the main.py script:

python main.py --transport stdio

Available transport options:

  • stdio: Standard input/output (default)
  • sse: Server-Sent Events

Integrating with Claude Desktop

Add this configuration to your Claude Desktop configuration file:

{
    "mcpServers": {
        "kafka": {
            "command": "python",
            "args": [
                "/path/to/your/project/main.py"
            ]
        }
    }
}

Replace /path/to/your/project with the absolute path to your project directory.

Available Tools

kafka-publish

Publishes information to the configured Kafka topic.

kafka-consume

Consumes information from the configured Kafka topic. Note that once a message is read from the topic, it cannot be read again using the same group ID.

Create-Topic

Creates a new Kafka topic with specified parameters.

  • Options:
    • --topic: Name of the topic to create
    • --partitions: Number of partitions to allocate
    • --replication-factor: Replication factor across brokers
    • --config: (optional) Topic-level configuration overrides (e.g., retention.ms=604800000)

Delete-Topic

Deletes an existing Kafka topic.

  • Options:
    • --topic: Name of the topic to delete
    • --timeout: (optional) Time to wait for deletion to complete

List-Topics

Lists all topics in the cluster (or filtered by pattern).

  • Options:
    • --bootstrap-server: Broker address
    • --pattern: (optional) Regular expression to filter topic names
    • --exclude-internal: (optional) Exclude internal topics (default: true)

Topic-Configuration

Displays or alters configuration for one or more topics.

  • Options:
    • --describe: Show current configs for a topic
    • --alter: Modify configs (e.g., --add-config retention.ms=86400000,--delete-config cleanup.policy)
    • --topic: Name of the topic

Topic-Metadata

Retrieves metadata about a topic or the cluster.

  • Options:
    • --topic: (If provided) Fetch metadata only for this topic
    • --bootstrap-server: Broker address
    • --include-offline: (optional) Include brokers or partitions that are offline

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "kafka" '{"command":"python","args":["main.py"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "kafka": {
            "command": "python",
            "args": [
                "main.py"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "kafka": {
            "command": "python",
            "args": [
                "main.py"
            ]
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later