scorecard-ai-mcp 1.0.0-alpha.4

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.
Files changed (274) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +228 -0
  3. package/compat.d.mts +53 -0
  4. package/compat.d.mts.map +1 -0
  5. package/compat.d.ts +53 -0
  6. package/compat.d.ts.map +1 -0
  7. package/compat.js +351 -0
  8. package/compat.js.map +1 -0
  9. package/compat.mjs +338 -0
  10. package/compat.mjs.map +1 -0
  11. package/compat.test.d.mts +2 -0
  12. package/compat.test.d.mts.map +1 -0
  13. package/compat.test.d.ts +2 -0
  14. package/compat.test.d.ts.map +1 -0
  15. package/compat.test.js +950 -0
  16. package/compat.test.js.map +1 -0
  17. package/compat.test.mjs +948 -0
  18. package/compat.test.mjs.map +1 -0
  19. package/index.d.mts +2 -0
  20. package/index.d.mts.map +1 -0
  21. package/index.d.ts +2 -0
  22. package/index.d.ts.map +1 -0
  23. package/index.js +89 -0
  24. package/index.js.map +1 -0
  25. package/index.mjs +86 -0
  26. package/index.mjs.map +1 -0
  27. package/options.d.mts +9 -0
  28. package/options.d.mts.map +1 -0
  29. package/options.d.ts +9 -0
  30. package/options.d.ts.map +1 -0
  31. package/options.js +321 -0
  32. package/options.js.map +1 -0
  33. package/options.mjs +314 -0
  34. package/options.mjs.map +1 -0
  35. package/options.test.d.mts +2 -0
  36. package/options.test.d.mts.map +1 -0
  37. package/options.test.d.ts +2 -0
  38. package/options.test.d.ts.map +1 -0
  39. package/options.test.js +154 -0
  40. package/options.test.js.map +1 -0
  41. package/options.test.mjs +152 -0
  42. package/options.test.mjs.map +1 -0
  43. package/package.json +129 -0
  44. package/server.d.mts +33 -0
  45. package/server.d.mts.map +1 -0
  46. package/server.d.ts +33 -0
  47. package/server.d.ts.map +1 -0
  48. package/server.js +85 -0
  49. package/server.js.map +1 -0
  50. package/server.mjs +74 -0
  51. package/server.mjs.map +1 -0
  52. package/src/compat.test.ts +1068 -0
  53. package/src/compat.ts +437 -0
  54. package/src/index.ts +106 -0
  55. package/src/options.test.ts +193 -0
  56. package/src/options.ts +339 -0
  57. package/src/server.ts +98 -0
  58. package/src/tools/index.ts +129 -0
  59. package/src/tools/projects/list-projects.ts +39 -0
  60. package/src/tools/records/create-records.ts +47 -0
  61. package/src/tools/runs/create-runs.ts +46 -0
  62. package/src/tools/runs/update-runs.ts +44 -0
  63. package/src/tools/system-configs/create-system-configs.ts +59 -0
  64. package/src/tools/system-configs/get-system-configs.ts +34 -0
  65. package/src/tools/system-configs/list-system-configs.ts +42 -0
  66. package/src/tools/systems/create-systems.ts +52 -0
  67. package/src/tools/systems/delete-systems.ts +31 -0
  68. package/src/tools/systems/get-systems.ts +31 -0
  69. package/src/tools/systems/list-systems.ts +41 -0
  70. package/src/tools/systems/update-systems.ts +52 -0
  71. package/src/tools/testcases/create-testcases.ts +47 -0
  72. package/src/tools/testcases/delete-testcases.ts +35 -0
  73. package/src/tools/testcases/get-testcases.ts +31 -0
  74. package/src/tools/testcases/list-testcases.ts +41 -0
  75. package/src/tools/testcases/update-testcases.ts +35 -0
  76. package/src/tools/testsets/create-testsets.ts +73 -0
  77. package/src/tools/testsets/delete-testsets.ts +31 -0
  78. package/src/tools/testsets/get-testsets.ts +31 -0
  79. package/src/tools/testsets/list-testsets.ts +41 -0
  80. package/src/tools/testsets/update-testsets.ts +73 -0
  81. package/src/tools.ts +1 -0
  82. package/src/tsconfig.json +11 -0
  83. package/tools/index.d.mts +21 -0
  84. package/tools/index.d.mts.map +1 -0
  85. package/tools/index.d.ts +21 -0
  86. package/tools/index.d.ts.map +1 -0
  87. package/tools/index.js +99 -0
  88. package/tools/index.js.map +1 -0
  89. package/tools/index.mjs +92 -0
  90. package/tools/index.mjs.map +1 -0
  91. package/tools/projects/list-projects.d.mts +24 -0
  92. package/tools/projects/list-projects.d.mts.map +1 -0
  93. package/tools/projects/list-projects.d.ts +24 -0
  94. package/tools/projects/list-projects.d.ts.map +1 -0
  95. package/tools/projects/list-projects.js +33 -0
  96. package/tools/projects/list-projects.js.map +1 -0
  97. package/tools/projects/list-projects.mjs +29 -0
  98. package/tools/projects/list-projects.mjs.map +1 -0
  99. package/tools/records/create-records.d.mts +24 -0
  100. package/tools/records/create-records.d.mts.map +1 -0
  101. package/tools/records/create-records.d.ts +24 -0
  102. package/tools/records/create-records.d.ts.map +1 -0
  103. package/tools/records/create-records.js +44 -0
  104. package/tools/records/create-records.js.map +1 -0
  105. package/tools/records/create-records.mjs +40 -0
  106. package/tools/records/create-records.mjs.map +1 -0
  107. package/tools/runs/create-runs.d.mts +24 -0
  108. package/tools/runs/create-runs.d.mts.map +1 -0
  109. package/tools/runs/create-runs.d.ts +24 -0
  110. package/tools/runs/create-runs.d.ts.map +1 -0
  111. package/tools/runs/create-runs.js +43 -0
  112. package/tools/runs/create-runs.js.map +1 -0
  113. package/tools/runs/create-runs.mjs +39 -0
  114. package/tools/runs/create-runs.mjs.map +1 -0
  115. package/tools/runs/update-runs.d.mts +24 -0
  116. package/tools/runs/update-runs.d.mts.map +1 -0
  117. package/tools/runs/update-runs.d.ts +24 -0
  118. package/tools/runs/update-runs.d.ts.map +1 -0
  119. package/tools/runs/update-runs.js +41 -0
  120. package/tools/runs/update-runs.js.map +1 -0
  121. package/tools/runs/update-runs.mjs +37 -0
  122. package/tools/runs/update-runs.mjs.map +1 -0
  123. package/tools/system-configs/create-system-configs.d.mts +24 -0
  124. package/tools/system-configs/create-system-configs.d.mts.map +1 -0
  125. package/tools/system-configs/create-system-configs.d.ts +24 -0
  126. package/tools/system-configs/create-system-configs.d.ts.map +1 -0
  127. package/tools/system-configs/create-system-configs.js +54 -0
  128. package/tools/system-configs/create-system-configs.js.map +1 -0
  129. package/tools/system-configs/create-system-configs.mjs +50 -0
  130. package/tools/system-configs/create-system-configs.mjs.map +1 -0
  131. package/tools/system-configs/get-system-configs.d.mts +24 -0
  132. package/tools/system-configs/get-system-configs.d.mts.map +1 -0
  133. package/tools/system-configs/get-system-configs.d.ts +24 -0
  134. package/tools/system-configs/get-system-configs.d.ts.map +1 -0
  135. package/tools/system-configs/get-system-configs.js +31 -0
  136. package/tools/system-configs/get-system-configs.js.map +1 -0
  137. package/tools/system-configs/get-system-configs.mjs +27 -0
  138. package/tools/system-configs/get-system-configs.mjs.map +1 -0
  139. package/tools/system-configs/list-system-configs.d.mts +24 -0
  140. package/tools/system-configs/list-system-configs.d.mts.map +1 -0
  141. package/tools/system-configs/list-system-configs.d.ts +24 -0
  142. package/tools/system-configs/list-system-configs.d.ts.map +1 -0
  143. package/tools/system-configs/list-system-configs.js +36 -0
  144. package/tools/system-configs/list-system-configs.js.map +1 -0
  145. package/tools/system-configs/list-system-configs.mjs +32 -0
  146. package/tools/system-configs/list-system-configs.mjs.map +1 -0
  147. package/tools/systems/create-systems.d.mts +24 -0
  148. package/tools/systems/create-systems.d.mts.map +1 -0
  149. package/tools/systems/create-systems.d.ts +24 -0
  150. package/tools/systems/create-systems.d.ts.map +1 -0
  151. package/tools/systems/create-systems.js +48 -0
  152. package/tools/systems/create-systems.js.map +1 -0
  153. package/tools/systems/create-systems.mjs +44 -0
  154. package/tools/systems/create-systems.mjs.map +1 -0
  155. package/tools/systems/delete-systems.d.mts +24 -0
  156. package/tools/systems/delete-systems.d.mts.map +1 -0
  157. package/tools/systems/delete-systems.d.ts +24 -0
  158. package/tools/systems/delete-systems.d.ts.map +1 -0
  159. package/tools/systems/delete-systems.js +28 -0
  160. package/tools/systems/delete-systems.js.map +1 -0
  161. package/tools/systems/delete-systems.mjs +24 -0
  162. package/tools/systems/delete-systems.mjs.map +1 -0
  163. package/tools/systems/get-systems.d.mts +24 -0
  164. package/tools/systems/get-systems.d.mts.map +1 -0
  165. package/tools/systems/get-systems.d.ts +24 -0
  166. package/tools/systems/get-systems.d.ts.map +1 -0
  167. package/tools/systems/get-systems.js +28 -0
  168. package/tools/systems/get-systems.js.map +1 -0
  169. package/tools/systems/get-systems.mjs +24 -0
  170. package/tools/systems/get-systems.mjs.map +1 -0
  171. package/tools/systems/list-systems.d.mts +24 -0
  172. package/tools/systems/list-systems.d.mts.map +1 -0
  173. package/tools/systems/list-systems.d.ts +24 -0
  174. package/tools/systems/list-systems.d.ts.map +1 -0
  175. package/tools/systems/list-systems.js +36 -0
  176. package/tools/systems/list-systems.js.map +1 -0
  177. package/tools/systems/list-systems.mjs +32 -0
  178. package/tools/systems/list-systems.mjs.map +1 -0
  179. package/tools/systems/update-systems.d.mts +24 -0
  180. package/tools/systems/update-systems.d.mts.map +1 -0
  181. package/tools/systems/update-systems.d.ts +24 -0
  182. package/tools/systems/update-systems.d.ts.map +1 -0
  183. package/tools/systems/update-systems.js +48 -0
  184. package/tools/systems/update-systems.js.map +1 -0
  185. package/tools/systems/update-systems.mjs +44 -0
  186. package/tools/systems/update-systems.mjs.map +1 -0
  187. package/tools/testcases/create-testcases.d.mts +24 -0
  188. package/tools/testcases/create-testcases.d.mts.map +1 -0
  189. package/tools/testcases/create-testcases.d.ts +24 -0
  190. package/tools/testcases/create-testcases.d.ts.map +1 -0
  191. package/tools/testcases/create-testcases.js +43 -0
  192. package/tools/testcases/create-testcases.js.map +1 -0
  193. package/tools/testcases/create-testcases.mjs +39 -0
  194. package/tools/testcases/create-testcases.mjs.map +1 -0
  195. package/tools/testcases/delete-testcases.d.mts +24 -0
  196. package/tools/testcases/delete-testcases.d.mts.map +1 -0
  197. package/tools/testcases/delete-testcases.d.ts +24 -0
  198. package/tools/testcases/delete-testcases.d.ts.map +1 -0
  199. package/tools/testcases/delete-testcases.js +32 -0
  200. package/tools/testcases/delete-testcases.js.map +1 -0
  201. package/tools/testcases/delete-testcases.mjs +28 -0
  202. package/tools/testcases/delete-testcases.mjs.map +1 -0
  203. package/tools/testcases/get-testcases.d.mts +24 -0
  204. package/tools/testcases/get-testcases.d.mts.map +1 -0
  205. package/tools/testcases/get-testcases.d.ts +24 -0
  206. package/tools/testcases/get-testcases.d.ts.map +1 -0
  207. package/tools/testcases/get-testcases.js +28 -0
  208. package/tools/testcases/get-testcases.js.map +1 -0
  209. package/tools/testcases/get-testcases.mjs +24 -0
  210. package/tools/testcases/get-testcases.mjs.map +1 -0
  211. package/tools/testcases/list-testcases.d.mts +24 -0
  212. package/tools/testcases/list-testcases.d.mts.map +1 -0
  213. package/tools/testcases/list-testcases.d.ts +24 -0
  214. package/tools/testcases/list-testcases.d.ts.map +1 -0
  215. package/tools/testcases/list-testcases.js +36 -0
  216. package/tools/testcases/list-testcases.js.map +1 -0
  217. package/tools/testcases/list-testcases.mjs +32 -0
  218. package/tools/testcases/list-testcases.mjs.map +1 -0
  219. package/tools/testcases/update-testcases.d.mts +24 -0
  220. package/tools/testcases/update-testcases.d.mts.map +1 -0
  221. package/tools/testcases/update-testcases.d.ts +24 -0
  222. package/tools/testcases/update-testcases.d.ts.map +1 -0
  223. package/tools/testcases/update-testcases.js +32 -0
  224. package/tools/testcases/update-testcases.js.map +1 -0
  225. package/tools/testcases/update-testcases.mjs +28 -0
  226. package/tools/testcases/update-testcases.mjs.map +1 -0
  227. package/tools/testsets/create-testsets.d.mts +24 -0
  228. package/tools/testsets/create-testsets.d.mts.map +1 -0
  229. package/tools/testsets/create-testsets.d.ts +24 -0
  230. package/tools/testsets/create-testsets.d.ts.map +1 -0
  231. package/tools/testsets/create-testsets.js +68 -0
  232. package/tools/testsets/create-testsets.js.map +1 -0
  233. package/tools/testsets/create-testsets.mjs +64 -0
  234. package/tools/testsets/create-testsets.mjs.map +1 -0
  235. package/tools/testsets/delete-testsets.d.mts +24 -0
  236. package/tools/testsets/delete-testsets.d.mts.map +1 -0
  237. package/tools/testsets/delete-testsets.d.ts +24 -0
  238. package/tools/testsets/delete-testsets.d.ts.map +1 -0
  239. package/tools/testsets/delete-testsets.js +28 -0
  240. package/tools/testsets/delete-testsets.js.map +1 -0
  241. package/tools/testsets/delete-testsets.mjs +24 -0
  242. package/tools/testsets/delete-testsets.mjs.map +1 -0
  243. package/tools/testsets/get-testsets.d.mts +24 -0
  244. package/tools/testsets/get-testsets.d.mts.map +1 -0
  245. package/tools/testsets/get-testsets.d.ts +24 -0
  246. package/tools/testsets/get-testsets.d.ts.map +1 -0
  247. package/tools/testsets/get-testsets.js +28 -0
  248. package/tools/testsets/get-testsets.js.map +1 -0
  249. package/tools/testsets/get-testsets.mjs +24 -0
  250. package/tools/testsets/get-testsets.mjs.map +1 -0
  251. package/tools/testsets/list-testsets.d.mts +24 -0
  252. package/tools/testsets/list-testsets.d.mts.map +1 -0
  253. package/tools/testsets/list-testsets.d.ts +24 -0
  254. package/tools/testsets/list-testsets.d.ts.map +1 -0
  255. package/tools/testsets/list-testsets.js +36 -0
  256. package/tools/testsets/list-testsets.js.map +1 -0
  257. package/tools/testsets/list-testsets.mjs +32 -0
  258. package/tools/testsets/list-testsets.mjs.map +1 -0
  259. package/tools/testsets/update-testsets.d.mts +24 -0
  260. package/tools/testsets/update-testsets.d.mts.map +1 -0
  261. package/tools/testsets/update-testsets.d.ts +24 -0
  262. package/tools/testsets/update-testsets.d.ts.map +1 -0
  263. package/tools/testsets/update-testsets.js +68 -0
  264. package/tools/testsets/update-testsets.js.map +1 -0
  265. package/tools/testsets/update-testsets.mjs +64 -0
  266. package/tools/testsets/update-testsets.mjs.map +1 -0
  267. package/tools.d.mts +2 -0
  268. package/tools.d.mts.map +1 -0
  269. package/tools.d.ts +2 -0
  270. package/tools.d.ts.map +1 -0
  271. package/tools.js +18 -0
  272. package/tools.js.map +1 -0
  273. package/tools.mjs +2 -0
  274. package/tools.mjs.map +1 -0
@@ -0,0 +1,193 @@
1
+ import { parseOptions } from './options';
2
+ import { Filter } from './tools';
3
+
4
+ // Mock process.argv
5
+ const mockArgv = (args: string[]) => {
6
+ const originalArgv = process.argv;
7
+ process.argv = ['node', 'test.js', ...args];
8
+ return () => {
9
+ process.argv = originalArgv;
10
+ };
11
+ };
12
+
13
+ describe('parseOptions', () => {
14
+ it('should parse basic filter options', () => {
15
+ const cleanup = mockArgv([
16
+ '--tool=test-tool',
17
+ '--resource=test-resource',
18
+ '--operation=read',
19
+ '--tag=test-tag',
20
+ ]);
21
+
22
+ const result = parseOptions();
23
+
24
+ expect(result.filters).toEqual([
25
+ { type: 'tag', op: 'include', value: 'test-tag' },
26
+ { type: 'resource', op: 'include', value: 'test-resource' },
27
+ { type: 'tool', op: 'include', value: 'test-tool' },
28
+ { type: 'operation', op: 'include', value: 'read' },
29
+ ] as Filter[]);
30
+
31
+ // Default client capabilities
32
+ expect(result.capabilities).toEqual({
33
+ topLevelUnions: true,
34
+ validJson: true,
35
+ refs: true,
36
+ unions: true,
37
+ formats: true,
38
+ toolNameLength: undefined,
39
+ });
40
+
41
+ expect(result.list).toBe(false);
42
+
43
+ cleanup();
44
+ });
45
+
46
+ it('should parse exclusion filters', () => {
47
+ const cleanup = mockArgv([
48
+ '--no-tool=exclude-tool',
49
+ '--no-resource=exclude-resource',
50
+ '--no-operation=write',
51
+ '--no-tag=exclude-tag',
52
+ ]);
53
+
54
+ const result = parseOptions();
55
+
56
+ expect(result.filters).toEqual([
57
+ { type: 'tag', op: 'exclude', value: 'exclude-tag' },
58
+ { type: 'resource', op: 'exclude', value: 'exclude-resource' },
59
+ { type: 'tool', op: 'exclude', value: 'exclude-tool' },
60
+ { type: 'operation', op: 'exclude', value: 'write' },
61
+ ] as Filter[]);
62
+
63
+ expect(result.capabilities).toEqual({
64
+ topLevelUnions: true,
65
+ validJson: true,
66
+ refs: true,
67
+ unions: true,
68
+ formats: true,
69
+ toolNameLength: undefined,
70
+ });
71
+
72
+ cleanup();
73
+ });
74
+
75
+ it('should parse client presets', () => {
76
+ const cleanup = mockArgv(['--client=openai-agents']);
77
+
78
+ const result = parseOptions();
79
+
80
+ expect(result.capabilities).toEqual({
81
+ topLevelUnions: false,
82
+ validJson: true,
83
+ refs: true,
84
+ unions: true,
85
+ formats: true,
86
+ toolNameLength: undefined,
87
+ });
88
+
89
+ cleanup();
90
+ });
91
+
92
+ it('should parse individual capabilities', () => {
93
+ const cleanup = mockArgv([
94
+ '--capability=top-level-unions',
95
+ '--capability=valid-json',
96
+ '--capability=refs',
97
+ '--capability=unions',
98
+ '--capability=tool-name-length=40',
99
+ ]);
100
+
101
+ const result = parseOptions();
102
+
103
+ expect(result.capabilities).toEqual({
104
+ topLevelUnions: true,
105
+ validJson: true,
106
+ refs: true,
107
+ unions: true,
108
+ formats: true,
109
+ toolNameLength: 40,
110
+ });
111
+
112
+ cleanup();
113
+ });
114
+
115
+ it('should handle list option', () => {
116
+ const cleanup = mockArgv(['--list']);
117
+
118
+ const result = parseOptions();
119
+
120
+ expect(result.list).toBe(true);
121
+
122
+ cleanup();
123
+ });
124
+
125
+ it('should handle multiple filters of the same type', () => {
126
+ const cleanup = mockArgv(['--tool=tool1', '--tool=tool2', '--resource=res1', '--resource=res2']);
127
+
128
+ const result = parseOptions();
129
+
130
+ expect(result.filters).toEqual([
131
+ { type: 'resource', op: 'include', value: 'res1' },
132
+ { type: 'resource', op: 'include', value: 'res2' },
133
+ { type: 'tool', op: 'include', value: 'tool1' },
134
+ { type: 'tool', op: 'include', value: 'tool2' },
135
+ ] as Filter[]);
136
+
137
+ cleanup();
138
+ });
139
+
140
+ it('should handle comma-separated values in array options', () => {
141
+ const cleanup = mockArgv([
142
+ '--tool=tool1,tool2',
143
+ '--resource=res1,res2',
144
+ '--capability=top-level-unions,valid-json,unions',
145
+ ]);
146
+
147
+ const result = parseOptions();
148
+
149
+ expect(result.filters).toEqual([
150
+ { type: 'resource', op: 'include', value: 'res1' },
151
+ { type: 'resource', op: 'include', value: 'res2' },
152
+ { type: 'tool', op: 'include', value: 'tool1' },
153
+ { type: 'tool', op: 'include', value: 'tool2' },
154
+ ] as Filter[]);
155
+
156
+ expect(result.capabilities).toEqual({
157
+ topLevelUnions: true,
158
+ validJson: true,
159
+ refs: true,
160
+ unions: true,
161
+ formats: true,
162
+ toolNameLength: undefined,
163
+ });
164
+
165
+ cleanup();
166
+ });
167
+
168
+ it('should handle invalid tool-name-length format', () => {
169
+ const cleanup = mockArgv(['--capability=tool-name-length=invalid']);
170
+
171
+ // Mock console.error to prevent output during test
172
+ const originalError = console.error;
173
+ console.error = jest.fn();
174
+
175
+ expect(() => parseOptions()).toThrow();
176
+
177
+ console.error = originalError;
178
+ cleanup();
179
+ });
180
+
181
+ it('should handle unknown capability', () => {
182
+ const cleanup = mockArgv(['--capability=unknown-capability']);
183
+
184
+ // Mock console.error to prevent output during test
185
+ const originalError = console.error;
186
+ console.error = jest.fn();
187
+
188
+ expect(() => parseOptions()).toThrow();
189
+
190
+ console.error = originalError;
191
+ cleanup();
192
+ });
193
+ });
package/src/options.ts ADDED
@@ -0,0 +1,339 @@
1
+ import yargs from 'yargs';
2
+ import { hideBin } from 'yargs/helpers';
3
+ import { endpoints, Filter } from './tools';
4
+ import { ClientCapabilities } from './compat';
5
+
6
+ type ClientType = 'openai-agents' | 'claude' | 'claude-code' | 'cursor';
7
+
8
+ // Client presets for compatibility
9
+ // Note that these could change over time as models get better, so this is
10
+ // a best effort.
11
+ const CLIENT_PRESETS: Record<ClientType, ClientCapabilities> = {
12
+ 'openai-agents': {
13
+ topLevelUnions: false,
14
+ validJson: true,
15
+ refs: true,
16
+ unions: true,
17
+ formats: true,
18
+ toolNameLength: undefined,
19
+ },
20
+ claude: {
21
+ topLevelUnions: true,
22
+ validJson: false,
23
+ refs: true,
24
+ unions: true,
25
+ formats: true,
26
+ toolNameLength: undefined,
27
+ },
28
+ 'claude-code': {
29
+ topLevelUnions: false,
30
+ validJson: true,
31
+ refs: true,
32
+ unions: true,
33
+ formats: true,
34
+ toolNameLength: undefined,
35
+ },
36
+ cursor: {
37
+ topLevelUnions: false,
38
+ validJson: true,
39
+ refs: false,
40
+ unions: false,
41
+ formats: false,
42
+ toolNameLength: 50,
43
+ },
44
+ };
45
+
46
+ export interface ParsedOptions {
47
+ filters: Filter[];
48
+ capabilities: ClientCapabilities;
49
+ list: boolean;
50
+ }
51
+
52
+ const CAPABILITY_CHOICES = [
53
+ 'top-level-unions',
54
+ 'valid-json',
55
+ 'refs',
56
+ 'unions',
57
+ 'formats',
58
+ 'tool-name-length',
59
+ ] as const;
60
+
61
+ type Capability = (typeof CAPABILITY_CHOICES)[number];
62
+
63
+ function parseCapabilityValue(cap: string): { name: Capability; value?: number } {
64
+ if (cap.startsWith('tool-name-length=')) {
65
+ const parts = cap.split('=');
66
+ if (parts.length === 2) {
67
+ const length = parseInt(parts[1]!, 10);
68
+ if (!isNaN(length)) {
69
+ return { name: 'tool-name-length', value: length };
70
+ }
71
+ throw new Error(`Invalid tool-name-length value: ${parts[1]}. Expected a number.`);
72
+ }
73
+ throw new Error(`Invalid format for tool-name-length. Expected tool-name-length=N.`);
74
+ }
75
+ if (!CAPABILITY_CHOICES.includes(cap as Capability)) {
76
+ throw new Error(`Unknown capability: ${cap}. Valid capabilities are: ${CAPABILITY_CHOICES.join(', ')}`);
77
+ }
78
+ return { name: cap as Capability };
79
+ }
80
+
81
+ export function parseOptions(): ParsedOptions {
82
+ const opts = yargs(hideBin(process.argv))
83
+ .option('tool', {
84
+ type: 'string',
85
+ array: true,
86
+ description: 'Include tools matching the specified names',
87
+ })
88
+ .option('resource', {
89
+ type: 'string',
90
+ array: true,
91
+ description: 'Include tools matching the specified resources',
92
+ })
93
+ .option('operation', {
94
+ type: 'string',
95
+ array: true,
96
+ choices: ['read', 'write'],
97
+ description: 'Include tools matching the specified operations',
98
+ })
99
+ .option('tag', {
100
+ type: 'string',
101
+ array: true,
102
+ description: 'Include tools with the specified tags',
103
+ })
104
+ .option('no-tool', {
105
+ type: 'string',
106
+ array: true,
107
+ description: 'Exclude tools matching the specified names',
108
+ })
109
+ .option('no-resource', {
110
+ type: 'string',
111
+ array: true,
112
+ description: 'Exclude tools matching the specified resources',
113
+ })
114
+ .option('no-operation', {
115
+ type: 'string',
116
+ array: true,
117
+ description: 'Exclude tools matching the specified operations',
118
+ })
119
+ .option('no-tag', {
120
+ type: 'string',
121
+ array: true,
122
+ description: 'Exclude tools with the specified tags',
123
+ })
124
+ .option('list', {
125
+ type: 'boolean',
126
+ description: 'List all tools and exit',
127
+ })
128
+ .option('client', {
129
+ type: 'string',
130
+ choices: Object.keys(CLIENT_PRESETS),
131
+ description: 'Specify the MCP client being used',
132
+ })
133
+ .option('capability', {
134
+ type: 'string',
135
+ array: true,
136
+ description: 'Specify client capabilities',
137
+ coerce: (values: string[]) => {
138
+ return values.flatMap((v) => v.split(','));
139
+ },
140
+ })
141
+ .option('no-capability', {
142
+ type: 'string',
143
+ array: true,
144
+ description: 'Unset client capabilities',
145
+ choices: CAPABILITY_CHOICES,
146
+ coerce: (values: string[]) => {
147
+ return values.flatMap((v) => v.split(','));
148
+ },
149
+ })
150
+ .option('describe-capabilities', {
151
+ type: 'boolean',
152
+ description: 'Print detailed explanation of client capabilities and exit',
153
+ })
154
+ .help();
155
+
156
+ for (const [command, desc] of examples()) {
157
+ opts.example(command, desc);
158
+ }
159
+
160
+ const argv = opts.parseSync();
161
+
162
+ // Handle describe-capabilities flag
163
+ if (argv.describeCapabilities) {
164
+ console.log(getCapabilitiesExplanation());
165
+ process.exit(0);
166
+ }
167
+
168
+ const filters: Filter[] = [];
169
+
170
+ // Helper function to support comma-separated values
171
+ const splitValues = (values: string[] | undefined): string[] => {
172
+ if (!values) return [];
173
+ return values.flatMap((v) => v.split(','));
174
+ };
175
+
176
+ for (const tag of splitValues(argv.tag)) {
177
+ filters.push({ type: 'tag', op: 'include', value: tag });
178
+ }
179
+
180
+ for (const tag of splitValues(argv.noTag)) {
181
+ filters.push({ type: 'tag', op: 'exclude', value: tag });
182
+ }
183
+
184
+ for (const resource of splitValues(argv.resource)) {
185
+ filters.push({ type: 'resource', op: 'include', value: resource });
186
+ }
187
+
188
+ for (const resource of splitValues(argv.noResource)) {
189
+ filters.push({ type: 'resource', op: 'exclude', value: resource });
190
+ }
191
+
192
+ for (const tool of splitValues(argv.tool)) {
193
+ filters.push({ type: 'tool', op: 'include', value: tool });
194
+ }
195
+
196
+ for (const tool of splitValues(argv.noTool)) {
197
+ filters.push({ type: 'tool', op: 'exclude', value: tool });
198
+ }
199
+
200
+ for (const operation of splitValues(argv.operation)) {
201
+ filters.push({ type: 'operation', op: 'include', value: operation });
202
+ }
203
+
204
+ for (const operation of splitValues(argv.noOperation)) {
205
+ filters.push({ type: 'operation', op: 'exclude', value: operation });
206
+ }
207
+
208
+ // Parse client capabilities
209
+ const clientCapabilities: ClientCapabilities = {
210
+ topLevelUnions: true,
211
+ validJson: true,
212
+ refs: true,
213
+ unions: true,
214
+ formats: true,
215
+ toolNameLength: undefined,
216
+ };
217
+
218
+ // Apply client preset if specified
219
+ if (typeof argv.client === 'string') {
220
+ const clientKey = argv.client as ClientType;
221
+ if (CLIENT_PRESETS[clientKey]) {
222
+ Object.assign(clientCapabilities, CLIENT_PRESETS[clientKey]);
223
+ }
224
+ }
225
+
226
+ // Apply individual capability overrides
227
+ if (Array.isArray(argv.capability)) {
228
+ for (const cap of argv.capability) {
229
+ const parsedCap = parseCapabilityValue(cap);
230
+ if (parsedCap.name === 'top-level-unions') {
231
+ clientCapabilities.topLevelUnions = true;
232
+ } else if (parsedCap.name === 'valid-json') {
233
+ clientCapabilities.validJson = true;
234
+ } else if (parsedCap.name === 'refs') {
235
+ clientCapabilities.refs = true;
236
+ } else if (parsedCap.name === 'unions') {
237
+ clientCapabilities.unions = true;
238
+ } else if (parsedCap.name === 'formats') {
239
+ clientCapabilities.formats = true;
240
+ } else if (parsedCap.name === 'tool-name-length') {
241
+ clientCapabilities.toolNameLength = parsedCap.value;
242
+ }
243
+ }
244
+ }
245
+
246
+ // Handle no-capability options to unset capabilities
247
+ if (Array.isArray(argv.noCapability)) {
248
+ for (const cap of argv.noCapability) {
249
+ if (cap === 'top-level-unions') {
250
+ clientCapabilities.topLevelUnions = false;
251
+ } else if (cap === 'valid-json') {
252
+ clientCapabilities.validJson = false;
253
+ } else if (cap === 'refs') {
254
+ clientCapabilities.refs = false;
255
+ } else if (cap === 'unions') {
256
+ clientCapabilities.unions = false;
257
+ } else if (cap === 'formats') {
258
+ clientCapabilities.formats = false;
259
+ } else if (cap === 'tool-name-length') {
260
+ clientCapabilities.toolNameLength = undefined;
261
+ }
262
+ }
263
+ }
264
+
265
+ return {
266
+ filters,
267
+ capabilities: clientCapabilities,
268
+ list: argv.list || false,
269
+ };
270
+ }
271
+
272
+ function getCapabilitiesExplanation(): string {
273
+ return `
274
+ Client Capabilities Explanation:
275
+
276
+ Different Language Models (LLMs) and the MCP clients that use them have varying limitations in how they handle tool schemas. Capability flags allow you to inform the MCP server about these limitations.
277
+
278
+ When a capability flag is set to false, the MCP server will automatically adjust the tool schemas to work around that limitation, ensuring broader compatibility.
279
+
280
+ Available Capabilities:
281
+
282
+ # top-level-unions
283
+ Some clients/LLMs do not support JSON schemas with a union type (anyOf) at the root level. If a client lacks this capability, the MCP server splits tools with top-level unions into multiple separate tools, one for each variant in the union.
284
+
285
+ # refs
286
+ Some clients/LLMs do not support $ref pointers for schema reuse. If a client lacks this capability, the MCP server automatically inlines all references ($defs) directly into the schema. Properties that would cause circular references are removed during this process.
287
+
288
+ # valid-json
289
+ Some clients/LLMs may incorrectly send arguments as a JSON-encoded string instead of a proper JSON object. If a client *has* this capability, the MCP server will attempt to parse string values as JSON if the initial validation against the schema fails.
290
+
291
+ # unions
292
+ Some clients/LLMs do not support union types (anyOf) in JSON schemas. If a client lacks this capability, the MCP server removes all anyOf fields and uses only the first variant as the schema.
293
+
294
+ # formats
295
+ Some clients/LLMs do not support the 'format' keyword in JSON Schema specifications. If a client lacks this capability, the MCP server removes all format fields and appends the format information to the field's description in parentheses.
296
+
297
+ # tool-name-length=N
298
+ Some clients/LLMs impose a maximum length on tool names. If this capability is set, the MCP server will automatically truncate tool names exceeding the specified length (N), ensuring uniqueness by appending numbers if necessary.
299
+
300
+ Client Presets (--client):
301
+ Presets like '--client=openai-agents' or '--client=cursor' automatically configure these capabilities based on current known limitations of those clients, simplifying setup.
302
+
303
+ Current presets:
304
+ ${JSON.stringify(CLIENT_PRESETS, null, 2)}
305
+ `;
306
+ }
307
+
308
+ function examples(): [string, string][] {
309
+ const firstEndpoint = endpoints[0]!;
310
+ const secondEndpoint =
311
+ endpoints.find((e) => e.metadata.resource !== firstEndpoint.metadata.resource) || endpoints[1];
312
+ const tag = endpoints.find((e) => e.metadata.tags.length > 0)?.metadata.tags[0];
313
+ const otherEndpoint = secondEndpoint || firstEndpoint;
314
+
315
+ return [
316
+ [
317
+ `--tool="${firstEndpoint.tool.name}" ${secondEndpoint ? `--tool="${secondEndpoint.tool.name}"` : ''}`,
318
+ 'Include tools by name',
319
+ ],
320
+ [
321
+ `--resource="${firstEndpoint.metadata.resource}" --operation="read"`,
322
+ 'Filter by resource and operation',
323
+ ],
324
+ [
325
+ `--resource="${otherEndpoint.metadata.resource}*" --no-tool="${otherEndpoint.tool.name}"`,
326
+ 'Use resource wildcards and exclusions',
327
+ ],
328
+ [`--client="cursor"`, 'Adjust schemas to be more compatible with Cursor'],
329
+ [
330
+ `--capability="top-level-unions" --capability="tool-name-length=40"`,
331
+ 'Specify individual client capabilities',
332
+ ],
333
+ [
334
+ `--client="cursor" --no-capability="tool-name-length"`,
335
+ 'Use cursor client preset but remove tool name length limit',
336
+ ],
337
+ ...(tag ? [[`--tag="${tag}"`, 'Filter based on tags'] as [string, string]] : []),
338
+ ];
339
+ }
package/src/server.ts ADDED
@@ -0,0 +1,98 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
4
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
5
+ import { endpoints, HandlerFunction } from './tools';
6
+ import { CallToolRequestSchema, ListToolsRequestSchema, Tool } from '@modelcontextprotocol/sdk/types.js';
7
+ import Scorecard from 'scorecard-ai';
8
+ import { ClientCapabilities, defaultClientCapabilities, parseEmbeddedJSON } from './compat';
9
+ export { endpoints } from './tools';
10
+
11
+ // Create server instance
12
+ export const server = new McpServer(
13
+ {
14
+ name: 'scorecard_ai_api',
15
+ version: '1.0.0-alpha.4',
16
+ },
17
+ {
18
+ capabilities: {
19
+ tools: {},
20
+ },
21
+ },
22
+ );
23
+
24
+ /**
25
+ * Initializes the provided MCP Server with the given tools and handlers.
26
+ * If not provided, the default client, tools and handlers will be used.
27
+ */
28
+ export function init(params: {
29
+ server: Server | McpServer;
30
+ client?: Scorecard;
31
+ endpoints?: { tool: Tool; handler: HandlerFunction }[];
32
+ capabilities?: Partial<ClientCapabilities>;
33
+ }) {
34
+ const server = params.server instanceof McpServer ? params.server.server : params.server;
35
+ const providedEndpoints = params.endpoints || endpoints;
36
+
37
+ const endpointMap = Object.fromEntries(providedEndpoints.map((endpoint) => [endpoint.tool.name, endpoint]));
38
+
39
+ const client = params.client || new Scorecard({});
40
+
41
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
42
+ return {
43
+ tools: providedEndpoints.map((endpoint) => endpoint.tool),
44
+ };
45
+ });
46
+
47
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
48
+ const { name, arguments: args } = request.params;
49
+ const endpoint = endpointMap[name];
50
+ if (!endpoint) {
51
+ throw new Error(`Unknown tool: ${name}`);
52
+ }
53
+
54
+ return executeHandler(endpoint.tool, endpoint.handler, client, args, params.capabilities);
55
+ });
56
+ }
57
+
58
+ /**
59
+ * Runs the provided handler with the given client and arguments.
60
+ */
61
+ export async function executeHandler(
62
+ tool: Tool,
63
+ handler: HandlerFunction,
64
+ client: Scorecard,
65
+ args: Record<string, unknown> | undefined,
66
+ compatibilityOptions?: Partial<ClientCapabilities>,
67
+ ) {
68
+ const options = { ...defaultClientCapabilities, ...compatibilityOptions };
69
+ if (options.validJson && args) {
70
+ args = args = parseEmbeddedJSON(args, tool.inputSchema);
71
+ }
72
+ const result = await handler(client, args || {});
73
+ return {
74
+ content: [
75
+ {
76
+ type: 'text',
77
+ text: JSON.stringify(result, null, 2),
78
+ },
79
+ ],
80
+ };
81
+ }
82
+
83
+ export const readEnv = (env: string): string | undefined => {
84
+ if (typeof (globalThis as any).process !== 'undefined') {
85
+ return (globalThis as any).process.env?.[env]?.trim();
86
+ } else if (typeof (globalThis as any).Deno !== 'undefined') {
87
+ return (globalThis as any).Deno.env?.get?.(env)?.trim();
88
+ }
89
+ return;
90
+ };
91
+
92
+ export const readEnvOrError = (env: string): string => {
93
+ let envValue = readEnv(env);
94
+ if (envValue === undefined) {
95
+ throw new Error(`Environment variable ${env} is not set`);
96
+ }
97
+ return envValue;
98
+ };