fix(mcp): function pagination drops blank lines at page boundaries

Ouverte
#8,717 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 2 jours

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
42/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
cpp

Piste de recherche

The report identifies bn_function_decompile and bn_function_disassembly in the built-in GUI MCP server, whose implementation ships inside the proprietary application. Start by reading the MCP guide’s “Ranges, Queries, and Pagination” section, then inspect the available tool implementation or tests if accessible. Reproduce with the supplied fixture and compare full output, concatenated pages, and counts while retaining the interior blank line.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Summary

bn_function_decompile and bn_function_disassembly report line counts that exceed the lines delivered in their fenced code blocks. For decompilation, concatenating successive pages also loses a blank line present in the unpaged output. This makes the text depend on page boundaries and prevents a client from reconstructing the same rendered function by following nextOffset.

Steps to reproduce

  1. Save the C source below as fixture.c, compile it, and open fixture in Binary Ninja. Enable and start the built-in GUI MCP server, then connect an MCP client and run tools/list.
#include <stdio.h>
volatile int fixture_global = 7;
__attribute__((noinline, used)) int fixture_leaf(int value) { puts("FIXTURE_LEAF"); return value + fixture_global; }
__attribute__((noinline, used)) int fixture_branch(int value) { return value > 3 ? fixture_leaf(value) : fixture_leaf(-value); }
int main(int argc, char **argv) { return fixture_branch(argc); }
clang -arch arm64 -O0 -g -fno-inline fixture.c -o fixture
  1. Call bn_binary_view_list, select the returned Mach-O view with bn_binary_view_set_active, and wait until bn_analysis_status reports IdleState. Use the returned handle unchanged; handle values are session-scoped.

  2. Call bn_function_decompile with {"function":"_fixture_branch","offset":0,"limit":1000} and count lines inside its code fence, excluding the opening/closing fences. Keep interior blank lines.

  3. Request the same function with (offset, limit) values (0, 2), (2, 3), (5, 3), and (8, 5), following each returned nextOffset. Concatenate the code-fence contents without adding separator lines and compare with step 3.

  4. Call bn_function_disassembly with {"function":"_fixture_branch","offset":0,"limit":1000} and compare its metadata with the code-fence line count.

Expected behavior

The tool schemas describe offset as a zero-based line or item offset and limit as the maximum function lines or items returned. The guide instructs clients to continue with nextOffset. Following that pagination should preserve the rendered function, including blank lines that appear inside the unpaged reply, and count should describe the returned lines consistently.

Actual behavior

The full decompile reply reported count: 10, total: 10, but contained eight code lines:

  int32_t _fixture_branch(int value)

{
    if (value <= 3)
        return _fixture_leaf(0 - value);

    return _fixture_leaf(value);
}

The four pages returned these results. Counts below include blank lines inside the fence, but exclude the fences themselves.

offset limit count total nextOffset truncated code lines received
0 2 2 10 2 true 1
2 3 3 10 5 true 2
5 3 3 10 8 true 3
8 5 2 10 null false 1

The concatenated pages contained seven lines: the blank line between the prototype and { disappeared, while the interior blank line in the third page survived. The full disassembly reply similarly reported count: 30, total: 30, but delivered 28 code lines. All observations came from the same analyzed function; the numbers describe this fixture, not a population-wide failure rate.

Evidence

  • Expected source: Installed tools/list schemas for both function rendering tools and the guide's “Ranges, Queries, and Pagination” section; versioned guide links appear under Runtime or environment.
  • Failure source: Direct raw HTTP tools/call replies for the full decompile, four pages, and full disassembly; the exact calls and meaningful results are transcribed above.
  • Evidence provenance: observed
  • Local verification: reproduced
  • Reproduction completeness: complete

Restoration check

For the supplied fixture, compare full and paged code-fence text while retaining blank lines: concatenating all pages must produce the same line sequence as the full reply, and each reply's metadata must consistently account for the lines delivered. Check both decompile and disassembly. Retain an interior blank line as a control so a pass cannot result from discarding every blank line.

Runtime or environment

  • Binary Ninja Version: Free 6.0.10905-Stable; bundle version 6.0.10905_free; built-in GUI HTTP MCP server binaryninja_ui_mcp version 0.1.0.
  • Edition: Free. OS: macOS 27.2; CPU architecture: arm64. Target: thin arm64 Mach-O built with the command above. Analysis status was IdleState before the observations.
  • The official stable release metadata matched the installed build. A fresh profile enabled ui.mcp.enabled; no user plugins or existing databases were involved. The target was analyzed, never executed, and no database was saved.
  • The stable MCP guide and the current default-branch MCP guide were compared. Their relevant calling conventions agree. The implementation ships inside the proprietary application, so public default-branch source inspection does not verify its runtime behavior.
  • The issue template requests development-build testing. That was not performed: Free cannot switch to the development channel. Personal/Commercial editions, development builds, Windows, and Linux are untested.

References

Closed issue #3292 requested adding arbitrary blank lines in the decompiler UI. Its body and full discussion concern rendering customization, not MCP pagination. This report concerns losing a line already present in the MCP tool's own full reply; it does not request that declined UI feature.

Triage assessment

  • Impact level: P2
  • Assessment status: supported
  • Impact basis: Function text changes when retrieved in pages, and reported counts cannot be reconciled with the delivered code lines. The observed loss is blank-line formatting, not missing instructions or changed analysis.
  • Workaround status: available
  • Workaround basis: For this small fixture, a single full decompile request preserves the interior blank line that paging loses. This was verified; the workaround does not establish a way to preserve arbitrary larger functions beyond the tool's 1000-line page cap.
Langage dominant
C++
Étoiles
1.3k
Forks
304
Merge moyen
2 j 20 h
PR mergées (30 j)
10

Préparer son environnement

Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de Vector35/binaryninja-api

Toutes les issues de Vector35/binaryninja-api

Issues similaires

Plus d'issues C++

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.