@@ -63,20 +63,29 @@ async function fetchCallHierarchy(
6363 return { objectUri : resolvedUri , result } ;
6464}
6565
66- export function registerGetCallersOfTool (
66+ type CallHierarchyToolConfig = {
67+ endpoint : 'callers' | 'callees' ;
68+ failureLabel : string ;
69+ resultKey : 'callers' | 'callees' ;
70+ toolDescription : string ;
71+ toolName : 'get_callers_of' | 'get_callees_of' ;
72+ } ;
73+
74+ function registerCallHierarchyTool (
6775 server : McpServer ,
6876 ctx : ToolContext ,
77+ config : CallHierarchyToolConfig ,
6978) : void {
7079 server . tool (
71- 'get_callers_of' ,
72- 'Find all callers (upward call hierarchy) of an ABAP method, function module, or subroutine' ,
80+ config . toolName ,
81+ config . toolDescription ,
7382 callHierarchyShape ,
7483 async ( args ) => {
7584 try {
7685 const client = ctx . getClient ( args ) ;
7786 const res = await fetchCallHierarchy (
7887 client ,
79- 'callers' ,
88+ config . endpoint ,
8089 args . objectName ,
8190 args . objectType ,
8291 args . objectUri ,
@@ -101,7 +110,7 @@ export function registerGetCallersOfTool(
101110 {
102111 objectName : args . objectName ,
103112 objectUri : res . objectUri ,
104- callers : res . result ,
113+ [ config . resultKey ] : res . result ,
105114 } ,
106115 null ,
107116 2 ,
@@ -115,7 +124,7 @@ export function registerGetCallersOfTool(
115124 content : [
116125 {
117126 type : 'text' as const ,
118- text : `Get callers failed : ${ error instanceof Error ? error . message : String ( error ) } ` ,
127+ text : `${ config . failureLabel } : ${ error instanceof Error ? error . message : String ( error ) } ` ,
119128 } ,
120129 ] ,
121130 } ;
@@ -124,63 +133,30 @@ export function registerGetCallersOfTool(
124133 ) ;
125134}
126135
136+ export function registerGetCallersOfTool (
137+ server : McpServer ,
138+ ctx : ToolContext ,
139+ ) : void {
140+ registerCallHierarchyTool ( server , ctx , {
141+ toolName : 'get_callers_of' ,
142+ toolDescription :
143+ 'Find all callers (upward call hierarchy) of an ABAP method, function module, or subroutine' ,
144+ endpoint : 'callers' ,
145+ resultKey : 'callers' ,
146+ failureLabel : 'Get callers failed' ,
147+ } ) ;
148+ }
149+
127150export function registerGetCalleesOfTool (
128151 server : McpServer ,
129152 ctx : ToolContext ,
130153) : void {
131- server . tool (
132- 'get_callees_of' ,
133- 'Find all callees (downward call hierarchy) of an ABAP method, function module, or subroutine' ,
134- callHierarchyShape ,
135- async ( args ) => {
136- try {
137- const client = ctx . getClient ( args ) ;
138- const res = await fetchCallHierarchy (
139- client ,
140- 'callees' ,
141- args . objectName ,
142- args . objectType ,
143- args . objectUri ,
144- args . maxResults ?? 50 ,
145- ) ;
146- if ( ! res ) {
147- return {
148- isError : true ,
149- content : [
150- {
151- type : 'text' as const ,
152- text : `Object '${ args . objectName } ' not found` ,
153- } ,
154- ] ,
155- } ;
156- }
157- return {
158- content : [
159- {
160- type : 'text' as const ,
161- text : JSON . stringify (
162- {
163- objectName : args . objectName ,
164- objectUri : res . objectUri ,
165- callees : res . result ,
166- } ,
167- null ,
168- 2 ,
169- ) ,
170- } ,
171- ] ,
172- } ;
173- } catch ( error ) {
174- return {
175- isError : true ,
176- content : [
177- {
178- type : 'text' as const ,
179- text : `Get callees failed: ${ error instanceof Error ? error . message : String ( error ) } ` ,
180- } ,
181- ] ,
182- } ;
183- }
184- } ,
185- ) ;
154+ registerCallHierarchyTool ( server , ctx , {
155+ toolName : 'get_callees_of' ,
156+ toolDescription :
157+ 'Find all callees (downward call hierarchy) of an ABAP method, function module, or subroutine' ,
158+ endpoint : 'callees' ,
159+ resultKey : 'callees' ,
160+ failureLabel : 'Get callees failed' ,
161+ } ) ;
186162}
0 commit comments