Skip to content

Conversation

sd2k
Copy link
Collaborator

@sd2k sd2k commented Apr 16, 2025

Commas in jsonschema description fields inside struct field tags need
to be escaped; otherwise, they're treated as another field and the
description is silently truncated. This commit fixes all instances of
that, and adds a linter which checks for the presence of any unescaped
commas in the jsonschema descriptions. The linter also includes a
--fix mode to automatically fix any issues, and is integrated in CI so
we should catch this in future. (Thanks Claude & Zed!)

@sd2k sd2k requested a review from a team as a code owner April 16, 2025 19:51
@sd2k
Copy link
Collaborator Author

sd2k commented Apr 16, 2025

Hmm the branch name is wrong (I started on another issue and got distracted) but I don't think that's a biggie.

@sd2k sd2k force-pushed the fix-list-datasources-tool-schema branch from 0933a84 to c90f0b9 Compare April 16, 2025 19:57
Copy link
Contributor

@annanay25 annanay25 left a comment

Choose a reason for hiding this comment

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

lgtm, the only thing was i couldn't spot how this is integrated in CI?

and is integrated in CI so we should catch this in future.

Shouldn't we have a make lint or something in the CI? I also don't see this in the Github actions output either: https://github.com/grafana/mcp-grafana/actions/runs/14501420096/job/40681760901?pr=98

@sd2k
Copy link
Collaborator Author

sd2k commented Apr 16, 2025

Oh yeah good call! We use the golangci-lint action in CI rather than make lint, we should fix that, I'll do it tomorrow

csmarchbanks
csmarchbanks previously approved these changes Apr 16, 2025
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.

Approving, though I think the linter could fail in at least one case. Not sure how perfect we need to be...

// It captures:
// 1. The jsonschema tag
// 2. Parts of the description containing unescaped commas
var tagPattern = regexp.MustCompile(`jsonschema:"([^"]*)description=([^"]*[^\\],[^"]*)"`)
Copy link
Contributor

@csmarchbanks csmarchbanks Apr 16, 2025

Choose a reason for hiding this comment

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

Does this fail if we use escaped quotes then have a comma inside of a jsonschema tag?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It did not! I pushed a second commit which fixes & adds a test case for that.

@csmarchbanks csmarchbanks dismissed their stale review April 16, 2025 20:47

Not actually using this in CI...

sd2k added 2 commits April 17, 2025 09:53
Commas in jsonschema `description` fields inside struct field tags need
to be escaped; otherwise, they're treated as another field and the
description is silently truncated. This commit fixes all instances of
that, and adds a linter which checks for the presence of any unescaped
commas in the `jsonschema` descriptions. The linter also includes a
`--fix` mode to automatically fix any issues, and is integrated in CI so
we should catch this in future. (Thanks Claude & Zed!)
@sd2k sd2k force-pushed the fix-list-datasources-tool-schema branch from c90f0b9 to ad2cb95 Compare April 17, 2025 08:53
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.

One small comment, but 👍

@sd2k sd2k enabled auto-merge (squash) April 17, 2025 14:26
@sd2k sd2k merged commit aa5bf95 into main Apr 17, 2025
5 checks passed
@sd2k sd2k deleted the fix-list-datasources-tool-schema branch April 17, 2025 14:26
ioanarm pushed a commit that referenced this pull request Apr 22, 2025
* Fix commas in JSONSchema descriptions and add linter

Commas in jsonschema `description` fields inside struct field tags need
to be escaped; otherwise, they're treated as another field and the
description is silently truncated. This commit fixes all instances of
that, and adds a linter which checks for the presence of any unescaped
commas in the `jsonschema` descriptions. The linter also includes a
`--fix` mode to automatically fix any issues, and is integrated in CI so
we should catch this in future. (Thanks Claude & Zed!)

* Handle escaped quotes then commas in linter

* Run custom linter in CI

* Just use make lint in CI
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.

3 participants