
Graylog MCP Server
io.github.jperelli由 GitHub 帳號 jperelli 發布v1.3.0更新於 Oct 24, 2026
Query logs from Graylog: get streams, search messages, aggregate, and get full data.
概覽
一個本機 MCP 伺服器,讓助理查詢 Graylog 日誌:列出串流與欄位、搜尋訊息、依欄位彙總,並取得完整文件。
- 可以做什麼
- 探索可讀取的串流以及索引中實際存在的訊息欄位,可用子字串篩選縮小範圍。跨一個或多個串流搜尋符合的日誌行,依最新優先合併,預設回傳精簡欄位投影,可選用詳細模式。依某個欄位的值彙總符合的訊息,可附上時間直方圖,以低成本找出故障服務或錯誤模式。依 id 與索引取得單一完整、未截斷的訊息。說明搜尋沒有結果的原因,區分查詢寫錯、時間範圍內確實沒有日誌,以及日誌尚未建立索引。透過標籤在一個伺服器中查詢多個 Graylog 執行個體。
- 適用情境
- 適合排查存放在 Graylog 中的應用程式或基礎設施日誌,讓助理代為搜尋、彙總並深入查看,不必手動複製查詢。適用於故障排查、找出哪些服務或容器產生最多錯誤,以及判斷日誌缺失是查詢問題還是索引延遲。
- 執行需求
- 以 npm 套件形式透過 npx 在本機執行,需要 Node.js 18 或更新版本。每個 Graylog 執行個體需要 GRAYLOG_BASE_URL_INSTANCE_N 中的基礎 URL 與 GRAYLOG_API_TOKEN_INSTANCE_N 中的 API 權杖,N 從 1 開始;選用標籤放在 GRAYLOG_LABEL_INSTANCE_N。只有同時設定 URL 與權杖的執行個體才會啟用。需要能連線到 Graylog 伺服器的網路。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Graylog MCP Server,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
Graylog MCP Server
[CI] [npm version] [npm downloads] [node] [license]
A minimal MCP (Model Context Protocol) server in JavaScript that integrates with Graylog.
Features
- JavaScript MCP server
- Tools:
search(read matching log lines across multiple streams),analyze(aggregate matches by a field, with an optional time histogram),list_fields(which fields exist),list_streams(discover readable streams), andget_message(fetch one full document) - Empty results explain themselves. A zero-match search reports whether the query is wrong, the window is quiet, or Graylog simply hasn't indexed the logs yet — three causes that otherwise look identical and send an agent in circles
- Discovery over guessing.
list_fieldsandanalyze'svalueContainslet an agent look up real field names and values instead of inventing them, since a wrong guess returns 0 hits and reads as "no logs exist" - Token-efficient by design,
searchreturns a concise projection of high-signal fields by default; opt into full documents withverbose - A server-level "instructions" manual teaches the client the query syntax, stream-scoping rules, and severity quirks up front
- Multi-instance support, query multiple Graylog servers from a single MCP server
Requirements
- Node.js 18+
Configuration
Configure one or more Graylog instances using numbered env vars:
Replace N with 1, 2, 3, … to register as many instances as needed. Only instances with both BASE_URL and API_TOKEN set will be active.
Use with an MCP client
No installation needed, npx downloads and runs the server automatically.
Claude Code
Or add it manually to ~/.claude.json:
Cursor
Add to ~/.cursor/mcp.json:
Claude Desktop
Config file locations:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Linux:
~/.config/claude-desktop/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
Use the same JSON structure shown above for Cursor.
Use
Once configured, the tools become available and are called automatically when needed. The usual flow is to search the Default Stream (000000000000000000000001), which covers everything the token can read, then analyze to spot patterns, search to read individual lines, and get_message to inspect one hit in full. Reach for list_streams only to scope to a specific named stream. Example prompts:
Don't let the agent guess field names or values. A query on a field or value that doesn't exist matches nothing, which looks exactly like "there are no logs". list_fields answers which fields exist, and analyze with valueContains answers which values a field actually has.
Available tools
list_streams
List the streams the configured API token can read (id + title). Only readable ones are returned.
You usually don't need this: pass the Default Stream id 000000000000000000000001 to search/analyze to cover everything the token can read. A cluster can hold thousands of streams (the author's has 1,205), so output is capped — use titleContains when you want one specific named stream.
Parameters:
instance(string, optional): Label of the Graylog instance to query. Defaults to the first configured instance.titleContains(string, optional): Case-insensitive substring filter on the stream title (e.g.catalogue).limit(number, optional): Max streams to return. Default:50. The Default Stream is always included and never counts against the cap.
list_fields
List the message fields that actually exist in the index. Use it before searching on a field you haven't seen in a result, so you never guess a field name.
A cluster indexes thousands of fields (the author's: 3,269), and near-duplicates are common — namespace_name, Pod_namespace, pod_namespace and Namespace may all exist while only one is populated by your shipper. Pass contains to narrow.
Parameters:
contains(string, optional): Case-insensitive substring filter on the field name, e.g.namespace,pod,level.limit(number, optional): Max field names to return. Default:100.instance(string, optional): Instance label. Defaults to the first configured instance.
search
Read matching log lines across one or more streams, merged newest-first. By default it returns a concise projection of high-signal fields (timestamp, source, level, container_name, pod_name, namespace_name, application_name, service, logger_name, name, msg, err, stack, message) plus each hit's _id/_index, with the raw message body truncated to 500 chars, this keeps the agent's context small. Set verbose: true (or pass explicit fields) to get every populated field, untruncated. Stream IDs are required, an all-streams search is not performed implicitly, because a limited-permission token would be rejected with 403 Not authorized.
name/msg/err/stack are there because a shipper that parses a JSON log line (pino, bunyan, structlog) extracts its keys into real fields. Those fields are the summary of the event, and they're cheap — the raw message body that contains them is neither, which is why it's truncated hard by default.
Reach for
analyzebeforesearch. Raw lines are the most expensive thing this server returns. A hundred repetitions of one error cost a hundred times as much viasearchas one aggregated row viaanalyze, and tell you less. Usesearchonce you know which line you want.
Tip: to search everything the token can see (including messages not routed to a named stream), pass the Default Stream id
000000000000000000000001.list_streamsalso surfaces it.
Parameters:
query(string, required): Search query, using Graylog/Elasticsearch syntax. Examples:msg:Error,namespace_name:app-payments-qa AND error,source:api-*,*.streams(string, required): Comma-separated stream IDs to search. Get them fromlist_streams.instance(string, optional): Label of the Graylog instance to query. Defaults to the first configured instance.searchTimeRangeInSeconds(number, optional): Relative time range in seconds. Default:900(15 minutes).from/to(string, optional): Absolute window in ISO-8601 UTC (e.g.2026-07-11 14:00:00). When both are set they override the relative range, use them to investigate a known incident window.searchCountLimit(number, optional): Max number of messages. Default:50.messageChars(number, optional): Max characters of the raw message body per hit. Default:500. Raise it only when the detail you need lives in the raw body rather than the parsed fields.verbose(boolean, optional): Return every populated field, untruncated, instead of the concise projection. Default:false.fields(string, optional): Comma-separated explicit field list to return. Overrides the concise projection.
The response is { returned, total_matched, streams, messages, note?, projection?, why_no_results? }, where total_matched is the total number of hits across the streams (may exceed returned, which is capped by searchCountLimit); when it does, note explains how to see more.
When a search matches nothing, it tells you why. A bare total_matched: 0 is ambiguous, and the three causes need opposite responses, so why_no_results names the one that applies:
- The window has messages, but none match. The streams and time range are fine, so the query is wrong — usually a guessed field name or value. Confirm with
list_fields/analyze. - The window is empty, and indexing is current. These streams are genuinely quiet.
- The window is empty, and the newest indexed message is hours old. Graylog is still indexing. The logs exist and have been received; they just aren't searchable yet. The response reports how far behind indexing is and the journal backlog. Don't conclude the logs are missing — widen the range or retry.
That last case is easy to misread as "this service produced no logs", and it's the reason this project exists in its current shape: the pipeline can lag ingestion by hours under load.
Note on log levels — severity must be discovered, not guessed. Some services emit a top-level Graylog
level(syslog: 3=error, 4=warn). Others log JSON, and the shipper extracts its keys into their own fields: pino's{"level":50,"msg":"Error","name":"SvcX"}typically becomes fieldsmsgandname, while its numericlevelis lost — it collides with the container's ownlevel(often7), solevel:50andlevel:ERRORboth match nothing even though the errors are plainly there. Guessing a disjunction likelevel:ERROR OR level:50 OR error OR exception OR fatalis how agents waste turns. Instead runlist_fields(contains: "level","msg","err"), thenanalyzeonmsgto see the actual values. Free-texterrorworks as a fallback; don't assumeexceptionorfatalexist. And avoid"level":50as a query, a quoted string before:is invalid Lucene.
analyze
Aggregate matching messages by the top values of a field instead of returning raw lines, e.g. which source, container_name, or level dominates the errors in a window. Optionally add a time histogram of total match volume. Two uses:
-
Find what is failing. Aggregate on a message field (
msg, or whatever short summary fieldlist_fieldsreveals) to collapse a thousand repetitions of one error into a single row with a count; onname/container_name/sourceto see who is emitting them. This is the fastest route from "is anything weird?" to an answer — and it costs a few hundred tokens where the equivalentsearchcosts tens of thousands: -
Discover a value before filtering on it. Set
valueContainsto find the exact name of a namespace/pod/service you only half-know. Elasticsearch rejects a leading wildcard, sonamespace_name:*catalogue*is a hard error, not an empty result — this is the only way to substring-match a value.
Parameters:
field(string, required): Field to break down by, e.g.source,namespace_name,container_name,level. Confirm it exists withlist_fieldsif you haven't seen it in a result.streams(string, required): Comma-separated stream IDs, or the Default Stream id.query(string, optional): Lucene filter applied before aggregating. Default:*.valueContains(string, optional): Case-insensitive substring filter on the returned values, applied locally over a wide bucket scan.instance(string, optional): Instance label. Defaults to the first configured instance.searchTimeRangeInSeconds(number, optional): Relative range in seconds. Default:900. Or usefrom/tofor an absolute window.size(number, optional): Number of top values to return. Default:20.histogramInterval(string, optional): One ofminute,hour,day,week,month. When set, the response also includes a time histogram of match counts.
The response is { field, query, streams, total_matched, top_values: [{ value, count }], not_in_top_values, histogram?, note?, warning?, failed_streams?, why_no_results? }, where not_in_top_values counts matches that the returned values don't account for — messages with no value for the field, plus any bucket past the cut-off.
A stream the token can't read is skipped, not fatal: you get the aggregation over the readable streams plus failed_streams and a warning naming the ones excluded, in the same response.
Implemented on Graylog's Views/Aggregations API (
POST /api/views/search/sync), which takes every stream in a single request. The legacysearch/universal/*/termsand/histogramendpoints this originally used were removed in Graylog 6.0 and return404there.
get_message
Fetch the full, untruncated document for a single message by its _id and _index (both returned by search). Use it after a concise search to inspect one hit in detail without pulling every result verbose.
Parameters:
messageId(string, required): The_idfrom a search result.index(string, required): The_indexfrom a search result.instance(string, optional): Instance label. Defaults to the first configured instance.
Design rationale
The tools here are shaped around published guidance on building MCP servers that AI agents can actually use well, rather than mirroring the Graylog REST API one endpoint at a time. The key ideas and where they come from:
-
Design for the agent's task, not the API surface, fewer, outcome-oriented tools. David Cramer (Sentry) makes the case that most MCP servers are still weak because they wrap raw endpoints instead of the jobs an agent needs to do; Sentry ships a curated, modest toolset instead. So this server exposes four task-shaped tools (discover → aggregate → read → drill in), not a wrapper per endpoint. , David Cramer, MCP Is Not Good Yet · Yes, Sentry has an MCP Server (…and it's pretty good)
-
Return high-signal context and protect the token budget. Anthropic's guidance is that tools should return concise, relevant results and support filtering/truncation/pagination rather than dumping raw data into the model's context. Hence
searchreturns a concise projection by default (withverboseandget_messageas opt-in escalation) and emits anotewhen results are capped. , Anthropic, Writing effective tools for agents -
Pair raw retrieval with an aggregation/analysis tool. New Relic's logging MCP does not only list log lines; it offers keyword search plus an analysis tool that surfaces error patterns and recurring issues.
analyzefills that role for Graylog (top values of a field + optional histogram) so an agent can find patterns cheaply before reading individual lines. , New Relic, MCP tool reference -
Put the "user manual" in server instructions, not in every tool description. The MCP project recommends a top-level
instructionsfield for cross-tool workflow, constraints, and quirks, keeping individual tool descriptions tight. This server'sinstructionsteach the query syntax, the mandatory stream-scoping rule (a limited token gets403otherwise), and the pino numeric-severity gotcha once, up front. , Model Context Protocol, Server Instructions: Giving LLMs a user manual for your server
Troubleshooting
- Ensure at least
GRAYLOG_BASE_URL_INSTANCE_1andGRAYLOG_API_TOKEN_INSTANCE_1are set. - Verify Node.js 18+ is installed.
- Set
DEBUG=truein the env to enable verbose logging to stderr.
Credits
Current implementation by Julian Perelli. Based on previous work from Leo Ruellas, lcaliani/graylog-mcp.
License
MIT
來源:README.md,提交 18bf53c
工具
0版本歷史
1- v1.3.0最新Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分