Skip to content

feat: add -debug flag to allow debugging of Grafana requests #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2025

Conversation

sd2k
Copy link
Collaborator

@sd2k sd2k commented Apr 16, 2025

Should resolve #80.

@sd2k sd2k requested a review from a team as a code owner April 16, 2025 19:04
@@ -135,6 +155,8 @@ var ExtractGrafanaClientFromEnv server.StdioContextFunc = func(ctx context.Conte
cfg.APIKey = apiKey
}

cfg.Debug = GrafanaDebugFromContext(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we pass all config options through env vars? wondering if using one way or the other will make it maintainable over time

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I do think we need to standardize here, and maybe revisit all of the config options to be honest. Ideally everything would be configurable via either env or CLI flag which we could get by using a more full featured CLI parsing library, but that feels like a future thing!

I chose a CLI flag because it feels similar to --log-level to me!

Copy link
Contributor

@csmarchbanks csmarchbanks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I am not seeing much different in the logs when trying with Claude Desktop. Is there something I should be looking for?

@sd2k
Copy link
Collaborator Author

sd2k commented Apr 17, 2025

When I run the server with --debug I see this in stderr:

❯ GRAFANA_URL=http://localhost:3000 go run ./cmd/mcp-grafana --debug
time=2025-04-17T09:18:28.098+01:00 level=INFO msg="Starting Grafana MCP server using stdio transport"
time=2025-04-17T09:18:28.098+01:00 level=INFO msg="Grafana transport debug mode enabled"
time=2025-04-17T09:18:28.098+01:00 level=INFO msg="Using Grafana configuration" url=http://localhost:3000 api_key_set=false
{"jsonrpc": "2.0", "id": 0, "method": "tools/call", "params": {"name": "list_datasources" }}
GET /api/datasources HTTP/1.1
Host: localhost:3000
User-Agent: Go-http-client/1.1
Accept: application/json
Accept-Encoding: gzip


HTTP/1.1 401 Unauthorized
Content-Length: 123
Cache-Control: no-store
Content-Type: application/json; charset=UTF-8
Date: Thu, 17 Apr 2025 08:18:29 GMT
X-Content-Type-Options: nosniff
X-Frame-Options: deny
X-Xss-Protection: 1; mode=block

{
  "extra": null,
  "message": "Unauthorized",
  "messageId": "auth.unauthorized",
  "statusCode": 401,
  "traceID": ""
}

{"jsonrpc":"2.0","id":0,"error":{"code":-32603,"message":"list datasources: [GET /datasources][401] getDataSourcesUnauthorized {\"message\":\"Unauthorized\"}"}}

I haven't tried with Claude desktop to be fair, not sure where it dumps the logs...

Copy link
Contributor

@csmarchbanks csmarchbanks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well I see them today so maybe I just did something odd with the build yesterday... 🤷

I'm good with the cli argument, it actually looks like grafana-runtime uses the DEBUG env var, but then overwrites it when creating the client. We could use that too in the future.

@sd2k sd2k merged commit 0e9f363 into main Apr 17, 2025
5 checks passed
@sd2k sd2k deleted the add-debug-flag branch April 17, 2025 14:07
ioanarm pushed a commit that referenced this pull request Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature require]Support Client Debug option
3 participants