Docs

Choose your preferred AI platform and authentication method to get started with Agentsfera.

TypeScript

TypeScript SDK

Agentsfera TypeScript SDK

The Agentsfera TypeScript SDK provides a modern, type-safe client for integrating MCP functionality into Node.js applications, browser-based tools, and server-side JavaScript projects. Built on the official Model Context Protocol SDK, it enables seamless access to 500+ business integrations through a clean, Promise-based API.

Why Use the TypeScript SDK?

  • Full Type Safety: Complete TypeScript definitions for all MCP operations, tools, and responses - catch errors at compile time.
  • Universal Compatibility: Works in Node.js, Bun, Deno, and modern browsers with full ESM support.
  • StreamableHTTP Transport: Efficient HTTP-based communication with built-in streaming for large responses and real-time data.
  • Session Management: Optional user-session-id headers maintain state across reconnections for stateful workflows.

Installation & Setup

Install via npm, yarn, pnpm, or bun. Authenticate with API keys passed in headers, then call tools from any of your enabled integrations using a unified interface.

Installation

Install the official MCP SDKs using your package manager:

npm install @modelcontextprotocol/sdk

TypeScript SDK

import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { Client } from "@modelcontextprotocol/sdk/client/index.js"

// Create MCP client
const client = new Client({
  name: "undefined",
  version: "1.0.0"
})

// Connect to the MCP server
await client.connect(new StreamableHTTPClientTransport(
  new URL("https://api.agentsfera.ai"),
  {
    requestInit: {
      headers: {
        "Authorization": "Bearer sk-7aefcd76-44c0-4687-a0a9-43599d050fdd",
        "Content-Type": "application/json",
        // Optional: Unique identifier for your user across MCP sessions
        // Use the same ID to maintain session continuity across reconnects
        "user-session-id": "your-user-unique-id"
      }
    }
  }
))

// List available tools from all enabled integrations
const { tools } = await client.listTools()
console.log(`Available tools: ${tools.map(t => t.name).join(", ")}`)

// Example: Call a tool (adjust based on your enabled integrations)
const result = await client.callTool({
  name: "gmail-search-emails", // Gmail integration example
  arguments: {
    query: "project update",
    max_results: 10
  }
})

console.log("Tool result:", result)

// Tool result will contain a redirect URL to Google OAuth2 login page.
// You can customize the redirect URL to your application/agent.
// After that your application/agent will repeat the tool call.

No API keys found. Create an API key first to use the TypeScript SDK integration.