11import SuperJSON from 'superjson'
22import type { McpOperation } from './types.js'
33
4- const READ_OPERATIONS = new Set ( [ 'findMany' , 'findFirst' , 'findUnique' , 'count' ] )
4+ const READ_OPERATIONS = new Set ( [
5+ 'findMany' ,
6+ 'findUnique' ,
7+ 'findFirst' ,
8+ 'count' ,
9+ 'aggregate' ,
10+ 'groupBy' ,
11+ ] )
12+ const DELETE_OPERATIONS = new Set ( [ 'delete' , 'deleteMany' ] )
13+ const UPDATE_OPERATIONS = new Set ( [ 'update' , 'updateMany' , 'updateManyAndReturn' ] )
514
615export async function executeProxyOperation (
716 proxyUrl : string ,
@@ -10,7 +19,8 @@ export async function executeProxyOperation(
1019) : Promise < unknown > {
1120 const { json, meta } = SuperJSON . serialize ( operation . args ?? { } )
1221 const isRead = READ_OPERATIONS . has ( operation . operation )
13- const isDelete = operation . operation === 'deleteMany'
22+ const isDelete = DELETE_OPERATIONS . has ( operation . operation )
23+ const isUpdate = UPDATE_OPERATIONS . has ( operation . operation )
1424
1525 const query = `q=${ encodeURIComponent ( JSON . stringify ( json ) ) } ${
1626 meta && Object . keys ( meta ) . length
@@ -30,13 +40,7 @@ export async function executeProxyOperation(
3040 const authHeader = authorization . startsWith ( 'Bearer ' ) ? authorization : `Bearer ${ authorization } `
3141
3242 const response = await fetch ( url , {
33- method : isRead
34- ? 'GET'
35- : isDelete
36- ? 'DELETE'
37- : operation . operation === 'update'
38- ? 'PUT'
39- : 'POST' ,
43+ method : isRead ? 'GET' : isDelete ? 'DELETE' : isUpdate ? 'PUT' : 'POST' ,
4044 headers : {
4145 Authorization : authHeader ,
4246 'Content-Type' : 'application/json' ,
0 commit comments