Welcome to Francis Academic Press

Academic Journal of Computing & Information Science, 2025, 8(7); doi: 10.25236/AJCIS.2025.080712.

Large Language Models Tool Retrieval and Context Compression via Dynamic Graph-Based Relation Modeling

Author(s)

Xiaoyi Nie1, Haitao Zhang1

Corresponding Author:
Xiaoyi Nie
Affiliation(s)

1College of Information and Intelligent Science and Technology, Hunan Agricultural University, Changsha, 410125, Hunan, China

Abstract

Large language models (LLMs) face two major obstacles in integrating external tools defined by the evolving Model Context Protocol (MCP): prompt redundancy and the complexity of tool selection. To overcome these limitations, we introduce GraphRAG-MCP, a framework that reimagines tool discovery as a graph-based retrieval task. By representing the MCP tool repository as a semantic graph and leveraging graph neural networks to capture dynamic relations among tool nodes, GraphRAG-MCP enables efficient and context-aware tool selection. Upon receiving a query, the system retrieves the most relevant MCP subgraphs via graph embeddings and injects only compact representations into the LLM prompt. Compared to standard vector-based retrieval, this approach reduces prompt token usage by 62% and improves tool selection accuracy to 51.8%. These results underscore the promise of graph-structured knowledge representations in enabling scalable and precise tool integration for LLMs.

Keywords

Retrieval-Augmented Generation; Model Context Protocol; Tool Selection; Graph Indexing

Cite This Paper

Xiaoyi Nie, Haitao Zhang. Large Language Models Tool Retrieval and Context Compression via Dynamic Graph-Based Relation Modeling. Academic Journal of Computing & Information Science (2025), Vol. 8, Issue 7: 95-104. https://doi.org/10.25236/AJCIS.2025.080712.

References

[1] Hasan M M, Li H, Fallahzadeh E, et al. Model context protocol (mcp) at first glance: Studying the security and maintainability of mcp servers[J]. arXiv preprint arXiv:2506.13538, 2025.

[2] Peng B, Zhu Y, Liu Y, et al. Graph retrieval-augmented generation: A survey[J]. arXiv preprint arXiv:2408.08921, 2024.

[3] Merritt R. What is retrieval-augmented generation aka RAG[J]. NVIDIA Blog. Available online: https://blogs. nvidia. com/blog/what-is-retrieval-augmented-generation/(accessed on 25 March 2024), 2023.

[4] Hou X, Zhao Y, Wang S, et al. Model context protocol (mcp): Landscape, security threats, and future research directions[J]. arXiv preprint arXiv:2503.23278, 2025.

[5] Chen Y C, Hsu P C, Hsu C J, et al. Enhancing function-calling capabilities in llms: Strategies for prompt formats, data integration, and multilingual translation[J]. arXiv preprint arXiv:2412.01130, 2024.

[6] Gao Y, Xiong Y, Gao X, et al. Retrieval-augmented generation for large language models: A survey[J]. arXiv preprint arXiv:2312.10997, 2023, 2(1).

[7] Luo Z, Shi X, Lin X, et al. Evaluation report on mcp servers[J]. arXiv preprint arXiv:2504.11094, 2025.

[8] Nakano R, Hilton J, Balaji S, et al. Webgpt: Browser-assisted question-answering with human feedback, 2022[J]. URL https://arxiv. org/abs/2112.09332, 2022.

[9] Patil S G, Zhang T, Wang X, et al. Gorilla: Large language model connected with massive apis[J]. Advances in Neural Information Processing Systems, 2024, 37: 126544-126565.

[10] Yao S, Zhao J, Yu D, et al. React: Synergizing reasoning and acting in language models[C]//International Conference on Learning Representations (ICLR). 2023.

[11] Schick T, Dwivedi-Yu J, Dessì R, et al. Toolformer: Language models can teach themselves to use tools[J]. Advances in Neural Information Processing Systems, 2023, 36: 68539-68551.

[12] Gan T, Sun Q. Rag-mcp: Mitigating prompt bloat in llm tool selection via retrieval-augmented generation[J]. arXiv preprint arXiv:2505.03275, 2025.