| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Browser Tool Calling Protocol (BTCP) JavaScript/TypeScript client for connecting browser extensions to AI agents.
This is a proof-of-concept implementation of the BTCP Specification, enabling AI agents to discover and invoke tools directly within browsers through client-defined interfaces.
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ AI Agent │────▶│ BTCP Server │◀────│ Browser Client │
│ (Tool Caller) │ │ (Message Broker)│ │ (Tool Provider)│
└─────────────────┘ └─────────────────┘ └─────────────────┘
│ │ │
│ POST /message │ SSE /events │ POST /message
│ SSE /events │ │ SSE /events
└───────────────────────┴───────────────────────┘
Communication:
• Server → Client: SSE (Server-Sent Events) - efficient streaming
• Client → Server: HTTP POST - only when needed
npm install btcp-clientnpm run build
npm run serverimport { BTCPClient } from 'btcp-client';
const client = new BTCPClient({
serverUrl: 'http://localhost:8765',
debug: true,
});
// Register a custom tool handler
client.getExecutor().registerHandler('greet', async (args) => {
return `Hello, ${args.name}!`;
});
// Connect and register tools
await client.connect();
await client.registerTools([
{
name: 'greet',
description: 'Greet a person by name',
inputSchema: {
type: 'object',
properties: {
name: { type: 'string' }
}
}
}
]);
console.log(`Session ID: ${client.getSessionId()}`);// Agent connects to the same server
const agent = new BTCPAgent(sessionId);
await agent.connect();
await agent.joinSession();
// Call tools on the browser
const result = await agent.callTool('greet', { name: 'World' });
// Result: "Hello, World!"The main client class for browser-side tool providers.
const client = new BTCPClient({
serverUrl: 'http://localhost:8765', // Server URL (HTTP, not WS)
sessionId: 'my-session', // Optional session ID
debug: true, // Enable debug logging
autoReconnect: true, // Auto-reconnect on disconnect
reconnectDelay: 1000, // Reconnection delay (ms)
maxReconnectAttempts: 5, // Max reconnection attempts
connectionTimeout: 10000, // Connection timeout (ms)
});Handles tool execution with optional browser agent integration.
const executor = client.getExecutor();
// Register a custom handler
executor.registerHandler('myTool', async (args) => {
return { result: args.value * 2 };
});
// Set browser agent for DOM automation
executor.setBrowserAgent(browserAgent);import {
createRequest,
createResponse,
createTextContent,
createImageContent,
parseMessage,
serializeMessage,
} from 'btcp-client';
// Create a text response
const content = createTextContent('Hello, World!');
// Create an image response
const image = createImageContent(base64Data, 'image/png');When a browser agent is configured, the following tools are automatically available:
| Tool | Description |
|---|---|
| browser_snapshot | Get DOM snapshot |
| browser_click | Click an element |
| browser_fill | Fill a form field |
| browser_type | Type text into element |
| browser_hover | Hover over element |
| browser_press | Press keyboard key |
| browser_scroll | Scroll page/element |
| browser_wait | Wait for element |
| browser_get_text | Get element text |
| browser_get_attribute | Get element attribute |
| browser_is_visible | Check visibility |
| browser_get_url | Get current URL |
| browser_get_title | Get page title |
| browser_screenshot | Take screenshot |
| browser_execute | Execute command |
| evaluate | Execute JavaScript |
| echo | Echo message (testing) |
# Build the project
npm install
npm run build
# Terminal 1: Start the server
npm run server
# Terminal 2: Start the browser client
npm run example
# Terminal 3: Run the agent (pass the session ID from terminal 2)
npm run agent -- <session-id>| Endpoint | Method | Description |
|---|---|---|
| /events | GET | SSE stream for receiving messages |
| /message | POST | Send JSON-RPC messages |
| /health | GET | Health check |
{
"jsonrpc": "2.0",
"id": "2",
"method": "tools/register",
"params": {
"tools": [
{
"name": "greet",
"description": "Greet a person",
"inputSchema": {
"type": "object",
"properties": {
"name": { "type": "string" }
}
}
}
]
}
}{
"jsonrpc": "2.0",
"id": "3",
"method": "tools/call",
"params": {
"name": "greet",
"arguments": { "name": "World" }
}
}{
"jsonrpc": "2.0",
"id": "3",
"result": {
"content": [
{ "type": "text", "text": "Hello, World!" }
],
"isError": false
}
}For use in a Chrome extension:
// In your extension's content script or background script
import { BTCPClient } from 'btcp-client';
import { BrowserAgent } from 'btcp-browser-agent';
const agent = new BrowserAgent();
await agent.launch();
const client = new BTCPClient({
serverUrl: 'http://localhost:8765',
debug: true
});
client.getExecutor().setBrowserAgent(agent);
await client.connect();
await client.registerTools(client.getExecutor().getToolDefinitions());MIT
| Back | FazBrowse Home | New Git URL |