@@ -11,33 +11,21 @@ const logger = createLogger('McpDiscoverAPI')
1111export const dynamic = 'force-dynamic'
1212
1313/**
14- * GET - Discover all published MCP servers available to the authenticated user
15- *
16- * This endpoint allows external MCP clients to discover available servers
17- * using just their API key, without needing to know workspace IDs.
18- *
19- * Authentication: API Key (X-API-Key header) or Session
20- *
21- * Returns all published MCP servers from workspaces the user has access to.
14+ * Discover all MCP servers available to the authenticated user.
2215 */
2316export async function GET ( request : NextRequest ) {
2417 try {
25- // Authenticate the request
2618 const auth = await checkHybridAuth ( request , { requireWorkflowId : false } )
2719
2820 if ( ! auth . success || ! auth . userId ) {
2921 return NextResponse . json (
30- {
31- success : false ,
32- error : 'Authentication required. Provide X-API-Key header with your Sim API key.' ,
33- } ,
22+ { success : false , error : 'Authentication required. Provide X-API-Key header.' } ,
3423 { status : 401 }
3524 )
3625 }
3726
3827 const userId = auth . userId
3928
40- // Get all workspaces the user has access to via permissions table
4129 const userWorkspacePermissions = await db
4230 . select ( { entityId : permissions . entityId } )
4331 . from ( permissions )
@@ -46,23 +34,17 @@ export async function GET(request: NextRequest) {
4634 const workspaceIds = userWorkspacePermissions . map ( ( w ) => w . entityId )
4735
4836 if ( workspaceIds . length === 0 ) {
49- return NextResponse . json ( {
50- success : true ,
51- servers : [ ] ,
52- message : 'No workspaces found for this user' ,
53- } )
37+ return NextResponse . json ( { success : true , servers : [ ] } )
5438 }
5539
56- // Get all published MCP servers from user's workspaces with tool count
5740 const servers = await db
5841 . select ( {
5942 id : workflowMcpServer . id ,
6043 name : workflowMcpServer . name ,
6144 description : workflowMcpServer . description ,
6245 workspaceId : workflowMcpServer . workspaceId ,
6346 workspaceName : workspace . name ,
64- isPublished : workflowMcpServer . isPublished ,
65- publishedAt : workflowMcpServer . publishedAt ,
47+ createdAt : workflowMcpServer . createdAt ,
6648 toolCount : sql < number > `(
6749 SELECT COUNT(*)::int
6850 FROM "workflow_mcp_tool"
@@ -71,31 +53,19 @@ export async function GET(request: NextRequest) {
7153 } )
7254 . from ( workflowMcpServer )
7355 . leftJoin ( workspace , eq ( workflowMcpServer . workspaceId , workspace . id ) )
74- . where (
75- and (
76- eq ( workflowMcpServer . isPublished , true ) ,
77- sql `${ workflowMcpServer . workspaceId } IN ${ workspaceIds } `
78- )
79- )
56+ . where ( sql `${ workflowMcpServer . workspaceId } IN ${ workspaceIds } ` )
8057 . orderBy ( workflowMcpServer . name )
8158
8259 const baseUrl = getBaseUrl ( )
8360
84- // Format response with connection URLs
8561 const formattedServers = servers . map ( ( server ) => ( {
8662 id : server . id ,
8763 name : server . name ,
8864 description : server . description ,
89- workspace : {
90- id : server . workspaceId ,
91- name : server . workspaceName ,
92- } ,
65+ workspace : { id : server . workspaceId , name : server . workspaceName } ,
9366 toolCount : server . toolCount || 0 ,
94- publishedAt : server . publishedAt ,
95- urls : {
96- http : `${ baseUrl } /api/mcp/serve/${ server . id } ` ,
97- sse : `${ baseUrl } /api/mcp/serve/${ server . id } /sse` ,
98- } ,
67+ createdAt : server . createdAt ,
68+ url : `${ baseUrl } /api/mcp/serve/${ server . id } ` ,
9969 } ) )
10070
10171 logger . info ( `User ${ userId } discovered ${ formattedServers . length } MCP servers` )
@@ -106,17 +76,6 @@ export async function GET(request: NextRequest) {
10676 authentication : {
10777 method : 'API Key' ,
10878 header : 'X-API-Key' ,
109- description : 'Include your Sim API key in the X-API-Key header for all MCP requests' ,
110- } ,
111- usage : {
112- listTools : {
113- method : 'POST' ,
114- body : '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' ,
115- } ,
116- callTool : {
117- method : 'POST' ,
118- body : '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"TOOL_NAME","arguments":{}}}' ,
119- } ,
12079 } ,
12180 } )
12281 } catch ( error ) {
0 commit comments