A FastMCP-based server that connects to Kafka to expose MCP tools for broker, topic, consumer, and retention operations.
Configuration
View docs{
"mcpServers": {
"jilanisayyad-kafka-mcp-server": {
"url": "http://localhost:8000/mcp",
"headers": {
"MCP_URL": "http://localhost:8000/mcp",
"KAFKA_TEST_GROUP": "mcp_smoke_group",
"KAFKA_TEST_TOPIC": "mcp_smoke",
"FASTMCP_SERVER_HOST": "127.0.0.1",
"FASTMCP_SERVER_PORT": "8080",
"KAFKA_BOOTSTRAP_SERVERS": "localhost:9092"
}
}
}
}You can run a FastMCP-based server that connects to Kafka and exposes MCP tools for managing brokers, topics, consumers, and retention. This server lets you inspect topics, stream messages, manage users locally, and monitor cluster metadata, all through a consistent MCP interface.
To use the Kafka MCP Server, connect your MCP client to the default HTTP endpoint and start the local server if you plan to run it directly. You can perform common Kafka operations through dedicated MCP tools, such as listing topics, creating topics with specific configurations, tailing messages, inspecting consumer groups, and retrieving cluster information.
Prerequisites you need before installation:
Install and run locally using the following steps. Start by creating a virtual environment and activating it, then install dependencies and run the server.
uv python install 3.13
uv venv .venv --python 3.13
source .venv/bin/activate
uv sync
uv run python -m app.mainThe server reads its settings from FastMCP ServerSettings. The default host and port are 0.0.0.0 and 8000, respectively. You can override these using environment variables FASTMCP_SERVER_HOST and FASTMCP_SERVER_PORT.
Smoke tests and clients can use the following environment variables to customize behavior and testing endpoints: MCP_URL defaults to http://localhost:8000/mcp, KAFKA_BOOTSTRAP_SERVERS defaults to localhost:9092, KAFKA_TEST_TOPIC defaults to mcp_smoke, and KAFKA_TEST_GROUP defaults to mcp_smoke_group.
Kafka connection payloads require a connection object with these fields: bootstrap_servers, security_protocol (default PLAINTEXT), optional sasl_mechanism, sasl_username, sasl_password, ssl_cafile, ssl_certfile, ssl_keyfile, and oauth_token when using OAUTHBEARER.
Kafka users can be stored locally for quick reference and management. User entries live in a local store and can be upserted or deleted through the MCP tools dedicated to user management.
Connect to the MCP endpoint from your client and perform operations such as listing topics, inspecting topic configurations, creating topics with optional configs, tailing messages, and inspecting consumer group lag. Use the provided tools to gather broker metadata and manage local Kafka users.
The server exposes a collection of MCP tools that you can call via the MCP client session. Each tool accepts a structured payload containing a Kafka connection and the specific parameters for the operation.
If you cannot reach the MCP endpoint, verify that the server is running and listening on the configured host and port. Check environment variable overrides and ensure your Kafka broker is accessible from the server environment. Review Kafka connection parameters for correctness, especially security settings when using SASL or TLS.
Return a simple status object indicating the server is healthy.
List topics with partition and replication details for the connected Kafka cluster.
Create a new topic with optional configurations such as partitions, replication factor, and topic configs.
Delete an existing topic by name.
Fetch the configuration values for a given topic.
Return the retention policy value (retention.ms) for a topic.
Read the most recent messages from a topic up to a specified limit.
Collect a short live stream of messages from a topic with configurable duration.
List consumer groups with their state and member count.
Compute lag per partition for a specific consumer group.
Return broker and controller metadata for the connected cluster.
List locally stored user entries used for authentication against Kafka.
Create or update a local user entry with specified SASL or authentication details.
Delete a local user entry by username.