scorecard-ai-mcp
Scorecard TypeScript API 库
该库为服务器端 TypeScript 或 JavaScript 提供了对 Scorecard REST API 的便捷访问。
REST API 文档可在 docs.scorecard.io 上找到。该库的完整 API 可在 api.md 中找到。
它由 Stainless 生成。
MCP Server
使用 Scorecard MCP Server 使 AI 助手能够与此 API 交互,允许它们探索端点、发出测试请求,并利用文档帮助将此 SDK 集成到您的应用程序中。
注意:您可能需要在 MCP 客户端中设置环境变量。
Related MCP server: @roarkanalytics/sdk-mcp
安装
npm install scorecard-ai用法
该库的完整 API 可在 api.md 中找到。
import Scorecard from 'scorecard-ai';
const client = new Scorecard({
apiKey: process.env['SCORECARD_API_KEY'], // This is the default and can be omitted
environment: 'staging', // or 'production' | 'local'; defaults to 'production'
});
const run = await client.runs.create('314', { metricIds: ['789', '101'], testsetId: '246' });
console.log(run.id);请求与响应类型
该库包含所有请求参数和响应字段的 TypeScript 定义。您可以像这样导入和使用它们:
import Scorecard from 'scorecard-ai';
const client = new Scorecard({
apiKey: process.env['SCORECARD_API_KEY'], // This is the default and can be omitted
environment: 'staging', // or 'production' | 'local'; defaults to 'production'
});
const testset: Scorecard.Testset = await client.testsets.get('246');每个方法、请求参数和响应字段的文档都可在 docstrings 中找到,并会在大多数现代编辑器中悬停时显示。
处理错误
当库无法连接到 API,或 API 返回非成功状态码(即 4xx 或 5xx 响应)时,将抛出 APIError 的子类:
const testset = await client.testsets.get('246').catch(async (err) => {
if (err instanceof Scorecard.APIError) {
console.log(err.status); // 400
console.log(err.name); // BadRequestError
console.log(err.headers); // {server: 'nginx', ...}
} else {
throw err;
}
});错误码如下:
状态码 | 错误类型 |
400 |
|
401 |
|
403 |
|
404 |
|
422 |
|
429 |
|
>=500 |
|
N/A |
|
重试
某些错误默认会自动重试 2 次,并采用短暂的指数退避。连接错误(例如由于网络连接问题)、408 请求超时、409 冲突、429 速率限制以及 >=500 内部错误默认都会重试。
您可以使用 maxRetries 选项来配置或禁用此功能:
// Configure the default for all requests:
const client = new Scorecard({
maxRetries: 0, // default is 2
});
// Or, configure per-request:
await client.testsets.get('246', {
maxRetries: 5,
});超时
请求默认在 1 分钟后超时。您可以使用 timeout 选项进行配置:
// Configure the default for all requests:
const client = new Scorecard({
timeout: 20 * 1000, // 20 seconds (default is 1 minute)
});
// Override per-request:
await client.testsets.get('246', {
timeout: 5 * 1000,
});超时时,会抛出 APIConnectionTimeoutError。
请注意,超时的请求将默认重试两次。
自动分页
Scorecard API 中的列表方法已分页。您可以使用 for await … of 语法遍历所有页面中的项目:
async function fetchAllTestcases(params) {
const allTestcases = [];
// Automatically fetches more pages as needed.
for await (const testcase of client.testcases.list('246', { limit: 30 })) {
allTestcases.push(testcase);
}
return allTestcases;
}或者,您可以一次请求单个页面:
let page = await client.testcases.list('246', { limit: 30 });
for (const testcase of page.data) {
console.log(testcase);
}
// Convenience methods are provided for manually paginating:
while (page.hasNextPage()) {
page = await page.getNextPage();
// ...
}高级用法
访问原始响应数据(例如标头)
可以通过所有方法返回的 APIPromise 类型上的 .asResponse() 方法访问 fetch() 返回的“原始” Response。此方法在收到成功响应的标头后立即返回,并且不会消耗响应主体,因此您可以自由编写自定义解析或流式逻辑。
您还可以使用 .withResponse() 方法获取原始 Response 以及解析后的数据。与 .asResponse() 不同,此方法会消耗主体,并在解析后返回。
const client = new Scorecard();
const response = await client.testsets.get('246').asResponse();
console.log(response.headers.get('X-My-Header'));
console.log(response.statusText); // access the underlying Response object
const { data: testset, response: raw } = await client.testsets.get('246').withResponse();
console.log(raw.headers.get('X-My-Header'));
console.log(testset.id);日志记录
[!IMPORTANT] 所有日志消息仅用于调试。日志消息的格式和内容可能在不同版本之间发生变化。
日志级别
日志级别可以通过两种方式配置:
通过
SCORECARD_LOG环境变量使用
logLevel客户端选项(如果设置,则覆盖环境变量)
import Scorecard from 'scorecard-ai';
const client = new Scorecard({
logLevel: 'debug', // Show all log messages
});可用的日志级别,从最详细到最不详细:
'debug'- 显示调试消息、信息、警告和错误'info'- 显示信息消息、警告和错误'warn'- 显示警告和错误(默认)'error'- 仅显示错误'off'- 禁用所有日志记录
在 'debug' 级别,所有 HTTP 请求和响应都会被记录,包括标头和主体。某些与身份验证相关的标头会被编辑,但请求和响应主体中的敏感数据可能仍然可见。
自定义记录器
默认情况下,此库记录到 globalThis.console。您也可以提供自定义记录器。支持大多数日志记录库,包括 pino、winston、bunyan、consola、signale 和 @std/log。如果您的记录器无法正常工作,请打开一个问题。
提供自定义记录器时,logLevel 选项仍控制发出哪些消息,低于配置级别的消息将不会发送到您的记录器。
import Scorecard from 'scorecard-ai';
import pino from 'pino';
const logger = pino();
const client = new Scorecard({
logger: logger.child({ name: 'Scorecard' }),
logLevel: 'debug', // Send all messages to pino, allowing it to filter
});发出自定义/未记录的请求
此库的类型设计用于方便访问已记录的 API。如果您需要访问未记录的端点、参数或响应属性,该库仍然可以使用。
未记录的端点
要向未记录的端点发出请求,您可以使用 client.get、client.post 和其他 HTTP 动词。客户端上的选项(例如重试)将在发出这些请求时得到尊重。
await client.post('/some/path', {
body: { some_prop: 'foo' },
query: { some_query_arg: 'bar' },
});未记录的请求参数
要使用未记录的参数发出请求,您可以在未记录的参数上使用 // @ts-expect-error。此库不会在运行时验证请求是否与类型匹配,因此您发送的任何额外值都将按原样发送。
client.runs.create({
// ...
// @ts-expect-error baz is not yet public
baz: 'undocumented option',
});对于使用 GET 动词的请求,任何额外参数都将放在查询中,所有其他请求将在主体中发送额外参数。
如果您想显式发送额外参数,可以使用 query、body 和 headers 请求选项。
未记录的响应属性
要访问未记录的响应属性,您可以在响应对象上使用 // @ts-expect-error 访问响应对象,或将响应对象转换为所需的类型。与请求参数一样,我们不会验证或剥离 API 响应中的额外属性。
自定义 fetch 客户端
默认情况下,此库期望定义全局 fetch 函数。
如果您想使用不同的 fetch 函数,您可以填充全局:
import fetch from 'my-fetch';
globalThis.fetch = fetch;或者将其传递给客户端:
import Scorecard from 'scorecard-ai';
import fetch from 'my-fetch';
const client = new Scorecard({ fetch });Fetch 选项
如果您想设置自定义 fetch 选项而不覆盖 fetch 函数,您可以在实例化客户端或发出请求时提供 fetchOptions 对象。(特定于请求的选项会覆盖客户端选项。)
import Scorecard from 'scorecard-ai';
const client = new Scorecard({
fetchOptions: {
// `RequestInit` options
},
});配置代理
要修改代理行为,您可以提供自定义 fetchOptions,为请求添加特定于运行时的代理选项:
Node [文档]
import Scorecard from 'scorecard-ai';
import * as undici from 'undici';
const proxyAgent = new undici.ProxyAgent('http://localhost:8888');
const client = new Scorecard({
fetchOptions: {
dispatcher: proxyAgent,
},
});Bun [文档]
import Scorecard from 'scorecard-ai';
const client = new Scorecard({
fetchOptions: {
proxy: 'http://localhost:8888',
},
});Deno [文档]
import Scorecard from 'npm:scorecard-ai';
const httpClient = Deno.createHttpClient({ proxy: { url: 'http://localhost:8888' } });
const client = new Scorecard({
fetchOptions: {
client: httpClient,
},
});常见问题
语义化版本
此包通常遵循 SemVer 约定,但某些不向后兼容的更改可能会作为次要版本发布:
仅影响静态类型而不破坏运行时行为的更改。
对库内部结构的更改,这些更改在技术上是公开的,但并非为外部使用而设计或记录。(如果您依赖此类内部结构,请打开 GitHub 问题告知我们。)
我们预计不会在实践中影响绝大多数用户的更改。
我们认真对待向后兼容性,并努力确保您能依赖顺畅的升级体验。
我们期待您的反馈;请打开一个 issue 提出疑问、错误或建议。
要求
支持 TypeScript >= 4.9。
支持以下运行时:
Web 浏览器(最新的 Chrome、Firefox、Safari、Edge 等)
Node.js 20 LTS 或更高版本(非 EOL)。
Deno v1.28.0 或更高版本。
Bun 1.0 或更高版本。
Cloudflare Workers。
Vercel Edge Runtime。
Jest 28 或更高版本,使用
"node"环境(目前不支持"jsdom")。Nitro v2.6 或更高版本。
请注意,目前不支持 React Native。
如果您对其他运行时环境感兴趣,请在 GitHub 上打开或点赞一个问题。
贡献
请参阅贡献文档。
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceEnables AI assistants to interact with the Test2w REST API to explore endpoints, make test requests, and access documentation. It facilitates the integration of the Test2w SDK into applications through natural language interfaces in supported AI clients.1Apache 2.0

@roarkanalytics/sdk-mcpofficial
AlicenseNot gradedqualityBmaintenanceEnables AI assistants to interact with the Roark REST API, allowing them to explore endpoints, make test requests, and use documentation to help integrate this SDK into your application.4,2087Apache 2.0
nimble-js-mcpofficial
AlicenseNot gradedqualityAmaintenanceEnables AI assistants to interact with the Nimble REST API, allowing them to explore endpoints, make test requests, and use documentation to help integrate this SDK into your application.1,775Apache 2.0- AlicenseNot gradedqualityCmaintenanceEnables AI assistants to interact with the Thrive MCP REST API for exploring endpoints, making test requests, and integrating with the API.8Apache 2.0
Related MCP Connectors
Provides AI assistants with direct access to Mapbox developer APIs and documentation.
Public social-data API and live docs for AI coding agents.
Gateway between LLM agents and world data through eight tools and a bundled endpoint catalog.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/scorecard-ai/scorecard-node'
If you have feedback or need assistance with the MCP directory API, please join our Discord server