MCPcopy Create free account
hub / github.com/Noumena-Network/code / validateInput

Function validateInput

src/tools/GrepTool/GrepTool.ts:222–264  ·  view source on GitHub ↗
({ path, pattern, output_mode })

Source from the content-addressed store, hash-verified

220 return rulePattern => matchWildcardPattern(rulePattern, pattern)
221 },
222 async validateInput({ path, pattern, output_mode }): Promise<ValidationResult> {
223 if (
224 (output_mode ?? 'files_with_matches') !== 'content' &&
225 looksLikeFilenameDiscoveryPattern(pattern)
226 ) {
227 return {
228 result: false,
229 message: GREP_FILENAME_DISCOVERY_ERROR,
230 errorCode: 2,
231 }
232 }
233
234 // If path is provided, validate that it exists
235 if (path) {
236 const fs = getFsImplementation()
237 const absolutePath = expandPath(path)
238
239 // SECURITY: Skip filesystem operations for UNC paths to prevent NTLM credential leaks.
240 if (absolutePath.startsWith('\\\\') || absolutePath.startsWith('//')) {
241 return { result: true }
242 }
243
244 try {
245 await fs.stat(absolutePath)
246 } catch (e: unknown) {
247 if (isENOENT(e)) {
248 const cwdSuggestion = await suggestPathUnderCwd(absolutePath)
249 let message = `Path does not exist: ${path}. ${FILE_NOT_FOUND_CWD_NOTE} ${getCwd()}.`
250 if (cwdSuggestion) {
251 message += ` Did you mean ${cwdSuggestion}?`
252 }
253 return {
254 result: false,
255 message,
256 errorCode: 1,
257 }
258 }
259 throw e
260 }
261 }
262
263 return { result: true }
264 },
265 async checkPermissions(input, context): Promise<PermissionDecision> {
266 const appState = context.getAppState()
267 return checkReadPermissionForTool(

Callers

nothing calls this directly

Calls 6

getFsImplementationFunction · 0.85
expandPathFunction · 0.85
isENOENTFunction · 0.85
suggestPathUnderCwdFunction · 0.85
getCwdFunction · 0.85

Tested by

no test coverage detected