@adcp/client

Official TypeScript/JavaScript client for the Ad Context Protocol (AdCP). Seamlessly communicate with advertising agents using MCP and A2A protocols.
Installation
npm install @adcp/client
Requirements
- Node.js: Version 18.0.0 or higher (specified in
.nvmrc)
- TypeScript: 5.3.0+ for full type safety
- Peer Dependencies:
@a2a-js/sdk and @modelcontextprotocol/sdk
Quick Start
import { ADCPMultiAgentClient } from '@adcp/client';
const client = new ADCPMultiAgentClient([{
id: 'premium-agent',
name: 'Premium Ad Agent',
agent_uri: 'https://agent.example.com/mcp/',
protocol: 'mcp',
auth_token_env: 'PREMIUM_AGENT_TOKEN'
}]);
const agent = client.agent('premium-agent');
const result = await agent.getProducts({
brief: 'Looking for premium coffee advertising',
promoted_offering: 'Artisan coffee blends'
});
if (result.success) {
console.log('Products:', result.data.products);
} else {
console.error('Error:', result.error);
}
🔧 Easy Configuration
Environment-based Setup (Recommended)
Set your agent configuration once and auto-discover everywhere:
ADCP_AGENTS='[{"id":"agent1","name":"My Agent","agent_uri":"https://agent.example.com","protocol":"mcp","auth_token_env":"MY_AGENT_TOKEN"}]'
MY_AGENT_TOKEN=your_actual_token_here
Security Best Practices:
- Use
auth_token_env to reference environment variables instead of hardcoding tokens
- Add
.env files to .gitignore
- Rotate tokens regularly
- Use different tokens for different environments
const client = ADCPMultiAgentClient.fromEnv();
console.log(`Found ${client.agentCount} agents`);
const client = new ADCPMultiAgentClient([
{ id: 'agent1', agent_uri: 'https://...', protocol: 'mcp' }
]);
Multiple Agents Made Simple
const client = new ADCPMultiAgentClient([
{ id: 'premium', agent_uri: 'https://premium.example.com', protocol: 'mcp' },
{ id: 'budget', agent_uri: 'https://budget.example.com', protocol: 'a2a' }
]);
const premium = client.agent('premium');
const budget = client.agent('budget');
const allResults = await client.getProducts(params);
🛡️ Type Safety
Get full TypeScript support with compile-time checking and IntelliSense:
const agent = client.agent('agent-id');
await agent.getProducts(params);
await agent.createMediaBuy(params);
await agent.listCreativeFormats(params);
const result = await agent.executeTask('get_products', params);
const customResult = await agent.executeTask<MyCustomResponse>('custom_task', params);
const withHandler = await agent.getProducts(
{ brief: "Premium inventory" },
async (inputRequest) => ({ approve: true })
);
Key Features
- 🔗 Unified Interface - Single API for MCP and A2A protocols
- ⚡ Async Support - Handle long-running tasks with webhooks and deferrals
- 🔐 Built-in Auth - Bearer tokens and API key support with environment variable security
- 🛡️ Type Safe - Full TypeScript with comprehensive types
- 📊 Production Ready - Circuit breakers, retries, and validation
- 🔒 Security-First - No hardcoded tokens, SSRF protection, secure defaults
- 🧪 Protocol Compliance - 100% A2A and MCP specification compliance
- 🌐 Cross-Platform - Works with Node.js 18+ and modern JavaScript environments
Async Execution Model
Handle complex async patterns with ease:
const client = ADCPClient.simple('https://agent.example.com', {
authToken: 'token',
inputHandler: async (request) => {
if (request.type === 'user_approval') {
const approved = await getUserApproval(request.data);
return { approved };
}
return { defer: true };
}
});
const result = await client.executeTask('analyze_campaign', {
campaign_id: '12345'
});
if (result.status === 'submitted') {
console.log('Task ID:', result.submitted.taskId);
console.log('Webhook:', result.submitted.webhookUrl);
}
if (result.status === 'deferred') {
const continuation = result.deferred;
const finalResult = await client.resumeDeferredTask(
continuation,
{ approved: true, budget: 50000 }
);
}
Multi-Agent Support
import { ADCPMultiAgentClient } from '@adcp/client';
const client = new ADCPMultiAgentClient([
{
id: 'agent1',
name: 'MCP Agent',
agent_uri: 'https://agent1.example.com/mcp/',
protocol: 'mcp',
requiresAuth: true,
auth_token_env: 'AGENT1_TOKEN'
},
{
id: 'agent2',
name: 'A2A Agent',
agent_uri: 'https://agent2.example.com',
protocol: 'a2a'
}
]);
const result = await client.executeTask('agent1', 'get_products', params);
const results = await client.executeTaskOnAll('get_products', params);
Documentation
Examples
git clone https://github.com/your-org/adcp-client
cd adcp-client/examples
npx tsx basic-usage.ts
npx tsx async-patterns.ts
npx tsx multi-agent.ts
Testing UI
The package includes an interactive testing framework:
git clone https://github.com/your-org/adcp-client
cd adcp-client
npm install
npm run dev
Contributing
We welcome contributions! See CONTRIBUTING.md for guidelines.
License
MIT - see LICENSE for details.
Links