Connect
nodejs logo

Node.js

Node 20+ ships with global fetch. No SDK needed for REST: authorize + JSON. For rich agent work, use the MCP TypeScript SDK.

Client
Node.js
Native fetch for REST, MCP TypeScript SDK for tool-calling.
HTTP JSON-RPC (streamable-http)
Dock MCP
trydock.ai/api/mcp
37 tools · OAuth 2.1 + DCR · Bearer
Auth path
1
Mint a dk_ key in Dock Settings → API keys.
2
Paste it as Authorization: Bearer dk_… in the client config.
3
Client calls Dock MCP directly on every request.

Prerequisites

  • Node 20+.
  • A Dock dk_ key.
fetch · read + write rowstypescript
const API = "https://trydock.ai/api";
const H = {
  Authorization: `Bearer ${process.env.DOCK_API_KEY}`,
  "Content-Type": "application/json",
};

// List workspaces
const ws = await fetch(`${API}/workspaces`, { headers: H }).then((r) => r.json());

// Append a row
const row = await fetch(
  `${API}/workspaces/content-pipeline/rows`,
  {
    method: "POST",
    headers: H,
    body: JSON.stringify({
      data: { title: "From Node", status: "drafted" },
    }),
  }
).then((r) => r.json());

// Seal it
await fetch(
  `${API}/workspaces/content-pipeline/rows/${row.id}`,
  {
    method: "PATCH",
    headers: H,
    body: JSON.stringify({ data: { status: "sealed" } }),
  }
);
SSE · listen for changestypescript
// Node 20+ supports EventSource via the 'eventsource' package
import { EventSource } from "eventsource";
import { connectorFaqs } from "@/lib/connector-faqs";

const es = new EventSource(
  "https://trydock.ai/api/workspaces/content-pipeline/subscribe",
  {
    fetch: (url, init) =>
      fetch(url, {
        ...init,
        headers: {
          ...init?.headers,
          Authorization: `Bearer ${process.env.DOCK_API_KEY}`,
        },
      }),
  }
);
es.addEventListener("row.updated", (e) => {
  console.log("row updated:", JSON.parse(e.data));
});

Verify

DOCK_API_KEY=dk_... node -e "fetch('https://trydock.ai/api/me', \
  {headers:{Authorization:\`Bearer ${process.env.DOCK_API_KEY}\`}}) \
  .then(r=>r.json()).then(console.log)"

Troubleshooting

Symptom
Fix
fetch not defined
Node version is below 20. Upgrade. On 18.x you can use node-fetch@3 as a drop-in polyfill.
Typescript typing gaps
Generate typed clients from https://trydock.ai/openapi.json with openapi-typescript.

Frequently asked questions

How do I connect Dock to Node.js (from scratch)?
Add Dock as a remote MCP server in Node.js (from scratch). Either let Node.js (from scratch)'s OAuth 2.1 + DCR flow handle auth (recommended; no credential ceremony), or paste a scoped Dock `dk_` API key in Node.js (from scratch)'s MCP config under the `Authorization: Bearer dk_…` header.
Does Node.js (from scratch) work with Dock's MCP server?
Yes. Dock exposes 43 MCP tools at `https://trydock.ai/api/mcp` over HTTP transport with OAuth 2.1 + DCR and Bearer-token auth. Any MCP-spec-compliant client, including Node.js (from scratch), discovers them via the standard `tools/list` handshake. Learn more →
How do I limit which Dock workspaces Node.js (from scratch) can write to?
When you mint the `dk_` key for Node.js (from scratch) in Settings → API keys, pick the workspace from the dropdown. The key returns 403 on every other workspace regardless of what the prompt asks. To scope across multiple, mint multiple keys or add the agent as an explicit member of each. Learn more →
How do I see what Node.js (from scratch) did in my Dock workspace?
Open the workspace in your browser. Every row Node.js (from scratch) created or updated is stamped with the agent's identity (orb + name) in the createdBy / updatedBy field. The workspace activity feed shows every action chronologically. Learn more →
How do I undo a row Node.js (from scratch) wrote to Dock?
Open the row, click the kebab menu, choose Delete (soft-delete preserves history). For bulk reverts use the activity feed to find the agent's session and delete its rows in batch. To prevent future writes, revoke Node.js (from scratch)'s `dk_` key in Settings → API keys.
Can multiple Node.js (from scratch) sessions share state through Dock?
Yes. Every Node.js (from scratch) session reads and writes the same workspace, so handoffs across machines or across long-running multi-session workflows just work. The Dock workspace IS the shared state; no separate message bus required.
Does Node.js (from scratch) need OAuth or a dk_ API key for Dock?
Either works. OAuth 2.1 + DCR is the recommended path: Node.js (from scratch) hits Dock's discovery endpoint at `/.well-known/oauth-authorization-server` and auto-registers as a client. The `dk_` Bearer token path is fine for owned-code agents and CI scripts; pick whichever fits your stack. Learn more →
How do I call Dock's REST API from a Node.js script?
Native `fetch`: `await fetch('https://trydock.ai/api/workspaces', { headers: { Authorization: `Bearer ${process.env.DOCK_API_KEY}` } })`. Works in Node 18+, Bun, and edge runtimes without a third-party HTTP library.
How do I call Dock's MCP server from raw Node.js (no SDK)?
POST JSON-RPC payloads with fetch: `fetch('https://trydock.ai/api/mcp', { method: 'POST', headers: { Authorization: 'Bearer dk_...', 'Content-Type': 'application/json' }, body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'tools/list' }) })`.
How do I authenticate a Node.js cron / Lambda / cloud function to Dock?
Store `DOCK_API_KEY` in your platform's secrets store (AWS Secrets Manager, Vercel env vars, Cloudflare Worker secrets). Read at runtime; never bundle into source. The same `dk_` key format works across every Node-runtime environment.

Related

Updated