@evantahler/mcpcli 0.1.1
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/LICENSE +21 -0
- package/README.md +432 -0
- package/package.json +56 -0
- package/skills/mcpcli.md +85 -0
- package/src/cli.ts +34 -0
- package/src/client/http.ts +99 -0
- package/src/client/manager.ts +204 -0
- package/src/client/oauth.ts +263 -0
- package/src/client/stdio.ts +12 -0
- package/src/commands/auth.ts +106 -0
- package/src/commands/call.ts +104 -0
- package/src/commands/index.ts +53 -0
- package/src/commands/info.ts +42 -0
- package/src/commands/list.ts +30 -0
- package/src/commands/search.ts +37 -0
- package/src/config/env.ts +41 -0
- package/src/config/loader.ts +118 -0
- package/src/config/schemas.ts +137 -0
- package/src/context.ts +41 -0
- package/src/output/formatter.ts +316 -0
- package/src/output/spinner.ts +39 -0
- package/src/search/index.ts +69 -0
- package/src/search/indexer.ts +91 -0
- package/src/search/keyword.ts +86 -0
- package/src/search/semantic.ts +75 -0
- package/src/validation/schema.ts +77 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import Ajv, { type ErrorObject } from "ajv";
|
|
2
|
+
import type { Tool } from "../config/schemas.ts";
|
|
3
|
+
|
|
4
|
+
const ajv = new Ajv({ allErrors: true, strict: false });
|
|
5
|
+
|
|
6
|
+
// Cache compiled validators by a key of "server/tool"
|
|
7
|
+
const validatorCache = new Map<string, ReturnType<typeof ajv.compile>>();
|
|
8
|
+
|
|
9
|
+
export interface ValidationError {
|
|
10
|
+
path: string;
|
|
11
|
+
message: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface ValidationResult {
|
|
15
|
+
valid: boolean;
|
|
16
|
+
errors: ValidationError[];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Validate tool arguments against the tool's inputSchema */
|
|
20
|
+
export function validateToolInput(
|
|
21
|
+
serverName: string,
|
|
22
|
+
tool: Tool,
|
|
23
|
+
input: Record<string, unknown>,
|
|
24
|
+
): ValidationResult {
|
|
25
|
+
const schema = tool.inputSchema;
|
|
26
|
+
if (!schema || Object.keys(schema).length === 0) {
|
|
27
|
+
return { valid: true, errors: [] };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const cacheKey = `${serverName}/${tool.name}`;
|
|
31
|
+
let validate = validatorCache.get(cacheKey);
|
|
32
|
+
|
|
33
|
+
if (!validate) {
|
|
34
|
+
try {
|
|
35
|
+
validate = ajv.compile(schema);
|
|
36
|
+
validatorCache.set(cacheKey, validate);
|
|
37
|
+
} catch {
|
|
38
|
+
// If schema can't be compiled, skip validation
|
|
39
|
+
return { valid: true, errors: [] };
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const valid = validate(input);
|
|
44
|
+
if (valid) {
|
|
45
|
+
return { valid: true, errors: [] };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const errors = (validate.errors ?? []).map(formatAjvError);
|
|
49
|
+
return { valid: false, errors };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function formatAjvError(err: ErrorObject): ValidationError {
|
|
53
|
+
const path = err.instancePath
|
|
54
|
+
? err.instancePath.replace(/^\//, "").replace(/\//g, ".")
|
|
55
|
+
: "(root)";
|
|
56
|
+
|
|
57
|
+
switch (err.keyword) {
|
|
58
|
+
case "required": {
|
|
59
|
+
const field = (err.params as { missingProperty: string }).missingProperty;
|
|
60
|
+
return { path: field, message: `missing required field "${field}"` };
|
|
61
|
+
}
|
|
62
|
+
case "type": {
|
|
63
|
+
const expected = (err.params as { type: string }).type;
|
|
64
|
+
return { path, message: `must be ${expected}` };
|
|
65
|
+
}
|
|
66
|
+
case "enum": {
|
|
67
|
+
const allowed = (err.params as { allowedValues: unknown[] }).allowedValues;
|
|
68
|
+
return { path, message: `must be one of: ${allowed.join(", ")}` };
|
|
69
|
+
}
|
|
70
|
+
case "additionalProperties": {
|
|
71
|
+
const extra = (err.params as { additionalProperty: string }).additionalProperty;
|
|
72
|
+
return { path: extra, message: `unknown property "${extra}"` };
|
|
73
|
+
}
|
|
74
|
+
default:
|
|
75
|
+
return { path, message: err.message ?? "validation failed" };
|
|
76
|
+
}
|
|
77
|
+
}
|