scorecard-ai-mcp 1.0.0-alpha.6 → 1.0.0-alpha.8
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 +63 -35
- package/compat.d.mts +2 -0
- package/compat.d.mts.map +1 -1
- package/compat.d.ts +2 -0
- package/compat.d.ts.map +1 -1
- package/compat.js +7 -4
- package/compat.js.map +1 -1
- package/compat.mjs +8 -4
- package/compat.mjs.map +1 -1
- package/dynamic-tools.d.mts +12 -0
- package/dynamic-tools.d.mts.map +1 -0
- package/dynamic-tools.d.ts +12 -0
- package/dynamic-tools.d.ts.map +1 -0
- package/dynamic-tools.js +134 -0
- package/dynamic-tools.js.map +1 -0
- package/dynamic-tools.mjs +131 -0
- package/dynamic-tools.mjs.map +1 -0
- package/index.js +15 -18
- package/index.js.map +1 -1
- package/index.mjs +17 -20
- package/index.mjs.map +1 -1
- package/options.d.mts +2 -0
- package/options.d.mts.map +1 -1
- package/options.d.ts +2 -0
- package/options.d.ts.map +1 -1
- package/options.js +17 -0
- package/options.js.map +1 -1
- package/options.mjs +17 -0
- package/options.mjs.map +1 -1
- package/package.json +13 -20
- package/server.d.mts +6 -1
- package/server.d.mts.map +1 -1
- package/server.d.ts +6 -1
- package/server.d.ts.map +1 -1
- package/server.js +21 -2
- package/server.js.map +1 -1
- package/server.mjs +22 -4
- package/server.mjs.map +1 -1
- package/src/compat.ts +13 -4
- package/src/dynamic-tools.ts +153 -0
- package/src/index.ts +19 -23
- package/src/options.ts +22 -0
- package/src/server.ts +35 -4
- package/src/tools/index.ts +5 -7
- package/src/tools/{runs/update-runs.ts → projects/create-projects.ts} +9 -17
- package/src/tools/records/create-records.ts +4 -4
- package/src/tools/scores/upsert-scores.ts +40 -0
- package/src/tools/testcases/create-testcases.ts +0 -2
- package/src/tools/testsets/create-testsets.ts +7 -7
- package/src/tools/testsets/update-testsets.ts +7 -7
- package/tools/index.d.mts.map +1 -1
- package/tools/index.d.ts.map +1 -1
- package/tools/index.js +5 -6
- package/tools/index.js.map +1 -1
- package/tools/index.mjs +5 -6
- package/tools/index.mjs.map +1 -1
- package/tools/projects/create-projects.d.mts +32 -0
- package/tools/projects/create-projects.d.mts.map +1 -0
- package/tools/projects/create-projects.d.ts +32 -0
- package/tools/projects/create-projects.d.ts.map +1 -0
- package/tools/{runs/update-runs.js → projects/create-projects.js} +10 -18
- package/tools/projects/create-projects.js.map +1 -0
- package/tools/projects/create-projects.mjs +29 -0
- package/tools/projects/create-projects.mjs.map +1 -0
- package/tools/projects/list-projects.d.mts +10 -2
- package/tools/projects/list-projects.d.mts.map +1 -1
- package/tools/projects/list-projects.d.ts +10 -2
- package/tools/projects/list-projects.d.ts.map +1 -1
- package/tools/records/create-records.d.mts +8 -0
- package/tools/records/create-records.d.mts.map +1 -1
- package/tools/records/create-records.d.ts +8 -0
- package/tools/records/create-records.d.ts.map +1 -1
- package/tools/records/create-records.js +4 -4
- package/tools/records/create-records.js.map +1 -1
- package/tools/records/create-records.mjs +4 -4
- package/tools/records/create-records.mjs.map +1 -1
- package/tools/runs/create-runs.d.mts +8 -0
- package/tools/runs/create-runs.d.mts.map +1 -1
- package/tools/runs/create-runs.d.ts +8 -0
- package/tools/runs/create-runs.d.ts.map +1 -1
- package/tools/{runs/update-runs.d.mts → scores/upsert-scores.d.mts} +11 -3
- package/tools/scores/upsert-scores.d.mts.map +1 -0
- package/tools/{runs/update-runs.d.ts → scores/upsert-scores.d.ts} +11 -3
- package/tools/scores/upsert-scores.d.ts.map +1 -0
- package/tools/scores/upsert-scores.js +35 -0
- package/tools/scores/upsert-scores.js.map +1 -0
- package/tools/scores/upsert-scores.mjs +31 -0
- package/tools/scores/upsert-scores.mjs.map +1 -0
- package/tools/system-configs/create-system-configs.d.mts +8 -0
- package/tools/system-configs/create-system-configs.d.mts.map +1 -1
- package/tools/system-configs/create-system-configs.d.ts +8 -0
- package/tools/system-configs/create-system-configs.d.ts.map +1 -1
- package/tools/system-configs/get-system-configs.d.mts +8 -0
- package/tools/system-configs/get-system-configs.d.mts.map +1 -1
- package/tools/system-configs/get-system-configs.d.ts +8 -0
- package/tools/system-configs/get-system-configs.d.ts.map +1 -1
- package/tools/system-configs/list-system-configs.d.mts +8 -0
- package/tools/system-configs/list-system-configs.d.mts.map +1 -1
- package/tools/system-configs/list-system-configs.d.ts +8 -0
- package/tools/system-configs/list-system-configs.d.ts.map +1 -1
- package/tools/systems/create-systems.d.mts +8 -0
- package/tools/systems/create-systems.d.mts.map +1 -1
- package/tools/systems/create-systems.d.ts +8 -0
- package/tools/systems/create-systems.d.ts.map +1 -1
- package/tools/systems/delete-systems.d.mts +8 -0
- package/tools/systems/delete-systems.d.mts.map +1 -1
- package/tools/systems/delete-systems.d.ts +8 -0
- package/tools/systems/delete-systems.d.ts.map +1 -1
- package/tools/systems/get-systems.d.mts +8 -0
- package/tools/systems/get-systems.d.mts.map +1 -1
- package/tools/systems/get-systems.d.ts +8 -0
- package/tools/systems/get-systems.d.ts.map +1 -1
- package/tools/systems/list-systems.d.mts +8 -0
- package/tools/systems/list-systems.d.mts.map +1 -1
- package/tools/systems/list-systems.d.ts +8 -0
- package/tools/systems/list-systems.d.ts.map +1 -1
- package/tools/systems/update-systems.d.mts +8 -0
- package/tools/systems/update-systems.d.mts.map +1 -1
- package/tools/systems/update-systems.d.ts +8 -0
- package/tools/systems/update-systems.d.ts.map +1 -1
- package/tools/testcases/create-testcases.d.mts +8 -0
- package/tools/testcases/create-testcases.d.mts.map +1 -1
- package/tools/testcases/create-testcases.d.ts +8 -0
- package/tools/testcases/create-testcases.d.ts.map +1 -1
- package/tools/testcases/create-testcases.js +0 -1
- package/tools/testcases/create-testcases.js.map +1 -1
- package/tools/testcases/create-testcases.mjs +0 -1
- package/tools/testcases/create-testcases.mjs.map +1 -1
- package/tools/testcases/delete-testcases.d.mts +8 -0
- package/tools/testcases/delete-testcases.d.mts.map +1 -1
- package/tools/testcases/delete-testcases.d.ts +8 -0
- package/tools/testcases/delete-testcases.d.ts.map +1 -1
- package/tools/testcases/get-testcases.d.mts +8 -0
- package/tools/testcases/get-testcases.d.mts.map +1 -1
- package/tools/testcases/get-testcases.d.ts +8 -0
- package/tools/testcases/get-testcases.d.ts.map +1 -1
- package/tools/testcases/list-testcases.d.mts +8 -0
- package/tools/testcases/list-testcases.d.mts.map +1 -1
- package/tools/testcases/list-testcases.d.ts +8 -0
- package/tools/testcases/list-testcases.d.ts.map +1 -1
- package/tools/testcases/update-testcases.d.mts +8 -0
- package/tools/testcases/update-testcases.d.mts.map +1 -1
- package/tools/testcases/update-testcases.d.ts +8 -0
- package/tools/testcases/update-testcases.d.ts.map +1 -1
- package/tools/testsets/create-testsets.d.mts +8 -0
- package/tools/testsets/create-testsets.d.mts.map +1 -1
- package/tools/testsets/create-testsets.d.ts +8 -0
- package/tools/testsets/create-testsets.d.ts.map +1 -1
- package/tools/testsets/create-testsets.js +7 -7
- package/tools/testsets/create-testsets.js.map +1 -1
- package/tools/testsets/create-testsets.mjs +7 -7
- package/tools/testsets/create-testsets.mjs.map +1 -1
- package/tools/testsets/delete-testsets.d.mts +8 -0
- package/tools/testsets/delete-testsets.d.mts.map +1 -1
- package/tools/testsets/delete-testsets.d.ts +8 -0
- package/tools/testsets/delete-testsets.d.ts.map +1 -1
- package/tools/testsets/get-testsets.d.mts +8 -0
- package/tools/testsets/get-testsets.d.mts.map +1 -1
- package/tools/testsets/get-testsets.d.ts +8 -0
- package/tools/testsets/get-testsets.d.ts.map +1 -1
- package/tools/testsets/list-testsets.d.mts +8 -0
- package/tools/testsets/list-testsets.d.mts.map +1 -1
- package/tools/testsets/list-testsets.d.ts +8 -0
- package/tools/testsets/list-testsets.d.ts.map +1 -1
- package/tools/testsets/update-testsets.d.mts +8 -0
- package/tools/testsets/update-testsets.d.mts.map +1 -1
- package/tools/testsets/update-testsets.d.ts +8 -0
- package/tools/testsets/update-testsets.d.ts.map +1 -1
- package/tools/testsets/update-testsets.js +7 -7
- package/tools/testsets/update-testsets.js.map +1 -1
- package/tools/testsets/update-testsets.mjs +7 -7
- package/tools/testsets/update-testsets.mjs.map +1 -1
- package/compat.test.d.mts +0 -2
- package/compat.test.d.mts.map +0 -1
- package/compat.test.d.ts +0 -2
- package/compat.test.d.ts.map +0 -1
- package/compat.test.js +0 -950
- package/compat.test.js.map +0 -1
- package/compat.test.mjs +0 -948
- package/compat.test.mjs.map +0 -1
- package/options.test.d.mts +0 -2
- package/options.test.d.mts.map +0 -1
- package/options.test.d.ts +0 -2
- package/options.test.d.ts.map +0 -1
- package/options.test.js +0 -154
- package/options.test.js.map +0 -1
- package/options.test.mjs +0 -152
- package/options.test.mjs.map +0 -1
- package/src/compat.test.ts +0 -1068
- package/src/options.test.ts +0 -193
- package/tools/runs/update-runs.d.mts.map +0 -1
- package/tools/runs/update-runs.d.ts.map +0 -1
- package/tools/runs/update-runs.js.map +0 -1
- package/tools/runs/update-runs.mjs +0 -37
- package/tools/runs/update-runs.mjs.map +0 -1
package/server.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
2
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
|
-
import { HandlerFunction } from "./tools.js";
|
|
3
|
+
import { Endpoint, HandlerFunction } from "./tools.js";
|
|
4
4
|
import { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
5
5
|
import Scorecard from 'scorecard-ai';
|
|
6
6
|
import { ClientCapabilities } from "./compat.js";
|
|
7
|
+
import { ParsedOptions } from "./options.js";
|
|
7
8
|
export { endpoints } from "./tools.js";
|
|
8
9
|
export declare const server: McpServer;
|
|
9
10
|
/**
|
|
@@ -19,6 +20,10 @@ export declare function init(params: {
|
|
|
19
20
|
}[];
|
|
20
21
|
capabilities?: Partial<ClientCapabilities>;
|
|
21
22
|
}): void;
|
|
23
|
+
/**
|
|
24
|
+
* Selects the tools to include in the MCP Server based on the provided options.
|
|
25
|
+
*/
|
|
26
|
+
export declare function selectTools(endpoints: Endpoint[], options: ParsedOptions): Endpoint[];
|
|
22
27
|
/**
|
|
23
28
|
* Runs the provided handler with the given client and arguments.
|
|
24
29
|
*/
|
package/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":"OAEO,EAAE,MAAM,EAAE,MAAM,2CAA2C;OAC3D,EAAE,SAAS,EAAE,MAAM,yCAAyC;OAC5D,EAAa,eAAe,
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":"OAEO,EAAE,MAAM,EAAE,MAAM,2CAA2C;OAC3D,EAAE,SAAS,EAAE,MAAM,yCAAyC;OAC5D,EAAE,QAAQ,EAAa,eAAe,EAAS;OAC/C,EAAiD,IAAI,EAAE,MAAM,oCAAoC;OACjG,SAAS,MAAM,cAAc;OAC7B,EAEL,kBAAkB,EAGnB;OAEM,EAAE,aAAa,EAAE;OACjB,EAAE,SAAS,EAAE;AAGpB,eAAO,MAAM,MAAM,WAUlB,CAAC;AAEF;;;GAGG;AACH,wBAAgB,IAAI,CAAC,MAAM,EAAE;IAC3B,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,SAAS,CAAC,EAAE;QAAE,IAAI,EAAE,IAAI,CAAC;QAAC,OAAO,EAAE,eAAe,CAAA;KAAE,EAAE,CAAC;IACvD,YAAY,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC;CAC5C,QAwBA;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,SAAS,EAAE,QAAQ,EAAE,EAAE,OAAO,EAAE,aAAa,cAkBxE;AAED;;GAEG;AACH,wBAAsB,cAAc,CAClC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,eAAe,EACxB,MAAM,EAAE,SAAS,EACjB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EACzC,oBAAoB,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC;;;;;GAenD;AAED,eAAO,MAAM,OAAO,GAAI,KAAK,MAAM,KAAG,MAAM,GAAG,SAO9C,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,KAAK,MAAM,KAAG,MAM5C,CAAC"}
|
package/server.js
CHANGED
|
@@ -6,18 +6,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.readEnvOrError = exports.readEnv = exports.server = exports.endpoints = void 0;
|
|
8
8
|
exports.init = init;
|
|
9
|
+
exports.selectTools = selectTools;
|
|
9
10
|
exports.executeHandler = executeHandler;
|
|
10
11
|
const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
11
12
|
const tools_1 = require("./tools.js");
|
|
12
13
|
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
13
14
|
const scorecard_ai_1 = __importDefault(require("scorecard-ai"));
|
|
14
15
|
const compat_1 = require("./compat.js");
|
|
16
|
+
const dynamic_tools_1 = require("./dynamic-tools.js");
|
|
15
17
|
var tools_2 = require("./tools.js");
|
|
16
18
|
Object.defineProperty(exports, "endpoints", { enumerable: true, get: function () { return tools_2.endpoints; } });
|
|
17
19
|
// Create server instance
|
|
18
20
|
exports.server = new mcp_js_1.McpServer({
|
|
19
21
|
name: 'scorecard_ai_api',
|
|
20
|
-
version: '1.0.0-alpha.
|
|
22
|
+
version: '1.0.0-alpha.8',
|
|
21
23
|
}, {
|
|
22
24
|
capabilities: {
|
|
23
25
|
tools: {},
|
|
@@ -31,7 +33,7 @@ function init(params) {
|
|
|
31
33
|
const server = params.server instanceof mcp_js_1.McpServer ? params.server.server : params.server;
|
|
32
34
|
const providedEndpoints = params.endpoints || tools_1.endpoints;
|
|
33
35
|
const endpointMap = Object.fromEntries(providedEndpoints.map((endpoint) => [endpoint.tool.name, endpoint]));
|
|
34
|
-
const client = params.client || new scorecard_ai_1.default({});
|
|
36
|
+
const client = params.client || new scorecard_ai_1.default({ environment: ((0, exports.readEnv)('SCORECARD_ENVIRONMENT') || undefined) });
|
|
35
37
|
server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => {
|
|
36
38
|
return {
|
|
37
39
|
tools: providedEndpoints.map((endpoint) => endpoint.tool),
|
|
@@ -46,6 +48,23 @@ function init(params) {
|
|
|
46
48
|
return executeHandler(endpoint.tool, endpoint.handler, client, args, params.capabilities);
|
|
47
49
|
});
|
|
48
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Selects the tools to include in the MCP Server based on the provided options.
|
|
53
|
+
*/
|
|
54
|
+
function selectTools(endpoints, options) {
|
|
55
|
+
const filteredEndpoints = (0, tools_1.query)(options.filters, endpoints);
|
|
56
|
+
const includedTools = filteredEndpoints;
|
|
57
|
+
if (options.includeAllTools && includedTools.length === 0) {
|
|
58
|
+
includedTools.push(...endpoints);
|
|
59
|
+
}
|
|
60
|
+
if (options.includeDynamicTools) {
|
|
61
|
+
includedTools.push(...(0, dynamic_tools_1.dynamicTools)(endpoints));
|
|
62
|
+
}
|
|
63
|
+
if (includedTools.length === 0) {
|
|
64
|
+
includedTools.push(...endpoints);
|
|
65
|
+
}
|
|
66
|
+
return (0, compat_1.applyCompatibilityTransformations)(includedTools, options.capabilities);
|
|
67
|
+
}
|
|
49
68
|
/**
|
|
50
69
|
* Runs the provided handler with the given client and arguments.
|
|
51
70
|
*/
|
package/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;;;;
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;;;;AAkCtF,oBA6BC;AAKD,kCAkBC;AAKD,wCAoBC;AA5GD,oEAAoE;AACpE,sCAAsE;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|
|
2
2
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
|
-
import { endpoints } from "./tools.mjs";
|
|
3
|
+
import { endpoints, query } from "./tools.mjs";
|
|
4
4
|
import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
5
5
|
import Scorecard from 'scorecard-ai';
|
|
6
|
-
import { defaultClientCapabilities, parseEmbeddedJSON } from "./compat.mjs";
|
|
6
|
+
import { applyCompatibilityTransformations, defaultClientCapabilities, parseEmbeddedJSON, } from "./compat.mjs";
|
|
7
|
+
import { dynamicTools } from "./dynamic-tools.mjs";
|
|
7
8
|
export { endpoints } from "./tools.mjs";
|
|
8
9
|
// Create server instance
|
|
9
10
|
export const server = new McpServer({
|
|
10
11
|
name: 'scorecard_ai_api',
|
|
11
|
-
version: '1.0.0-alpha.
|
|
12
|
+
version: '1.0.0-alpha.8',
|
|
12
13
|
}, {
|
|
13
14
|
capabilities: {
|
|
14
15
|
tools: {},
|
|
@@ -22,7 +23,7 @@ export function init(params) {
|
|
|
22
23
|
const server = params.server instanceof McpServer ? params.server.server : params.server;
|
|
23
24
|
const providedEndpoints = params.endpoints || endpoints;
|
|
24
25
|
const endpointMap = Object.fromEntries(providedEndpoints.map((endpoint) => [endpoint.tool.name, endpoint]));
|
|
25
|
-
const client = params.client || new Scorecard({});
|
|
26
|
+
const client = params.client || new Scorecard({ environment: (readEnv('SCORECARD_ENVIRONMENT') || undefined) });
|
|
26
27
|
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
27
28
|
return {
|
|
28
29
|
tools: providedEndpoints.map((endpoint) => endpoint.tool),
|
|
@@ -37,6 +38,23 @@ export function init(params) {
|
|
|
37
38
|
return executeHandler(endpoint.tool, endpoint.handler, client, args, params.capabilities);
|
|
38
39
|
});
|
|
39
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Selects the tools to include in the MCP Server based on the provided options.
|
|
43
|
+
*/
|
|
44
|
+
export function selectTools(endpoints, options) {
|
|
45
|
+
const filteredEndpoints = query(options.filters, endpoints);
|
|
46
|
+
const includedTools = filteredEndpoints;
|
|
47
|
+
if (options.includeAllTools && includedTools.length === 0) {
|
|
48
|
+
includedTools.push(...endpoints);
|
|
49
|
+
}
|
|
50
|
+
if (options.includeDynamicTools) {
|
|
51
|
+
includedTools.push(...dynamicTools(endpoints));
|
|
52
|
+
}
|
|
53
|
+
if (includedTools.length === 0) {
|
|
54
|
+
includedTools.push(...endpoints);
|
|
55
|
+
}
|
|
56
|
+
return applyCompatibilityTransformations(includedTools, options.capabilities);
|
|
57
|
+
}
|
|
40
58
|
/**
|
|
41
59
|
* Runs the provided handler with the given client and arguments.
|
|
42
60
|
*/
|
package/server.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.mjs","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAG/E,EAAE,SAAS,EAAE,MAAM,yCAAyC;OAC5D,
|
|
1
|
+
{"version":3,"file":"server.mjs","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAG/E,EAAE,SAAS,EAAE,MAAM,yCAAyC;OAC5D,EAAY,SAAS,EAAmB,KAAK,EAAE;OAC/C,EAAE,qBAAqB,EAAE,sBAAsB,EAAQ,MAAM,oCAAoC;OACjG,SAAS,MAAM,cAAc;OAC7B,EACL,iCAAiC,EAEjC,yBAAyB,EACzB,iBAAiB,GAClB;OACM,EAAE,YAAY,EAAE;OAEhB,EAAE,SAAS,EAAE;AAEpB,yBAAyB;AACzB,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,SAAS,CACjC;IACE,IAAI,EAAE,kBAAkB;IACxB,OAAO,EAAE,eAAe;CACzB,EACD;IACE,YAAY,EAAE;QACZ,KAAK,EAAE,EAAE;KACV;CACF,CACF,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,IAAI,CAAC,MAKpB;IACC,MAAM,MAAM,GAAG,MAA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AACJ,CAAC;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,GAAW,EAAsB,EAAE;IACzD,IAAI,OAAQ,UAAkB,CAAC,OAAO,KAAK,WAAW,EAAE,CAAC;QACvD,OAAQ,UAAkB,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC;IACxD,CAAC;SAAM,IAAI,OAAQ,UAAkB,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;QAC3D,OAAQ,UAAkB,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC;IAC1D,CAAC;IACD,OAAO;AACT,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,GAAW,EAAU,EAAE;IACpD,IAAI,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAC5B,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,wBAAwB,GAAG,aAAa,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC"}
|
package/src/compat.ts
CHANGED
|
@@ -148,7 +148,11 @@ export function removeTopLevelUnions(tool: Tool): Tool[] {
|
|
|
148
148
|
});
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
function findUsedDefs(
|
|
151
|
+
function findUsedDefs(
|
|
152
|
+
schema: JSONSchema,
|
|
153
|
+
defs: Record<string, JSONSchema>,
|
|
154
|
+
visited: Set<string> = new Set(),
|
|
155
|
+
): Record<string, JSONSchema> {
|
|
152
156
|
const usedDefs: Record<string, JSONSchema> = {};
|
|
153
157
|
|
|
154
158
|
if (typeof schema !== 'object' || schema === null) {
|
|
@@ -160,9 +164,11 @@ function findUsedDefs(schema: JSONSchema, defs: Record<string, JSONSchema>): Rec
|
|
|
160
164
|
if (refParts[0] === '#' && refParts[1] === '$defs' && refParts[2]) {
|
|
161
165
|
const defName = refParts[2];
|
|
162
166
|
const def = defs[defName];
|
|
163
|
-
if (def) {
|
|
167
|
+
if (def && !visited.has(schema.$ref)) {
|
|
164
168
|
usedDefs[defName] = def;
|
|
165
|
-
|
|
169
|
+
visited.add(schema.$ref);
|
|
170
|
+
Object.assign(usedDefs, findUsedDefs(def, defs, visited));
|
|
171
|
+
visited.delete(schema.$ref);
|
|
166
172
|
}
|
|
167
173
|
}
|
|
168
174
|
return usedDefs;
|
|
@@ -170,13 +176,16 @@ function findUsedDefs(schema: JSONSchema, defs: Record<string, JSONSchema>): Rec
|
|
|
170
176
|
|
|
171
177
|
for (const key in schema) {
|
|
172
178
|
if (key !== '$defs' && typeof schema[key] === 'object' && schema[key] !== null) {
|
|
173
|
-
Object.assign(usedDefs, findUsedDefs(schema[key] as JSONSchema, defs));
|
|
179
|
+
Object.assign(usedDefs, findUsedDefs(schema[key] as JSONSchema, defs, visited));
|
|
174
180
|
}
|
|
175
181
|
}
|
|
176
182
|
|
|
177
183
|
return usedDefs;
|
|
178
184
|
}
|
|
179
185
|
|
|
186
|
+
// Export for testing
|
|
187
|
+
export { findUsedDefs };
|
|
188
|
+
|
|
180
189
|
/**
|
|
181
190
|
* Inlines all $refs in a schema, eliminating $defs.
|
|
182
191
|
* If a circular reference is detected, the circular property is removed.
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import Scorecard from 'scorecard-ai';
|
|
2
|
+
import { Endpoint } from './tools';
|
|
3
|
+
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { Cabidela } from '@cloudflare/cabidela';
|
|
6
|
+
|
|
7
|
+
function zodToInputSchema(schema: z.ZodSchema) {
|
|
8
|
+
return {
|
|
9
|
+
type: 'object' as const,
|
|
10
|
+
...(zodToJsonSchema(schema) as any),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A list of tools that expose all the endpoints in the API dynamically.
|
|
16
|
+
*
|
|
17
|
+
* Instead of exposing every endpoint as it's own tool, which uses up too many tokens for LLMs to use at once,
|
|
18
|
+
* we expose a single tool that can be used to search for endpoints by name, resource, operation, or tag, and then
|
|
19
|
+
* a generic endpoint that can be used to invoke any endpoint with the provided arguments.
|
|
20
|
+
*
|
|
21
|
+
* @param endpoints - The endpoints to include in the list.
|
|
22
|
+
*/
|
|
23
|
+
export function dynamicTools(endpoints: Endpoint[]): Endpoint[] {
|
|
24
|
+
const listEndpointsSchema = z.object({
|
|
25
|
+
search_query: z
|
|
26
|
+
.string()
|
|
27
|
+
.optional()
|
|
28
|
+
.describe(
|
|
29
|
+
'An optional search query to filter the endpoints by. Provide a partial name, resource, operation, or tag to filter the endpoints returned.',
|
|
30
|
+
),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const listEndpointsTool = {
|
|
34
|
+
metadata: {
|
|
35
|
+
resource: 'dynamic_tools',
|
|
36
|
+
operation: 'read' as const,
|
|
37
|
+
tags: [],
|
|
38
|
+
},
|
|
39
|
+
tool: {
|
|
40
|
+
name: 'list_api_endpoints',
|
|
41
|
+
description: 'List or search for all endpoints in the Scorecard TypeScript API',
|
|
42
|
+
inputSchema: zodToInputSchema(listEndpointsSchema),
|
|
43
|
+
},
|
|
44
|
+
handler: async (client: Scorecard, args: Record<string, unknown> | undefined) => {
|
|
45
|
+
const query = args && listEndpointsSchema.parse(args).search_query?.trim();
|
|
46
|
+
|
|
47
|
+
const filteredEndpoints =
|
|
48
|
+
query && query.length > 0 ?
|
|
49
|
+
endpoints.filter((endpoint) => {
|
|
50
|
+
const fieldsToMatch = [
|
|
51
|
+
endpoint.tool.name,
|
|
52
|
+
endpoint.tool.description,
|
|
53
|
+
endpoint.metadata.resource,
|
|
54
|
+
endpoint.metadata.operation,
|
|
55
|
+
...endpoint.metadata.tags,
|
|
56
|
+
];
|
|
57
|
+
return fieldsToMatch.some((field) => field && field.toLowerCase().includes(query.toLowerCase()));
|
|
58
|
+
})
|
|
59
|
+
: endpoints;
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
tools: filteredEndpoints.map(({ tool, metadata }) => ({
|
|
63
|
+
name: tool.name,
|
|
64
|
+
description: tool.description,
|
|
65
|
+
resource: metadata.resource,
|
|
66
|
+
operation: metadata.operation,
|
|
67
|
+
tags: metadata.tags,
|
|
68
|
+
})),
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const getEndpointSchema = z.object({
|
|
74
|
+
endpoint: z.string().describe('The name of the endpoint to get the schema for.'),
|
|
75
|
+
});
|
|
76
|
+
const getEndpointTool = {
|
|
77
|
+
metadata: {
|
|
78
|
+
resource: 'dynamic_tools',
|
|
79
|
+
operation: 'read' as const,
|
|
80
|
+
tags: [],
|
|
81
|
+
},
|
|
82
|
+
tool: {
|
|
83
|
+
name: 'get_api_endpoint_schema',
|
|
84
|
+
description:
|
|
85
|
+
'Get the schema for an endpoint in the Scorecard TypeScript API. You can use the schema returned by this tool to invoke an endpoint with the `invoke_api_endpoint` tool.',
|
|
86
|
+
inputSchema: zodToInputSchema(getEndpointSchema),
|
|
87
|
+
},
|
|
88
|
+
handler: async (client: Scorecard, args: Record<string, unknown> | undefined) => {
|
|
89
|
+
if (!args) {
|
|
90
|
+
throw new Error('No endpoint provided');
|
|
91
|
+
}
|
|
92
|
+
const endpointName = getEndpointSchema.parse(args).endpoint;
|
|
93
|
+
|
|
94
|
+
const endpoint = endpoints.find((e) => e.tool.name === endpointName);
|
|
95
|
+
if (!endpoint) {
|
|
96
|
+
throw new Error(`Endpoint ${endpointName} not found`);
|
|
97
|
+
}
|
|
98
|
+
return endpoint.tool;
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const invokeEndpointSchema = z.object({
|
|
103
|
+
endpoint_name: z.string().describe('The name of the endpoint to invoke.'),
|
|
104
|
+
args: z
|
|
105
|
+
.record(z.string(), z.any())
|
|
106
|
+
.describe(
|
|
107
|
+
'The arguments to pass to the endpoint. This must match the schema returned by the `get_api_endpoint_schema` tool.',
|
|
108
|
+
),
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const invokeEndpointTool = {
|
|
112
|
+
metadata: {
|
|
113
|
+
resource: 'dynamic_tools',
|
|
114
|
+
operation: 'write' as const,
|
|
115
|
+
tags: [],
|
|
116
|
+
},
|
|
117
|
+
tool: {
|
|
118
|
+
name: 'invoke_api_endpoint',
|
|
119
|
+
description:
|
|
120
|
+
'Invoke an endpoint in the Scorecard TypeScript API. Note: use the `list_api_endpoints` tool to get the list of endpoints and `get_api_endpoint_schema` tool to get the schema for an endpoint.',
|
|
121
|
+
inputSchema: zodToInputSchema(invokeEndpointSchema),
|
|
122
|
+
},
|
|
123
|
+
handler: async (client: Scorecard, args: Record<string, unknown> | undefined) => {
|
|
124
|
+
if (!args) {
|
|
125
|
+
throw new Error('No endpoint provided');
|
|
126
|
+
}
|
|
127
|
+
const { success, data, error } = invokeEndpointSchema.safeParse(args);
|
|
128
|
+
if (!success) {
|
|
129
|
+
throw new Error(`Invalid arguments for endpoint. ${error?.format()}`);
|
|
130
|
+
}
|
|
131
|
+
const { endpoint_name, args: endpointArgs } = data;
|
|
132
|
+
|
|
133
|
+
const endpoint = endpoints.find((e) => e.tool.name === endpoint_name);
|
|
134
|
+
if (!endpoint) {
|
|
135
|
+
throw new Error(
|
|
136
|
+
`Endpoint ${endpoint_name} not found. Use the \`list_api_endpoints\` tool to get the list of available endpoints.`,
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
try {
|
|
141
|
+
// Try to validate the arguments for a better error message
|
|
142
|
+
const cabidela = new Cabidela(endpoint.tool.inputSchema, { fullErrors: true });
|
|
143
|
+
cabidela.validate(endpointArgs);
|
|
144
|
+
} catch (error) {
|
|
145
|
+
throw new Error(`Invalid arguments for endpoint ${endpoint_name}:\n${error}`);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return endpoint.handler(client, endpointArgs);
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
return [getEndpointTool, listEndpointsTool, invokeEndpointTool];
|
|
153
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,28 +1,24 @@
|
|
|
1
1
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
2
|
-
import { init, server } from './server';
|
|
3
|
-
import { Endpoint, endpoints
|
|
4
|
-
import {
|
|
5
|
-
import { parseOptions } from './options';
|
|
2
|
+
import { init, selectTools, server } from './server';
|
|
3
|
+
import { Endpoint, endpoints } from './tools';
|
|
4
|
+
import { ParsedOptions, parseOptions } from './options';
|
|
6
5
|
|
|
7
6
|
async function main() {
|
|
8
|
-
const
|
|
7
|
+
const options = parseOptionsOrError();
|
|
9
8
|
|
|
10
|
-
if (list) {
|
|
9
|
+
if (options.list) {
|
|
11
10
|
listAllTools();
|
|
12
11
|
return;
|
|
13
12
|
}
|
|
14
13
|
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
// Apply compatibility transformations
|
|
18
|
-
const transformedEndpoints = applyCompatibilityTransformations(filteredEndpoints, capabilities);
|
|
14
|
+
const includedTools = selectToolsOrError(endpoints, options);
|
|
19
15
|
|
|
20
16
|
console.error(
|
|
21
|
-
`MCP Server starting with ${
|
|
22
|
-
|
|
17
|
+
`MCP Server starting with ${includedTools.length} tools:`,
|
|
18
|
+
includedTools.map((e) => e.tool.name),
|
|
23
19
|
);
|
|
24
20
|
|
|
25
|
-
init({ server, endpoints:
|
|
21
|
+
init({ server, endpoints: includedTools });
|
|
26
22
|
|
|
27
23
|
const transport = new StdioServerTransport();
|
|
28
24
|
await server.connect(transport);
|
|
@@ -45,14 +41,14 @@ function parseOptionsOrError() {
|
|
|
45
41
|
}
|
|
46
42
|
}
|
|
47
43
|
|
|
48
|
-
function
|
|
44
|
+
function selectToolsOrError(endpoints: Endpoint[], options: ParsedOptions) {
|
|
49
45
|
try {
|
|
50
|
-
const
|
|
51
|
-
if (
|
|
46
|
+
const includedTools = selectTools(endpoints, options);
|
|
47
|
+
if (includedTools.length === 0) {
|
|
52
48
|
console.error('No tools match the provided filters.');
|
|
53
49
|
process.exit(1);
|
|
54
50
|
}
|
|
55
|
-
return
|
|
51
|
+
return includedTools;
|
|
56
52
|
} catch (error) {
|
|
57
53
|
if (error instanceof Error) {
|
|
58
54
|
console.error('Error filtering tools:', error.message);
|
|
@@ -65,10 +61,10 @@ function filterEndpointsOrError(filters: Filter[], endpoints: Endpoint[]) {
|
|
|
65
61
|
|
|
66
62
|
function listAllTools() {
|
|
67
63
|
if (endpoints.length === 0) {
|
|
68
|
-
console.
|
|
64
|
+
console.log('No tools available.');
|
|
69
65
|
return;
|
|
70
66
|
}
|
|
71
|
-
console.
|
|
67
|
+
console.log('Available tools:\n');
|
|
72
68
|
|
|
73
69
|
// Group endpoints by resource
|
|
74
70
|
const resourceGroups = new Map<string, typeof endpoints>();
|
|
@@ -86,7 +82,7 @@ function listAllTools() {
|
|
|
86
82
|
|
|
87
83
|
// Display hierarchically by resource
|
|
88
84
|
for (const resource of sortedResources) {
|
|
89
|
-
console.
|
|
85
|
+
console.log(`Resource: ${resource}`);
|
|
90
86
|
|
|
91
87
|
const resourceEndpoints = resourceGroups.get(resource)!;
|
|
92
88
|
// Sort endpoints by tool name
|
|
@@ -98,9 +94,9 @@ function listAllTools() {
|
|
|
98
94
|
metadata: { operation, tags },
|
|
99
95
|
} = endpoint;
|
|
100
96
|
|
|
101
|
-
console.
|
|
102
|
-
console.
|
|
97
|
+
console.log(` - ${tool.name} (${operation}) ${tags.length > 0 ? `tags: ${tags.join(', ')}` : ''}`);
|
|
98
|
+
console.log(` Description: ${tool.description}`);
|
|
103
99
|
}
|
|
104
|
-
console.
|
|
100
|
+
console.log('');
|
|
105
101
|
}
|
|
106
102
|
}
|
package/src/options.ts
CHANGED
|
@@ -44,6 +44,8 @@ const CLIENT_PRESETS: Record<ClientType, ClientCapabilities> = {
|
|
|
44
44
|
};
|
|
45
45
|
|
|
46
46
|
export interface ParsedOptions {
|
|
47
|
+
includeDynamicTools: boolean | undefined;
|
|
48
|
+
includeAllTools: boolean | undefined;
|
|
47
49
|
filters: Filter[];
|
|
48
50
|
capabilities: ClientCapabilities;
|
|
49
51
|
list: boolean;
|
|
@@ -80,6 +82,18 @@ function parseCapabilityValue(cap: string): { name: Capability; value?: number }
|
|
|
80
82
|
|
|
81
83
|
export function parseOptions(): ParsedOptions {
|
|
82
84
|
const opts = yargs(hideBin(process.argv))
|
|
85
|
+
.option('tools', {
|
|
86
|
+
type: 'string',
|
|
87
|
+
array: true,
|
|
88
|
+
choices: ['dynamic', 'all'],
|
|
89
|
+
description: 'Use dynamic tools or all tools',
|
|
90
|
+
})
|
|
91
|
+
.option('no-tools', {
|
|
92
|
+
type: 'string',
|
|
93
|
+
array: true,
|
|
94
|
+
choices: ['dynamic', 'all'],
|
|
95
|
+
description: 'Do not use any dynamic or all tools',
|
|
96
|
+
})
|
|
83
97
|
.option('tool', {
|
|
84
98
|
type: 'string',
|
|
85
99
|
array: true,
|
|
@@ -262,7 +276,15 @@ export function parseOptions(): ParsedOptions {
|
|
|
262
276
|
}
|
|
263
277
|
}
|
|
264
278
|
|
|
279
|
+
const explicitTools = Boolean(argv.tools || argv.noTools);
|
|
280
|
+
const includeDynamicTools =
|
|
281
|
+
explicitTools ? argv.tools?.includes('dynamic') && !argv.noTools?.includes('dynamic') : undefined;
|
|
282
|
+
const includeAllTools =
|
|
283
|
+
explicitTools ? argv.tools?.includes('all') && !argv.noTools?.includes('all') : undefined;
|
|
284
|
+
|
|
265
285
|
return {
|
|
286
|
+
includeDynamicTools,
|
|
287
|
+
includeAllTools,
|
|
266
288
|
filters,
|
|
267
289
|
capabilities: clientCapabilities,
|
|
268
290
|
list: argv.list || false,
|
package/src/server.ts
CHANGED
|
@@ -2,17 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
4
4
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
5
|
-
import { endpoints, HandlerFunction } from './tools';
|
|
5
|
+
import { Endpoint, endpoints, HandlerFunction, query } from './tools';
|
|
6
6
|
import { CallToolRequestSchema, ListToolsRequestSchema, Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
7
7
|
import Scorecard from 'scorecard-ai';
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
applyCompatibilityTransformations,
|
|
10
|
+
ClientCapabilities,
|
|
11
|
+
defaultClientCapabilities,
|
|
12
|
+
parseEmbeddedJSON,
|
|
13
|
+
} from './compat';
|
|
14
|
+
import { dynamicTools } from './dynamic-tools';
|
|
15
|
+
import { ParsedOptions } from './options';
|
|
9
16
|
export { endpoints } from './tools';
|
|
10
17
|
|
|
11
18
|
// Create server instance
|
|
12
19
|
export const server = new McpServer(
|
|
13
20
|
{
|
|
14
21
|
name: 'scorecard_ai_api',
|
|
15
|
-
version: '1.0.0-alpha.
|
|
22
|
+
version: '1.0.0-alpha.8',
|
|
16
23
|
},
|
|
17
24
|
{
|
|
18
25
|
capabilities: {
|
|
@@ -36,7 +43,8 @@ export function init(params: {
|
|
|
36
43
|
|
|
37
44
|
const endpointMap = Object.fromEntries(providedEndpoints.map((endpoint) => [endpoint.tool.name, endpoint]));
|
|
38
45
|
|
|
39
|
-
const client =
|
|
46
|
+
const client =
|
|
47
|
+
params.client || new Scorecard({ environment: (readEnv('SCORECARD_ENVIRONMENT') || undefined) as any });
|
|
40
48
|
|
|
41
49
|
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
42
50
|
return {
|
|
@@ -55,6 +63,29 @@ export function init(params: {
|
|
|
55
63
|
});
|
|
56
64
|
}
|
|
57
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Selects the tools to include in the MCP Server based on the provided options.
|
|
68
|
+
*/
|
|
69
|
+
export function selectTools(endpoints: Endpoint[], options: ParsedOptions) {
|
|
70
|
+
const filteredEndpoints = query(options.filters, endpoints);
|
|
71
|
+
|
|
72
|
+
const includedTools = filteredEndpoints;
|
|
73
|
+
|
|
74
|
+
if (options.includeAllTools && includedTools.length === 0) {
|
|
75
|
+
includedTools.push(...endpoints);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (options.includeDynamicTools) {
|
|
79
|
+
includedTools.push(...dynamicTools(endpoints));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (includedTools.length === 0) {
|
|
83
|
+
includedTools.push(...endpoints);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return applyCompatibilityTransformations(includedTools, options.capabilities);
|
|
87
|
+
}
|
|
88
|
+
|
|
58
89
|
/**
|
|
59
90
|
* Runs the provided handler with the given client and arguments.
|
|
60
91
|
*/
|
package/src/tools/index.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import Scorecard from 'scorecard-ai';
|
|
4
4
|
import { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
5
5
|
|
|
6
|
+
import create_projects from './projects/create-projects';
|
|
6
7
|
import list_projects from './projects/list-projects';
|
|
7
8
|
import create_testsets from './testsets/create-testsets';
|
|
8
9
|
import update_testsets from './testsets/update-testsets';
|
|
@@ -15,8 +16,8 @@ import list_testcases from './testcases/list-testcases';
|
|
|
15
16
|
import delete_testcases from './testcases/delete-testcases';
|
|
16
17
|
import get_testcases from './testcases/get-testcases';
|
|
17
18
|
import create_runs from './runs/create-runs';
|
|
18
|
-
import update_runs from './runs/update-runs';
|
|
19
19
|
import create_records from './records/create-records';
|
|
20
|
+
import upsert_scores from './scores/upsert-scores';
|
|
20
21
|
import create_systems from './systems/create-systems';
|
|
21
22
|
import update_systems from './systems/update-systems';
|
|
22
23
|
import list_systems from './systems/list-systems';
|
|
@@ -46,6 +47,7 @@ function addEndpoint(endpoint: Endpoint) {
|
|
|
46
47
|
endpoints.push(endpoint);
|
|
47
48
|
}
|
|
48
49
|
|
|
50
|
+
addEndpoint(create_projects);
|
|
49
51
|
addEndpoint(list_projects);
|
|
50
52
|
addEndpoint(create_testsets);
|
|
51
53
|
addEndpoint(update_testsets);
|
|
@@ -58,8 +60,8 @@ addEndpoint(list_testcases);
|
|
|
58
60
|
addEndpoint(delete_testcases);
|
|
59
61
|
addEndpoint(get_testcases);
|
|
60
62
|
addEndpoint(create_runs);
|
|
61
|
-
addEndpoint(update_runs);
|
|
62
63
|
addEndpoint(create_records);
|
|
64
|
+
addEndpoint(upsert_scores);
|
|
63
65
|
addEndpoint(create_systems);
|
|
64
66
|
addEndpoint(update_systems);
|
|
65
67
|
addEndpoint(list_systems);
|
|
@@ -76,11 +78,7 @@ export type Filter = {
|
|
|
76
78
|
};
|
|
77
79
|
|
|
78
80
|
export function query(filters: Filter[], endpoints: Endpoint[]): Endpoint[] {
|
|
79
|
-
|
|
80
|
-
return endpoints;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const allExcludes = filters.every((filter) => filter.op === 'exclude');
|
|
81
|
+
const allExcludes = filters.length > 0 && filters.every((filter) => filter.op === 'exclude');
|
|
84
82
|
const unmatchedFilters = new Set(filters);
|
|
85
83
|
|
|
86
84
|
const filtered = endpoints.filter((endpoint: Endpoint) => {
|
|
@@ -5,40 +5,32 @@ import type { Metadata } from '../';
|
|
|
5
5
|
import Scorecard from 'scorecard-ai';
|
|
6
6
|
|
|
7
7
|
export const metadata: Metadata = {
|
|
8
|
-
resource: '
|
|
8
|
+
resource: 'projects',
|
|
9
9
|
operation: 'write',
|
|
10
10
|
tags: [],
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
export const tool: Tool = {
|
|
14
|
-
name: '
|
|
15
|
-
description: '
|
|
14
|
+
name: 'create_projects',
|
|
15
|
+
description: 'Create a new Project.',
|
|
16
16
|
inputSchema: {
|
|
17
17
|
type: 'object',
|
|
18
18
|
properties: {
|
|
19
|
-
|
|
19
|
+
description: {
|
|
20
20
|
type: 'string',
|
|
21
|
+
description: 'The description of the Project.',
|
|
21
22
|
},
|
|
22
|
-
|
|
23
|
+
name: {
|
|
23
24
|
type: 'string',
|
|
24
|
-
description: 'The
|
|
25
|
-
enum: [
|
|
26
|
-
'pending',
|
|
27
|
-
'awaiting_execution',
|
|
28
|
-
'running_execution',
|
|
29
|
-
'awaiting_scoring',
|
|
30
|
-
'running_scoring',
|
|
31
|
-
'awaiting_human_scoring',
|
|
32
|
-
'completed',
|
|
33
|
-
],
|
|
25
|
+
description: 'The name of the Project.',
|
|
34
26
|
},
|
|
35
27
|
},
|
|
36
28
|
},
|
|
37
29
|
};
|
|
38
30
|
|
|
39
31
|
export const handler = (client: Scorecard, args: Record<string, unknown> | undefined) => {
|
|
40
|
-
const
|
|
41
|
-
return client.
|
|
32
|
+
const body = args as any;
|
|
33
|
+
return client.projects.create(body);
|
|
42
34
|
};
|
|
43
35
|
|
|
44
36
|
export default { metadata, tool, handler };
|