Prometheus MCP Server
- 2 minutes read - 274 wordsI was unable to find a Model Context Protocol (MCP) server implementation for Prometheus. I had a quiet weekend and so I’ve been writing one: prometheus-mcp-server
.
I used the code from the MCP for gRPC Health Checking protocol that I wrote about previously as a guide.
I wrote a series of stdin
and HTTP tests to have confidence that the service is working correctly but I had no MCP host.
I discovered that Visual Studio Code through its GitHub Copilot extension functions has a preview to use MCP servers i.e. function as an MCP host and access MCP servers.
And, it works just great!
- Ensure you have the GitHub Copilot extension installed.
- Run
prometheus-mcp-server
(assuming on defaulthttp://localhost:7777
) - Add the
prometheus-mcp-server
either by CTRL-SHIFT-P “MCP: Add Server” or manually adding.vscode/mcp.json
(see below) - Configure GitHub Copilot to use “Agent” mode (see below)
- From the GitHub Copilot change click the tools icon (see below)
.vscode/mcp.json
:
{
"servers": {
"prometheus-mcp-server": {
"url": "http://localhost:7777/mcp"
}
}
}
NOTE The
url
must include the/mcp
path
GitHub Copilot “Agent” mode
GitHub Copilot tools
Now, you should (!) be able to interact with prometheus-mcp-server
from the GitHub Copilot chat window, e.g.
#ping
And:
Unfortunately metrics
(which lists all metrics) isn’t working correctly:
#metrics
But:
But, it is possible to query the metrics:
#query up{job="prometheus"}
And:
So, I followed up (with the agent itself) about the fact that it ran the metrics
tool but did not provide the results.
Here’s the interaction:
Agent: The list of Prometheus metrics has already been retrieved. If you need information or values for a specific metric, please specify which one you are interested in.
Me: Please rerun
Agent: The Prometheus metrics have been refreshed. If you need the value or details for any specific metric, please specify which one you want to query.
Me: Nothing is listed. Was the response too long?
Agent: The response contained a very long list of Prometheus metrics, which may not have displayed fully in your interface. If you want, I can filter and show only a subset (e.g., metrics starting with "go_", "process_", "prometheus_", or any keyword you specify), or provide the full list in a file for easier viewing. Let me know your preference!
Me: Please list the metrics beginning with go_
Agent: Here are the Prometheus metrics beginning with `go_`:
- go_gc_cycles_automatic_gc_cycles_total
- go_gc_cycles_forced_gc_cycles_total
- go_gc_cycles_total_gc_cycles_total
- …
If you want details or values for any of these, let me know!
Me: How should I configured the tool so that you respond with the number of results and prompt me to provide a filter for the results?
Agent: To configure the tool for a better user experience, you should:
- Display the number of results found (e.g., “There are 120 metrics available.”).
- Prompt the user to provide a filter (e.g., “Please specify a keyword or prefix to filter the results, such as go_, process_, or prometheus_.”).
This approach helps avoid overwhelming output and guides the user to get relevant information efficiently. If you want, I can help you implement this logic in your code or workflow. Let me know your preferred language or tool!
Me: When using you (GitHub Copilot agent mode) to query the MCP server, you retrieved the results but you did not display them nor did you prompt me that you'd retrieved the results but the list was too long and that I should provide a filter. So, I want to reconfigure the server's tool to do this but I don't know how to do it. I'm using github.com/mark3labs/mcp-go, how should I configure the tool
Agent: Thank you for clarifying. The behavior you’re describing—where the GitHub Copilot agent (me) summarizes the number of results and prompts for a filter instead of displaying a long list—is not controlled by the MCP server or the `github.com/mark3labs/mcp-go` library itself. Instead, it is determined by how the client (the agent or your own code) handles and presents the results.
What you can do:
- …
- If you want the Copilot agent to always behave this way, you would need to request this as a feature from the Copilot team or adjust your workflow to always ask for a filter.
Per the Agent’s suggestion, I filed an issue
That’s all (for now)!