@@ -3,8 +3,9 @@ import { LinkedApi, LinkedApiError, TLinkedApiConfig } from 'linkedapi-node';
33import { buildLinkedApiHttpClient } from 'linkedapi-node/dist/core' ;
44
55import { LinkedApiTools } from './linked-api-tools' ;
6- import { debugLog } from './utils/debug-log ' ;
6+ import { defineRequestTimeoutInSeconds } from './utils/define-request-timeout ' ;
77import { handleLinkedApiError } from './utils/handle-linked-api-error' ;
8+ import { logger } from './utils/logger' ;
89import {
910 CallToolResult ,
1011 ExtendedCallToolRequest ,
@@ -24,26 +25,52 @@ export class LinkedApiMCPServer {
2425
2526 public async executeWithTokens (
2627 request : ExtendedCallToolRequest [ 'params' ] ,
27- config : TLinkedApiConfig ,
28+ { linkedApiToken , identificationToken , mcpClient } : TLinkedApiConfig & { mcpClient : string } ,
2829 ) : Promise < CallToolResult > {
29- const linkedApi = new LinkedApi (
30+ const workflowTimeout = defineRequestTimeoutInSeconds ( mcpClient ) * 1000 ;
31+ logger . info (
32+ {
33+ toolName : request . name ,
34+ arguments : request . arguments ,
35+ mcpClient,
36+ workflowTimeout,
37+ } ,
38+ 'Tool execution started' ,
39+ ) ;
40+ const linkedapi = new LinkedApi (
3041 buildLinkedApiHttpClient (
3142 {
32- linkedApiToken : config . linkedApiToken ! ,
33- identificationToken : config . identificationToken ! ,
43+ linkedApiToken : linkedApiToken ,
44+ identificationToken : identificationToken ,
3445 } ,
3546 'mcp' ,
3647 ) ,
3748 ) ;
3849
39- const { name, arguments : args , _meta } = request ;
50+ const { name : toolName , arguments : args , _meta } = request ;
4051 const progressToken = _meta ?. progressToken ;
4152
53+ const startTime = Date . now ( ) ;
4254 try {
43- const tool = this . tools . toolByName ( name ) ! ;
55+ const tool = this . tools . toolByName ( toolName ) ! ;
4456 const params = tool . validate ( args ) ;
45- const { data, errors } = await tool . execute ( linkedApi , params , progressToken ) ;
57+ const { data, errors } = await tool . execute ( {
58+ linkedapi,
59+ args : params ,
60+ workflowTimeout,
61+ progressToken,
62+ } ) ;
63+ const endTime = Date . now ( ) ;
64+ const duration = `${ ( ( endTime - startTime ) / 1000 ) . toFixed ( 2 ) } seconds` ;
4665 if ( errors . length > 0 && ! data ) {
66+ logger . error (
67+ {
68+ toolName,
69+ duration,
70+ errors,
71+ } ,
72+ 'Tool execution failed' ,
73+ ) ;
4774 return {
4875 content : [
4976 {
@@ -53,6 +80,14 @@ export class LinkedApiMCPServer {
5380 ] ,
5481 } ;
5582 }
83+ logger . info (
84+ {
85+ toolName,
86+ duration,
87+ data,
88+ } ,
89+ 'Tool execution successful' ,
90+ ) ;
5691 if ( data ) {
5792 return {
5893 content : [
@@ -72,8 +107,17 @@ export class LinkedApiMCPServer {
72107 ] ,
73108 } ;
74109 } catch ( error ) {
110+ const duration = this . calculateDuration ( startTime ) ;
75111 if ( error instanceof LinkedApiError ) {
76112 const body = handleLinkedApiError ( error ) ;
113+ logger . error (
114+ {
115+ toolName,
116+ duration,
117+ body,
118+ } ,
119+ 'Tool execution failed with Linked API error' ,
120+ ) ;
77121 return {
78122 content : [
79123 {
@@ -84,19 +128,29 @@ export class LinkedApiMCPServer {
84128 } ;
85129 }
86130 const errorMessage = error instanceof Error ? error . message : String ( error ) ;
87- debugLog ( `Tool ${ name } execution failed` , {
88- error : errorMessage ,
89- stack : error instanceof Error ? error . stack : undefined ,
90- } ) ;
131+ logger . error (
132+ {
133+ toolName,
134+ duration,
135+ error : errorMessage ,
136+ stack : error instanceof Error ? error . stack : undefined ,
137+ } ,
138+ 'Tool execution failed with unknown error' ,
139+ ) ;
91140
92141 return {
93142 content : [
94143 {
95144 type : 'text' as const ,
96- text : `Error executing ${ name } : ${ errorMessage } ` ,
145+ text : `Error executing ${ toolName } : ${ errorMessage } ` ,
97146 } ,
98147 ] ,
99148 } ;
100149 }
101150 }
151+
152+ private calculateDuration ( startTime : number ) : string {
153+ const endTime = Date . now ( ) ;
154+ return `${ ( ( endTime - startTime ) / 1000 ) . toFixed ( 2 ) } seconds` ;
155+ }
102156}
0 commit comments