11/* eslint-disable callback-return */
22
3+ const { randomUUID } = require ( 'crypto' ) ;
4+
35const modules = Runtime . getFunctions ( ) ;
46const createServer = require ( modules . server . path ) ;
57const createReq = require ( modules . req . path ) ;
68const createRes = require ( modules . res . path ) ;
79
10+ const defaultMessaging = [
11+ 'Api20100401Message' ,
12+ 'Api20100401IncomingPhoneNumber' ,
13+ ] ;
14+
815const TWILIO_TAG_MAP = {
9- Messaging : [ 'Api20100401Message' , 'Api20100401IncomingPhoneNumber' ] ,
16+ Messaging : defaultMessaging ,
1017 Voice : [ 'Api20100401Call' ] ,
1118 VoiceAddOns : [
1219 'Api20100401Recording' ,
@@ -26,6 +33,7 @@ const TWILIO_TAG_MAP = {
2633 'StudioV2ExecutionStep' ,
2734 'StudioV2Flow' ,
2835 'StudioV2FlowRevision' ,
36+ 'StudioV2FlowValidate' ,
2937 ] ,
3038 TaskRouter : [
3139 'TaskrouterV1Activity' ,
@@ -78,7 +86,7 @@ const validateContext = (context, callback) => {
7886
7987const getTags = ( event ) => {
8088 if ( ! event . services ) {
81- return [ 'Api20100401Message' ] ;
89+ return defaultMessaging ;
8290 }
8391
8492 const services =
@@ -101,9 +109,11 @@ const getTags = (event) => {
101109} ;
102110
103111exports . handler = async function ( context , event , callback ) {
104- console . log ( 'MCPServer called with method' , event . method ) ;
112+ const id = randomUUID ( ) . substring ( 0 , 6 ) ;
113+ console . log ( `[${ id } ]` , 'STARTED MCP called with method' , event . method ) ;
105114 if ( event . method === 'tools/call' ) {
106115 console . log (
116+ `[${ id } ]` ,
107117 'Calling tool' ,
108118 event . params . name ,
109119 'with arguments' ,
@@ -123,11 +133,14 @@ exports.handler = async function (context, event, callback) {
123133
124134 await transport . handleRequest ( req , res ) ;
125135 } catch ( error ) {
136+ console . log ( `[${ id } ]` , 'FAILED MCP request with method' , event . method ) ;
126137 console . log ( error ) ;
127- console . error ( 'Error handling request:' , error ) ;
128- const twilioResponse = new Twilio . Response ( ) ;
129- twilioResponse . setStatusCode ( 500 ) ;
130- twilioResponse . setBody ( { error : error . message } ) ;
131- callback ( twilioResponse ) ;
138+
139+ const response = new Twilio . Response ( ) ;
140+ response . setStatusCode ( 500 ) ;
141+ response . setBody ( { error : error . message } ) ;
142+ callback ( null , response ) ;
143+ } finally {
144+ console . log ( `[${ id } ]` , 'COMPLETED MCP request with method' , event . method ) ;
132145 }
133146} ;
0 commit comments