TypeScript SDK
The agentbridge-sdk package is a type-safe, ESM-first client for the AgentBridge API. Install it with one command and start executing MCP tools immediately — no need to construct HTTP requests, manage headers, or parse response envelopes manually.
The SDK is ESM-first and works in Node.js 18+, Deno, Bun, and modern bundlers (Vite, esbuild, Webpack 5). CommonJS (require()) is also supported via a dual-package build.
Installation #
npm install agentbridge-sdk
yarn add agentbridge-sdk
pnpm add agentbridge-sdk
Environment Setup #
Create a .env file (or use your platform's secret management) and add your API key:
# AgentBridge API Key — never commit this file
AGENTBRIDGE_API_KEY=ab_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Add .env to your .gitignore. If you use dotenv, load it before initializing the SDK. In Node.js 20.6+ you can use the built-in --env-file=.env flag.
Quick Example #
import { AgentBridge } from 'agentbridge-sdk';
const bridge = new AgentBridge(process.env.AGENTBRIDGE_API_KEY!);
const result = await bridge.execute({
provider: 'notion',
tool: 'create_page',
params: {
parent_id: 'abc123',
title: 'My First Page',
},
});
console.log(result.status); // "success"
console.log(result.data); // { id: '...', url: '...' }
console.log(result.latencyMs); // 381
console.log(result.executionId); // "exec_01HXZ..."
Constructor Options #
new AgentBridge(apiKey: string, options?: AgentBridgeOptions)
ab_live_. The SDK validates the prefix and throws if malformed.
https://api.agentbridge.in. Useful for self-hosted environments, local development proxies, or testing.
30000 (30 seconds). Set higher for providers with slow response times.
bridge.execute() #
Execute any tool on any connected provider. This is the primary method you will use.
bridge.execute(params: ExecuteParams): Promise<ExecuteResult>
"create_issue") paired with provider, or a combined "provider.tool" string (e.g. "github.create_issue") with no provider needed.
"notion", "slack", "github", "google-drive", "gmail". Omit when using the "provider.tool" shorthand in tool.
Both calling styles are supported:
// Shorthand: provider.tool in a single field (recommended for agent routing)
await bridge.execute({
tool: "github.create_issue",
params: { repo: "acme/backend", title: "Fix memory leak" },
});
// Explicit: provider and tool as separate fields (backwards compatible)
await bridge.execute({
provider: "github",
tool: "create_issue",
params: { repo: "acme/backend", title: "Fix memory leak" },
});
bridge.getTools() #
Returns a sorted list of every tool across all providers as provider.tool strings. Ideal for populating an agent's tool list or building a UI tool-picker without needing to query each provider separately.
bridge.getTools(): Promise<string[]>
const tools = await bridge.getTools();
// [
// { name: "github.create_issue", description: "Create a new issue in a GitHub repository" },
// { name: "gmail.send_email", description: "Send an email via Gmail" },
// { name: "notion.create_page", description: "Create a new page in Notion" },
// { name: "slack.send_message", description: "Send a message to a Slack channel" },
// ...
// ]
// Pass descriptions to the LLM, then execute by name — no parsing needed
const chosen = tools.find(t => t.name.startsWith('github'));
await bridge.execute({ tool: chosen!.name, params: { repo: "acme/api", title: "Bug" } });
Other Methods #
bridge.integrations.list() #
List all integrations (connected providers) for the authenticated user.
const integrations = await bridge.integrations.list();
// Returns: Integration[]
// [{ id: '...', provider: 'notion', status: 'active', connectedAt: '...' }]
bridge.logs.list() #
Retrieve paginated execution logs for the authenticated user.
const logs = await bridge.logs.list({ page: 1, limit: 20 });
// Returns: PaginatedResponse<ExecutionLog[]>
console.log(logs.total); // 84
console.log(logs.data[0]); // { id, provider, tool, status, latencyMs, createdAt }
bridge.apiKeys methods #
Manage API keys programmatically. Requires admin scope.
// List all API keys (returns metadata only, not the key value)
const keys = await bridge.apiKeys.list();
// [{ id, name, prefix: 'ab_live_aBcD...', scope, createdAt }]
// Create a new API key — the full key is in the response
const newKey = await bridge.apiKeys.create({
name: 'prod-agent-v2',
scope: 'write',
});
console.log(newKey.key); // ab_live_... — save this immediately!
// Delete (revoke) an API key by its ID
await bridge.apiKeys.delete('key_01HXZ...');
// Subsequent requests with the deleted key return 401
TypeScript Interfaces #
The SDK ships with full TypeScript type definitions. Here are the core interfaces:
interface AgentBridgeOptions {
baseUrl?: string; // Default: 'https://api.agentbridge.in'
timeout?: number; // Default: 30000 (ms)
}
interface ExecuteParams {
tool: string; // bare name or "provider.tool" shorthand
provider?: string; // omit when using "provider.tool" in tool
params: Record<string, unknown>;
}
interface ExecuteResult {
status: 'success' | 'error';
data: Record<string, unknown>;
latencyMs: number;
executionId: string;
}
interface Integration {
id: string;
provider: string;
status: 'active' | 'disconnected';
connectedAt: string; // ISO 8601
}
interface ExecutionLog {
id: string;
provider: string;
tool: string;
status: 'success' | 'error';
latencyMs: number;
createdAt: string; // ISO 8601
}
interface ApiKey {
id: string;
name: string;
prefix: string; // e.g. 'ab_live_aBcD...'
scope: 'read' | 'write' | 'admin';
createdAt: string;
}
interface PaginatedResponse<T> {
data: T;
total: number;
page: number;
limit: number;
}
class AgentBridgeError extends Error {
statusCode: number;
error: string;
providerError?: Record<string, unknown>;
}
Error Handling #
The SDK throws an AgentBridgeError on any non-2xx response. Wrap calls in a try/catch block to handle errors gracefully:
import { AgentBridge, AgentBridgeError } from 'agentbridge-sdk';
const bridge = new AgentBridge(process.env.AGENTBRIDGE_API_KEY!);
try {
const result = await bridge.execute({
provider: 'notion',
tool: 'create_page',
params: { parent_id: 'bad-id', title: 'Test' },
});
console.log('Created:', result.data);
} catch (err) {
if (err instanceof AgentBridgeError) {
console.error('Status:', err.statusCode); // 422
console.error('Message:', err.message); // "Provider returned an error"
console.error('Provider:', err.providerError); // { object: 'error', code: '...' }
if (err.statusCode === 429) {
console.warn('Rate limited. Retry after backoff.');
}
} else {
// Network error, timeout, or unexpected exception
throw err;
}
}
Usage with Vercel AI SDK #
Use AgentBridge as a tool handler in the Vercel AI SDK's tool() pattern. This lets your AI model call AgentBridge tools naturally during a conversation:
import { openai } from '@ai-sdk/openai';
import { generateText, tool } from 'ai';
import { AgentBridge } from 'agentbridge-sdk';
import { z } from 'zod';
const bridge = new AgentBridge(process.env.AGENTBRIDGE_API_KEY!);
const { text } = await generateText({
model: openai('gpt-4o'),
prompt: 'Create a Notion page titled "Weekly Standup" in my workspace.',
tools: {
createNotionPage: tool({
description: 'Creates a new page in the user\'s Notion workspace',
parameters: z.object({
parent_id: z.string().describe('Parent page or database ID'),
title: z.string().describe('Page title'),
}),
execute: async ({ parent_id, title }) => {
const result = await bridge.execute({
provider: 'notion',
tool: 'create_page',
params: { parent_id, title },
});
return result.data;
},
}),
sendSlackMessage: tool({
description: 'Sends a message to a Slack channel',
parameters: z.object({
channel: z.string().describe('Slack channel ID'),
text: z.string().describe('Message text'),
}),
execute: async ({ channel, text }) => {
const result = await bridge.execute({
provider: 'slack',
tool: 'send_message',
params: { channel, text },
});
return result.data;
},
}),
},
});
Usage with LangChain #
Wrap AgentBridge tools as LangChain DynamicStructuredTool instances for use with any LangChain agent:
import { DynamicStructuredTool } from 'langchain/tools';
import { AgentBridge } from 'agentbridge-sdk';
import { z } from 'zod';
const bridge = new AgentBridge(process.env.AGENTBRIDGE_API_KEY!);
const slackTool = new DynamicStructuredTool({
name: 'send_slack_message',
description: 'Send a message to a Slack channel via AgentBridge',
schema: z.object({
channel: z.string().describe('Slack channel ID (e.g. C012AB3CD)'),
text: z.string().describe('Message text to send'),
}),
func: async ({ channel, text }) => {
const result = await bridge.execute({
provider: 'slack',
tool: 'send_message',
params: { channel, text },
});
return JSON.stringify(result.data);
},
});
const githubTool = new DynamicStructuredTool({
name: 'create_github_issue',
description: 'Create a new issue in a GitHub repository',
schema: z.object({
repo: z.string().describe('Repository in owner/repo format'),
title: z.string().describe('Issue title'),
body: z.string().optional().describe('Issue body (markdown)'),
labels: z.array(z.string()).optional().describe('Labels to apply'),
}),
func: async ({ repo, title, body, labels }) => {
const result = await bridge.execute({
provider: 'github',
tool: 'create_issue',
params: { repo, title, body, labels },
});
return JSON.stringify(result.data);
},
});
// Use with any LangChain agent:
// const agent = createOpenAIFunctionsAgent({ llm, tools: [slackTool, githubTool], prompt });