scorecard-ai-mcp 2.4.1 → 2.5.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/README.md +38 -1
- package/code-tool-worker.d.mts.map +1 -1
- package/code-tool-worker.d.ts.map +1 -1
- package/code-tool-worker.js +141 -7
- package/code-tool-worker.js.map +1 -1
- package/code-tool-worker.mjs +141 -7
- package/code-tool-worker.mjs.map +1 -1
- package/code-tool.d.mts +1 -1
- package/code-tool.d.mts.map +1 -1
- package/code-tool.d.ts +1 -1
- package/code-tool.d.ts.map +1 -1
- package/code-tool.js +11 -13
- package/code-tool.js.map +1 -1
- package/code-tool.mjs +11 -13
- package/code-tool.mjs.map +1 -1
- package/dynamic-tools.d.mts +1 -1
- package/dynamic-tools.d.ts +1 -1
- package/dynamic-tools.js +1 -1
- package/dynamic-tools.mjs +1 -1
- package/filtering.d.mts +1 -0
- package/filtering.d.mts.map +1 -1
- package/filtering.d.ts +1 -0
- package/filtering.d.ts.map +1 -1
- package/filtering.js +4 -0
- package/filtering.js.map +1 -1
- package/filtering.mjs +3 -0
- package/filtering.mjs.map +1 -1
- package/headers.d.mts.map +1 -1
- package/headers.d.ts.map +1 -1
- package/headers.js +1 -1
- package/headers.js.map +1 -1
- package/headers.mjs +1 -1
- package/headers.mjs.map +1 -1
- package/http.js +2 -2
- package/http.js.map +1 -1
- package/http.mjs +2 -2
- package/http.mjs.map +1 -1
- package/options.d.mts.map +1 -1
- package/options.d.ts.map +1 -1
- package/options.js +6 -3
- package/options.js.map +1 -1
- package/options.mjs +6 -3
- package/options.mjs.map +1 -1
- package/package.json +5 -3
- package/server.js +1 -1
- package/server.mjs +1 -1
- package/src/code-tool-worker.ts +186 -7
- package/src/code-tool.ts +14 -13
- package/src/dynamic-tools.ts +1 -1
- package/src/filtering.ts +4 -0
- package/src/headers.ts +3 -1
- package/src/http.ts +2 -2
- package/src/options.ts +10 -3
- package/src/server.ts +1 -1
- package/src/tools/index.ts +2 -0
- package/src/tools/metrics/delete-metrics.ts +54 -0
- package/src/tools/projects/create-projects.ts +10 -3
- package/src/tools/projects/list-projects.ts +10 -3
- package/src/tools/records/create-records.ts +10 -3
- package/src/tools/records/delete-records.ts +10 -3
- package/src/tools/records/list-records.ts +10 -3
- package/src/tools/runs/create-runs.ts +10 -3
- package/src/tools/runs/get-runs.ts +10 -3
- package/src/tools/runs/list-runs.ts +10 -3
- package/src/tools/scores/upsert-scores.ts +12 -3
- package/src/tools/systems/delete-systems.ts +10 -3
- package/src/tools/systems/get-systems.ts +10 -3
- package/src/tools/systems/list-systems.ts +10 -3
- package/src/tools/systems/update-systems.ts +10 -3
- package/src/tools/systems/upsert-systems.ts +10 -3
- package/src/tools/systems/versions/get-systems-versions.ts +12 -5
- package/src/tools/systems/versions/upsert-systems-versions.ts +12 -5
- package/src/tools/testcases/create-testcases.ts +10 -3
- package/src/tools/testcases/delete-testcases.ts +10 -3
- package/src/tools/testcases/get-testcases.ts +10 -3
- package/src/tools/testcases/list-testcases.ts +10 -3
- package/src/tools/testcases/update-testcases.ts +10 -3
- package/src/tools/testsets/create-testsets.ts +10 -3
- package/src/tools/testsets/delete-testsets.ts +10 -3
- package/src/tools/testsets/get-testsets.ts +10 -3
- package/src/tools/testsets/list-testsets.ts +10 -3
- package/src/tools/testsets/update-testsets.ts +10 -3
- package/src/tools/types.ts +12 -0
- package/tools/index.d.mts.map +1 -1
- package/tools/index.d.ts.map +1 -1
- package/tools/index.js +2 -0
- package/tools/index.js.map +1 -1
- package/tools/index.mjs +2 -0
- package/tools/index.mjs.map +1 -1
- package/tools/metrics/delete-metrics.d.mts +45 -0
- package/tools/metrics/delete-metrics.d.mts.map +1 -0
- package/tools/metrics/delete-metrics.d.ts +45 -0
- package/tools/metrics/delete-metrics.d.ts.map +1 -0
- package/tools/metrics/delete-metrics.js +50 -0
- package/tools/metrics/delete-metrics.js.map +1 -0
- package/tools/metrics/delete-metrics.mjs +46 -0
- package/tools/metrics/delete-metrics.mjs.map +1 -0
- package/tools/projects/create-projects.d.mts.map +1 -1
- package/tools/projects/create-projects.d.ts.map +1 -1
- package/tools/projects/create-projects.js +9 -1
- package/tools/projects/create-projects.js.map +1 -1
- package/tools/projects/create-projects.mjs +11 -3
- package/tools/projects/create-projects.mjs.map +1 -1
- package/tools/projects/list-projects.d.mts.map +1 -1
- package/tools/projects/list-projects.d.ts.map +1 -1
- package/tools/projects/list-projects.js +9 -1
- package/tools/projects/list-projects.js.map +1 -1
- package/tools/projects/list-projects.mjs +11 -3
- package/tools/projects/list-projects.mjs.map +1 -1
- package/tools/records/create-records.d.mts.map +1 -1
- package/tools/records/create-records.d.ts.map +1 -1
- package/tools/records/create-records.js +9 -1
- package/tools/records/create-records.js.map +1 -1
- package/tools/records/create-records.mjs +11 -3
- package/tools/records/create-records.mjs.map +1 -1
- package/tools/records/delete-records.d.mts.map +1 -1
- package/tools/records/delete-records.d.ts.map +1 -1
- package/tools/records/delete-records.js +9 -1
- package/tools/records/delete-records.js.map +1 -1
- package/tools/records/delete-records.mjs +11 -3
- package/tools/records/delete-records.mjs.map +1 -1
- package/tools/records/list-records.d.mts.map +1 -1
- package/tools/records/list-records.d.ts.map +1 -1
- package/tools/records/list-records.js +9 -1
- package/tools/records/list-records.js.map +1 -1
- package/tools/records/list-records.mjs +11 -3
- package/tools/records/list-records.mjs.map +1 -1
- package/tools/runs/create-runs.d.mts.map +1 -1
- package/tools/runs/create-runs.d.ts.map +1 -1
- package/tools/runs/create-runs.js +9 -1
- package/tools/runs/create-runs.js.map +1 -1
- package/tools/runs/create-runs.mjs +11 -3
- package/tools/runs/create-runs.mjs.map +1 -1
- package/tools/runs/get-runs.d.mts.map +1 -1
- package/tools/runs/get-runs.d.ts.map +1 -1
- package/tools/runs/get-runs.js +9 -1
- package/tools/runs/get-runs.js.map +1 -1
- package/tools/runs/get-runs.mjs +11 -3
- package/tools/runs/get-runs.mjs.map +1 -1
- package/tools/runs/list-runs.d.mts.map +1 -1
- package/tools/runs/list-runs.d.ts.map +1 -1
- package/tools/runs/list-runs.js +9 -1
- package/tools/runs/list-runs.js.map +1 -1
- package/tools/runs/list-runs.mjs +11 -3
- package/tools/runs/list-runs.mjs.map +1 -1
- package/tools/scores/upsert-scores.d.mts.map +1 -1
- package/tools/scores/upsert-scores.d.ts.map +1 -1
- package/tools/scores/upsert-scores.js +9 -1
- package/tools/scores/upsert-scores.js.map +1 -1
- package/tools/scores/upsert-scores.mjs +11 -3
- package/tools/scores/upsert-scores.mjs.map +1 -1
- package/tools/systems/delete-systems.d.mts.map +1 -1
- package/tools/systems/delete-systems.d.ts.map +1 -1
- package/tools/systems/delete-systems.js +9 -1
- package/tools/systems/delete-systems.js.map +1 -1
- package/tools/systems/delete-systems.mjs +11 -3
- package/tools/systems/delete-systems.mjs.map +1 -1
- package/tools/systems/get-systems.d.mts.map +1 -1
- package/tools/systems/get-systems.d.ts.map +1 -1
- package/tools/systems/get-systems.js +9 -1
- package/tools/systems/get-systems.js.map +1 -1
- package/tools/systems/get-systems.mjs +11 -3
- package/tools/systems/get-systems.mjs.map +1 -1
- package/tools/systems/list-systems.d.mts.map +1 -1
- package/tools/systems/list-systems.d.ts.map +1 -1
- package/tools/systems/list-systems.js +9 -1
- package/tools/systems/list-systems.js.map +1 -1
- package/tools/systems/list-systems.mjs +11 -3
- package/tools/systems/list-systems.mjs.map +1 -1
- package/tools/systems/update-systems.d.mts.map +1 -1
- package/tools/systems/update-systems.d.ts.map +1 -1
- package/tools/systems/update-systems.js +9 -1
- package/tools/systems/update-systems.js.map +1 -1
- package/tools/systems/update-systems.mjs +11 -3
- package/tools/systems/update-systems.mjs.map +1 -1
- package/tools/systems/upsert-systems.d.mts.map +1 -1
- package/tools/systems/upsert-systems.d.ts.map +1 -1
- package/tools/systems/upsert-systems.js +9 -1
- package/tools/systems/upsert-systems.js.map +1 -1
- package/tools/systems/upsert-systems.mjs +11 -3
- package/tools/systems/upsert-systems.mjs.map +1 -1
- package/tools/systems/versions/get-systems-versions.d.mts.map +1 -1
- package/tools/systems/versions/get-systems-versions.d.ts.map +1 -1
- package/tools/systems/versions/get-systems-versions.js +9 -1
- package/tools/systems/versions/get-systems-versions.js.map +1 -1
- package/tools/systems/versions/get-systems-versions.mjs +11 -3
- package/tools/systems/versions/get-systems-versions.mjs.map +1 -1
- package/tools/systems/versions/upsert-systems-versions.d.mts.map +1 -1
- package/tools/systems/versions/upsert-systems-versions.d.ts.map +1 -1
- package/tools/systems/versions/upsert-systems-versions.js +9 -1
- package/tools/systems/versions/upsert-systems-versions.js.map +1 -1
- package/tools/systems/versions/upsert-systems-versions.mjs +11 -3
- package/tools/systems/versions/upsert-systems-versions.mjs.map +1 -1
- package/tools/testcases/create-testcases.d.mts.map +1 -1
- package/tools/testcases/create-testcases.d.ts.map +1 -1
- package/tools/testcases/create-testcases.js +9 -1
- package/tools/testcases/create-testcases.js.map +1 -1
- package/tools/testcases/create-testcases.mjs +11 -3
- package/tools/testcases/create-testcases.mjs.map +1 -1
- package/tools/testcases/delete-testcases.d.mts.map +1 -1
- package/tools/testcases/delete-testcases.d.ts.map +1 -1
- package/tools/testcases/delete-testcases.js +9 -1
- package/tools/testcases/delete-testcases.js.map +1 -1
- package/tools/testcases/delete-testcases.mjs +11 -3
- package/tools/testcases/delete-testcases.mjs.map +1 -1
- package/tools/testcases/get-testcases.d.mts.map +1 -1
- package/tools/testcases/get-testcases.d.ts.map +1 -1
- package/tools/testcases/get-testcases.js +9 -1
- package/tools/testcases/get-testcases.js.map +1 -1
- package/tools/testcases/get-testcases.mjs +11 -3
- package/tools/testcases/get-testcases.mjs.map +1 -1
- package/tools/testcases/list-testcases.d.mts.map +1 -1
- package/tools/testcases/list-testcases.d.ts.map +1 -1
- package/tools/testcases/list-testcases.js +9 -1
- package/tools/testcases/list-testcases.js.map +1 -1
- package/tools/testcases/list-testcases.mjs +11 -3
- package/tools/testcases/list-testcases.mjs.map +1 -1
- package/tools/testcases/update-testcases.d.mts.map +1 -1
- package/tools/testcases/update-testcases.d.ts.map +1 -1
- package/tools/testcases/update-testcases.js +9 -1
- package/tools/testcases/update-testcases.js.map +1 -1
- package/tools/testcases/update-testcases.mjs +11 -3
- package/tools/testcases/update-testcases.mjs.map +1 -1
- package/tools/testsets/create-testsets.d.mts.map +1 -1
- package/tools/testsets/create-testsets.d.ts.map +1 -1
- package/tools/testsets/create-testsets.js +9 -1
- package/tools/testsets/create-testsets.js.map +1 -1
- package/tools/testsets/create-testsets.mjs +11 -3
- package/tools/testsets/create-testsets.mjs.map +1 -1
- package/tools/testsets/delete-testsets.d.mts.map +1 -1
- package/tools/testsets/delete-testsets.d.ts.map +1 -1
- package/tools/testsets/delete-testsets.js +9 -1
- package/tools/testsets/delete-testsets.js.map +1 -1
- package/tools/testsets/delete-testsets.mjs +11 -3
- package/tools/testsets/delete-testsets.mjs.map +1 -1
- package/tools/testsets/get-testsets.d.mts.map +1 -1
- package/tools/testsets/get-testsets.d.ts.map +1 -1
- package/tools/testsets/get-testsets.js +9 -1
- package/tools/testsets/get-testsets.js.map +1 -1
- package/tools/testsets/get-testsets.mjs +11 -3
- package/tools/testsets/get-testsets.mjs.map +1 -1
- package/tools/testsets/list-testsets.d.mts.map +1 -1
- package/tools/testsets/list-testsets.d.ts.map +1 -1
- package/tools/testsets/list-testsets.js +9 -1
- package/tools/testsets/list-testsets.js.map +1 -1
- package/tools/testsets/list-testsets.mjs +11 -3
- package/tools/testsets/list-testsets.mjs.map +1 -1
- package/tools/testsets/update-testsets.d.mts.map +1 -1
- package/tools/testsets/update-testsets.d.ts.map +1 -1
- package/tools/testsets/update-testsets.js +9 -1
- package/tools/testsets/update-testsets.js.map +1 -1
- package/tools/testsets/update-testsets.mjs +11 -3
- package/tools/testsets/update-testsets.mjs.map +1 -1
- package/tools/types.d.mts +1 -0
- package/tools/types.d.mts.map +1 -1
- package/tools/types.d.ts +1 -0
- package/tools/types.d.ts.map +1 -1
- package/tools/types.js +12 -0
- package/tools/types.js.map +1 -1
- package/tools/types.mjs +11 -0
- package/tools/types.mjs.map +1 -1
package/src/code-tool-worker.ts
CHANGED
|
@@ -1,11 +1,194 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
3
|
import util from 'node:util';
|
|
4
|
+
|
|
5
|
+
import Fuse from 'fuse.js';
|
|
6
|
+
import ts from 'typescript';
|
|
7
|
+
|
|
4
8
|
import { WorkerInput, WorkerSuccess, WorkerError } from './code-tool-types';
|
|
5
9
|
import { Scorecard } from 'scorecard-ai';
|
|
6
10
|
|
|
11
|
+
function getRunFunctionNode(
|
|
12
|
+
code: string,
|
|
13
|
+
): ts.FunctionDeclaration | ts.FunctionExpression | ts.ArrowFunction | null {
|
|
14
|
+
const sourceFile = ts.createSourceFile('code.ts', code, ts.ScriptTarget.Latest, true);
|
|
15
|
+
|
|
16
|
+
for (const statement of sourceFile.statements) {
|
|
17
|
+
// Check for top-level function declarations
|
|
18
|
+
if (ts.isFunctionDeclaration(statement)) {
|
|
19
|
+
if (statement.name?.text === 'run') {
|
|
20
|
+
return statement;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Check for variable declarations: const run = () => {} or const run = function() {}
|
|
25
|
+
if (ts.isVariableStatement(statement)) {
|
|
26
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
27
|
+
if (ts.isIdentifier(declaration.name) && declaration.name.text === 'run') {
|
|
28
|
+
// Check if it's initialized with a function
|
|
29
|
+
if (
|
|
30
|
+
declaration.initializer &&
|
|
31
|
+
(ts.isFunctionExpression(declaration.initializer) || ts.isArrowFunction(declaration.initializer))
|
|
32
|
+
) {
|
|
33
|
+
return declaration.initializer;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const fuse = new Fuse(
|
|
44
|
+
[
|
|
45
|
+
'client.projects.create',
|
|
46
|
+
'client.projects.list',
|
|
47
|
+
'client.testsets.create',
|
|
48
|
+
'client.testsets.delete',
|
|
49
|
+
'client.testsets.get',
|
|
50
|
+
'client.testsets.list',
|
|
51
|
+
'client.testsets.update',
|
|
52
|
+
'client.testcases.create',
|
|
53
|
+
'client.testcases.delete',
|
|
54
|
+
'client.testcases.get',
|
|
55
|
+
'client.testcases.list',
|
|
56
|
+
'client.testcases.update',
|
|
57
|
+
'client.runs.create',
|
|
58
|
+
'client.runs.get',
|
|
59
|
+
'client.runs.list',
|
|
60
|
+
'client.metrics.create',
|
|
61
|
+
'client.metrics.delete',
|
|
62
|
+
'client.metrics.get',
|
|
63
|
+
'client.metrics.list',
|
|
64
|
+
'client.metrics.update',
|
|
65
|
+
'client.records.create',
|
|
66
|
+
'client.records.delete',
|
|
67
|
+
'client.records.list',
|
|
68
|
+
'client.scores.upsert',
|
|
69
|
+
'client.systems.delete',
|
|
70
|
+
'client.systems.get',
|
|
71
|
+
'client.systems.list',
|
|
72
|
+
'client.systems.update',
|
|
73
|
+
'client.systems.upsert',
|
|
74
|
+
'client.systems.versions.get',
|
|
75
|
+
'client.systems.versions.upsert',
|
|
76
|
+
],
|
|
77
|
+
{ threshold: 1, shouldSort: true },
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
function getMethodSuggestions(fullyQualifiedMethodName: string): string[] {
|
|
81
|
+
return fuse
|
|
82
|
+
.search(fullyQualifiedMethodName)
|
|
83
|
+
.map(({ item }) => item)
|
|
84
|
+
.slice(0, 5);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const proxyToObj = new WeakMap<any, any>();
|
|
88
|
+
const objToProxy = new WeakMap<any, any>();
|
|
89
|
+
|
|
90
|
+
type ClientProxyConfig = {
|
|
91
|
+
path: string[];
|
|
92
|
+
isBelievedBad?: boolean;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
function makeSdkProxy<T extends object>(obj: T, { path, isBelievedBad = false }: ClientProxyConfig): T {
|
|
96
|
+
let proxy: T = objToProxy.get(obj);
|
|
97
|
+
|
|
98
|
+
if (!proxy) {
|
|
99
|
+
proxy = new Proxy(obj, {
|
|
100
|
+
get(target, prop, receiver) {
|
|
101
|
+
const propPath = [...path, String(prop)];
|
|
102
|
+
const value = Reflect.get(target, prop, receiver);
|
|
103
|
+
|
|
104
|
+
if (isBelievedBad || (!(prop in target) && value === undefined)) {
|
|
105
|
+
// If we're accessing a path that doesn't exist, it will probably eventually error.
|
|
106
|
+
// Let's proxy it and mark it bad so that we can control the error message.
|
|
107
|
+
// We proxy an empty class so that an invocation or construction attempt is possible.
|
|
108
|
+
return makeSdkProxy(class {}, { path: propPath, isBelievedBad: true });
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (value !== null && (typeof value === 'object' || typeof value === 'function')) {
|
|
112
|
+
return makeSdkProxy(value, { path: propPath, isBelievedBad });
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return value;
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
apply(target, thisArg, args) {
|
|
119
|
+
if (isBelievedBad || typeof target !== 'function') {
|
|
120
|
+
const fullyQualifiedMethodName = path.join('.');
|
|
121
|
+
const suggestions = getMethodSuggestions(fullyQualifiedMethodName);
|
|
122
|
+
throw new Error(
|
|
123
|
+
`${fullyQualifiedMethodName} is not a function. Did you mean: ${suggestions.join(', ')}`,
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return Reflect.apply(target, proxyToObj.get(thisArg) ?? thisArg, args);
|
|
128
|
+
},
|
|
129
|
+
|
|
130
|
+
construct(target, args, newTarget) {
|
|
131
|
+
if (isBelievedBad || typeof target !== 'function') {
|
|
132
|
+
const fullyQualifiedMethodName = path.join('.');
|
|
133
|
+
const suggestions = getMethodSuggestions(fullyQualifiedMethodName);
|
|
134
|
+
throw new Error(
|
|
135
|
+
`${fullyQualifiedMethodName} is not a constructor. Did you mean: ${suggestions.join(', ')}`,
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return Reflect.construct(target, args, newTarget);
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
objToProxy.set(obj, proxy);
|
|
144
|
+
proxyToObj.set(proxy, obj);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return proxy;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function parseError(code: string, error: unknown): string | undefined {
|
|
151
|
+
if (!(error instanceof Error)) return;
|
|
152
|
+
const message = error.name ? `${error.name}: ${error.message}` : error.message;
|
|
153
|
+
try {
|
|
154
|
+
// Deno uses V8; the first "<anonymous>:LINE:COLUMN" is the top of stack.
|
|
155
|
+
const lineNumber = error.stack?.match(/<anonymous>:([0-9]+):[0-9]+/)?.[1];
|
|
156
|
+
// -1 for the zero-based indexing
|
|
157
|
+
const line =
|
|
158
|
+
lineNumber &&
|
|
159
|
+
code
|
|
160
|
+
.split('\n')
|
|
161
|
+
.at(parseInt(lineNumber, 10) - 1)
|
|
162
|
+
?.trim();
|
|
163
|
+
return line ? `${message}\n at line ${lineNumber}\n ${line}` : message;
|
|
164
|
+
} catch {
|
|
165
|
+
return message;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
7
169
|
const fetch = async (req: Request): Promise<Response> => {
|
|
8
170
|
const { opts, code } = (await req.json()) as WorkerInput;
|
|
171
|
+
if (code == null) {
|
|
172
|
+
return Response.json(
|
|
173
|
+
{
|
|
174
|
+
message:
|
|
175
|
+
'The code param is missing. Provide one containing a top-level `run` function. Write code within this template:\n\n```\nasync function run(client) {\n // Fill this out\n}\n```',
|
|
176
|
+
} satisfies WorkerError,
|
|
177
|
+
{ status: 400, statusText: 'Code execution error' },
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const runFunctionNode = getRunFunctionNode(code);
|
|
182
|
+
if (!runFunctionNode) {
|
|
183
|
+
return Response.json(
|
|
184
|
+
{
|
|
185
|
+
message:
|
|
186
|
+
'The code is missing a top-level `run` function. Write code within this template:\n\n```\nasync function run(client) {\n // Fill this out\n}\n```',
|
|
187
|
+
} satisfies WorkerError,
|
|
188
|
+
{ status: 400, statusText: 'Code execution error' },
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
|
|
9
192
|
const client = new Scorecard({
|
|
10
193
|
...opts,
|
|
11
194
|
});
|
|
@@ -22,21 +205,17 @@ const fetch = async (req: Request): Promise<Response> => {
|
|
|
22
205
|
};
|
|
23
206
|
try {
|
|
24
207
|
let run_ = async (client: any) => {};
|
|
25
|
-
eval(
|
|
26
|
-
|
|
27
|
-
run_ = run;
|
|
28
|
-
`);
|
|
29
|
-
const result = await run_(client);
|
|
208
|
+
eval(`${code}\nrun_ = run;`);
|
|
209
|
+
const result = await run_(makeSdkProxy(client, { path: ['client'] }));
|
|
30
210
|
return Response.json({
|
|
31
211
|
result,
|
|
32
212
|
logLines,
|
|
33
213
|
errLines,
|
|
34
214
|
} satisfies WorkerSuccess);
|
|
35
215
|
} catch (e) {
|
|
36
|
-
const message = e instanceof Error ? e.message : undefined;
|
|
37
216
|
return Response.json(
|
|
38
217
|
{
|
|
39
|
-
message,
|
|
218
|
+
message: parseError(code, e),
|
|
40
219
|
} satisfies WorkerError,
|
|
41
220
|
{ status: 400, statusText: 'Code execution error' },
|
|
42
221
|
);
|
package/src/code-tool.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { dirname } from 'node:path';
|
|
4
4
|
import { pathToFileURL } from 'node:url';
|
|
5
5
|
import Scorecard, { ClientOptions } from 'scorecard-ai';
|
|
6
|
-
import {
|
|
6
|
+
import { ContentBlock, Endpoint, Metadata, ToolCallResult } from './tools/types';
|
|
7
7
|
|
|
8
8
|
import { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
9
9
|
|
|
@@ -12,7 +12,7 @@ import { WorkerInput, WorkerError, WorkerSuccess } from './code-tool-types';
|
|
|
12
12
|
/**
|
|
13
13
|
* A tool that runs code against a copy of the SDK.
|
|
14
14
|
*
|
|
15
|
-
* Instead of exposing every endpoint as
|
|
15
|
+
* Instead of exposing every endpoint as its own tool, which uses up too many tokens for LLMs to use at once,
|
|
16
16
|
* we expose a single tool that can be used to search for endpoints by name, resource, operation, or tag, and then
|
|
17
17
|
* a generic endpoint that can be used to invoke any endpoint with the provided arguments.
|
|
18
18
|
*
|
|
@@ -23,7 +23,7 @@ export async function codeTool(): Promise<Endpoint> {
|
|
|
23
23
|
const tool: Tool = {
|
|
24
24
|
name: 'execute',
|
|
25
25
|
description:
|
|
26
|
-
'Runs
|
|
26
|
+
'Runs JavaScript code to interact with the API.\n\nYou are a skilled programmer writing code to interface with the service.\nDefine an async function named "run" that takes a single parameter of an initialized client named "client", and it will be run.\nWrite code within this template:\n\n```\nasync function run(client) {\n // Fill this out\n}\n```\n\nYou will be returned anything that your function returns, plus the results of any console.log statements.\nIf any code triggers an error, the tool will return an error response, so you do not need to add error handling unless you want to output something more helpful than the raw error.\nIt is not necessary to add comments to code, unless by adding those comments you believe that you can generate better code.\nThis code will run in a container, and you will not be able to use fetch or otherwise interact with the network calls other than through the client you are given.\nAny variables you define won\'t live between successive uses of this call, so make sure to return or log any data you might need later.',
|
|
27
27
|
inputSchema: { type: 'object', properties: { code: { type: 'string' } } },
|
|
28
28
|
};
|
|
29
29
|
|
|
@@ -31,7 +31,7 @@ export async function codeTool(): Promise<Endpoint> {
|
|
|
31
31
|
const { newDenoHTTPWorker } = await import('@valtown/deno-http-worker');
|
|
32
32
|
const { workerPath } = await import('./code-tool-paths.cjs');
|
|
33
33
|
|
|
34
|
-
const handler = async (client: Scorecard, args: unknown) => {
|
|
34
|
+
const handler = async (client: Scorecard, args: unknown): Promise<ToolCallResult> => {
|
|
35
35
|
const baseURLHostname = new URL(client.baseURL).hostname;
|
|
36
36
|
const { code } = args as { code: string };
|
|
37
37
|
|
|
@@ -97,7 +97,7 @@ export async function codeTool(): Promise<Endpoint> {
|
|
|
97
97
|
} satisfies WorkerInput);
|
|
98
98
|
|
|
99
99
|
req.write(body, (err) => {
|
|
100
|
-
if (err
|
|
100
|
+
if (err != null) {
|
|
101
101
|
reject(err);
|
|
102
102
|
}
|
|
103
103
|
});
|
|
@@ -108,12 +108,12 @@ export async function codeTool(): Promise<Endpoint> {
|
|
|
108
108
|
if (resp.status === 200) {
|
|
109
109
|
const { result, logLines, errLines } = (await resp.json()) as WorkerSuccess;
|
|
110
110
|
const returnOutput: ContentBlock | null =
|
|
111
|
-
result
|
|
112
|
-
|
|
113
|
-
: {
|
|
111
|
+
result == null ? null : (
|
|
112
|
+
{
|
|
114
113
|
type: 'text',
|
|
115
|
-
text: typeof result === 'string' ?
|
|
116
|
-
}
|
|
114
|
+
text: typeof result === 'string' ? result : JSON.stringify(result),
|
|
115
|
+
}
|
|
116
|
+
);
|
|
117
117
|
const logOutput: ContentBlock | null =
|
|
118
118
|
logLines.length === 0 ?
|
|
119
119
|
null
|
|
@@ -133,10 +133,11 @@ export async function codeTool(): Promise<Endpoint> {
|
|
|
133
133
|
};
|
|
134
134
|
} else {
|
|
135
135
|
const { message } = (await resp.json()) as WorkerError;
|
|
136
|
-
|
|
136
|
+
return {
|
|
137
|
+
content: message == null ? [] : [{ type: 'text', text: message }],
|
|
138
|
+
isError: true,
|
|
139
|
+
};
|
|
137
140
|
}
|
|
138
|
-
} catch (e) {
|
|
139
|
-
throw e;
|
|
140
141
|
} finally {
|
|
141
142
|
worker.terminate();
|
|
142
143
|
}
|
package/src/dynamic-tools.ts
CHANGED
|
@@ -14,7 +14,7 @@ function zodToInputSchema(schema: z.ZodSchema) {
|
|
|
14
14
|
/**
|
|
15
15
|
* A list of tools that expose all the endpoints in the API dynamically.
|
|
16
16
|
*
|
|
17
|
-
* Instead of exposing every endpoint as
|
|
17
|
+
* Instead of exposing every endpoint as its own tool, which uses up too many tokens for LLMs to use at once,
|
|
18
18
|
* we expose a single tool that can be used to search for endpoints by name, resource, operation, or tag, and then
|
|
19
19
|
* a generic endpoint that can be used to invoke any endpoint with the provided arguments.
|
|
20
20
|
*
|
package/src/filtering.ts
CHANGED
|
@@ -12,3 +12,7 @@ export async function maybeFilter(jqFilter: unknown | undefined, response: any):
|
|
|
12
12
|
async function jq(json: any, jqFilter: string) {
|
|
13
13
|
return (await initJq).json(json, jqFilter);
|
|
14
14
|
}
|
|
15
|
+
|
|
16
|
+
export function isJqError(error: any): error is Error {
|
|
17
|
+
return error instanceof Error && 'stderr' in error;
|
|
18
|
+
}
|
package/src/headers.ts
CHANGED
|
@@ -11,7 +11,9 @@ export const parseAuthHeaders = (req: IncomingMessage): Partial<ClientOptions> =
|
|
|
11
11
|
case 'Bearer':
|
|
12
12
|
return { apiKey: req.headers.authorization.slice('Bearer '.length) };
|
|
13
13
|
default:
|
|
14
|
-
throw new Error(
|
|
14
|
+
throw new Error(
|
|
15
|
+
'Unsupported authorization scheme. Expected the "Authorization" header to be a supported scheme (Bearer).',
|
|
16
|
+
);
|
|
15
17
|
}
|
|
16
18
|
}
|
|
17
19
|
|
package/src/http.ts
CHANGED
|
@@ -46,12 +46,12 @@ const newServer = ({
|
|
|
46
46
|
},
|
|
47
47
|
mcpOptions,
|
|
48
48
|
});
|
|
49
|
-
} catch {
|
|
49
|
+
} catch (error) {
|
|
50
50
|
res.status(401).json({
|
|
51
51
|
jsonrpc: '2.0',
|
|
52
52
|
error: {
|
|
53
53
|
code: -32000,
|
|
54
|
-
message:
|
|
54
|
+
message: `Unauthorized: ${error instanceof Error ? error.message : error}`,
|
|
55
55
|
},
|
|
56
56
|
});
|
|
57
57
|
return null;
|
package/src/options.ts
CHANGED
|
@@ -284,8 +284,10 @@ const coerceArray = <T extends z.ZodTypeAny>(zodType: T) =>
|
|
|
284
284
|
);
|
|
285
285
|
|
|
286
286
|
const QueryOptions = z.object({
|
|
287
|
-
tools: coerceArray(z.enum(['dynamic', 'all', 'docs'])).describe('
|
|
288
|
-
no_tools: coerceArray(z.enum(['dynamic', 'all', 'docs'])).describe(
|
|
287
|
+
tools: coerceArray(z.enum(['dynamic', 'all', 'code', 'docs'])).describe('Specify which MCP tools to use'),
|
|
288
|
+
no_tools: coerceArray(z.enum(['dynamic', 'all', 'code', 'docs'])).describe(
|
|
289
|
+
'Specify which MCP tools to not use.',
|
|
290
|
+
),
|
|
289
291
|
tool: coerceArray(z.string()).describe('Include tools matching the specified names'),
|
|
290
292
|
resource: coerceArray(z.string()).describe('Include tools matching the specified resources'),
|
|
291
293
|
operation: coerceArray(z.enum(['read', 'write'])).describe(
|
|
@@ -385,11 +387,16 @@ export function parseQueryOptions(defaultOptions: McpOptions, query: unknown): M
|
|
|
385
387
|
: queryOptions.tools?.includes('docs') ? true
|
|
386
388
|
: defaultOptions.includeDocsTools;
|
|
387
389
|
|
|
390
|
+
let codeTools: boolean | undefined =
|
|
391
|
+
queryOptions.no_tools && queryOptions.no_tools?.includes('code') ? false
|
|
392
|
+
: queryOptions.tools?.includes('code') && defaultOptions.includeCodeTools ? true
|
|
393
|
+
: defaultOptions.includeCodeTools;
|
|
394
|
+
|
|
388
395
|
return {
|
|
389
396
|
client: queryOptions.client ?? defaultOptions.client,
|
|
390
397
|
includeDynamicTools: dynamicTools,
|
|
391
398
|
includeAllTools: allTools,
|
|
392
|
-
includeCodeTools:
|
|
399
|
+
includeCodeTools: codeTools,
|
|
393
400
|
includeDocsTools: docsTools,
|
|
394
401
|
filters,
|
|
395
402
|
capabilities: clientCapabilities,
|
package/src/server.ts
CHANGED
package/src/tools/index.ts
CHANGED
|
@@ -22,6 +22,7 @@ import get_runs from './runs/get-runs';
|
|
|
22
22
|
import create_metrics from './metrics/create-metrics';
|
|
23
23
|
import update_metrics from './metrics/update-metrics';
|
|
24
24
|
import list_metrics from './metrics/list-metrics';
|
|
25
|
+
import delete_metrics from './metrics/delete-metrics';
|
|
25
26
|
import get_metrics from './metrics/get-metrics';
|
|
26
27
|
import create_records from './records/create-records';
|
|
27
28
|
import list_records from './records/list-records';
|
|
@@ -59,6 +60,7 @@ addEndpoint(get_runs);
|
|
|
59
60
|
addEndpoint(create_metrics);
|
|
60
61
|
addEndpoint(update_metrics);
|
|
61
62
|
addEndpoint(list_metrics);
|
|
63
|
+
addEndpoint(delete_metrics);
|
|
62
64
|
addEndpoint(get_metrics);
|
|
63
65
|
addEndpoint(create_records);
|
|
64
66
|
addEndpoint(list_records);
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { isJqError, maybeFilter } from 'scorecard-ai-mcp/filtering';
|
|
4
|
+
import { Metadata, asErrorResult, asTextContentResult } from 'scorecard-ai-mcp/tools/types';
|
|
5
|
+
|
|
6
|
+
import { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
7
|
+
import Scorecard from 'scorecard-ai';
|
|
8
|
+
|
|
9
|
+
export const metadata: Metadata = {
|
|
10
|
+
resource: 'metrics',
|
|
11
|
+
operation: 'write',
|
|
12
|
+
tags: [],
|
|
13
|
+
httpMethod: 'delete',
|
|
14
|
+
httpPath: '/metrics/{metricId}',
|
|
15
|
+
operationId: 'deleteMetric',
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const tool: Tool = {
|
|
19
|
+
name: 'delete_metrics',
|
|
20
|
+
description:
|
|
21
|
+
"When using this tool, always use the `jq_filter` parameter to reduce the response size and improve performance.\n\nOnly omit if you're sure you don't need the data.\n\nDelete a specific Metric by ID. The metric will be removed from metric groups and monitors.\n\n# Response Schema\n```json\n{\n $ref: '#/$defs/metric_delete_response',\n $defs: {\n metric_delete_response: {\n type: 'object',\n properties: {\n success: {\n type: 'boolean',\n description: 'Whether the deletion was successful.'\n }\n },\n required: [ 'success'\n ]\n }\n }\n}\n```",
|
|
22
|
+
inputSchema: {
|
|
23
|
+
type: 'object',
|
|
24
|
+
properties: {
|
|
25
|
+
metricId: {
|
|
26
|
+
type: 'string',
|
|
27
|
+
},
|
|
28
|
+
jq_filter: {
|
|
29
|
+
type: 'string',
|
|
30
|
+
title: 'jq Filter',
|
|
31
|
+
description:
|
|
32
|
+
'A jq filter to apply to the response to include certain fields. Consult the output schema in the tool description to see the fields that are available.\n\nFor example: to include only the `name` field in every object of a results array, you can provide ".results[].name".\n\nFor more information, see the [jq documentation](https://jqlang.org/manual/).',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
required: ['metricId'],
|
|
36
|
+
},
|
|
37
|
+
annotations: {
|
|
38
|
+
idempotentHint: true,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const handler = async (client: Scorecard, args: Record<string, unknown> | undefined) => {
|
|
43
|
+
const { metricId, jq_filter, ...body } = args as any;
|
|
44
|
+
try {
|
|
45
|
+
return asTextContentResult(await maybeFilter(jq_filter, await client.metrics.delete(metricId)));
|
|
46
|
+
} catch (error) {
|
|
47
|
+
if (isJqError(error)) {
|
|
48
|
+
return asErrorResult(error.message);
|
|
49
|
+
}
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export default { metadata, tool, handler };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import { maybeFilter } from 'scorecard-ai-mcp/filtering';
|
|
4
|
-
import { Metadata, asTextContentResult } from 'scorecard-ai-mcp/tools/types';
|
|
3
|
+
import { isJqError, maybeFilter } from 'scorecard-ai-mcp/filtering';
|
|
4
|
+
import { Metadata, asErrorResult, asTextContentResult } from 'scorecard-ai-mcp/tools/types';
|
|
5
5
|
|
|
6
6
|
import { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
7
7
|
import Scorecard from 'scorecard-ai';
|
|
@@ -44,7 +44,14 @@ export const tool: Tool = {
|
|
|
44
44
|
|
|
45
45
|
export const handler = async (client: Scorecard, args: Record<string, unknown> | undefined) => {
|
|
46
46
|
const { jq_filter, ...body } = args as any;
|
|
47
|
-
|
|
47
|
+
try {
|
|
48
|
+
return asTextContentResult(await maybeFilter(jq_filter, await client.projects.create(body)));
|
|
49
|
+
} catch (error) {
|
|
50
|
+
if (isJqError(error)) {
|
|
51
|
+
return asErrorResult(error.message);
|
|
52
|
+
}
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
48
55
|
};
|
|
49
56
|
|
|
50
57
|
export default { metadata, tool, handler };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import { maybeFilter } from 'scorecard-ai-mcp/filtering';
|
|
4
|
-
import { Metadata, asTextContentResult } from 'scorecard-ai-mcp/tools/types';
|
|
3
|
+
import { isJqError, maybeFilter } from 'scorecard-ai-mcp/filtering';
|
|
4
|
+
import { Metadata, asErrorResult, asTextContentResult } from 'scorecard-ai-mcp/tools/types';
|
|
5
5
|
|
|
6
6
|
import { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
7
7
|
import Scorecard from 'scorecard-ai';
|
|
@@ -49,7 +49,14 @@ export const tool: Tool = {
|
|
|
49
49
|
export const handler = async (client: Scorecard, args: Record<string, unknown> | undefined) => {
|
|
50
50
|
const { jq_filter, ...body } = args as any;
|
|
51
51
|
const response = await client.projects.list(body).asResponse();
|
|
52
|
-
|
|
52
|
+
try {
|
|
53
|
+
return asTextContentResult(await maybeFilter(jq_filter, await response.json()));
|
|
54
|
+
} catch (error) {
|
|
55
|
+
if (isJqError(error)) {
|
|
56
|
+
return asErrorResult(error.message);
|
|
57
|
+
}
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
53
60
|
};
|
|
54
61
|
|
|
55
62
|
export default { metadata, tool, handler };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import { maybeFilter } from 'scorecard-ai-mcp/filtering';
|
|
4
|
-
import { Metadata, asTextContentResult } from 'scorecard-ai-mcp/tools/types';
|
|
3
|
+
import { isJqError, maybeFilter } from 'scorecard-ai-mcp/filtering';
|
|
4
|
+
import { Metadata, asErrorResult, asTextContentResult } from 'scorecard-ai-mcp/tools/types';
|
|
5
5
|
|
|
6
6
|
import { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
7
7
|
import Scorecard from 'scorecard-ai';
|
|
@@ -58,7 +58,14 @@ export const tool: Tool = {
|
|
|
58
58
|
|
|
59
59
|
export const handler = async (client: Scorecard, args: Record<string, unknown> | undefined) => {
|
|
60
60
|
const { runId, jq_filter, ...body } = args as any;
|
|
61
|
-
|
|
61
|
+
try {
|
|
62
|
+
return asTextContentResult(await maybeFilter(jq_filter, await client.records.create(runId, body)));
|
|
63
|
+
} catch (error) {
|
|
64
|
+
if (isJqError(error)) {
|
|
65
|
+
return asErrorResult(error.message);
|
|
66
|
+
}
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
62
69
|
};
|
|
63
70
|
|
|
64
71
|
export default { metadata, tool, handler };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import { maybeFilter } from 'scorecard-ai-mcp/filtering';
|
|
4
|
-
import { Metadata, asTextContentResult } from 'scorecard-ai-mcp/tools/types';
|
|
3
|
+
import { isJqError, maybeFilter } from 'scorecard-ai-mcp/filtering';
|
|
4
|
+
import { Metadata, asErrorResult, asTextContentResult } from 'scorecard-ai-mcp/tools/types';
|
|
5
5
|
|
|
6
6
|
import { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
7
7
|
import Scorecard from 'scorecard-ai';
|
|
@@ -41,7 +41,14 @@ export const tool: Tool = {
|
|
|
41
41
|
|
|
42
42
|
export const handler = async (client: Scorecard, args: Record<string, unknown> | undefined) => {
|
|
43
43
|
const { recordId, jq_filter, ...body } = args as any;
|
|
44
|
-
|
|
44
|
+
try {
|
|
45
|
+
return asTextContentResult(await maybeFilter(jq_filter, await client.records.delete(recordId)));
|
|
46
|
+
} catch (error) {
|
|
47
|
+
if (isJqError(error)) {
|
|
48
|
+
return asErrorResult(error.message);
|
|
49
|
+
}
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
45
52
|
};
|
|
46
53
|
|
|
47
54
|
export default { metadata, tool, handler };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import { maybeFilter } from 'scorecard-ai-mcp/filtering';
|
|
4
|
-
import { Metadata, asTextContentResult } from 'scorecard-ai-mcp/tools/types';
|
|
3
|
+
import { isJqError, maybeFilter } from 'scorecard-ai-mcp/filtering';
|
|
4
|
+
import { Metadata, asErrorResult, asTextContentResult } from 'scorecard-ai-mcp/tools/types';
|
|
5
5
|
|
|
6
6
|
import { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
7
7
|
import Scorecard from 'scorecard-ai';
|
|
@@ -52,7 +52,14 @@ export const tool: Tool = {
|
|
|
52
52
|
export const handler = async (client: Scorecard, args: Record<string, unknown> | undefined) => {
|
|
53
53
|
const { runId, jq_filter, ...body } = args as any;
|
|
54
54
|
const response = await client.records.list(runId, body).asResponse();
|
|
55
|
-
|
|
55
|
+
try {
|
|
56
|
+
return asTextContentResult(await maybeFilter(jq_filter, await response.json()));
|
|
57
|
+
} catch (error) {
|
|
58
|
+
if (isJqError(error)) {
|
|
59
|
+
return asErrorResult(error.message);
|
|
60
|
+
}
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
56
63
|
};
|
|
57
64
|
|
|
58
65
|
export default { metadata, tool, handler };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import { maybeFilter } from 'scorecard-ai-mcp/filtering';
|
|
4
|
-
import { Metadata, asTextContentResult } from 'scorecard-ai-mcp/tools/types';
|
|
3
|
+
import { isJqError, maybeFilter } from 'scorecard-ai-mcp/filtering';
|
|
4
|
+
import { Metadata, asErrorResult, asTextContentResult } from 'scorecard-ai-mcp/tools/types';
|
|
5
5
|
|
|
6
6
|
import { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
7
7
|
import Scorecard from 'scorecard-ai';
|
|
@@ -54,7 +54,14 @@ export const tool: Tool = {
|
|
|
54
54
|
|
|
55
55
|
export const handler = async (client: Scorecard, args: Record<string, unknown> | undefined) => {
|
|
56
56
|
const { projectId, jq_filter, ...body } = args as any;
|
|
57
|
-
|
|
57
|
+
try {
|
|
58
|
+
return asTextContentResult(await maybeFilter(jq_filter, await client.runs.create(projectId, body)));
|
|
59
|
+
} catch (error) {
|
|
60
|
+
if (isJqError(error)) {
|
|
61
|
+
return asErrorResult(error.message);
|
|
62
|
+
}
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
58
65
|
};
|
|
59
66
|
|
|
60
67
|
export default { metadata, tool, handler };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import { maybeFilter } from 'scorecard-ai-mcp/filtering';
|
|
4
|
-
import { Metadata, asTextContentResult } from 'scorecard-ai-mcp/tools/types';
|
|
3
|
+
import { isJqError, maybeFilter } from 'scorecard-ai-mcp/filtering';
|
|
4
|
+
import { Metadata, asErrorResult, asTextContentResult } from 'scorecard-ai-mcp/tools/types';
|
|
5
5
|
|
|
6
6
|
import { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
7
7
|
import Scorecard from 'scorecard-ai';
|
|
@@ -41,7 +41,14 @@ export const tool: Tool = {
|
|
|
41
41
|
|
|
42
42
|
export const handler = async (client: Scorecard, args: Record<string, unknown> | undefined) => {
|
|
43
43
|
const { runId, jq_filter, ...body } = args as any;
|
|
44
|
-
|
|
44
|
+
try {
|
|
45
|
+
return asTextContentResult(await maybeFilter(jq_filter, await client.runs.get(runId)));
|
|
46
|
+
} catch (error) {
|
|
47
|
+
if (isJqError(error)) {
|
|
48
|
+
return asErrorResult(error.message);
|
|
49
|
+
}
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
45
52
|
};
|
|
46
53
|
|
|
47
54
|
export default { metadata, tool, handler };
|