Skip to content

Commenting on position frequently has tiny offsets

We had recently started implementing this MCP for auto-reviewing merge requests using gemini.

Now that we can comment on specific positions, we've converted our prompt to use this feature and to also add suggestion blocks(as documented in their docs).

What we noticed was that many times both the position and the suggestion block range are off by a bit. for example:

  • bug on line 75
  • creates a comment on line 73(no range)
  • in the suggestion, it uses line 73 -2+0, which is not the problematic code, and that will cause the suggestion to break other parts.

I am not sure if this happens due to the model misunderstanding the different line numbers for different responses, such as from list_merge_request_diffs and get_repository_file_contents, which is why it has a small offset from the actual problematic line.

There is only so much fine-tuning we can do via the prompt. We wanted to see if this is something that might be worth adding to the MCP itself, or if it should be handled at the model/prompt level.

points for discussion:

  1. Should the MCP have a better interpretation of the MR diff? For example, by parsing it into a format that is perhaps simpler for the model to understand?
  2. Is there a need for a tool for forming suggestions correctly for a positioned comment?
  3. How can we better guarantee that the positioned comment will be on the right line number?
  4. Is it possible to create positioned comments on a line range(for example commenting on lines 75-80)?

We might be able to assist with implementing this, but wanted to raise for discussion first.