Skip to content

Commit 54b6a50

Browse files
committed
fix(mcp): guard undefined url in probe and use canonical McpAuthType
1 parent 27a0cfd commit 54b6a50

3 files changed

Lines changed: 20 additions & 12 deletions

File tree

apps/sim/app/api/mcp/servers/test-connection/route.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
import { getParsedBody, withMcpAuth } from '@/lib/mcp/middleware'
1515
import { detectMcpAuthType } from '@/lib/mcp/oauth'
1616
import { resolveMcpConfigEnvVars } from '@/lib/mcp/resolve-config'
17-
import type { McpTransport } from '@/lib/mcp/types'
17+
import type { McpAuthType, McpTransport } from '@/lib/mcp/types'
1818
import { createMcpErrorResponse, createMcpSuccessResponse } from '@/lib/mcp/utils'
1919

2020
const logger = createLogger('McpServerTestAPI')
@@ -33,7 +33,7 @@ interface TestConnectionResult {
3333
success: boolean
3434
error?: string
3535
authRequired?: boolean
36-
authType?: 'none' | 'headers' | 'oauth'
36+
authType?: McpAuthType
3737
serverInfo?: {
3838
name: string
3939
version: string
@@ -168,13 +168,15 @@ export const POST = withRouteHandler(
168168
const result: TestConnectionResult = { success: false }
169169

170170
// Skip unauth connect when the server returns an RFC 9728 OAuth challenge.
171-
const detectedAuthType = await detectMcpAuthType(testConfig.url)
172-
if (detectedAuthType === 'oauth') {
173-
result.authRequired = true
174-
result.authType = 'oauth'
175-
return createMcpSuccessResponse(result, 200)
171+
if (testConfig.url) {
172+
const detectedAuthType = await detectMcpAuthType(testConfig.url)
173+
if (detectedAuthType === 'oauth') {
174+
result.authRequired = true
175+
result.authType = 'oauth'
176+
return createMcpSuccessResponse(result, 200)
177+
}
178+
result.authType = detectedAuthType
176179
}
177-
result.authType = detectedAuthType
178180

179181
let client: McpClient | null = null
180182

apps/sim/app/workspace/[workspaceId]/settings/components/mcp/components/mcp-server-form-modal/mcp-server-form-modal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
Textarea,
1818
} from '@/components/emcn'
1919
import { cn } from '@/lib/core/utils/cn'
20-
import type { McpTransport } from '@/lib/mcp/types'
20+
import type { McpAuthType, McpTransport } from '@/lib/mcp/types'
2121
import {
2222
checkEnvVarTrigger,
2323
EnvVarDropdown,
@@ -52,7 +52,7 @@ export interface McpServerFormConfig {
5252
timeout: number
5353
oauthClientId?: string
5454
oauthClientSecret?: string
55-
authType?: 'none' | 'headers' | 'oauth'
55+
authType?: McpAuthType
5656
}
5757

5858
export interface McpServerFormModalProps {

apps/sim/hooks/queries/mcp.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ import {
2222
} from '@/lib/api/contracts/mcp'
2323
import { isLoopbackHostname } from '@/lib/core/utils/urls'
2424
import { sanitizeForHttp, sanitizeHeaders } from '@/lib/mcp/shared'
25-
import type { McpServerStatusConfig, McpTool, McpTransport, StoredMcpTool } from '@/lib/mcp/types'
25+
import type {
26+
McpAuthType,
27+
McpServerStatusConfig,
28+
McpTool,
29+
McpTransport,
30+
StoredMcpTool,
31+
} from '@/lib/mcp/types'
2632
import { workflowMcpServerKeys } from '@/hooks/queries/workflow-mcp-servers'
2733

2834
const logger = createLogger('McpQueries')
@@ -54,7 +60,7 @@ export interface McpServerInput {
5460
enabled: boolean
5561
oauthClientId?: string
5662
oauthClientSecret?: string
57-
authType?: 'none' | 'headers' | 'oauth'
63+
authType?: McpAuthType
5864
}
5965

6066
async function fetchMcpServers(workspaceId: string, signal?: AbortSignal): Promise<McpServer[]> {

0 commit comments

Comments
 (0)