Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/studio-mcp-remote",
"version": "1.1.0",
"version": "1.2.0",
"description": "Local stdio MCP server bridging client calls and ZenStack local database proxy",
"type": "module",
"main": "./dist/index.js",
Expand Down Expand Up @@ -36,4 +36,4 @@
"engines": {
"node": ">=18.0.0"
}
}
}
22 changes: 13 additions & 9 deletions src/proxy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import SuperJSON from 'superjson'
import type { McpOperation } from './types.js'

const READ_OPERATIONS = new Set(['findMany', 'findFirst', 'findUnique', 'count'])
const READ_OPERATIONS = new Set([
'findMany',
'findUnique',
'findFirst',
'count',
'aggregate',
'groupBy',
])
const DELETE_OPERATIONS = new Set(['delete', 'deleteMany'])
const UPDATE_OPERATIONS = new Set(['update', 'updateMany', 'updateManyAndReturn'])

export async function executeProxyOperation(
proxyUrl: string,
Expand All @@ -10,7 +19,8 @@ export async function executeProxyOperation(
): Promise<unknown> {
const { json, meta } = SuperJSON.serialize(operation.args ?? {})
const isRead = READ_OPERATIONS.has(operation.operation)
const isDelete = operation.operation === 'deleteMany'
const isDelete = DELETE_OPERATIONS.has(operation.operation)
const isUpdate = UPDATE_OPERATIONS.has(operation.operation)

const query = `q=${encodeURIComponent(JSON.stringify(json))}${
meta && Object.keys(meta).length
Expand All @@ -30,13 +40,7 @@ export async function executeProxyOperation(
const authHeader = authorization.startsWith('Bearer ') ? authorization : `Bearer ${authorization}`

const response = await fetch(url, {
method: isRead
? 'GET'
: isDelete
? 'DELETE'
: operation.operation === 'update'
? 'PUT'
: 'POST',
method: isRead ? 'GET' : isDelete ? 'DELETE' : isUpdate ? 'PUT' : 'POST',
headers: {
Authorization: authHeader,
'Content-Type': 'application/json',
Expand Down
Loading