MCP ExplorerExplorer

Mcp Agent Example

@wuzhuoyanon 22 days ago
1 MIT
FreeCommunity
AI Systems
a sample for ai agent with mcp

Overview

What is Mcp Agent Example

mcp-agent-example is a Java-based project that serves as a sample implementation of an AI agent interacting with MCP tools. It can perform tasks such as querying weather information, calculations, and reasoning.

Use cases

Use cases include querying real-time weather data, performing mathematical calculations, and providing reasoning capabilities in AI-driven applications.

How to use

To use mcp-agent-example, clone the repository, navigate to the project directory, build the project using Maven, configure the application.yml file, and start the application using the command ‘mvn spring-boot:run’. Access the server at http://localhost:5678.

Key features

Key features include integration with MCP tools for weather information and calculations, AI bridge support for reasoning and natural language processing, configurable settings via application.yml, and graceful resource management.

Where to use

mcp-agent-example can be used in various fields such as weather forecasting applications, educational tools for teaching AI concepts, and any application requiring interaction with MCP tools for data retrieval and processing.

Content

Here is a basic README.md for the mcp-agent-example project:

MCP Agent Example

Overview

mcp-agent-example is a Java-based project built with Maven and Spring Boot. It serves as an example implementation of an agent that interacts with MCP (Multi-Client Platform) tools and AI bridges to perform various tasks such as querying weather information, performing calculations, and handling reasoning steps.

Features

  • Integration with MCP tools for weather information and calculations.
  • AI bridge support for reasoning and natural language processing.
  • Configurable via application.yml.
  • Graceful resource management with closeGracefully().

Requirements

  • Java: JDK 11 or higher
  • Maven: 3.6 or higher
  • Spring Boot: 2.x or higher

Installation

  1. Clone the repository:

    git clone https://github.com/your-repo/mcp-agent-example.git
    
  2. Navigate to the project directory:

    cd mcp-agent-example
    
  3. Build the project:

    mvn clean install
    

Configuration

Edit the application.yml file located in src/main/resources to configure the server and tools:

server:
  port: 5678
  address: 0.0.0.0
spring:
  application:
    name: agent-sample-with-mcp
ai:
  bridge:
    zhipu:
      api_key: your_key
  mcp:
    getRealWeatherInfo:
      tool-name: getRealWeatherInfo
      base-url: http://localhost:8080
      api-key: your_key
    calculate:
      tool-name: calculate
      base-url: http://localhost:8080
      api-key: your_key
    queryAllValidWeatherLocation:
      tool-name: queryAllValidWeatherLocation
      base-url: http://localhost:8080
      api-key: your_key

Replace your_key and http://localhost:8080 with your actual API keys and MCP server URL.

Usage

  1. Start the application:

    mvn spring-boot:run
    
  2. Access the server at:

    http://localhost:5678
    
  3. Example HTTP request:

    GET http://localhost:5678/server?从杭州到广州怎么样
    

Project Structure

  • src/main/java: Contains the Java source code.
    • common: Includes core classes like ReasoningStep.
    • llm: Handles AI bridge interactions.
    • mcp: Manages MCP tool selection and execution.
  • src/main/resources: Contains configuration files like application.yml.

Key Classes

ReasoningStep

Handles reasoning logic, including appending prompts, interacting with tools, and managing context.

Tool

Represents an MCP tool with caching capabilities.

Contributing

Contributions are welcome! Please submit a pull request or open an issue for any improvements or bug fixes.

Tools

No tools

Comments