@@ -19,12 +19,13 @@ export const insertTool: ToolConfig<SupabaseInsertParams, SupabaseInsertResponse
1919 } ,
2020 request : {
2121 url : ( params ) =>
22- `https://${ params . projectId } .supabase.co/rest/v1/${ params . table } ` ,
22+ `https://${ params . projectId } .supabase.co/rest/v1/${ params . table } ?select=* ` ,
2323 method : 'POST' ,
2424 headers : ( params ) => ( {
2525 'apikey' : params . apiKey ,
2626 'Authorization' : `Bearer ${ params . apiKey } ` ,
2727 'Content-Type' : 'application/json' ,
28+ 'Prefer' : 'return=representation'
2829 } ) ,
2930 body : ( params ) => {
3031 // If data is an object but not an array, wrap it in an array
@@ -37,8 +38,8 @@ export const insertTool: ToolConfig<SupabaseInsertParams, SupabaseInsertResponse
3738 } ,
3839 directExecution : async ( params : SupabaseInsertParams ) => {
3940 try {
40- // Construct the URL for the Supabase REST API
41- const url = `https://${ params . projectId } .supabase.co/rest/v1/${ params . table } ` ;
41+ // Construct the URL for the Supabase REST API with select=* to return inserted data
42+ const url = `https://${ params . projectId } .supabase.co/rest/v1/${ params . table } ?select=* ` ;
4243
4344 // Prepare the data - if it's an object but not an array, wrap it in an array
4445 const dataToSend = typeof params . data === 'object' && ! Array . isArray ( params . data )
@@ -52,6 +53,7 @@ export const insertTool: ToolConfig<SupabaseInsertParams, SupabaseInsertResponse
5253 'apikey' : params . apiKey ,
5354 'Authorization' : `Bearer ${ params . apiKey } ` ,
5455 'Content-Type' : 'application/json' ,
56+ 'Prefer' : 'return=representation'
5557 } ,
5658 body : JSON . stringify ( dataToSend ) ,
5759 } ) ;
@@ -69,16 +71,15 @@ export const insertTool: ToolConfig<SupabaseInsertParams, SupabaseInsertResponse
6971 message : `Successfully inserted data into ${ params . table } ` ,
7072 results : data ,
7173 } ,
72- data : data ,
73- error : null ,
74+ error : undefined ,
7475 }
7576 } catch ( error ) {
7677 return {
7778 success : false ,
7879 output : {
7980 message : `Error inserting into Supabase: ${ error instanceof Error ? error . message : String ( error ) } ` ,
81+ results : [ ] ,
8082 } ,
81- data : [ ] ,
8283 error : error instanceof Error ? error . message : String ( error ) ,
8384 }
8485 }
@@ -89,17 +90,28 @@ export const insertTool: ToolConfig<SupabaseInsertParams, SupabaseInsertResponse
8990 throw new Error ( error . message || 'Failed to insert data into Supabase' ) ;
9091 }
9192
92- const data = await response . json ( ) ;
93+ // Handle empty response case
94+ const text = await response . text ( ) ;
95+ if ( ! text || text . trim ( ) === '' ) {
96+ return {
97+ success : true ,
98+ output : {
99+ message : 'Successfully inserted data into Supabase (no data returned)' ,
100+ results : [ ] ,
101+ } ,
102+ error : undefined ,
103+ }
104+ }
105+
106+ const data = JSON . parse ( text ) ;
93107
94108 return {
95109 success : true ,
96110 output : {
97111 message : 'Successfully inserted data into Supabase' ,
98112 results : data ,
99113 } ,
100- severity : 'info' ,
101- data : data ,
102- error : null ,
114+ error : undefined ,
103115 }
104116 } ,
105117 transformError : ( error : any ) => {
0 commit comments