DEV Community

Cover image for Building an Agentic Mesh: A Practical Implementation with Multiple MCP Servers
vishalmysore
vishalmysore

Posted on

Building an Agentic Mesh: A Practical Implementation with Multiple MCP Servers

Introduction to Agentic Mesh

Agentic Mesh represents a new paradigm in distributed AI systems where multiple specialized AI agents work together in a coordinated network. Unlike traditional monolithic AI systems, an Agentic Mesh distributes capabilities across multiple specialized servers, each handling specific domains while maintaining the ability to communicate and collaborate.

Project Overview: A Four-Server Agentic Mesh Implementation

This project demonstrates a practical implementation of an Agentic Mesh using four specialized servers:

  1. Dessert Server: Manages dessert-related queries and recipes
  2. Gym Server: Handles fitness and workout related operations
  3. Restaurant Server: Manages restaurant bookings and cuisine information
  4. Yoga Server: Provides yoga-related guidance and poses

Each server operates independently but can be combined into a mesh for complex queries that span multiple domains.

Image description

Image description

Image description

Technical Architecture

Protocol Support

The implementation supports two key protocols:

  • MCP (Model Context Protocol): Enables interaction with AI models and tools
  • A2A (Agent-to-Agent): Google's protocol for communication between AI agents

Server Configuration

Each server is implemented as a Spring Boot application with:

  • Unique port assignments (7863-7866)
  • Independent configuration through properties files
  • Domain-specific service implementations
  • JSON-RPC endpoints for tool invocation

Server Implementations

1. Dessert Server (Port 7863)

@Agent(groupName = "dessertOperations")
public class DessertService {
    @Action(description = "Find popular Indian sweets")
    public String findIndianSweets() {
        return "Popular Indian Sweets: Gulab Jamun, Jalebi, Rasgulla...";
    }
}
Enter fullscreen mode Exit fullscreen mode

2. Gym Server (Port 7864)

@Agent(groupName = "gymOperations")
public class GymService {
    @Action(description = "Find a trainer for specific workout")
    public String findTrainer(String workoutType) {
        // Implementation for trainer matching
    }
}
Enter fullscreen mode Exit fullscreen mode

3. Restaurant Server (Port 7865)

@Agent(groupName = "restaurantOperations")
public class RestaurantService {
    @Action(description = "Make a restaurant reservation")
    public String makeReservation(String restaurant, String date, String time) {
        // Reservation logic
    }
}
Enter fullscreen mode Exit fullscreen mode

4. Yoga Server (Port 7866)

@Agent(groupName = "yogaOperations")
public class YogaService {
    @Action(description = "Get meditation techniques")
    public String getMeditationTechniques() {
        return "Meditation Techniques: Mindfulness, Transcendental...";
    }
}
Enter fullscreen mode Exit fullscreen mode

Mesh Integration

The real power of this implementation lies in its mesh capabilities. Using the AgentCatalog and AgenticMesh classes, you can:

  1. Connect to multiple servers simultaneously
  2. Process queries across different domains
  3. Combine results for comprehensive responses

Example of mesh integration:

@Log
public class MeshClient {
    public static void main(String[] args) {
        AgentCatalog agentCatalog = new AgentCatalog();
        // Connect to multiple servers
        agentCatalog.addAgent("http://localhost:7863/"); // Dessert Server
        agentCatalog.addAgent("http://localhost:7865/"); // Restaurant Server

        // Process cross-domain query
        String answer = agentCatalog.processQuery("Find a restaurant that serves good Gulab Jamun")
            .getTextResult();
    }
}
Enter fullscreen mode Exit fullscreen mode

Testing and Integration

Tool Discovery

Each server exposes its capabilities through a tools/list endpoint:

curl -H "Content-Type: application/json" `
-d '{"jsonrpc":"2.0","method":"tools/list","params":{},"id":9}' `
http://localhost:7863/
Enter fullscreen mode Exit fullscreen mode

Tool Invocation

Tools can be called using JSON-RPC format:

curl -H "Content-Type: application/json" `
-d '{
    "jsonrpc": "2.0",
    "method": "tools/call",
    "params": {
        "name": "findIndianSweets",
        "arguments": {
            "provideAllValuesInPlainEnglish": {}
        }
    },
    "id": 25
}' `
http://localhost:7863/
Enter fullscreen mode Exit fullscreen mode

Integration with AI Platforms

The implementation includes integration with Claude Desktop, allowing AI models to directly interact with the mesh:

{
"mcpServers": {
    "yogaserver": {
        "command": "java",
        "args": [
            "-jar",
            "mcp-connector-full.jar",
            "http://localhost:7866"
        ],
        "timeout": 30000
    }
}
}
Enter fullscreen mode Exit fullscreen mode

Benefits of This Architecture

  1. Modularity: Each server is independently deployable and maintainable
  2. Scalability: New domains can be added by implementing new servers
  3. Flexibility: Servers can be combined in different ways for various use cases
  4. Domain Specialization: Each server can be optimized for its specific domain
  5. Protocol Support: Dual support for MCP and A2A enables broad compatibility

Use Cases

  1. Cross-Domain Queries: "Find a gym near a restaurant that serves healthy desserts"
  2. Complex Workflows: Booking a yoga session followed by a restaurant reservation
  3. Integrated Experiences: Combining workout plans with dietary recommendations

Conclusion

This implementation demonstrates how Agentic Mesh can be practically realized using Spring Boot and modern protocols. The architecture provides a flexible, scalable framework for building distributed AI systems that can handle complex, multi-domain queries while maintaining modularity and ease of maintenance.

The project serves as a blueprint for building similar systems, showing how to:

  • Implement domain-specific AI agents
  • Configure inter-agent communication
  • Set up protocol support
  • Create mesh integrations
  • Handle cross-domain queries

This approach to AI system architecture represents a significant step forward in building more flexible, maintainable, and powerful AI solutions.

Code for the article is here

Top comments (0)