MCPcopy
hub / github.com/promptfoo/promptfoo / checkServerFeatureSupport

Function checkServerFeatureSupport

src/util/server.ts:46–100  ·  view source on GitHub ↗
(
  featureName: string,
  requiredBuildDate: string,
)

Source from the content-addressed store, hash-verified

44 * @returns Promise<boolean> - true if server supports the feature
45 */
46export async function checkServerFeatureSupport(
47 featureName: string,
48 requiredBuildDate: string,
49): Promise<boolean> {
50 const cacheKey = `${featureName}`;
51
52 // Return cached result if available
53 if (featureCache.has(cacheKey)) {
54 return featureCache.get(cacheKey)!;
55 }
56
57 let supported = false;
58
59 try {
60 logger.debug(`[Feature Detection] Checking server support for feature: ${featureName}`);
61
62 const versionUrl = getRemoteVersionUrl();
63
64 if (versionUrl) {
65 const response = await fetchWithProxy(versionUrl, {
66 method: 'GET',
67 headers: { 'Content-Type': 'application/json' },
68 });
69
70 const data = await response.json();
71
72 if (data.buildDate) {
73 // Parse build date and check if it's after the required date
74 const buildDate = new Date(data.buildDate);
75 const featureDate = new Date(requiredBuildDate);
76 supported = buildDate >= featureDate;
77 logger.debug(
78 `[Feature Detection] ${featureName}: buildDate=${data.buildDate}, required=${requiredBuildDate}, supported=${supported}`,
79 );
80 } else {
81 logger.debug(`[Feature Detection] ${featureName}: no version info, assuming not supported`);
82 supported = false;
83 }
84 } else {
85 logger.debug(
86 `[Feature Detection] No remote URL available for ${featureName}, assuming local server supports it`,
87 );
88 supported = true;
89 }
90 } catch (error) {
91 logger.debug(
92 `[Feature Detection] Version check failed for ${featureName}, assuming not supported: ${error}`,
93 );
94 supported = false;
95 }
96
97 // Cache the result
98 featureCache.set(cacheKey, supported);
99 return supported;
100}
101
102export async function checkServerRunning(port = getDefaultPort()): Promise<boolean> {
103 logger.debug(`Checking for existing server on port ${port}...`);

Callers 3

server.test.tsFile · 0.90
checkCloudPermissionsFunction · 0.90
tryUnblockingFunction · 0.85

Calls 5

getRemoteVersionUrlFunction · 0.90
fetchWithProxyFunction · 0.90
hasMethod · 0.45
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…