Skip to content

Commit 6856b26

Browse files
committed
fix discovery calls
1 parent cfdbcee commit 6856b26

File tree

9 files changed

+115
-201
lines changed

9 files changed

+115
-201
lines changed

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

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,12 @@ const logger = createLogger('McpServerRefreshAPI')
1212

1313
export const dynamic = 'force-dynamic'
1414

15-
/**
16-
* POST - Refresh an MCP server connection (requires any workspace permission)
17-
*/
1815
export const POST = withMcpAuth<{ id: string }>('read')(
1916
async (request: NextRequest, { userId, workspaceId, requestId }, { params }) => {
2017
const { id: serverId } = await params
2118

2219
try {
23-
logger.info(
24-
`[${requestId}] Refreshing MCP server: ${serverId} in workspace: ${workspaceId}`,
25-
{
26-
userId,
27-
}
28-
)
20+
logger.info(`[${requestId}] Refreshing MCP server: ${serverId}`)
2921

3022
const [server] = await db
3123
.select()
@@ -61,9 +53,7 @@ export const POST = withMcpAuth<{ id: string }>('read')(
6153
const tools = await mcpService.discoverServerTools(userId, serverId, workspaceId)
6254
connectionStatus = 'connected'
6355
toolCount = tools.length
64-
logger.info(
65-
`[${requestId}] Successfully connected to server ${serverId}, discovered ${toolCount} tools`
66-
)
56+
logger.info(`[${requestId}] Discovered ${toolCount} tools from server ${serverId}`)
6757
} catch (error) {
6858
connectionStatus = 'error'
6959
lastError = error instanceof Error ? error.message : 'Connection test failed'
@@ -94,14 +84,7 @@ export const POST = withMcpAuth<{ id: string }>('read')(
9484
.returning()
9585

9686
if (connectionStatus === 'connected') {
97-
logger.info(
98-
`[${requestId}] Successfully refreshed MCP server: ${serverId} (${toolCount} tools)`
99-
)
10087
await mcpService.clearCache(workspaceId)
101-
} else {
102-
logger.warn(
103-
`[${requestId}] Refresh completed for MCP server ${serverId} but connection failed: ${lastError}`
104-
)
10588
}
10689

10790
return createMcpSuccessResponse({

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

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,18 @@ const logger = createLogger('McpToolDiscoveryAPI')
99

1010
export const dynamic = 'force-dynamic'
1111

12-
/**
13-
* GET - Discover all tools from user's MCP servers
14-
*/
1512
export const GET = withMcpAuth('read')(
1613
async (request: NextRequest, { userId, workspaceId, requestId }) => {
1714
try {
1815
const { searchParams } = new URL(request.url)
1916
const serverId = searchParams.get('serverId')
2017
const forceRefresh = searchParams.get('refresh') === 'true'
2118

22-
logger.info(`[${requestId}] Discovering MCP tools for user ${userId}`, {
23-
serverId,
24-
workspaceId,
25-
forceRefresh,
26-
})
19+
logger.info(`[${requestId}] Discovering MCP tools`, { serverId, workspaceId, forceRefresh })
2720

28-
let tools
29-
if (serverId) {
30-
tools = await mcpService.discoverServerTools(userId, serverId, workspaceId)
31-
} else {
32-
tools = await mcpService.discoverTools(userId, workspaceId, forceRefresh)
33-
}
21+
const tools = serverId
22+
? await mcpService.discoverServerTools(userId, serverId, workspaceId)
23+
: await mcpService.discoverTools(userId, workspaceId, forceRefresh)
3424

3525
const byServer: Record<string, number> = {}
3626
for (const tool of tools) {
@@ -55,9 +45,6 @@ export const GET = withMcpAuth('read')(
5545
}
5646
)
5747

58-
/**
59-
* POST - Refresh tool discovery for specific servers
60-
*/
6148
export const POST = withMcpAuth('read')(
6249
async (request: NextRequest, { userId, workspaceId, requestId }) => {
6350
try {
@@ -72,10 +59,7 @@ export const POST = withMcpAuth('read')(
7259
)
7360
}
7461

75-
logger.info(
76-
`[${requestId}] Refreshing tool discovery for user ${userId}, servers:`,
77-
serverIds
78-
)
62+
logger.info(`[${requestId}] Refreshing tools for ${serverIds.length} servers`)
7963

8064
const results = await Promise.allSettled(
8165
serverIds.map(async (serverId: string) => {
@@ -99,20 +83,16 @@ export const POST = withMcpAuth('read')(
9983
}
10084
})
10185

102-
const responseData = {
86+
logger.info(`[${requestId}] Refresh completed: ${successes.length}/${serverIds.length}`)
87+
return createMcpSuccessResponse({
10388
refreshed: successes,
10489
failed: failures,
10590
summary: {
10691
total: serverIds.length,
10792
successful: successes.length,
10893
failed: failures.length,
10994
},
110-
}
111-
112-
logger.info(
113-
`[${requestId}] Tool discovery refresh completed: ${successes.length}/${serverIds.length} successful`
114-
)
115-
return createMcpSuccessResponse(responseData)
95+
})
11696
} catch (error) {
11797
logger.error(`[${requestId}] Error refreshing tool discovery:`, error)
11898
const { message, status } = categorizeError(error)

apps/sim/app/api/mcp/tools/stored/route.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,13 @@ interface StoredMcpTool {
1919
schema?: Record<string, unknown>
2020
}
2121

22-
/**
23-
* GET - Get all stored MCP tools from workflows in the workspace
24-
*
25-
* Scans all workflows in the workspace and extracts MCP tools that have been
26-
* added to agent blocks. Returns the stored state of each tool for comparison
27-
* against current server state.
28-
*/
2922
export const GET = withMcpAuth('read')(
3023
async (request: NextRequest, { userId, workspaceId, requestId }) => {
3124
try {
3225
logger.info(`[${requestId}] Fetching stored MCP tools for workspace ${workspaceId}`)
3326

34-
// Get all workflows in workspace
3527
const workflows = await db
36-
.select({
37-
id: workflow.id,
38-
name: workflow.name,
39-
})
28+
.select({ id: workflow.id, name: workflow.name })
4029
.from(workflow)
4130
.where(eq(workflow.workspaceId, workspaceId))
4231

@@ -47,12 +36,8 @@ export const GET = withMcpAuth('read')(
4736
return createMcpSuccessResponse({ tools: [] })
4837
}
4938

50-
// Get all agent blocks from these workflows
5139
const agentBlocks = await db
52-
.select({
53-
workflowId: workflowBlocks.workflowId,
54-
subBlocks: workflowBlocks.subBlocks,
55-
})
40+
.select({ workflowId: workflowBlocks.workflowId, subBlocks: workflowBlocks.subBlocks })
5641
.from(workflowBlocks)
5742
.where(eq(workflowBlocks.type, 'agent'))
5843

0 commit comments

Comments
 (0)