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
26 changes: 26 additions & 0 deletions apps/sim/executor/handlers/agent/agent-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3779,6 +3779,32 @@ describe('AgentBlockHandler', () => {
])
})

it('does not create tools for a blank advanced MCP server binding', async () => {
await handler.execute(
{
...mockContext,
workspaceId: 'test-workspace-123',
workflowId: 'test-workflow-456',
},
mockBlock,
{
model: 'gpt-4o',
userPrompt: 'Continue without MCP tools',
apiKey: 'test-api-key',
tools: [
{
type: 'mcp-server-advanced',
params: { serverId: '' },
usageControl: 'auto' as const,
},
],
}
)

expect(mockDiscoverMcpServerToolsAsExecutor).not.toHaveBeenCalled()
expect(mockExecuteProviderRequest.mock.calls[0][1].tools).toEqual([])
})

describe('customToolId resolution - DB as source of truth', () => {
const staleInlineSchema = {
function: {
Expand Down
2 changes: 2 additions & 0 deletions apps/sim/executor/handlers/agent/agent-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,8 @@ export class AgentBlockHandler implements BlockHandler {
if (entry.tool.type === 'mcp') {
mcpTools.push(entry)
} else if (entry.tool.type === MCP_SERVER_ADVANCED_TOOL_TYPE) {
const serverId = entry.tool.params?.serverId
if (typeof serverId === 'string' && !serverId.trim()) continue
advancedMcpServers.push(entry)
} else {
otherTools.push(entry)
Expand Down
19 changes: 19 additions & 0 deletions apps/sim/executor/handlers/mothership/mothership-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,25 @@ describe('MothershipBlockHandler', () => {
])
})

it('does not forward tools for a blank advanced MCP server binding', async () => {
fetchMock.mockResolvedValue(createJsonResponse({ content: 'done', toolCalls: [] }))

await handler.execute(context, block, {
prompt: 'Continue without MCP tools',
tools: [
{
type: 'mcp-server-advanced',
params: { serverId: '' },
usageControl: 'auto',
},
],
})

expect(mockDiscoverMcpServerToolsAsExecutor).not.toHaveBeenCalled()
const [, options] = fetchMock.mock.calls[0] as [string, RequestInit]
expect(JSON.parse(String(options.body))).not.toHaveProperty('mcpTools')
})

it('does not scan arbitrary Mothership metadata, attachment names, or payloads', async () => {
const secret = 'boundary-secret'
const registry = new ResolvedSecretTraceRegistry([
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/executor/handlers/mothership/mothership-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,10 @@ async function expandMothershipMcpTools(
throw new Error('MCP Server (Advanced) requires params.serverId')
}
const serverId = candidate.params.serverId
if (typeof serverId !== 'string' || !serverId.trim()) {
if (typeof serverId !== 'string') {
throw new Error('MCP Server (Advanced) requires params.serverId')
}
if (!serverId.trim()) return []
const usageControl: 'auto' | 'force' = candidate.usageControl === 'force' ? 'force' : 'auto'
return [{ serverId, usageControl }]
}
Expand Down
11 changes: 10 additions & 1 deletion apps/sim/lib/mcp/shared.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,18 @@ describe('assertValidMcpServerToolBindings', () => {
).not.toThrow()
})

it('ignores server-wide bindings with blank server IDs', () => {
expect(() =>
assertValidMcpServerToolBindings([
{ type: 'mcp-server-advanced', params: { serverId: '' } },
{ type: 'mcp-server-advanced', params: { serverId: ' ' } },
])
).not.toThrow()
})

it('fails fast on a malformed active server-wide binding', () => {
expect(() =>
assertValidMcpServerToolBindings([{ type: 'mcp-server-advanced', params: { serverId: '' } }])
assertValidMcpServerToolBindings([{ type: 'mcp-server-advanced', params: {} }])
).toThrow('requires params.serverId')
})
})
3 changes: 2 additions & 1 deletion apps/sim/lib/mcp/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ export function assertValidMcpServerToolBindings(value: unknown): void {
}
if (tool.type !== MCP_SERVER_ADVANCED_TOOL_TYPE) continue
const serverId = tool.params?.serverId
if (typeof serverId !== 'string' || !serverId.trim()) {
if (typeof serverId !== 'string') {
throw new Error('MCP Server (Advanced) requires params.serverId')
}
if (!serverId.trim()) continue

@cubic-dev-ai cubic-dev-ai Bot Sep 2, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: When MCP tools are disabled for a workspace, a blank advanced binding now blocks the agent run even though it is intended to be inactive: validateToolPermissions sees the advanced entry before formatTools ignores it. Filter blank advanced bindings before the permission check, or make the permission check consider only active MCP bindings.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/sim/lib/mcp/shared.ts, line 55:

<comment>When MCP tools are disabled for a workspace, a blank advanced binding now blocks the agent run even though it is intended to be inactive: `validateToolPermissions` sees the advanced entry before `formatTools` ignores it. Filter blank advanced bindings before the permission check, or make the permission check consider only active MCP bindings.</comment>

<file context>
@@ -49,9 +49,10 @@ export function assertValidMcpServerToolBindings(value: unknown): void {
+    if (typeof serverId !== 'string') {
       throw new Error('MCP Server (Advanced) requires params.serverId')
     }
+    if (!serverId.trim()) continue
     if (advancedServerIds.has(serverId)) {
       throw new Error(`Duplicate MCP Server (Advanced) binding for ${serverId}`)
</file context>
Fix with cubic

if (advancedServerIds.has(serverId)) {
throw new Error(`Duplicate MCP Server (Advanced) binding for ${serverId}`)
}
Expand Down
Loading