|
1 | 1 | import axios from "axios"; |
2 | 2 | import { StdioServerParameters } from "@modelcontextprotocol/sdk/client/stdio.js"; |
| 3 | +import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js'; |
3 | 4 | import { |
4 | 5 | getDefaultEnvironment, |
5 | 6 | getMetaMcpApiBaseUrl, |
6 | 7 | getMetaMcpApiKey, |
7 | 8 | } from "./utils.js"; |
8 | 9 |
|
9 | | -let _mcpServersCache: Record<string, StdioServerParameters> | null = null; |
| 10 | +// Define a new interface for server parameters that can be either STDIO or SSE |
| 11 | +export interface ServerParameters { |
| 12 | + uuid: string; |
| 13 | + name: string; |
| 14 | + description: string; |
| 15 | + type: "STDIO" | "SSE"; |
| 16 | + command?: string | null; |
| 17 | + args?: string[] | null; |
| 18 | + env?: Record<string, string> | null; |
| 19 | + url?: string | null; |
| 20 | + created_at: string; |
| 21 | + profile_uuid: string; |
| 22 | + status: string; |
| 23 | +} |
| 24 | + |
| 25 | +let _mcpServersCache: Record<string, ServerParameters> | null = null; |
10 | 26 | let _mcpServersCacheTimestamp: number = 0; |
11 | 27 | const CACHE_TTL_MS = 1000; // 1 second cache TTL |
12 | 28 |
|
13 | 29 | export async function getMcpServers( |
14 | 30 | forceRefresh: boolean = false |
15 | | -): Promise<Record<string, StdioServerParameters>> { |
| 31 | +): Promise<Record<string, ServerParameters>> { |
16 | 32 | const currentTime = Date.now(); |
17 | 33 | const cacheAge = currentTime - _mcpServersCacheTimestamp; |
18 | 34 |
|
@@ -40,27 +56,29 @@ export async function getMcpServers( |
40 | 56 | }); |
41 | 57 | const data = response.data; |
42 | 58 |
|
43 | | - const serverDict: Record<string, StdioServerParameters> = {}; |
| 59 | + const serverDict: Record<string, ServerParameters> = {}; |
44 | 60 | for (const params of data) { |
45 | | - if ("args" in params && !params.args) { |
46 | | - params.args = undefined; |
47 | | - } |
| 61 | + // Process based on server type |
| 62 | + if (params.type === "STDIO") { |
| 63 | + if ("args" in params && !params.args) { |
| 64 | + params.args = undefined; |
| 65 | + } |
48 | 66 |
|
49 | | - params.env = { |
50 | | - ...getDefaultEnvironment(), |
51 | | - ...(params.env || {}), |
52 | | - }; |
53 | | - |
54 | | - const serverParams: StdioServerParameters = { |
55 | | - ...params, |
56 | | - env: { |
| 67 | + params.env = { |
57 | 68 | ...getDefaultEnvironment(), |
58 | 69 | ...(params.env || {}), |
59 | | - }, |
60 | | - }; |
| 70 | + }; |
| 71 | + } else if (params.type === "SSE") { |
| 72 | + // For SSE servers, ensure url is present |
| 73 | + if (!params.url) { |
| 74 | + console.warn(`SSE server ${params.uuid} is missing url field, skipping`); |
| 75 | + continue; |
| 76 | + } |
| 77 | + } |
| 78 | + |
61 | 79 | const uuid = params.uuid; |
62 | 80 | if (uuid) { |
63 | | - serverDict[uuid] = serverParams; |
| 81 | + serverDict[uuid] = params; |
64 | 82 | } |
65 | 83 | } |
66 | 84 |
|
|
0 commit comments