elk-mcp-server
Provides read-only access to Elastic Cloud logs across multiple regions, enabling AI agents to query and analyze log data without modifying or deleting anything.
Enables querying Elasticsearch indices for log retrieval, error pattern deduplication, cursor-paginated searches, and context around specific log events.
Generates Kibana deep links with the same filters used in log queries, allowing direct navigation to relevant Kibana log views.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@elk-mcp-servercheck errors in tenant-abc on ap-south-1 over the last 2 hours"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
elk-mcp-server
An MCP (Model Context Protocol) server that lets an AI coding agent (Claude
Code or any other MCP host) read Elastic Cloud logs across multiple regions
(currently ap-south-1 Mumbai and us-east-1, configured in .env) —
read-only, nothing can be changed or deleted. A standalone CLI is included
for humans who want to run the same queries by hand.
Why
An agent could just shell out to the CLI script directly, but that's expensive in tokens: it has to read the whole script to learn the flags, then parse pretty-printed, verbose text back out of every response.
This server avoids both costs. It wraps the same querying logic in six purpose-built MCP tools, so the agent sees a short, ready-made list of tools instead of a script to read, and gets back compact TSV rows instead of raw JSON. Less text in means less text (and cost) out.
Related MCP server: CloudWatch Log Analyst MCP
Tools
Tool | Use it to |
| Always call first. Time histogram + top levels/namespaces/pods — counts only, no log lines. |
| Deduplicate repeated errors (UUIDs/hex/IPs/numbers normalized) into ranked patterns. |
| Compact TSV log rows, field-filtered, cursor-paginated. |
| One full document (untruncated message/stack trace) by id + index. |
| Logs immediately before/after a specific moment for a pod/namespace. |
| Bulk export to a local JSONL file for |
All tools are read-only (ToolAnnotations(readOnlyHint=True)) and cover both
ap-south-1 (Mumbai) and us-east-1.
Setup
Requires uv.
Copy .env.example to .env and fill in the credentials for each region you
use:
cp .env.example .env# maps each region to the env var names below — only edit this if you add
# a region or rename a variable
REGION_ENV_MAPPING={"ap-south-1":{...},"us-east-1":{...}}
# ap-south-1 (Mumbai)
ES_URL_MUMBAI=https://...
ES_API_KEY_MUMBAI=...
KIBANA_URL_MUMBAI=https://...
KIBANA_INDEX_ID_MUMBAI=...
# us-east-1
ES_URL_US_EAST=https://...
ES_API_KEY_US_EAST=...
KIBANA_URL_US_EAST=https://...
KIBANA_INDEX_ID_US_EAST=...You only need the credentials for the region(s) you plan to query.
REGION_ENV_MAPPING and the KIBANA_INDEX_ID_* values aren't secrets (just
config), but .env as a whole is gitignored — never commit it.
Use as an MCP server (Claude Code / any MCP host)
Point your MCP host at this script, e.g. a .mcp.json in your project root:
{
"mcpServers": {
"elk": {
"command": "uv",
"args": ["run", "--script", "/path/to/elk_mcp_server.py"]
}
}
}uv resolves the pinned dependencies from the script's inline metadata, so
there's no separate install step — the elk server starts on demand.
Use the CLI directly
python3 elk_query.py --region ap-south-1 --namespace tenant-abc --hours 2
python3 elk_query.py --region us-east-1 --namespace tenant-abc --level error --json -o logs.jsonRun python3 elk_query.py --help for the full flag list.
Testing
uv sync --group dev
uv run pytestTests cover the pure logic (timestamp parsing, pattern dedup, TSV rendering, Kibana URL building, request construction) with dummy credentials — no live Elasticsearch connection required.
Design notes
Shared core — the MCP server imports
ELKQueryClientfromelk_query.pydirectly; the CLI and the AI-facing tools can never drift apart.Token budget — TSV output, a hard 20,000-char response cap with a visible truncation marker, and regex-based pattern dedup keep multi-step investigations inside an LLM's context window.
Cursor pagination —
elk_searchusessearch_afterwith a_doctiebreaker, stable even across same-millisecond log lines.Case-insensitive level matching — Go/Python services log lowercase
error, Java services log uppercaseERROR, in the same indices.Kibana deep links — every tool response includes a
kibana_urlbuilt from the same filters, generated locally at zero extra query cost.
Layout
elk-mcp-server/
├── elk_query.py # ELKQueryClient — core querying + Kibana URL builder, plus a CLI
├── elk_mcp_server.py # FastMCP server exposing the 6 tools above
├── tests/ # pytest suite for the pure logic in both scripts above
├── pyproject.toml # dependencies + dev group (pytest), for `uv sync`/`uv run pytest`
├── uv.lock # pinned dependency versions
├── .env.example # template for the credentials/config below (safe to commit)
└── .env # actual credentials + config, not tracked in git (create this yourself)This server cannot be deployed
Maintenance
Related MCP Connectors
Query application logs, traces, and metrics from your AI coding assistant via Foam's MCP server.
Your org's AI agents, tasks, runs, search, and brain files as MCP tools and resources.
Provides capabilities that let LLM agents perform a range of infrastructure management tasks.
Read-only MCP tools for AI agent discovery, structured resources, and NIULAI information.
Related MCP Servers
- AlicenseBqualityDmaintenanceEnables AI assistants to interact with Kibana dashboards, visualizations, and Elasticsearch data through read-only resources and executable tools for searching logs, exporting dashboards, and querying data.710 npm3MIT
- AlicenseNot gradedqualityDmaintenanceEnables LLMs to autonomously query AWS CloudWatch Logs and perform structured root-cause analysis via natural language prompts, using MCP tools for log group listing and Insights queries.MIT
- AlicenseAqualityBmaintenanceA read-only MCP server that enables AI assistants to search, aggregate, and explore OpenSearch log data through 12 tools for connectivity, index discovery, search, and aggregations.17MIT
- AlicenseAqualityCmaintenanceEnables LLM agents to search and analyze Elasticsearch logs for errors, detect recurring patterns, analyze error-rate trends, and retrieve full trace context through MCP tools.6MIT