Agentsfera Logo
AgentsferaAgentsfera
HomeUse CasesIntegrationsPricingDocs
Contact

Docs

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

Platforms

Java SDK

Agentsfera Java SDK

The Agentsfera Java SDK provides an enterprise-grade JVM client for integrating MCP functionality into Java applications, microservices, and backend systems. Built on the official Model Context Protocol Java library, it delivers robust access to 500+ business integrations through a type-safe, concurrent API designed for production environments.

Why Use the Java SDK?

  • Enterprise JVM Compatibility: Works seamlessly with Spring Boot, Jakarta EE, Micronaut, Quarkus, and traditional Java applications on JDK 11+.
  • Concurrent Programming: Built-in CompletableFuture support for non-blocking, asynchronous tool calls with thread-safe operations.
  • Type Safety & Generics: Full Java type system integration with compile-time checking and IDE autocomplete for all MCP operations.
  • Flexible Dependency Management: Install via Maven Central, Gradle, or SBT with automatic transitive dependency resolution.

Installation & Setup

Add the dependency to your build configuration (Maven, Gradle, or SBT), configure HTTP headers for authentication, then access tools from any enabled integration using standard Java patterns and try-with-resources for connection management.

Installation

Add the official MCP Java SDK to your project:

<dependency>
    <groupId>io.github.modelcontextprotocol</groupId>
    <artifactId>mcp-java-sdk</artifactId>
    <version>1.0.0</version>
</dependency>

Java SDK

import io.github.mcp.client.McpClient;
import io.github.mcp.client.transport.HttpTransport;
import io.github.mcp.client.transport.TransportConfig;
import io.github.mcp.types.CallToolRequest;
import io.github.mcp.types.Tool;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;

public class McpExample {
    public static void main(String[] args) throws Exception {
        // Configure HTTP transport for Agentsfera
        Map<String, String> headers = new HashMap<>();
        headers.put("Authorization", "Bearer sk-7aefcd76-44c0-4687-a0a9-43599d050fdd");
        headers.put("Content-Type", "application/json");
        // Optional: Unique identifier for your user across MCP sessions
        // Use the same ID to maintain session continuity across reconnects
        headers.put("user-session-id", "your-user-unique-id");
        
        TransportConfig config = TransportConfig.builder()
            .baseUrl("https://api.agentsfera.ai")
            .headers(headers)
            .build();
        
        HttpTransport transport = new HttpTransport(config);
        
        // Create and initialize the MCP client
        try (McpClient client = new McpClient(transport)) {
            // Initialize connection
            client.initialize().get();
            
            // List available tools from all enabled integrations
            CompletableFuture<List<Tool>> toolsFuture = client.listTools();
            List<Tool> tools = toolsFuture.get();
            
            System.out.println("Available tools: " + 
                tools.stream()
                    .map(Tool::getName)
                    .reduce((a, b) -> a + ", " + b)
                    .orElse("none"));
            
            // Example: Call a tool (adjust based on your enabled integrations)
            Map<String, Object> arguments = new HashMap<>();
            arguments.put("query", "project update");
            arguments.put("max_results", 10);
            
            CallToolRequest request = CallToolRequest.builder()
                .name("gmail-search-emails")  // Gmail integration example
                .arguments(arguments)
                .build();
            
            CompletableFuture<Object> resultFuture = client.callTool(request);
            Object result = resultFuture.get();
            
            System.out.println("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 Java SDK integration.

Agentsfera

Agentsfera

Connect your AI solution to data with built-in authentication.

Product

  • Home
  • Use Cases
  • Integrations
  • Pricing
  • Docs

Company

  • Newsroom
  • Contact
  • Our Story

© 2025 Agentsfera. All rights reserved.

  • Terms of Service
  • Privacy Policy