@hasna/connectors
Open-source connector platform for enabling, authenticating, and running API connectors from one package.
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 installwrites project enablement to.connectors/manifest.jsonconnectors listandconnectors searchbrowse the shared catalogconnectors docsreads connector docs from the internal registryconnectors authstores credentials in the connectors data home (resolved by the in-package resolver)connectors auth <name> --key-stdinreads an API key or bearer token from stdin, and--key-env <VAR>reads it from the named environment variable.connectors setupandconnectors llm settake the same two flags. Do not pass a key as a command-line value: it lands in shell history and the process list.connectors runexecutes connector commands from the one-product runtimeconnectors statusandconnectors doctorverify 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 listshows a compact page. Use--cursor <n>or--offset <n>for the next page,--limit <n>to change page size,--verbosefor wider rows, or--all --verbosefor the full human catalog.--jsonnow returns a minified 20-row envelope with truthfultotal,limit,cursor,next_cursor, andhas_more; use--json --verbosefor full fields within that bounded page, or--json --full/--json --allfor the legacy bare array. Bounded JSON limits above 100 are refused with full-output guidance.connectors docs <name>shows a summary. Use--verbosefor full parsed sections,--essentialfor auth/env vars only,--rawfor raw markdown, or--jsonfor 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--jsonwhen full detail is needed.connectors runpreserves JSON-style command output, but truncates very large human stdout. Useconnectors 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.
| Setting | Purpose |
|---|---|
PORT / CONNECTORS_PORT | Port to listen on (default 9876). |
CONNECTORS_HOST | Interface to bind (default 127.0.0.1; --host overrides). |
CONNECTORS_DATABASE_URL | PostgreSQL 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_MS | PostgreSQL statement_timeout for pooled connections (default 15000). |
CONNECTORS_ENCRYPTION_KEY | Base64, 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_KEY | Enables the admin routes (at least 24 characters). Unset: they return 404. |
CONNECTORS_API_KEY_SIGNING_SECRET | Optional HMAC secret for stored API-key hashes. |
CONNECTORS_ORIGIN_AUTH / CONNECTORS_ORIGIN_AUTH_HEADER | Optional shared secret (at least 24 characters) that a fronting gateway must send on /v1. |
CONNECTORS_PUBLIC_URL | Public base URL, used for OAuth redirect URIs and relative redirect_after paths. Required for OAuth in public mode. |
CONNECTORS_OAUTH_REDIRECT_ORIGINS | Comma-separated exact origins (for example https://app.example.com) an absolute OAuth redirect_after may use. |
CONNECTORS_ALLOW_SQLITE_ON_PUBLIC_BIND | 1 lets a SQLite server bind a non-loopback address; it then runs in public mode. |
CONNECTORS_BASE_PATH | Accept 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:
HASNA_CONNECTORS_SERVE_TOKENin the environment.- The owner-only file
<connectors home>/serve-token(mode0600, 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