88import { createRequire } from 'node:module' ;
99import { findCycles } from './cycles.js' ;
1010import { findDbPath } from './db.js' ;
11+ import { MCP_DEFAULTS , MCP_MAX_LIMIT } from './paginate.js' ;
1112import { ALL_SYMBOL_KINDS , diffImpactMermaid , VALID_ROLES } from './queries.js' ;
1213
1314const REPO_PROP = {
@@ -17,6 +18,11 @@ const REPO_PROP = {
1718 } ,
1819} ;
1920
21+ const PAGINATION_PROPS = {
22+ limit : { type : 'number' , description : 'Max results to return (pagination)' } ,
23+ offset : { type : 'number' , description : 'Skip this many results (pagination, default: 0)' } ,
24+ } ;
25+
2026const BASE_TOOLS = [
2127 {
2228 name : 'query_function' ,
@@ -31,6 +37,7 @@ const BASE_TOOLS = [
3137 default : 2 ,
3238 } ,
3339 no_tests : { type : 'boolean' , description : 'Exclude test files' , default : false } ,
40+ ...PAGINATION_PROPS ,
3441 } ,
3542 required : [ 'name' ] ,
3643 } ,
@@ -214,6 +221,7 @@ const BASE_TOOLS = [
214221 default : false ,
215222 } ,
216223 no_tests : { type : 'boolean' , description : 'Exclude test files' , default : false } ,
224+ ...PAGINATION_PROPS ,
217225 } ,
218226 required : [ 'target' ] ,
219227 } ,
@@ -266,6 +274,7 @@ const BASE_TOOLS = [
266274 description : 'File-level graph (true) or function-level (false)' ,
267275 default : true ,
268276 } ,
277+ ...PAGINATION_PROPS ,
269278 } ,
270279 required : [ 'format' ] ,
271280 } ,
@@ -280,6 +289,7 @@ const BASE_TOOLS = [
280289 file : { type : 'string' , description : 'Filter by file path (partial match)' } ,
281290 pattern : { type : 'string' , description : 'Filter by function name (partial match)' } ,
282291 no_tests : { type : 'boolean' , description : 'Exclude test files' , default : false } ,
292+ ...PAGINATION_PROPS ,
283293 } ,
284294 } ,
285295 } ,
@@ -319,6 +329,7 @@ const BASE_TOOLS = [
319329 } ,
320330 file : { type : 'string' , description : 'Scope to a specific file (partial match)' } ,
321331 no_tests : { type : 'boolean' , description : 'Exclude test files' , default : false } ,
332+ ...PAGINATION_PROPS ,
322333 } ,
323334 } ,
324335 } ,
@@ -400,6 +411,7 @@ const BASE_TOOLS = [
400411 type : 'object' ,
401412 properties : {
402413 no_tests : { type : 'boolean' , description : 'Exclude test files' , default : false } ,
414+ ...PAGINATION_PROPS ,
403415 } ,
404416 } ,
405417 } ,
@@ -604,7 +616,11 @@ export async function startMCPServer(customDbPath, options = {}) {
604616 let result ;
605617 switch ( name ) {
606618 case 'query_function' :
607- result = queryNameData ( args . name , dbPath , { noTests : args . no_tests } ) ;
619+ result = queryNameData ( args . name , dbPath , {
620+ noTests : args . no_tests ,
621+ limit : Math . min ( args . limit ?? MCP_DEFAULTS . query_function , MCP_MAX_LIMIT ) ,
622+ offset : args . offset ?? 0 ,
623+ } ) ;
608624 break ;
609625 case 'file_deps' :
610626 result = fileDepsData ( args . file , dbPath , { noTests : args . no_tests } ) ;
@@ -666,6 +682,8 @@ export async function startMCPServer(customDbPath, options = {}) {
666682 result = whereData ( args . target , dbPath , {
667683 file : args . file_mode ,
668684 noTests : args . no_tests ,
685+ limit : Math . min ( args . limit ?? MCP_DEFAULTS . where , MCP_MAX_LIMIT ) ,
686+ offset : args . offset ?? 0 ,
669687 } ) ;
670688 break ;
671689 case 'diff_impact' :
@@ -705,15 +723,21 @@ export async function startMCPServer(customDbPath, options = {}) {
705723 const { exportDOT, exportMermaid, exportJSON } = await import ( './export.js' ) ;
706724 const db = new Database ( findDbPath ( dbPath ) , { readonly : true } ) ;
707725 const fileLevel = args . file_level !== false ;
726+ const exportLimit = args . limit
727+ ? Math . min ( args . limit , MCP_MAX_LIMIT )
728+ : MCP_DEFAULTS . export_graph ;
708729 switch ( args . format ) {
709730 case 'dot' :
710- result = exportDOT ( db , { fileLevel } ) ;
731+ result = exportDOT ( db , { fileLevel, limit : exportLimit } ) ;
711732 break ;
712733 case 'mermaid' :
713- result = exportMermaid ( db , { fileLevel } ) ;
734+ result = exportMermaid ( db , { fileLevel, limit : exportLimit } ) ;
714735 break ;
715736 case 'json' :
716- result = exportJSON ( db ) ;
737+ result = exportJSON ( db , {
738+ limit : exportLimit ,
739+ offset : args . offset ?? 0 ,
740+ } ) ;
717741 break ;
718742 default :
719743 db . close ( ) ;
@@ -735,13 +759,17 @@ export async function startMCPServer(customDbPath, options = {}) {
735759 file : args . file ,
736760 pattern : args . pattern ,
737761 noTests : args . no_tests ,
762+ limit : Math . min ( args . limit ?? MCP_DEFAULTS . list_functions , MCP_MAX_LIMIT ) ,
763+ offset : args . offset ?? 0 ,
738764 } ) ;
739765 break ;
740766 case 'node_roles' :
741767 result = rolesData ( dbPath , {
742768 role : args . role ,
743769 file : args . file ,
744770 noTests : args . no_tests ,
771+ limit : Math . min ( args . limit ?? MCP_DEFAULTS . node_roles , MCP_MAX_LIMIT ) ,
772+ offset : args . offset ?? 0 ,
745773 } ) ;
746774 break ;
747775 case 'structure' : {
@@ -793,6 +821,8 @@ export async function startMCPServer(customDbPath, options = {}) {
793821 const { listEntryPointsData } = await import ( './flow.js' ) ;
794822 result = listEntryPointsData ( dbPath , {
795823 noTests : args . no_tests ,
824+ limit : Math . min ( args . limit ?? MCP_DEFAULTS . list_entry_points , MCP_MAX_LIMIT ) ,
825+ offset : args . offset ?? 0 ,
796826 } ) ;
797827 break ;
798828 }
0 commit comments