@hasna/connectors

中文文档
1.8.0发布于 2026/10/17Apache-2.0TypeScriptES Module近 30 天下载 4.7万

Open source connector library - Install API connectors with a single command

原始使用文档
文档目录15 节
  1. Install
  2. What It Is
  3. Local or remote
  4. CLI
  5. Compact Output Defaults
  6. MCP Server
  7. HTTP mode
  8. Run your own server
  9. Local REST API ( /api )
  10. Authentication
  11. SDK ( @hasna/connectors/sdk )
  12. Project Layout
  13. Data Directory
  14. Contributor Notes
  15. License

@hasna/connectors

Open-source connector platform for enabling, authenticating, and running API connectors from one package.

npm License

Install

bun install -g @hasna/connectors

What It Is

@hasna/connectors is a single-product runtime:

  • connectors stay inside this repo and package
  • projects enable the connectors they want through .connectors/manifest.json
  • credentials live in the connectors data home (resolved by the in-package resolver; ~/.hasna/connectors/ until the XDG data home is adopted)
  • CLI, MCP, REST, and the local API/OAuth server all use the same connector registry

Local or remote

Connectors runs locally by default, with nothing to configure: the CLI, the MCP server and the SDK run the connector engine in-process and keep connections in the local store.

To use a server instead (one you run yourself, or any service that speaks the /v1 API), point the client at it:

# One shell or CI job: environment variables
export CONNECTORS_API_URL=https://connectors.example.com
export CONNECTORS_API_KEY=...            # from your server administrator

# Or save it: the key is read from stdin or a hidden prompt, never from arguments
connectors login --api-url https://connectors.example.com
connectors config show                   # mode, server URL, whether a key is set
connectors logout                        # delete the stored key
connectors config unset api-url          # back to local mode

Settings resolve in this order: the --api-url / --api-key-stdin flags, then CONNECTORS_API_URL / CONNECTORS_API_KEY, then <connectors home>/config.json (mode 0600, written by connectors login), then local mode. A saved key is only sent to the server it was saved for, a server URL without a key is an error rather than a silent fall back to local mode, and plain http:// is refused for anything but loopback unless CONNECTORS_ALLOW_INSECURE_HTTP=1.

Service connectors work the same way in both modes:

connectors service list
connectors service describe openai       # auth methods, operations and their effects
printf '{"adminKey":"%s"}' "$OPENAI_ADMIN_KEY" | \
  connectors connections add openai --auth admin_key --label prod-admin --secrets-stdin
connectors connections add openai --auth admin_key --label ci --secret-env adminKey=OPENAI_ADMIN_KEY
connectors connections list
connectors connections check openai:prod-admin
connectors call openai <operation> --connection prod-admin --input '<json object>'
connectors runs list --limit 20

The shipped service connectors are anthropic, brandsight, cloudflare, cursor, godaddy, openai, opencode, stable and youtrust (Youtrust, formerly Yousign: signature requests, documents, recipients, audit trails and webhooks; see docs/providers/youtrust.md). A Youtrust connection picks its environment with a plain field:

connectors connections add youtrust --auth api_key --label prod \
  --field environment=production --secret-env apiKey=YOUTRUST_API_KEY   # default: sandbox
connectors call youtrust signature_requests.list --connection prod --input '{"limit":10}'

Secret connection fields are never accepted as arguments (--field refuses them); use --secret-env key=ENV_NAME, --secrets-stdin or the hidden prompt. Any operation that is not a read (write, billable, destructive, credential) needs --confirm. A credential result, such as a newly minted key, is shown once and never stored.

CLI

connectors --help

Typical flow:

connectors install github stripe
connectors auth github
printf '%s\n' "$STRIPE_API_KEY" | connectors auth stripe --key-stdin
connectors run github --help
connectors run stripe products list --limit 5

Key commands:

  • connectors install writes project enablement to .connectors/manifest.json
  • connectors list and connectors search browse the shared catalog
  • connectors docs reads connector docs from the internal registry
  • connectors auth stores credentials in the connectors data home (resolved by the in-package resolver)
  • connectors auth <name> --key-stdin reads an API key or bearer token from stdin, and --key-env <VAR> reads it from the named environment variable. connectors setup and connectors llm set take the same two flags. Do not pass a key as a command-line value: it lands in shell history and the process list.
  • connectors run executes connector commands from the one-product runtime
  • connectors status and connectors doctor verify setup and auth state

Compact Output Defaults

CLI output is compact by default so agent terminals do not fill with huge catalogs, README sections, credential status tables, or API records.

  • connectors list shows a compact page. Use --cursor <n> or --offset <n> for the next page, --limit <n> to change page size, --verbose for wider rows, or --all --verbose for the full human catalog. --json now returns a minified 20-row envelope with truthful total, limit, cursor, next_cursor, and has_more; use --json --verbose for full fields within that bounded page, or --json --full / --json --all for the legacy bare array. Bounded JSON limits above 100 are refused with full-output guidance.
  • connectors docs <name> shows a summary. Use --verbose for full parsed sections, --essential for auth/env vars only, --raw for raw markdown, or --json for structured docs.
  • connectors status, connectors doctor, connectors jobs list, connectors workflows list, connectors whoami, and dry-run install output page or truncate human rows by default. Use --verbose, show/inspect, or --json when full detail is needed.
  • connectors run preserves JSON-style command output, but truncates very large human stdout. Use connectors run --verbose <connector> ... for full stdout.

MCP Server

connectors-mcp

MCP tools also use compact defaults. list_connectors, list_jobs, list_workflows, and list_agents return paged objects with count, total, limit, cursor, nextCursor, and hasMore; pass cursor to continue, limit to change page size, and verbose: true for full records. list_connectors page receipts bypass optional probabilistic output stripping, so continuation metadata cannot be removed. connector_docs and operation discovery return summaries unless verbose: true or a specific detail path is requested.

Service-connector tools run through the same backend as the CLI (local, or the server from CONNECTORS_API_URL / connectors login): connectors_service_list, connectors_service_describe, connections_list, connections_check, connectors_call (pass confirm: true for anything that is not a read) and runs_list. No tool accepts a secret value; connections are created with the CLI or the API, so raw keys never pass through an agent's tool arguments. When connectors_call runs a credential operation (one that mints a key), the secret values in its result (key, token, secret, api_key, access_token, refresh_token, client_secret, value, at any depth) come back as [redacted: pass reveal_secret=true to return it] unless the call sets reveal_secret: true. The CLI's connectors call still prints the value, once, with a warning.

HTTP mode

connectors-mcp --http            # http://127.0.0.1:8808/mcp
MCP_HTTP=1 connectors-mcp

Health: GET http://127.0.0.1:8808/health. MCP is also mounted on connectors-serve at /mcp.

Run your own server

connectors-serve serves the /v1 API that the CLI, MCP server and SDK use in remote mode.

connectors-serve                         # http://127.0.0.1:9876, SQLite in the connectors home
PORT=8080 connectors-serve
connectors-serve --host 0.0.0.0          # shared server: needs CONNECTORS_DATABASE_URL (containers, behind TLS)

Only a SQLite server on loopback is in local mode (serve token, private base_urls, the local /api/* routes). PostgreSQL, or any non-loopback address, is public mode: tenant API keys only, public https base_urls only (their hosts are resolved and checked before every provider request), and OAuth only with CONNECTORS_PUBLIC_URL. A SQLite server refuses a non-loopback address unless CONNECTORS_ALLOW_SQLITE_ON_PUBLIC_BIND=1. Restrict the server's network egress as well (deny the metadata address, link-local, loopback and private ranges): the DNS check cannot stop a name that changes its answer between the check and the request.

SettingPurpose
PORT / CONNECTORS_PORTPort to listen on (default 9876).
CONNECTORS_HOSTInterface to bind (default 127.0.0.1; --host overrides).
CONNECTORS_DATABASE_URLPostgreSQL DSN. Unset: SQLite at <connectors home>/connectors.db. A generic DATABASE_URL is ignored. TLS follows the DSN's sslmode; CONNECTORS_DATABASE_CA_FILE pins a CA bundle.
CONNECTORS_DATABASE_STATEMENT_TIMEOUT_MSPostgreSQL statement_timeout for pooled connections (default 15000).
CONNECTORS_ENCRYPTION_KEYBase64, 32 bytes. Encrypts stored credentials (AES-256-GCM). Local mode generates <connectors home>/encryption.key (mode 0600) instead. Its fingerprint is recorded per key version; a server started with a different key for a recorded version refuses to start.
CONNECTORS_ADMIN_KEYEnables the admin routes (at least 24 characters). Unset: they return 404.
CONNECTORS_API_KEY_SIGNING_SECRETOptional HMAC secret for stored API-key hashes.
CONNECTORS_ORIGIN_AUTH / CONNECTORS_ORIGIN_AUTH_HEADEROptional shared secret (at least 24 characters) that a fronting gateway must send on /v1.
CONNECTORS_PUBLIC_URLPublic base URL, used for OAuth redirect URIs and relative redirect_after paths. Required for OAuth in public mode.
CONNECTORS_OAUTH_REDIRECT_ORIGINSComma-separated exact origins (for example https://app.example.com) an absolute OAuth redirect_after may use.
CONNECTORS_ALLOW_SQLITE_ON_PUBLIC_BIND1 lets a SQLite server bind a non-loopback address; it then runs in public mode.
CONNECTORS_BASE_PATHAccept requests under a reverse-proxy prefix, for example /connectors.

Migrations are versioned and checksummed. Apply them before starting, or let the server apply them on start:

connectors-serve migrate
connectors-serve --migrate

Tenants and API keys are managed from the server's own CLI (same environment as the server, secrets from the environment, never from arguments):

connectors-serve admin create-tenant acme
connectors-serve admin create-key <tenantId> --label ci     # the key is printed once
connectors-serve admin list-tenants
connectors-serve admin revoke-key <keyId>

or through the admin API with Authorization: Bearer <CONNECTORS_ADMIN_KEY>: POST /v1/admin/tenants, POST /v1/admin/tenants/{id}/keys, GET /v1/admin/tenants/{id}/keys and DELETE /v1/admin/keys/{id}. Give each user their key; they run connectors login --api-url <your server>.

In Docker, install the package on a Bun image and run connectors-serve, with PostgreSQL and the encryption key passed as environment variables:

FROM oven/bun:1
RUN bun install -g @hasna/connectors
ENV PORT=9876 CONNECTORS_HOST=0.0.0.0
EXPOSE 9876
CMD ["connectors-serve", "--migrate"]
docker run -p 9876:9876 \
  -e CONNECTORS_DATABASE_URL -e CONNECTORS_ENCRYPTION_KEY -e CONNECTORS_ADMIN_KEY \
  my-connectors-server

A container must listen on a non-loopback interface (CONNECTORS_HOST=0.0.0.0) for the published port to reach it. Put TLS in front of the server (a reverse proxy or load balancer), since clients refuse plain http:// to anything but loopback. The package's own Dockerfile builds a slimmer image from the prebuilt bin/serve.js bundle (bun run build first).

Local REST API (/api)

The local REST API is served by the one-product runtime at http://127.0.0.1:9876 (loopback only by default).

Authentication

Every /api/* route and the /mcp mount require a bearer token: Authorization: Bearer <token> (or X-Connectors-Token: <token>). GET /api/export returns every configured vendor credential, so the server never answers it — or anything else under /api/ — anonymously. /health and the OAuth browser routes (/oauth/:name/start, /oauth/:name/callback) are public.

The token is resolved in this order and never printed:

  1. HASNA_CONNECTORS_SERVE_TOKEN in the environment.
  2. The owner-only file <connectors home>/serve-token (mode 0600, default ~/.hasna/connectors/serve-token), generated on first start.

The connectors CLI, connectors-mcp and the ./sdk client read the same two sources, so a same-user process on the box authenticates with no configuration while a remote or other-user process gets 401 CONNECTORS_SERVE_UNAUTHORIZED. There is no anonymous mode. To listen on another interface deliberately, call startServer(port, { hostname }).

SDK (@hasna/connectors/sdk)

The TypeScript SDK ships inside this package as the ./sdk export subpath (one package per app — there is no separate -sdk package; the former @hasna/connectors-sdk is superseded by this subpath). It is the HTTP client only (ConnectorsApiClient, createHttpBackend, BackendError and the types), and it runs in Node as well as Bun: the built dist/sdk/index.js imports Node builtins only, never the local engine or bun:sqlite.

Local mode, and resolving the backend exactly as the CLI does, need Bun and live in @hasna/connectors/local (resolveBackend, createLocalBackend, describeMode); the package's main entry re-exports them. Each entry is its own bundle, so check instanceof BackendError with the class from the entry you called (./sdk for ConnectorsApiClient, ./local for resolveBackend), or compare err.code.

import { ConnectorsApiClient, BackendError } from "@hasna/connectors/sdk";

// Any server that speaks the /v1 API (Node or Bun)
const client = new ConnectorsApiClient({
  baseUrl: "https://connectors.example.com",
  apiKey: process.env.CONNECTORS_API_KEY!,
});
const connections = await client.listConnections({ connector: "openai" });
// Bun only: resolve like the CLI (flags/env, then the saved config, then local mode)
import { resolveBackend, BackendError } from "@hasna/connectors/local";

const backend = await resolveBackend();
try {
  const { result, run_id } = await backend.run({
    connector: "openai",
    operation: "<operation>", // a name from (await backend.getConnector("openai")).operations
    connection: "prod-admin",
    input: {},
  });
} catch (err) {
  if (err instanceof BackendError && err.code === "CONFIRMATION_REQUIRED") {
    // not a read operation: pass confirm: true once the action is approved
  }
}

LocalConnectorsClient (and its alias ConnectorsClient), which talk to the local /api routes, and HostedConnectorsClient are still exported for compatibility but are deprecated in favour of ConnectorsApiClient and resolveBackend (from @hasna/connectors/local).

Project Layout

Project-local enablement is lightweight:

.connectors/
├── manifest.json
└── index.ts

The package no longer copies full connector source trees into each project.

Data Directory

The connectors data home is resolved by the in-package resolver (XDG/macOS home layout). The legacy ~/.hasna/connectors/ default stays the effective data home until the store is actually migrated to the XDG data home (~/.local/share/hasna/connectors on Linux, with connectors.db present there) or the operator sets the data-kind override HASNA_DATA_HOME. The exact-app override HASNA_CONNECTORS_DIR wins unconditionally. An existing live store never becomes invisible on upgrade.

Contributor Notes

Contributor guidance for the one-repo / one-product model lives in docs/one-repo-one-product.md.

License

Apache-2.0 -- see LICENSE

版本与发布记录

@hasna/connectors 共发布 149 个版本,首次发布于 2026/02/14;过去 12 个月发布了 149 个版本。

版本发布日期距今
1.8.0latest2026/10/171 个月前
1.7.02026/10/151 个月前
1.6.02026/10/141 个月前
1.5.02026/10/141 个月前
1.4.82026/09/271 个月前
1.4.72026/09/201 个月前

关于 @hasna/connectors 的常见问题

@hasna/connectors 是什么?

Open source connector library - Install API connectors with a single command

如何安装 @hasna/connectors?

在项目目录运行 npm install @hasna/connectors,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 connectors、connectors-mcp、connectors-serve,可以用 npx connectors 直接运行。

@hasna/connectors 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@hasna/connectors 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@hasna/connectors 可以商用吗?

@hasna/connectors 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@hasna/connectors 的下载量有多少?

根据 npm 官方下载统计,@hasna/connectors 在 2026/10/18 – 2026/11/16 这 30 天内被下载 47,411 次,日均约 1,580 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@hasna/connectors 还在维护吗?

最新版本 1.8.0 发布于 2026/10/17(1 个月前);至今共发布 149 个版本,其中过去 12 个月发布了 149 个;首次发布于 2026/02/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。