+
Skip to content

Pure java implementation of Google A2A protocol. Integrate your spring boot java applications with A2A protocol , includes client and sever both. Any agent built with a2ajava will also be exposed as MCP tool automatically

License

Notifications You must be signed in to change notification settings

vishalmysore/a2ajava

Repository files navigation

Java Implementation of Google's A2A Protocol: Connecting the Agentverse

This project provides a Java implementation for both an A2A (Agent-to-Agent) server and client. A2A is an open protocol developed by Google to standardize how AI agents communicate and exchange information, fostering a vibrant ecosystem of interoperable AI. This api also supports building MCP Servers in Java with use of simple annotations. Imagine a world where diverse AI agents, built with different tools and by different creators, can seamlessly collaborate to solve complex problems - that's the vision A2A is bringing to life. This implementation demonstrates how to set up this communication in Java, using the Spring Framework, with a focus on sending and retrieving tasks. a2ajava is a Swiss Army knife for building agentic applications. It is multi-protocol — works seamlessly with both A2A (Agent-to-Agent) and MCP (Model Context Protocol). It is multi-language — supports Java, Kotlin, and Groovy. It is multi-platform — compatible with Gemini, OpenAI, Claude, and Grok. It is multi-client — includes A2A and MCP clients with connectors in Java, Node, and Python. It offers multi-integration — out-of-the-box support for Selenium, human-in-the-loop workflows, and multi-LLM voting for consensus-based decision making. Agents built using the A2A protocol with a2ajava run seamlessly on MCP as well, ensuring maximum interoperability across platforms.

Need More Info? Ask DeepWiki codecov Test Number MIT License Java Version Spring Boot

Quick Start

Use these example to quickly build agents using this library , forking and cloning these examples is the best way to get started with a2ajava.

  • Spring A2A Agent - Use a2ajava to build a spring agent using A2A and MCP, can work with a2a client or with mcp client like claude desktop or connect to visual studio code as agent. This should be the first project to learn if you are new to agentic ai.
  • Connect MCP Agent in Java - MCP Connector for Java Based agents , connect your a2a server to MCP client like claude or connect your MCP server to a2a client. Or vice versa or any permutation and combination
  • Database Agent - Use a2ajava to build a database agent using Derby DB, start stop database , insert data , create table all with agentic operation for both mcp as well as a2a
  • Standalone Java - Several Examples on how to Use a2ajava to build a standalone java agent using A2A and MCP work with any client
  • Log Monitoring Agent - Use a2ajava to build a log monitoring agent which triggers a2a task based on the log messages. Works with both a2a and mcp clients dual protocol
  • A2A Kafka Agent - Use a2ajava to build a kafka agent which can trigger a2a task or mcp tool based on the kafka messages.
  • A2A Selenium Web Agent - Use a2ajava to build a selenium agent which can trigger a2a task or mcp tool for web browsing , validation of web pages.
  • A2A Grafana Agent - Build observable Agents using A2A or MCP and Grafana
  • A2A MongoDB RAG Agent – Perform semantic search and reasoning across agent tasks using RAG with MongoDB Agent.
  • Simple Agent in Kotlin - Use A2AJava to build a simple agent in Kotlin.
  • Build Agent in MCP - Use A2AJava to build a simple agent in MCP.
  • MCP Agent in Kotlin - Build MCP Agent in Kotlin and connect to Claude or A2A Clients
  • MCP and A2A RAG Server - State of the art RAG server using A2A and MCP with MongoDB Atlas works with both MCP as well as A2A clients
  • A2A and MCP Agent with Security - Build A2A and MCP agent with security using Spring Security and JWT.
  • A2A and MCP in Groovy - Build A2A and MCP agent in Groovy using A2AJava library.
  • A2A and MCP in Scala - Build A2A and MCP agent in Scala using A2AJava library.
  • A2A and MCP with Playwright - Build A2A and MCP agent with Playwright for web automation using A2AJava library.
  • MCP and A2A with Apache Thrift - Build A2A and MCP agent with Apache Thrift for cross-language communication using A2AJava library. This example demonstrates how to use Thrift to call a service implemented in another language (e.g., Python, Go, C++) from a Java-based A2A or MCP agent.
  • Single MCP Server and Client- Build a MCP server and client using A2AJava library. This example demonstrates how to build a MCP server and client using A2AJava library. It also demonstrates how to use the MCP protocol to call tools and tasks from the server.
  • MCP Multi Server and Client - Build a MCP server and client with multiple servers using A2AJava library. This example demonstrates how to build a MCP server and client with multiple servers using A2AJava library. It also demonstrates how to use the MCP protocol to call tools and tasks from the server.
  • Agentic Mesh - 4 Servers- Build a Agentic Mesh using A2AJava library. This example demonstrates how to build a Agentic Mesh using A2AJava library. It also demonstrates how to use the A2A protocol to call tools and tasks from the server.*

Coming Soon

  • A2A Sensor Agent – Use A2A to stream data from physical sensors and trigger real-time actions. ( Please look at ChotuRobo Series)
  • A2A Home Automation Agent – Use A2A to control smart home devices via MQTT or Home Assistant integrations. ( Please look at ChotuRobo Series)
  • A2A MyScale Agent – Use A2A to run scalable, SQL-based vector searches on tasks and documents with MyScale.

Tutorials

Live Demo

Live demos have been deployed on hugginface you are welcome to try them out. Or clone the space and create your own space

  • A2A MCP RAG Application with Tool calling - A2A Java Agent with Spring Boot and MongoDB Atlas for semantic search and reasoning. This application demonstrates how to use A2A and MCP protocols to build a RAG application with tool calling capabilities. It uses MongoDB Atlas for vector search and reasoning across agent tasks.
  • A2A and MCP RBAC Security - A2A and MCP demo with RBAC security. This application demonstrates how to use A2A and MCP protocols to build a secure application with role-based access control. It uses Spring Security and JWT for authentication and authorization.
  • A2A and MCP with Selenium - A2A and MCP demo with Selenium integration. This application demonstrates how to use A2A and MCP protocols to build a web automation application with Selenium. It uses Spring Boot and Selenium for web automation and A2A and MCP protocols for communication.
  • A2A and MCP with Playwright - A2A and MCP demo with Playwright integration. This application demonstrates how to use A2A and MCP protocols to build a web automation application with Playwright. It uses Spring Boot and Playwright for web automation and A2A and MCP protocols for communication.
  • A2A and MCP with Spring - A2A and MCP demo with Spring integration. This application demonstrates how to use A2A and MCP protocols to build a web application with Spring Boot. It uses Spring Boot and A2A and MCP protocols for communication.
  • A2A and MCP with Database - A2A and MCP demo with Database integration. This application demonstrates how to use A2A and MCP protocols to build a database application with Spring Boot and Derby DB. It uses Spring Boot and A2A and MCP protocols for communication.

Whats so special about A2AJava library?

You can simple annotate your classes with @Agent and @Action and build a server. The library will take care of the rest. You can also use this library to build a client to send and receive messages from the server. The library is built on top of Spring Boot and uses Jackson for JSON serialization/deserialization. The library is designed to be easy to use and extend, so you can build your own agents quickly and easily. ALl methods annotated with @Action are exposed as A2A tasks and also MCP tools you dont need to do anything . Infuse AI in any running application

You can convert you entire springboot based application into a2a and mcp compliant agent by using these 4 annotations:

1 @EnableAgent  - converts your springboot application into an A2A agent
2 @EnabaleAgentSecurity- adds security features to your agent
3 @Agent(groupName = "", groupDescription = "") - creates an agent group
4 @Action(description = "") - creates an action within the agent group

Maven Dependency

you can include this library in your project by following dependency in your pom.xml file:

<dependency>
    <groupId>io.github.vishalmysore</groupId>
    <artifactId>a2ajava</artifactId>
    <version>0.1.8.2</version>
</dependency>

and for annotations you can use the following dependency:

<dependency>
    <groupId>io.github.vishalmysore</groupId>
    <artifactId>tools4ai-annotations</artifactId>
    <version>0.0.2</version>
</dependency>

optionally for security you can use the following dependency:

<dependency>
<groupId>io.github.vishalmysore</groupId>
<artifactId>tools4ai-security</artifactId>
<version>0.0.3</version>
</dependency>

Get the latest version from here

Articles

A2A Protocol: A Universal Agent Language + MCP Protocol USB-C port for AI applications

The A2A protocol, spearheaded by Google, is designed to be the universal language for AI agents. It moves us away from a closed way of agent communication methods and towards a future where agents can:

  • Discover each other's capabilities.
  • Securely exchange information.
  • Coordinate actions to achieve common goals.

Key components of the A2A protocol include:

  • Agents: The autonomous entities that communicate.
  • Messages: The containers for information exchanged between agents.
  • Parts: The building blocks of a message (text, files, structured data).
  • Tasks: The units of work that agents perform for each other.
  • Agent Card: A cornerstone of A2A, think of it as an agent's digital business card.

The Agent Card: An Agent's Identity

The Agent Card is a JSON-formatted file that an agent publishes to advertise its capabilities. It's typically located at a well-known URL (/.well-known/agent.json) and provides essential information for other agents to discover and interact with it. An Agent Card typically includes:

  • Agent Name and Description: Human-readable information about the agent.
  • Endpoint URL: The address where the agent can be reached for A2A communication.
  • Version: The A2A protocol version the agent supports.
  • Capabilities: The features the agent supports (e.g., streaming, push notifications).
  • Authentication: The security mechanisms the agent requires.
  • Skills: A detailed description of the specific functions the agent can perform.

With Agent Cards, agents can dynamically discover each other and understand how to communicate, enabling flexible and extensible multi-agent systems.

In our case we have exposed it as a rest end point

Features

This Java implementation provides the foundation for building A2A and MCP compliant agents:

  • A2A Server:

    • Receives and processes tasks from client agents, acting as a hub for agent collaboration.
    • Manages the lifecycle of tasks, tracking their state and history.
    • Serializes task data into JSON for standardized communication.
    • Exposes A2A endpoints using the Spring MVC framework. As rest calls as well as one endpoint for JSONRPC communicaiton
  • A2A Client:

    • Sends tasks to A2A servers, initiating agent interactions.
    • Retrieves task information, allowing agents to monitor progress and obtain results.
    • Communicates with A2A servers using Spring's RestTemplate. With JSONRPC protocol, there is only one endpoint to send and receive messages.
  • JSON Handling: Uses Jackson, a Java library, for seamless JSON serialization/deserialization.

  • Task Management: Supports the core A2A task operations: sending tasks and retrieving their information, including historical data.

  • Message Parts: Handles TextPart, FilePart, and DataPart, providing flexibility in message content to support various data formats.

  • ** MCP Server:**

    • Exposes MCP endpoints using the Spring MVC framework.
    • Supports MCP tools and tasks, allowing agents to interact with MCP clients.
    • Provides a unified interface for both A2A and MCP clients, enabling seamless communication across protocols.

Usage

Fastest way to use to create the A2A amd MCP server is by using the annonvation

@SpringBootApplication
@EnableAgent
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}

This will expose all the services annotated with @Action as A2A tasks and MCP tools. You can also use the @Agent annotation to create an agent and register it with the A2A server.

@Service
@Agent(groupName ="whatThisPersonFavFood", groupDescription = "Provide persons name and then find out what does that person like")
@Slf4j
public class SimpleService {

    /**
     * Each action has access to AIProcessor and ActionCallback which are autowired by tools4ai
     */
    private ActionCallback callback;

    /**
     * Each action has access to AIProcessor and ActionCallback which are autowired by tools4ai
     */
    private AIProcessor processor;
    public SimpleService(){
      log.info(" Created Simple Service");
    }

    @Action(description = "Get the favourite food of a person")
    public String whatThisPersonFavFood(String name) {
        if("vishal".equalsIgnoreCase(name))
        return "Paneer Butter Masala";
        else if ("vinod".equalsIgnoreCase(name)) {
            return "aloo kofta";
        }else
            return "something yummy";
    }

}

Thats it , yeah its that simple!!!

Now this agent will be avaiable to both a2a as well as MCP clients. For more advanced features look at the tutorials section

Client

If you want to connect a java base client you can use

  A2AAgent a2aagent = new A2AAgent();
  a2aagent.connect("http://localhost:7860");
  Object task = a2aagent.remoteMethodCall("vishal is coming home what should i cook");

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change

Important Disclaimer(s)

  • The A2A and MCP protocol is an evolving standard, and this implementation may need to be updated as the protocols matures. Always refer to the official A2A documentation for the latest specifications and best practices.
  • This implementation is not affiliated with or endorsed by Google or Anthropic. It is my independent effort to demonstrate the A2A and MCP protocol in Java.
  • Unit test coverage needs to be enhanced , will be working on it

About

Pure java implementation of Google A2A protocol. Integrate your spring boot java applications with A2A protocol , includes client and sever both. Any agent built with a2ajava will also be exposed as MCP tool automatically

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载