@bryan-thompson/inspector-assessment 1.36.5 → 1.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/build/lib/assessment-runner/assessment-executor.js +40 -0
- package/cli/build/lib/assessment-runner/source-loader.js +11 -0
- package/cli/package.json +1 -1
- package/client/dist/assets/{OAuthCallback-DJ1av7om.js → OAuthCallback-AngeBaCl.js} +1 -1
- package/client/dist/assets/{OAuthDebugCallback-lRXgX7wV.js → OAuthDebugCallback--FE6_fPs.js} +1 -1
- package/client/dist/assets/{index-DEdS99fp.js → index-BQC95Boo.js} +4 -4
- package/client/dist/index.html +1 -1
- package/client/lib/lib/assessment/coreTypes.d.ts +37 -0
- package/client/lib/lib/assessment/coreTypes.d.ts.map +1 -1
- package/client/lib/lib/assessment/resultTypes.d.ts +30 -1
- package/client/lib/lib/assessment/resultTypes.d.ts.map +1 -1
- package/client/lib/lib/assessment/sharedSchemas.d.ts +10 -0
- package/client/lib/lib/assessment/sharedSchemas.d.ts.map +1 -1
- package/client/lib/lib/assessment/sharedSchemas.js +4 -0
- package/client/lib/lib/securityPatterns/advancedExploitPatterns.d.ts +13 -0
- package/client/lib/lib/securityPatterns/advancedExploitPatterns.d.ts.map +1 -0
- package/client/lib/lib/securityPatterns/advancedExploitPatterns.js +504 -0
- package/client/lib/lib/securityPatterns/authSessionPatterns.d.ts +12 -0
- package/client/lib/lib/securityPatterns/authSessionPatterns.d.ts.map +1 -0
- package/client/lib/lib/securityPatterns/authSessionPatterns.js +357 -0
- package/client/lib/lib/securityPatterns/index.d.ts +18 -0
- package/client/lib/lib/securityPatterns/index.d.ts.map +1 -0
- package/client/lib/lib/securityPatterns/index.js +18 -0
- package/client/lib/lib/securityPatterns/injectionPatterns.d.ts +13 -0
- package/client/lib/lib/securityPatterns/injectionPatterns.d.ts.map +1 -0
- package/client/lib/lib/securityPatterns/injectionPatterns.js +356 -0
- package/client/lib/lib/securityPatterns/resourceExhaustionPatterns.d.ts +12 -0
- package/client/lib/lib/securityPatterns/resourceExhaustionPatterns.d.ts.map +1 -0
- package/client/lib/lib/securityPatterns/resourceExhaustionPatterns.js +215 -0
- package/client/lib/lib/securityPatterns/toolSpecificPatterns.d.ts +13 -0
- package/client/lib/lib/securityPatterns/toolSpecificPatterns.d.ts.map +1 -0
- package/client/lib/lib/securityPatterns/toolSpecificPatterns.js +373 -0
- package/client/lib/lib/securityPatterns/types.d.ts +20 -0
- package/client/lib/lib/securityPatterns/types.d.ts.map +1 -0
- package/client/lib/lib/securityPatterns/types.js +6 -0
- package/client/lib/lib/securityPatterns/utils.d.ts +56 -0
- package/client/lib/lib/securityPatterns/utils.d.ts.map +1 -0
- package/client/lib/lib/securityPatterns/utils.js +96 -0
- package/client/lib/lib/securityPatterns/validationPatterns.d.ts +13 -0
- package/client/lib/lib/securityPatterns/validationPatterns.d.ts.map +1 -0
- package/client/lib/lib/securityPatterns/validationPatterns.js +110 -0
- package/client/lib/lib/securityPatterns.d.ts +18 -69
- package/client/lib/lib/securityPatterns.d.ts.map +1 -1
- package/client/lib/lib/securityPatterns.js +18 -1946
- package/client/lib/services/assessment/AssessmentOrchestrator.d.ts +6 -1
- package/client/lib/services/assessment/AssessmentOrchestrator.d.ts.map +1 -1
- package/client/lib/services/assessment/config/performanceConfig.d.ts +18 -0
- package/client/lib/services/assessment/config/performanceConfig.d.ts.map +1 -1
- package/client/lib/services/assessment/config/performanceConfig.js +6 -0
- package/client/lib/services/assessment/config/performanceConfigSchemas.d.ts +18 -0
- package/client/lib/services/assessment/config/performanceConfigSchemas.d.ts.map +1 -1
- package/client/lib/services/assessment/config/performanceConfigSchemas.js +20 -0
- package/client/lib/services/assessment/helpers/ExternalAPIDependencyDetector.d.ts +165 -0
- package/client/lib/services/assessment/helpers/ExternalAPIDependencyDetector.d.ts.map +1 -0
- package/client/lib/services/assessment/helpers/ExternalAPIDependencyDetector.js +317 -0
- package/client/lib/services/assessment/helpers/StdioTransportDetector.d.ts +137 -0
- package/client/lib/services/assessment/helpers/StdioTransportDetector.d.ts.map +1 -0
- package/client/lib/services/assessment/helpers/StdioTransportDetector.js +315 -0
- package/client/lib/services/assessment/helpers/ToolAnnotationExtractor.d.ts +34 -0
- package/client/lib/services/assessment/helpers/ToolAnnotationExtractor.d.ts.map +1 -0
- package/client/lib/services/assessment/helpers/ToolAnnotationExtractor.js +85 -0
- package/client/lib/services/assessment/modules/ErrorHandlingAssessor.d.ts +23 -0
- package/client/lib/services/assessment/modules/ErrorHandlingAssessor.d.ts.map +1 -1
- package/client/lib/services/assessment/modules/ErrorHandlingAssessor.js +255 -20
- package/client/lib/services/assessment/modules/FunctionalityAssessor.d.ts +10 -0
- package/client/lib/services/assessment/modules/FunctionalityAssessor.d.ts.map +1 -1
- package/client/lib/services/assessment/modules/FunctionalityAssessor.js +65 -3
- package/client/lib/services/assessment/modules/ProtocolComplianceAssessor.d.ts.map +1 -1
- package/client/lib/services/assessment/modules/ProtocolComplianceAssessor.js +30 -0
- package/client/lib/services/assessment/modules/SecurityAssessor.d.ts.map +1 -1
- package/client/lib/services/assessment/modules/SecurityAssessor.js +6 -0
- package/client/lib/services/assessment/modules/TemporalAssessor.d.ts.map +1 -1
- package/client/lib/services/assessment/modules/TemporalAssessor.js +16 -3
- package/client/lib/services/assessment/modules/annotations/AlignmentChecker.d.ts.map +1 -1
- package/client/lib/services/assessment/modules/annotations/AlignmentChecker.js +6 -2
- package/client/lib/services/assessment/modules/annotations/DescriptionPoisoningDetector.d.ts.map +1 -1
- package/client/lib/services/assessment/modules/annotations/DescriptionPoisoningDetector.js +16 -7
- package/client/lib/services/assessment/modules/securityTests/AnnotationAwareSeverity.d.ts +55 -0
- package/client/lib/services/assessment/modules/securityTests/AnnotationAwareSeverity.d.ts.map +1 -0
- package/client/lib/services/assessment/modules/securityTests/AnnotationAwareSeverity.js +135 -0
- package/client/lib/services/assessment/modules/securityTests/ErrorClassifier.d.ts +14 -0
- package/client/lib/services/assessment/modules/securityTests/ErrorClassifier.d.ts.map +1 -1
- package/client/lib/services/assessment/modules/securityTests/ErrorClassifier.js +24 -1
- package/client/lib/services/assessment/modules/securityTests/SafeResponseDetector.d.ts +6 -0
- package/client/lib/services/assessment/modules/securityTests/SafeResponseDetector.d.ts.map +1 -1
- package/client/lib/services/assessment/modules/securityTests/SafeResponseDetector.js +9 -1
- package/client/lib/services/assessment/modules/securityTests/SecurityPatternLibrary.d.ts +43 -1
- package/client/lib/services/assessment/modules/securityTests/SecurityPatternLibrary.d.ts.map +1 -1
- package/client/lib/services/assessment/modules/securityTests/SecurityPatternLibrary.js +87 -1
- package/client/lib/services/assessment/modules/securityTests/SecurityPayloadTester.d.ts +39 -1
- package/client/lib/services/assessment/modules/securityTests/SecurityPayloadTester.d.ts.map +1 -1
- package/client/lib/services/assessment/modules/securityTests/SecurityPayloadTester.js +93 -3
- package/client/lib/services/assessment/modules/securityTests/SecurityResponseAnalyzer.d.ts +1 -1
- package/client/lib/services/assessment/modules/securityTests/SecurityResponseAnalyzer.d.ts.map +1 -1
- package/client/lib/services/assessment/modules/securityTests/SecurityResponseAnalyzer.js +10 -1
- package/client/lib/services/assessment/modules/securityTests/index.d.ts +1 -0
- package/client/lib/services/assessment/modules/securityTests/index.d.ts.map +1 -1
- package/client/lib/services/assessment/modules/securityTests/index.js +1 -0
- package/client/lib/services/assessment/modules/temporal/VarianceClassifier.d.ts +16 -1
- package/client/lib/services/assessment/modules/temporal/VarianceClassifier.d.ts.map +1 -1
- package/client/lib/services/assessment/modules/temporal/VarianceClassifier.js +43 -1
- package/client/package.json +1 -1
- package/package.json +1 -1
- package/server/package.json +1 -1
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External API Dependency Detector
|
|
3
|
+
*
|
|
4
|
+
* Identifies tools that depend on external APIs based on:
|
|
5
|
+
* 1. Tool name and description patterns (fast, always available)
|
|
6
|
+
* 2. Source code scanning for API calls (more accurate, when source available)
|
|
7
|
+
*
|
|
8
|
+
* This information enables downstream assessors to adjust their behavior:
|
|
9
|
+
* - TemporalAssessor: Relaxed variance thresholds for external API tools
|
|
10
|
+
* - FunctionalityAssessor: Accept API errors as valid responses
|
|
11
|
+
* - ErrorHandlingAssessor: Account for external service failures
|
|
12
|
+
*
|
|
13
|
+
* Issue #168: Enhanced with source code scanning support
|
|
14
|
+
*
|
|
15
|
+
* @module helpers/ExternalAPIDependencyDetector
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Detects external API dependencies in MCP tools based on name and description patterns.
|
|
19
|
+
* Designed to run during context preparation before assessors execute.
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export class ExternalAPIDependencyDetector {
|
|
24
|
+
/**
|
|
25
|
+
* Tool name patterns that suggest external API dependency.
|
|
26
|
+
* Uses word-boundary matching to prevent false positives.
|
|
27
|
+
*
|
|
28
|
+
* Extracted from VarianceClassifier (Issue #166) for reuse across modules.
|
|
29
|
+
*/
|
|
30
|
+
EXTERNAL_API_PATTERNS = [
|
|
31
|
+
// API-related prefixes
|
|
32
|
+
"api",
|
|
33
|
+
"external",
|
|
34
|
+
"remote",
|
|
35
|
+
"live",
|
|
36
|
+
// Data type patterns (typically from external sources)
|
|
37
|
+
"weather",
|
|
38
|
+
"stock",
|
|
39
|
+
"price",
|
|
40
|
+
"market",
|
|
41
|
+
"currency",
|
|
42
|
+
"exchange",
|
|
43
|
+
"rate",
|
|
44
|
+
"forex",
|
|
45
|
+
// Service-specific prefixes
|
|
46
|
+
"wb", // World Bank
|
|
47
|
+
"worldbank",
|
|
48
|
+
// Action patterns suggesting external fetch
|
|
49
|
+
"fetch_from",
|
|
50
|
+
"poll",
|
|
51
|
+
"realtime",
|
|
52
|
+
"current",
|
|
53
|
+
];
|
|
54
|
+
/**
|
|
55
|
+
* Description patterns that suggest external API dependency.
|
|
56
|
+
* Regex patterns for more flexible matching.
|
|
57
|
+
*/
|
|
58
|
+
EXTERNAL_API_DESCRIPTION_PATTERNS = [
|
|
59
|
+
/external\s*(api|service)/i,
|
|
60
|
+
/fetche?s?\s*(from|data\s+from)/i,
|
|
61
|
+
/calls?\s*(external|remote)/i,
|
|
62
|
+
/live\s*(data|feed|stream)/i,
|
|
63
|
+
/real[- ]?time/i,
|
|
64
|
+
/world\s*bank/i,
|
|
65
|
+
/third[- ]?party\s*(api|service)/i,
|
|
66
|
+
];
|
|
67
|
+
/**
|
|
68
|
+
* Source code patterns that indicate external API calls.
|
|
69
|
+
* Each pattern captures the URL in group 1.
|
|
70
|
+
*
|
|
71
|
+
* Issue #168: Patterns from proposal for source code scanning
|
|
72
|
+
*/
|
|
73
|
+
SOURCE_CODE_API_PATTERNS = [
|
|
74
|
+
// fetch() calls - JavaScript/TypeScript
|
|
75
|
+
/fetch\s*\(\s*['"`](https?:\/\/[^'"`\s]+)/gi,
|
|
76
|
+
// axios HTTP client calls
|
|
77
|
+
/axios\s*\.\s*(?:get|post|put|patch|delete|request)\s*\(\s*['"`](https?:\/\/[^'"`\s]+)/gi,
|
|
78
|
+
// URL construction
|
|
79
|
+
/new\s+URL\s*\(\s*['"`](https?:\/\/[^'"`\s]+)/gi,
|
|
80
|
+
// Common API base URL constants
|
|
81
|
+
/(?:API_BASE_URL|BASE_URL|API_URL|ENDPOINT)\s*=\s*['"`](https?:\/\/[^'"`\s]+)/gi,
|
|
82
|
+
// Generic HTTP client .get/.post calls
|
|
83
|
+
/\.\s*(?:get|post)\s*\(\s*['"`](https?:\/\/[^'"`\s]+)/gi,
|
|
84
|
+
// Python requests library
|
|
85
|
+
/requests\s*\.\s*(?:get|post|put|patch|delete)\s*\(\s*['"`](https?:\/\/[^'"`\s]+)/gi,
|
|
86
|
+
// Python httpx library
|
|
87
|
+
/httpx\s*\.\s*(?:get|post|put|patch|delete)\s*\(\s*['"`](https?:\/\/[^'"`\s]+)/gi,
|
|
88
|
+
];
|
|
89
|
+
/**
|
|
90
|
+
* URL patterns to skip (localhost, local networks, documentation)
|
|
91
|
+
*/
|
|
92
|
+
LOCALHOST_PATTERNS = [
|
|
93
|
+
/localhost/i,
|
|
94
|
+
/127\.0\.0\.1/,
|
|
95
|
+
/0\.0\.0\.0/,
|
|
96
|
+
/192\.168\./,
|
|
97
|
+
/10\.\d+\./,
|
|
98
|
+
/172\.(?:1[6-9]|2[0-9]|3[01])\./,
|
|
99
|
+
/\.local\b/i,
|
|
100
|
+
/example\.com/i,
|
|
101
|
+
/test\.com/i,
|
|
102
|
+
];
|
|
103
|
+
/**
|
|
104
|
+
* File patterns to skip during source code scanning
|
|
105
|
+
*/
|
|
106
|
+
SKIP_FILE_PATTERNS = [
|
|
107
|
+
/node_modules/i,
|
|
108
|
+
/\.test\.(ts|js|tsx|jsx)$/i,
|
|
109
|
+
/\.spec\.(ts|js|tsx|jsx)$/i,
|
|
110
|
+
/\.d\.ts$/i,
|
|
111
|
+
/package-lock\.json$/i,
|
|
112
|
+
/yarn\.lock$/i,
|
|
113
|
+
/\.map$/i,
|
|
114
|
+
/\.git\//i,
|
|
115
|
+
/dist\//i,
|
|
116
|
+
/build\//i,
|
|
117
|
+
/__tests__\//i,
|
|
118
|
+
/__mocks__\//i,
|
|
119
|
+
];
|
|
120
|
+
/**
|
|
121
|
+
* Detect external API dependencies from tools and optionally source code.
|
|
122
|
+
*
|
|
123
|
+
* Detection strategy:
|
|
124
|
+
* 1. Always analyze tool names and descriptions (fast, no source needed)
|
|
125
|
+
* 2. If sourceCodeFiles provided, scan for actual API calls (more accurate)
|
|
126
|
+
* 3. Combine results and compute confidence
|
|
127
|
+
*
|
|
128
|
+
* @param tools - List of MCP tools to analyze
|
|
129
|
+
* @param sourceCodeFiles - Optional map of file paths to content for source scanning
|
|
130
|
+
* @returns Detection results with tool names, domains, and implications
|
|
131
|
+
*/
|
|
132
|
+
detect(tools, sourceCodeFiles) {
|
|
133
|
+
// Phase 1: Name/description pattern matching (always runs)
|
|
134
|
+
const toolsWithExternalAPI = new Set();
|
|
135
|
+
for (const tool of tools) {
|
|
136
|
+
if (this.isExternalAPITool(tool)) {
|
|
137
|
+
toolsWithExternalAPI.add(tool.name);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const detectedCount = toolsWithExternalAPI.size;
|
|
141
|
+
// Phase 2: Source code scanning (when available)
|
|
142
|
+
let domains;
|
|
143
|
+
let sourceCodeScanned = false;
|
|
144
|
+
if (sourceCodeFiles && sourceCodeFiles.size > 0) {
|
|
145
|
+
sourceCodeScanned = true;
|
|
146
|
+
domains = this.scanSourceCode(sourceCodeFiles);
|
|
147
|
+
}
|
|
148
|
+
// Compute confidence based on both detection methods
|
|
149
|
+
const confidence = this.computeConfidence(detectedCount, domains);
|
|
150
|
+
// Generate implications if any external APIs were detected
|
|
151
|
+
const hasExternalDependencies = detectedCount > 0 || (domains && domains.length > 0);
|
|
152
|
+
const implications = hasExternalDependencies
|
|
153
|
+
? this.generateImplications(domains)
|
|
154
|
+
: undefined;
|
|
155
|
+
return {
|
|
156
|
+
toolsWithExternalAPIDependency: toolsWithExternalAPI,
|
|
157
|
+
detectedCount,
|
|
158
|
+
confidence,
|
|
159
|
+
detectedTools: Array.from(toolsWithExternalAPI),
|
|
160
|
+
domains,
|
|
161
|
+
sourceCodeScanned,
|
|
162
|
+
implications,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/** Maximum content length per file (500KB) - prevents ReDoS attacks */
|
|
166
|
+
MAX_CONTENT_LENGTH = 500_000;
|
|
167
|
+
/** Maximum matches per file - prevents runaway matching */
|
|
168
|
+
MAX_MATCHES_PER_FILE = 100;
|
|
169
|
+
/**
|
|
170
|
+
* Scan source code files for external API URLs.
|
|
171
|
+
* Returns unique external domains found in the code.
|
|
172
|
+
*
|
|
173
|
+
* @param sourceCodeFiles - Map of file paths to content
|
|
174
|
+
* @returns Array of unique external domain names
|
|
175
|
+
*/
|
|
176
|
+
scanSourceCode(sourceCodeFiles) {
|
|
177
|
+
const domains = new Set();
|
|
178
|
+
sourceCodeFiles.forEach((content, filePath) => {
|
|
179
|
+
// Skip test files, node_modules, etc.
|
|
180
|
+
if (this.shouldSkipFile(filePath))
|
|
181
|
+
return;
|
|
182
|
+
// Skip oversized files to prevent ReDoS
|
|
183
|
+
if (content.length > this.MAX_CONTENT_LENGTH)
|
|
184
|
+
return;
|
|
185
|
+
// Try each API call pattern using matchAll (thread-safe, no lastIndex issues)
|
|
186
|
+
for (const pattern of this.SOURCE_CODE_API_PATTERNS) {
|
|
187
|
+
// Use Array.from for compatibility with older TS targets
|
|
188
|
+
const matches = Array.from(content.matchAll(pattern));
|
|
189
|
+
let matchCount = 0;
|
|
190
|
+
for (const match of matches) {
|
|
191
|
+
if (matchCount >= this.MAX_MATCHES_PER_FILE)
|
|
192
|
+
break;
|
|
193
|
+
matchCount++;
|
|
194
|
+
const url = match[1];
|
|
195
|
+
// Skip localhost and local network URLs
|
|
196
|
+
if (this.isLocalhost(url))
|
|
197
|
+
continue;
|
|
198
|
+
// Extract domain from URL
|
|
199
|
+
const domain = this.extractDomain(url);
|
|
200
|
+
if (domain) {
|
|
201
|
+
domains.add(domain);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
return Array.from(domains);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Extract the hostname from a URL string.
|
|
210
|
+
*
|
|
211
|
+
* @param url - URL string (may be partial)
|
|
212
|
+
* @returns Hostname or null if extraction fails
|
|
213
|
+
*/
|
|
214
|
+
extractDomain(url) {
|
|
215
|
+
try {
|
|
216
|
+
// Handle URLs that may not have protocol
|
|
217
|
+
const fullUrl = url.startsWith("http") ? url : `https://${url}`;
|
|
218
|
+
return new URL(fullUrl).hostname;
|
|
219
|
+
}
|
|
220
|
+
catch {
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Check if a URL points to localhost or local network.
|
|
226
|
+
*
|
|
227
|
+
* @param url - URL string to check
|
|
228
|
+
* @returns true if URL is local
|
|
229
|
+
*/
|
|
230
|
+
isLocalhost(url) {
|
|
231
|
+
return this.LOCALHOST_PATTERNS.some((pattern) => pattern.test(url));
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Check if a file should be skipped during source scanning.
|
|
235
|
+
*
|
|
236
|
+
* @param filePath - Path to check
|
|
237
|
+
* @returns true if file should be skipped
|
|
238
|
+
*/
|
|
239
|
+
shouldSkipFile(filePath) {
|
|
240
|
+
return this.SKIP_FILE_PATTERNS.some((pattern) => pattern.test(filePath));
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Compute detection confidence based on both methods.
|
|
244
|
+
* Source code confirmation boosts confidence.
|
|
245
|
+
*
|
|
246
|
+
* @param toolCount - Number of tools detected via name/description
|
|
247
|
+
* @param domains - Domains found in source code
|
|
248
|
+
* @returns Confidence level
|
|
249
|
+
*/
|
|
250
|
+
computeConfidence(toolCount, domains) {
|
|
251
|
+
const domainCount = domains?.length ?? 0;
|
|
252
|
+
// Both methods agree = high confidence
|
|
253
|
+
if (toolCount > 0 && domainCount > 0) {
|
|
254
|
+
return "high";
|
|
255
|
+
}
|
|
256
|
+
// Either method found multiple = high confidence
|
|
257
|
+
if (toolCount >= 3 || domainCount >= 3) {
|
|
258
|
+
return "high";
|
|
259
|
+
}
|
|
260
|
+
// Either method found something = medium confidence
|
|
261
|
+
if (toolCount > 0 || domainCount > 0) {
|
|
262
|
+
return "medium";
|
|
263
|
+
}
|
|
264
|
+
// Nothing found = low confidence (no external APIs)
|
|
265
|
+
return "low";
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Generate implications for downstream assessors.
|
|
269
|
+
*
|
|
270
|
+
* @param domains - External domains found
|
|
271
|
+
* @returns Implications object
|
|
272
|
+
*/
|
|
273
|
+
generateImplications(domains) {
|
|
274
|
+
const domainList = domains && domains.length > 0 ? domains.join(", ") : "external services";
|
|
275
|
+
return {
|
|
276
|
+
temporalVariance: "Expected - external data changes between invocations",
|
|
277
|
+
availabilityDependency: `Server depends on ${domainList} uptime`,
|
|
278
|
+
rateLimitingRisk: domains && domains.length > 0
|
|
279
|
+
? `May encounter rate limits from ${domainList}`
|
|
280
|
+
: undefined,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Check if a single tool depends on external APIs.
|
|
285
|
+
* Uses BOTH name patterns AND description analysis for detection.
|
|
286
|
+
*
|
|
287
|
+
* @param tool - MCP tool to check
|
|
288
|
+
* @returns true if tool appears to depend on external APIs
|
|
289
|
+
*/
|
|
290
|
+
isExternalAPITool(tool) {
|
|
291
|
+
const toolName = tool.name.toLowerCase();
|
|
292
|
+
const description = (tool.description || "").toLowerCase();
|
|
293
|
+
// Check name patterns with word-boundary matching
|
|
294
|
+
// "weather_api" matches "api" but "capital_gains" doesn't match "api"
|
|
295
|
+
const nameMatch = this.EXTERNAL_API_PATTERNS.some((pattern) => {
|
|
296
|
+
const wordBoundaryRegex = new RegExp(`(^|_|-)${pattern}($|_|-|s)`);
|
|
297
|
+
return wordBoundaryRegex.test(toolName);
|
|
298
|
+
});
|
|
299
|
+
// Check description for external API indicators
|
|
300
|
+
const descriptionMatch = this.EXTERNAL_API_DESCRIPTION_PATTERNS.some((regex) => regex.test(description));
|
|
301
|
+
return nameMatch || descriptionMatch;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Get the list of name patterns used for detection.
|
|
305
|
+
* Useful for debugging and documentation.
|
|
306
|
+
*/
|
|
307
|
+
getNamePatterns() {
|
|
308
|
+
return this.EXTERNAL_API_PATTERNS;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Get the list of description patterns used for detection.
|
|
312
|
+
* Useful for debugging and documentation.
|
|
313
|
+
*/
|
|
314
|
+
getDescriptionPatterns() {
|
|
315
|
+
return this.EXTERNAL_API_DESCRIPTION_PATTERNS;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stdio Transport Detector
|
|
3
|
+
*
|
|
4
|
+
* Identifies stdio transport support from multiple sources:
|
|
5
|
+
* 1. server.json manifest (packages[0].transport.type)
|
|
6
|
+
* 2. package.json bin entries (indicates CLI/stdio)
|
|
7
|
+
* 3. Source code scanning for transport patterns
|
|
8
|
+
* 4. Runtime transport configuration
|
|
9
|
+
*
|
|
10
|
+
* This fixes Issue #172: C6/F6 incorrectly fails for valid stdio servers
|
|
11
|
+
* because transport detection previously relied solely on serverInfo metadata.
|
|
12
|
+
*
|
|
13
|
+
* @module helpers/StdioTransportDetector
|
|
14
|
+
*/
|
|
15
|
+
import type { TransportMode } from "../config/architecturePatterns.js";
|
|
16
|
+
/**
|
|
17
|
+
* Evidence source for transport detection
|
|
18
|
+
*/
|
|
19
|
+
export type TransportEvidenceSource = "server.json" | "package.json" | "source-code" | "runtime-config";
|
|
20
|
+
/**
|
|
21
|
+
* Individual piece of transport detection evidence
|
|
22
|
+
*/
|
|
23
|
+
export interface TransportEvidence {
|
|
24
|
+
/** Source of the evidence */
|
|
25
|
+
source: TransportEvidenceSource;
|
|
26
|
+
/** Transport type detected */
|
|
27
|
+
transport: TransportMode;
|
|
28
|
+
/** Confidence level for this evidence */
|
|
29
|
+
confidence: "high" | "medium" | "low";
|
|
30
|
+
/** Human-readable detail about the detection */
|
|
31
|
+
detail: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Transport detection results
|
|
35
|
+
*/
|
|
36
|
+
export interface TransportDetectionResult {
|
|
37
|
+
/** Set of detected transport modes */
|
|
38
|
+
detectedTransports: Set<TransportMode>;
|
|
39
|
+
/** Overall detection confidence */
|
|
40
|
+
confidence: "high" | "medium" | "low";
|
|
41
|
+
/** All evidence collected during detection */
|
|
42
|
+
evidence: TransportEvidence[];
|
|
43
|
+
/** Whether stdio transport is supported */
|
|
44
|
+
supportsStdio: boolean;
|
|
45
|
+
/** Whether HTTP transport is supported */
|
|
46
|
+
supportsHTTP: boolean;
|
|
47
|
+
/** Whether SSE transport is supported */
|
|
48
|
+
supportsSSE: boolean;
|
|
49
|
+
/** Whether source code was scanned */
|
|
50
|
+
sourceCodeScanned: boolean;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* server.json structure (partial - transport fields only)
|
|
54
|
+
*/
|
|
55
|
+
export interface ServerJsonTransport {
|
|
56
|
+
packages?: Array<{
|
|
57
|
+
transport?: {
|
|
58
|
+
type?: string;
|
|
59
|
+
};
|
|
60
|
+
}>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* package.json structure (partial - bin field only)
|
|
64
|
+
*/
|
|
65
|
+
export interface PackageJsonBin {
|
|
66
|
+
bin?: Record<string, string> | string;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Detects transport capabilities from multiple sources.
|
|
70
|
+
*
|
|
71
|
+
* Detection priority (highest confidence first):
|
|
72
|
+
* 1. Runtime transport configuration (actual runtime proof)
|
|
73
|
+
* 2. server.json transport declaration (explicit manifest)
|
|
74
|
+
* 3. package.json bin entries (strong CLI/stdio indicator)
|
|
75
|
+
* 4. Source code patterns (StdioServerTransport, mcp.run, etc.)
|
|
76
|
+
*
|
|
77
|
+
* @public
|
|
78
|
+
*/
|
|
79
|
+
export declare class StdioTransportDetector {
|
|
80
|
+
/**
|
|
81
|
+
* TypeScript/JavaScript patterns for stdio transport
|
|
82
|
+
*/
|
|
83
|
+
private readonly STDIO_CODE_PATTERNS;
|
|
84
|
+
/**
|
|
85
|
+
* Python/FastMCP patterns for stdio transport
|
|
86
|
+
*/
|
|
87
|
+
private readonly PYTHON_STDIO_PATTERNS;
|
|
88
|
+
/**
|
|
89
|
+
* HTTP/SSE transport patterns
|
|
90
|
+
*/
|
|
91
|
+
private readonly HTTP_CODE_PATTERNS;
|
|
92
|
+
/**
|
|
93
|
+
* File patterns to skip during source code scanning
|
|
94
|
+
*/
|
|
95
|
+
private readonly SKIP_FILE_PATTERNS;
|
|
96
|
+
/** Maximum file size for source scanning (500KB) */
|
|
97
|
+
private readonly MAX_FILE_SIZE;
|
|
98
|
+
/**
|
|
99
|
+
* Detect transport capabilities from all available sources.
|
|
100
|
+
*
|
|
101
|
+
* @param sourceCodeFiles - Map of file paths to content
|
|
102
|
+
* @param packageJson - Parsed package.json content
|
|
103
|
+
* @param serverJson - Parsed server.json content
|
|
104
|
+
* @param runtimeTransport - Transport type from runtime config
|
|
105
|
+
* @returns Transport detection results
|
|
106
|
+
*/
|
|
107
|
+
detect(sourceCodeFiles?: Map<string, string>, packageJson?: PackageJsonBin, serverJson?: ServerJsonTransport, runtimeTransport?: TransportMode): TransportDetectionResult;
|
|
108
|
+
/**
|
|
109
|
+
* Scan source code files for transport patterns.
|
|
110
|
+
*
|
|
111
|
+
* @param sourceCodeFiles - Map of file paths to content
|
|
112
|
+
* @returns Array of evidence from source code analysis
|
|
113
|
+
*/
|
|
114
|
+
private scanSourceCode;
|
|
115
|
+
/**
|
|
116
|
+
* Check if a transport type is valid.
|
|
117
|
+
*/
|
|
118
|
+
private isValidTransport;
|
|
119
|
+
/**
|
|
120
|
+
* Check if a file should be skipped during scanning.
|
|
121
|
+
*/
|
|
122
|
+
private shouldSkipFile;
|
|
123
|
+
/**
|
|
124
|
+
* Shorten file path for display.
|
|
125
|
+
*/
|
|
126
|
+
private shortenPath;
|
|
127
|
+
/**
|
|
128
|
+
* Compute overall confidence from collected evidence.
|
|
129
|
+
*
|
|
130
|
+
* Confidence rules:
|
|
131
|
+
* - High: Any high-confidence evidence present
|
|
132
|
+
* - Medium: Only medium-confidence evidence OR multiple sources agree
|
|
133
|
+
* - Low: No evidence or only weak patterns
|
|
134
|
+
*/
|
|
135
|
+
private computeConfidence;
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=StdioTransportDetector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StdioTransportDetector.d.ts","sourceRoot":"","sources":["../../../../src/services/assessment/helpers/StdioTransportDetector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAEvE;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAC/B,aAAa,GACb,cAAc,GACd,aAAa,GACb,gBAAgB,CAAC;AAErB;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,6BAA6B;IAC7B,MAAM,EAAE,uBAAuB,CAAC;IAChC,8BAA8B;IAC9B,SAAS,EAAE,aAAa,CAAC;IACzB,yCAAyC;IACzC,UAAU,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;IACtC,gDAAgD;IAChD,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,sCAAsC;IACtC,kBAAkB,EAAE,GAAG,CAAC,aAAa,CAAC,CAAC;IACvC,mCAAmC;IACnC,UAAU,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;IACtC,8CAA8C;IAC9C,QAAQ,EAAE,iBAAiB,EAAE,CAAC;IAC9B,2CAA2C;IAC3C,aAAa,EAAE,OAAO,CAAC;IACvB,0CAA0C;IAC1C,YAAY,EAAE,OAAO,CAAC;IACtB,yCAAyC;IACzC,WAAW,EAAE,OAAO,CAAC;IACrB,sCAAsC;IACtC,iBAAiB,EAAE,OAAO,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,EAAE,KAAK,CAAC;QACf,SAAS,CAAC,EAAE;YACV,IAAI,CAAC,EAAE,MAAM,CAAC;SACf,CAAC;KACH,CAAC,CAAC;CACJ;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC;CACvC;AAED;;;;;;;;;;GAUG;AACH,qBAAa,sBAAsB;IACjC;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAwBlC;IAEF;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAoBpC;IAEF;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAwCjC;IAEF;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAejC;IAEF,oDAAoD;IACpD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAW;IAEzC;;;;;;;;OAQG;IACH,MAAM,CACJ,eAAe,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EACrC,WAAW,CAAC,EAAE,cAAc,EAC5B,UAAU,CAAC,EAAE,mBAAmB,EAChC,gBAAgB,CAAC,EAAE,aAAa,GAC/B,wBAAwB;IAwE3B;;;;;OAKG;IACH,OAAO,CAAC,cAAc;IA4DtB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAIxB;;OAEG;IACH,OAAO,CAAC,cAAc;IAItB;;OAEG;IACH,OAAO,CAAC,WAAW;IAQnB;;;;;;;OAOG;IACH,OAAO,CAAC,iBAAiB;CA0B1B"}
|