Agentsfera Logo
AgentsferaAgentsfera
HomeUse CasesIntegrationsPricingDocs
Contact

Docs

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

Platforms

Java SDK

Use the official Java SDK to integrate this server into your Java applications and services.

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