Tool

Expose Java methods as MCP server actions via annotations

Java library implementing Google's A2A protocol as both server and client, with annotations that also expose the same methods as MCP tools.

Works with javamcp

66
Spark score
out of 100
Updated 7 days ago
Version 1.0.0

Add to Favorites

Why it matters

Enable Java developers to rapidly expose existing business logic and methods as MCP-compatible server actions without writing integration boilerplate or managing service registration infrastructure.

Outcomes

What it gets done

01

Annotate Java methods to mark them for MCP export

02

Automatically generate MCP server endpoints from annotated methods

03

Bridge Java application logic to A2A-MCP protocol standards

04

Eliminate manual service registration and boilerplate code

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/vb-a2a-mcp-java-bridge | bash

Overview

A2A-MCP Java Bridge Server

A Java implementation of Google's A2A protocol, providing both server and client, that also exposes the same @Action-annotated methods as MCP tools automatically, so one Spring Boot codebase serves both A2A and MCP clients without separate implementations. Use it to add A2A agent-to-agent communication, MCP tool exposure, or both to a Java or Spring Boot application with a handful of annotations, rather than implementing either protocol's message and task handling from scratch.

What it does

a2ajava is a Java implementation of Google's A2A (Agent-to-Agent) protocol - the open standard for how AI agents discover each other, exchange messages, and coordinate on tasks - built as both a server and a client on top of Spring Boot. The same library also builds MCP servers: any method annotated @Action is automatically exposed as both an A2A task and an MCP tool, so one codebase serves both protocols without writing separate integrations for each. It is multi-protocol (A2A and MCP), multi-language (Java, Kotlin, Groovy), multi-platform (works with Gemini, OpenAI, Claude, and Grok), and multi-client (A2A and MCP client connectors in Java, Node, and Python), with out-of-the-box integrations for Selenium, human-in-the-loop workflows, and multi-LLM voting for consensus decisions.

When to use - and when NOT to

Use it to add agent-to-agent communication or MCP tool exposure to an existing Spring Boot application, or to build a new Java, Kotlin, or Groovy agent from scratch, when the goal is interoperability with both A2A-speaking agents and MCP clients like Claude Desktop from one implementation. It fits well for enterprise Java shops already on Spring who want agentic capability without adopting a separate Python or Node stack. It is not a managed or hosted agent platform - it is a library that has to be embedded in and deployed with the application; and per the project's own disclaimer, it is an independent implementation not affiliated with or endorsed by Google or Anthropic, tracking an evolving protocol that may need updates as it matures, so pinning to a specific tested version rather than always-latest is worth considering for production use.

Inputs and outputs

Input is Java, Kotlin, or Groovy source annotated with @EnableAgent on the Spring Boot application class, optionally @EnableAgentSecurity to add security features, @Agent(groupName, groupDescription) to group related actions, and @Action(description) on individual methods - those four annotations cover the whole surface. Output is a running application that exposes those actions as A2A tasks over REST and JSON-RPC, and as MCP tools, simultaneously, plus a published Agent Card, a JSON file typically at /.well-known/agent.json, advertising the agent's name, endpoint, protocol version, capabilities, authentication requirements, and skills to other agents. Messages carry TextPart, FilePart, or DataPart content; the newer protocol surface adds message/send and message/stream, succeeding tasks/send and tasks/sendSubscribe, push notification config CRUD, authenticated extended agent cards, additional task states such as rejected and auth-required, conversation context fields like messageId, taskId, and contextId, and JWS-signed agent cards.

Integrations

Ships as Maven dependencies: io.github.vishalmysore:a2ajava (core), tools4ai-annotations (for the annotation API), and an optional tools4ai-security module adding Spring Security and JWT-based authentication. Built on Spring Boot 3.2.4, Java 23, and Jackson for JSON serialization. The project's own example catalog demonstrates integrations with MongoDB Atlas for RAG and vector search, Kafka, Grafana, Selenium and Playwright for web automation, Apache Thrift for cross-language calls, and Kubernetes deployment, plus ports of the library to Kotlin, Groovy, and Scala.

Who it's for

Java and Spring developers who want to add A2A agent communication and MCP tool exposure to an application through annotations rather than hand-rolled protocol code, especially teams already standardized on the Spring ecosystem who want to interoperate with MCP clients like Claude alongside other A2A agents. The project is MIT licensed.

Source README

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.

Latest A2A Protocol Support

a2ajava tracks the evolution of the A2A specification. In addition to the original tasks/* methods, the JSON-RPC endpoint now speaks the newer protocol surface, so clients written against either generation of the spec work unchanged:

Capability Methods / Types
Message-centric messaging (successor of tasks/send / tasks/sendSubscribe) message/send, message/stream
Push notification config CRUD tasks/pushNotificationConfig/set / get / list / delete (legacy tasks/setPushNotification / tasks/getPushNotification still supported)
Authenticated extended agent card agent/getAuthenticatedExtendedCard, AgentCard.supportsAuthenticatedExtendedCard
Additional task states rejected, auth-required
Conversation context Message.messageId / taskId / contextId / referenceTaskIds / extensions, Task.contextId
Agent card security metadata securitySchemes (OpenAPI-style SecurityScheme), security requirements, iconUrl
Signed agent cards AgentCard.signatures (AgentCardSignature, JWS detached signatures per RFC 7515)
Standard error codes -32005 ContentTypeNotSupportedError, -32006 InvalidAgentResponseError, -32007 AuthenticatedExtendedCardNotConfiguredError

Sending a message with the new API from Java:

A2ATaskClient client = new A2ATaskClient("http://localhost:8080/rpc");
SendTaskResponse response = client.sendMessage("vishal is coming home what should i cook");
// continue the same conversation by passing the contextId
client.sendMessage("make it spicy", "ctx-1234");

See the Latest A2A Protocol Features tutorial for details, including how to publish an authenticated extended card and declare security schemes.

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");

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

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.