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.
Clone the repository:
git clone <repository-url>
cd <repository-directory>
Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows, use: venv\Scripts\activate
Install dependencies:
pip install -r requirements.txt
If requirements.txt is missing, install these packages:
pip install aiokafka python-dotenv pydantic-settings mcp-server
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"
Start the server using the main.py script:
python main.py --transport stdio
Available transport options:
stdio
: Standard input/output (default)sse
: Server-Sent EventsAdd 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.
Publishes information to the configured Kafka topic.
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.
Creates a new Kafka topic with specified parameters.
--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
)Deletes an existing Kafka topic.
--topic
: Name of the topic to delete--timeout
: (optional) Time to wait for deletion to completeLists all topics in the cluster (or filtered by pattern).
--bootstrap-server
: Broker address--pattern
: (optional) Regular expression to filter topic names--exclude-internal
: (optional) Exclude internal topics (default: true)Displays or alters configuration for one or more topics.
--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 topicRetrieves metadata about a topic or the cluster.
--topic
: (If provided) Fetch metadata only for this topic--bootstrap-server
: Broker address--include-offline
: (optional) Include brokers or partitions that are offlineTo 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.
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.
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"
]
}
}
}
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.
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.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.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