Skip to content

Commit 5f76c2a

Browse files
author
priyanshu.solanki
committed
fixing lint issues
1 parent 835e69d commit 5f76c2a

File tree

19 files changed

+408
-707
lines changed

19 files changed

+408
-707
lines changed

apps/sim/app/api/mcp/discover/route.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { db } from '@sim/db'
22
import { permissions, workflowMcpServer, workspace } from '@sim/db/schema'
3-
import { eq, and, sql } from 'drizzle-orm'
3+
import { and, eq, sql } from 'drizzle-orm'
44
import { type NextRequest, NextResponse } from 'next/server'
55
import { checkHybridAuth } from '@/lib/auth/hybrid'
66
import { getBaseUrl } from '@/lib/core/utils/urls'
@@ -12,24 +12,24 @@ export const dynamic = 'force-dynamic'
1212

1313
/**
1414
* GET - Discover all published MCP servers available to the authenticated user
15-
*
15+
*
1616
* This endpoint allows external MCP clients to discover available servers
1717
* using just their API key, without needing to know workspace IDs.
18-
*
18+
*
1919
* Authentication: API Key (X-API-Key header) or Session
20-
*
20+
*
2121
* Returns all published MCP servers from workspaces the user has access to.
2222
*/
2323
export async function GET(request: NextRequest) {
2424
try {
2525
// Authenticate the request
2626
const auth = await checkHybridAuth(request, { requireWorkflowId: false })
27-
27+
2828
if (!auth.success || !auth.userId) {
2929
return NextResponse.json(
30-
{
31-
success: false,
32-
error: 'Authentication required. Provide X-API-Key header with your Sim API key.'
30+
{
31+
success: false,
32+
error: 'Authentication required. Provide X-API-Key header with your Sim API key.',
3333
},
3434
{ status: 401 }
3535
)
@@ -41,14 +41,9 @@ export async function GET(request: NextRequest) {
4141
const userWorkspacePermissions = await db
4242
.select({ entityId: permissions.entityId })
4343
.from(permissions)
44-
.where(
45-
and(
46-
eq(permissions.userId, userId),
47-
eq(permissions.entityType, 'workspace')
48-
)
49-
)
44+
.where(and(eq(permissions.userId, userId), eq(permissions.entityType, 'workspace')))
5045

51-
const workspaceIds = userWorkspacePermissions.map(w => w.entityId)
46+
const workspaceIds = userWorkspacePermissions.map((w) => w.entityId)
5247

5348
if (workspaceIds.length === 0) {
5449
return NextResponse.json({
@@ -87,7 +82,7 @@ export async function GET(request: NextRequest) {
8782
const baseUrl = getBaseUrl()
8883

8984
// Format response with connection URLs
90-
const formattedServers = servers.map(server => ({
85+
const formattedServers = servers.map((server) => ({
9186
id: server.id,
9287
name: server.name,
9388
description: server.description,
@@ -119,7 +114,7 @@ export async function GET(request: NextRequest) {
119114
body: '{"jsonrpc":"2.0","id":1,"method":"tools/list"}',
120115
},
121116
callTool: {
122-
method: 'POST',
117+
method: 'POST',
123118
body: '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"TOOL_NAME","arguments":{}}}',
124119
},
125120
},

apps/sim/app/api/mcp/serve/[serverId]/route.ts

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,7 @@ async function validateServer(serverId: string) {
8686
/**
8787
* GET - Server info and capabilities (MCP initialize)
8888
*/
89-
export async function GET(
90-
request: NextRequest,
91-
{ params }: { params: Promise<RouteParams> }
92-
) {
89+
export async function GET(request: NextRequest, { params }: { params: Promise<RouteParams> }) {
9390
const { serverId } = await params
9491

9592
try {
@@ -122,10 +119,7 @@ export async function GET(
122119
/**
123120
* POST - Handle MCP JSON-RPC requests
124121
*/
125-
export async function POST(
126-
request: NextRequest,
127-
{ params }: { params: Promise<RouteParams> }
128-
) {
122+
export async function POST(request: NextRequest, { params }: { params: Promise<RouteParams> }) {
129123
const { serverId } = await params
130124

131125
try {
@@ -151,10 +145,9 @@ export async function POST(
151145
const rpcRequest = body as JsonRpcRequest
152146

153147
if (rpcRequest.jsonrpc !== '2.0' || !rpcRequest.method) {
154-
return NextResponse.json(
155-
createJsonRpcError(rpcRequest?.id || 0, -32600, 'Invalid Request'),
156-
{ status: 400 }
157-
)
148+
return NextResponse.json(createJsonRpcError(rpcRequest?.id || 0, -32600, 'Invalid Request'), {
149+
status: 400,
150+
})
158151
}
159152

160153
// Handle different MCP methods
@@ -178,7 +171,9 @@ export async function POST(
178171

179172
case 'tools/call': {
180173
// Get the API key from the request to forward to the workflow execute call
181-
const apiKey = request.headers.get('X-API-Key') || request.headers.get('Authorization')?.replace('Bearer ', '')
174+
const apiKey =
175+
request.headers.get('X-API-Key') ||
176+
request.headers.get('Authorization')?.replace('Bearer ', '')
182177
return handleToolsCall(rpcRequest, serverId, auth.userId, server.workspaceId, apiKey)
183178
}
184179

@@ -193,10 +188,7 @@ export async function POST(
193188
}
194189
} catch (error) {
195190
logger.error('Error handling MCP request:', error)
196-
return NextResponse.json(
197-
createJsonRpcError(0, -32603, 'Internal error'),
198-
{ status: 500 }
199-
)
191+
return NextResponse.json(createJsonRpcError(0, -32603, 'Internal error'), { status: 500 })
200192
}
201193
}
202194

@@ -236,15 +228,12 @@ async function handleToolsList(
236228
},
237229
}))
238230

239-
return NextResponse.json(
240-
createJsonRpcResponse(rpcRequest.id, { tools: mcpTools })
241-
)
231+
return NextResponse.json(createJsonRpcResponse(rpcRequest.id, { tools: mcpTools }))
242232
} catch (error) {
243233
logger.error('Error listing tools:', error)
244-
return NextResponse.json(
245-
createJsonRpcError(rpcRequest.id, -32603, 'Failed to list tools'),
246-
{ status: 500 }
247-
)
234+
return NextResponse.json(createJsonRpcError(rpcRequest.id, -32603, 'Failed to list tools'), {
235+
status: 500,
236+
})
248237
}
249238
}
250239

@@ -259,7 +248,9 @@ async function handleToolsCall(
259248
apiKey?: string | null
260249
): Promise<NextResponse> {
261250
try {
262-
const params = rpcRequest.params as { name: string; arguments?: Record<string, unknown> } | undefined
251+
const params = rpcRequest.params as
252+
| { name: string; arguments?: Record<string, unknown> }
253+
| undefined
263254

264255
if (!params?.name) {
265256
return NextResponse.json(
@@ -318,7 +309,7 @@ async function handleToolsCall(
318309
const executeHeaders: Record<string, string> = {
319310
'Content-Type': 'application/json',
320311
}
321-
312+
322313
// Forward the API key for authentication
323314
if (apiKey) {
324315
executeHeaders['X-API-Key'] = apiKey
@@ -362,9 +353,8 @@ async function handleToolsCall(
362353
)
363354
} catch (error) {
364355
logger.error('Error calling tool:', error)
365-
return NextResponse.json(
366-
createJsonRpcError(rpcRequest.id, -32603, 'Tool execution failed'),
367-
{ status: 500 }
368-
)
356+
return NextResponse.json(createJsonRpcError(rpcRequest.id, -32603, 'Tool execution failed'), {
357+
status: 500,
358+
})
369359
}
370360
}

apps/sim/app/api/mcp/serve/[serverId]/sse/route.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { workflow, workflowMcpServer, workflowMcpTool } from '@sim/db/schema'
33
import { eq } from 'drizzle-orm'
44
import { type NextRequest, NextResponse } from 'next/server'
55
import { checkHybridAuth } from '@/lib/auth/hybrid'
6-
import { getBaseUrl } from '@/lib/core/utils/urls'
76
import { SSE_HEADERS } from '@/lib/core/utils/sse'
7+
import { getBaseUrl } from '@/lib/core/utils/urls'
88
import { createLogger } from '@/lib/logs/console/logger'
99

1010
const logger = createLogger('WorkflowMcpSSE')
@@ -54,10 +54,7 @@ async function validateServer(serverId: string) {
5454
* GET - SSE endpoint for MCP protocol
5555
* This establishes a Server-Sent Events connection for bidirectional MCP communication
5656
*/
57-
export async function GET(
58-
request: NextRequest,
59-
{ params }: { params: Promise<RouteParams> }
60-
) {
57+
export async function GET(request: NextRequest, { params }: { params: Promise<RouteParams> }) {
6158
const { serverId } = await params
6259

6360
try {
@@ -160,10 +157,7 @@ export async function GET(
160157
* POST - Handle messages sent to the SSE endpoint
161158
* This is used for the message channel in MCP streamable-http transport
162159
*/
163-
export async function POST(
164-
request: NextRequest,
165-
{ params }: { params: Promise<RouteParams> }
166-
) {
160+
export async function POST(request: NextRequest, { params }: { params: Promise<RouteParams> }) {
167161
const { serverId } = await params
168162

169163
try {
@@ -224,7 +218,9 @@ export async function POST(
224218

225219
case 'tools/call': {
226220
// Get the API key from the request to forward to the workflow execute call
227-
const apiKey = request.headers.get('X-API-Key') || request.headers.get('Authorization')?.replace('Bearer ', '')
221+
const apiKey =
222+
request.headers.get('X-API-Key') ||
223+
request.headers.get('Authorization')?.replace('Bearer ', '')
228224
return handleToolsCall(message, serverId, userId, workspaceId, apiKey)
229225
}
230226

@@ -258,10 +254,7 @@ export async function POST(
258254
/**
259255
* Handle tools/list method
260256
*/
261-
async function handleToolsList(
262-
id: string | number,
263-
serverId: string
264-
): Promise<NextResponse> {
257+
async function handleToolsList(id: string | number, serverId: string): Promise<NextResponse> {
265258
const tools = await db
266259
.select({
267260
toolName: workflowMcpTool.toolName,
@@ -369,7 +362,7 @@ async function handleToolsCall(
369362
const executeHeaders: Record<string, string> = {
370363
'Content-Type': 'application/json',
371364
}
372-
365+
373366
// Forward the API key for authentication
374367
if (apiKey) {
375368
executeHeaders['X-API-Key'] = apiKey

apps/sim/app/api/mcp/workflow-servers/[id]/publish/route.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ export const POST = withMcpAuth<RouteParams>('admin')(
5454

5555
if (tools.length === 0) {
5656
return createMcpErrorResponse(
57-
new Error('Cannot publish server without any tools. Add at least one workflow as a tool first.'),
57+
new Error(
58+
'Cannot publish server without any tools. Add at least one workflow as a tool first.'
59+
),
5860
'Server has no tools',
5961
400
6062
)

apps/sim/app/api/mcp/workflow-servers/[id]/route.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { db } from '@sim/db'
22
import { workflowMcpServer, workflowMcpTool } from '@sim/db/schema'
3-
import { and, eq, sql } from 'drizzle-orm'
3+
import { and, eq } from 'drizzle-orm'
44
import type { NextRequest } from 'next/server'
55
import { createLogger } from '@/lib/logs/console/logger'
66
import { getParsedBody, withMcpAuth } from '@/lib/mcp/middleware'
@@ -51,7 +51,9 @@ export const GET = withMcpAuth<RouteParams>('read')(
5151
.from(workflowMcpTool)
5252
.where(eq(workflowMcpTool.serverId, serverId))
5353

54-
logger.info(`[${requestId}] Found workflow MCP server: ${server.name} with ${tools.length} tools`)
54+
logger.info(
55+
`[${requestId}] Found workflow MCP server: ${server.name} with ${tools.length} tools`
56+
)
5557

5658
return createMcpSuccessResponse({ server, tools })
5759
} catch (error) {

apps/sim/app/api/mcp/workflow-servers/[id]/tools/route.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ interface RouteParams {
2020
* Tool names should be lowercase, alphanumeric with underscores.
2121
*/
2222
function sanitizeToolName(name: string): string {
23-
return name
24-
.toLowerCase()
25-
.replace(/[^a-z0-9\s_-]/g, '')
26-
.replace(/[\s-]+/g, '_')
27-
.replace(/_+/g, '_')
28-
.replace(/^_|_$/g, '')
29-
.substring(0, 64) || 'workflow_tool'
23+
return (
24+
name
25+
.toLowerCase()
26+
.replace(/[^a-z0-9\s_-]/g, '')
27+
.replace(/[\s-]+/g, '_')
28+
.replace(/_+/g, '_')
29+
.replace(/^_|_$/g, '')
30+
.substring(0, 64) || 'workflow_tool'
31+
)
3032
}
3133

3234
/**
@@ -217,7 +219,9 @@ export const POST = withMcpAuth<RouteParams>('write')(
217219
// Generate tool name and description
218220
const toolName = body.toolName?.trim() || sanitizeToolName(workflowRecord.name)
219221
const toolDescription =
220-
body.toolDescription?.trim() || workflowRecord.description || `Execute ${workflowRecord.name} workflow`
222+
body.toolDescription?.trim() ||
223+
workflowRecord.description ||
224+
`Execute ${workflowRecord.name} workflow`
221225

222226
// Create the tool
223227
const toolId = crypto.randomUUID()

apps/sim/app/api/mcp/workflow-servers/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { db } from '@sim/db'
2-
import { workflowMcpServer, workflowMcpTool } from '@sim/db/schema'
3-
import { and, eq, sql } from 'drizzle-orm'
2+
import { workflowMcpServer } from '@sim/db/schema'
3+
import { eq, sql } from 'drizzle-orm'
44
import type { NextRequest } from 'next/server'
55
import { createLogger } from '@/lib/logs/console/logger'
66
import { getParsedBody, withMcpAuth } from '@/lib/mcp/middleware'

apps/sim/app/api/workflows/[id]/deploy/route.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ async function syncMcpToolsOnDeploy(workflowId: string, requestId: string): Prom
138138
const hasStart = await hasValidStartBlock(workflowId)
139139
if (!hasStart) {
140140
// No start block - remove all MCP tools for this workflow
141-
await db
142-
.delete(workflowMcpTool)
143-
.where(eq(workflowMcpTool.workflowId, workflowId))
144-
145-
logger.info(`[${requestId}] Removed ${tools.length} MCP tool(s) - workflow no longer has a start block: ${workflowId}`)
141+
await db.delete(workflowMcpTool).where(eq(workflowMcpTool.workflowId, workflowId))
142+
143+
logger.info(
144+
`[${requestId}] Removed ${tools.length} MCP tool(s) - workflow no longer has a start block: ${workflowId}`
145+
)
146146
return
147147
}
148148

apps/sim/app/api/workflows/[id]/deployments/[version]/activate/route.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,11 @@ async function syncMcpToolsOnVersionActivate(
133133
// Check if the activated version has a valid start block
134134
if (!hasValidStartBlockInState(versionState)) {
135135
// No start block - remove all MCP tools for this workflow
136-
await db
137-
.delete(workflowMcpTool)
138-
.where(eq(workflowMcpTool.workflowId, workflowId))
139-
140-
logger.info(`[${requestId}] Removed ${tools.length} MCP tool(s) - activated version has no start block: ${workflowId}`)
136+
await db.delete(workflowMcpTool).where(eq(workflowMcpTool.workflowId, workflowId))
137+
138+
logger.info(
139+
`[${requestId}] Removed ${tools.length} MCP tool(s) - activated version has no start block: ${workflowId}`
140+
)
141141
return
142142
}
143143

@@ -153,7 +153,9 @@ async function syncMcpToolsOnVersionActivate(
153153
})
154154
.where(eq(workflowMcpTool.workflowId, workflowId))
155155

156-
logger.info(`[${requestId}] Synced ${tools.length} MCP tool(s) for workflow version activation: ${workflowId}`)
156+
logger.info(
157+
`[${requestId}] Synced ${tools.length} MCP tool(s) for workflow version activation: ${workflowId}`
158+
)
157159
} catch (error) {
158160
logger.error(`[${requestId}] Error syncing MCP tools on version activate:`, error)
159161
// Don't throw - this is a non-critical operation

0 commit comments

Comments
 (0)