A TypeScript project that implements an A2A-compatible agent using LangGraph's ReAct agent with Model Context Protocol (MCP) integration.
a2a-langgraph-agent/
├── src/ # TypeScript source files
│ ├── index.ts # Server entry point
│ ├── cli.ts # CLI client for interacting with the agent
│ └── a2a/ # A2A implementation
│ ├── executor.ts # LangGraph React agent executor
│ ├── agentCard.ts # Agent card definition
│ ├── tools.ts # Local tool definitions
│ └── mcp/ # Model Context Protocol integration
│ ├── client.ts # MCP client implementation
│ └── mcp-servers.json # MCP server configurations
├── dist/ # Compiled JavaScript output (generated)
├── tsconfig.json # TypeScript configuration
├── package.json # Project configuration and dependencies
└── README.md # This file
- Node.js (v16 or higher recommended)
- npm (comes with Node.js)
Clone the repository and install dependencies:
git clone <repository-url>
cd a2a-langgraph-agent
npm install
The agent uses OpenAI's models through LangChain. You'll need to set up your OpenAI API key as an environment variable:
# For Linux/macOS
export OPENAI_API_KEY=your-api-key-here
# For Windows (Command Prompt)
set OPENAI_API_KEY=your-api-key-here
# For Windows (PowerShell)
$env:OPENAI_API_KEY="your-api-key-here"
Alternatively, you can create a .env
file in the project root:
OPENAI_API_KEY=your-api-key-here
In one terminal, start the agent server:
npm run dev
This will start the A2A server on http://localhost:3000.
In another terminal, use the CLI client to interact with the agent:
npm run cli
You can also specify a different server URL:
npm run cli http://localhost:3000
- Type your message and press Enter to send it to the agent
/new
- Start a new session (clears task and context IDs)/exit
- Exit the CLI
In the project directory, you can run:
Compiles the TypeScript code to JavaScript in the dist
directory.
Runs the compiled JavaScript from the dist
directory.
Runs the agent server directly using tsx without compiling.
Runs the CLI client to interact with the agent.
- A2A Protocol Support: Implements the A2A protocol for agent communication
- LangGraph React Agent: Uses LangChain's React agent for reasoning and tool use
- Built-in Tools: Includes calculator and time tools out of the box
- MCP Integration: Connects to external Model Context Protocol servers
- CLI Client: Interactive command-line interface for testing the agent
The agent comes with several built-in tools defined in src/a2a/tools.ts
:
Performs basic mathematical operations:
- Addition
- Subtraction
- Multiplication
- Division
Example usage: "Calculate 25 divided by 5" or "What's 123 + 456?"
Returns the current date and time.
Example usage: "What time is it?" or "Tell me the current date"
The agent can connect to external Model Context Protocol (MCP) servers to extend its capabilities. MCP servers are configured in the src/a2a/mcp/mcp-servers.json
file.
Example configuration:
{
"github": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-github"
],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "your-github-token"
}
}
}
Each entry in the JSON file represents an MCP server with:
- A unique name (e.g., "github")
- The command to run the server
- Command arguments
- Environment variables needed by the server
The agent will automatically start these MCP servers when it initializes and make their tools available to the LangGraph React agent.
The project is configured to work with various MCP servers, including:
- GitHub: Interact with GitHub repositories, issues, and pull requests
- Weather: Get weather forecasts and conditions
- Search: Perform web searches
- File System: Access and manipulate files
To use these servers, you'll need to configure them in the mcp-servers.json
file with appropriate credentials.
- @a2a-js/sdk: A2A JavaScript SDK
- @langchain/langgraph: LangChain's LangGraph library for agent workflows
- @langchain/openai: LangChain's OpenAI integration
- @langchain/mcp-adapters: Model Context Protocol adapters for LangChain
- express: Web server framework
- uuid: For generating unique IDs
- zod: Schema validation for tool definitions
MIT