# mcp-client **Repository Path**: snow-sun/mcp-client ## Basic Information - **Project Name**: mcp-client - **Description**: 测试使用 - **Primary Language**: Java - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-11-20 - **Last Updated**: 2025-12-03 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # MCP Client This project serves as a client for integrating with Large Language Models (LLMs) and connecting to the MCP Spring Repeater service. ## Features 1. Integration with Alibaba Cloud Bailian (DashScope) Qwen models 2. Connection to the MCP Spring Repeater service 3. RESTful APIs for interacting with both services 4. SSE (Server-Sent Events) streaming support for real-time responses 5. Tool calling capability to allow LLMs to invoke MCP services 6. Dynamic tool loading from local tool service ## Project Structure ``` mcp-client/ ├── src/ │ ├── main/ │ │ ├── java/ │ │ │ └── com/mcp/client/ │ │ │ ├── config/ # Configuration classes │ │ │ ├── controller/ # REST controllers │ │ │ ├── service/ # Business logic services │ │ │ └── McpClientApplication.java # Main application class │ │ └── resources/ │ │ ├── application.yml # Application configuration │ │ └── static/ # Static resources (HTML test page) │ └── test/ # Unit and integration tests ├── pom.xml # Maven configuration └── README.md # Project documentation ``` ## Configuration The application can be configured via `application.yml`. Key configuration options include: - `app.llm.openai-api-key`: Your DashScope API key (default: sk-6ea152938bea4279a82eb5908baabebe) - `app.llm.openai-base-url`: Base URL for DashScope API (default: https://dashscope.aliyuncs.com/compatible-mode/v1) - `app.llm.model`: Model to use (default: qwen-plus) - `app.repeater.base-url`: Base URL for the MCP Spring Repeater service - `app.repeater.api-key`: API key for the MCP Spring Repeater service - `app.local-tools.url`: URL for the local tool service (default: http://127.0.0.1:7777/mcp-short/tools/list) These values can also be overridden with environment variables. ## Building and Running To build the project: ```bash mvn clean package ``` To run the project: ```bash mvn spring-boot:run ``` Or after building: ```bash java -jar target/mcp-client-1.0-SNAPSHOT.jar ``` ## APIs ### Chat Completion (Regular) POST `/api/mcp/chat` Send a prompt to the LLM and receive a complete response. Example: ```bash curl -X POST http://localhost:8080/api/mcp/chat \ -H "Content-Type: application/json" \ -d "Hello, how are you?" ``` ### Chat Completion (With Tool Calling) POST `/api/mcp/chat-with-tools` Send a prompt to the LLM and receive a response, with the ability for the LLM to call MCP services when needed. Example: ```bash curl -X POST http://localhost:8080/api/mcp/chat-with-tools \ -H "Content-Type: application/json" \ -d "Please use the MCP service to process this request: {\"action\": \"get_user_info\", \"user_id\": 123}" ``` ### Chat Completion (Streaming with SSE) POST `/api/mcp/sse/chat` Send a prompt to the LLM and receive a streaming response using Server-Sent Events (SSE). Example: ```bash curl -X POST http://localhost:8080/api/mcp/sse/chat \ -H "Content-Type: application/json" \ -d "Write a short poem about technology" ``` ### Repeater Service POST `/api/mcp/repeater` Forward data to the MCP Spring Repeater service. Example: ```bash curl -X POST http://localhost:8080/api/mcp/repeater \ -H "Content-Type: application/json" \ -d '{"message": "Hello from MCP Client"}' ``` ## Tool Calling The tool calling feature allows the LLM to automatically invoke your MCP services when needed. The system provides: 1. A predefined tool called `call_mcp_service` which forwards requests to your MCP service through the repeater 2. Dynamic tools loaded from your local tool service at `http://127.0.0.1:7777/mcp-short/tools/list` When you use the `/api/mcp/chat-with-tools` endpoint, the LLM can decide to call your MCP service by generating a tool call with a payload. The system will automatically execute the tool call and provide the result back to the LLM to generate a final response. ## Testing SSE Functionality After starting the application, visit `http://localhost:8080` in your browser to access a test page with buttons for both regular and streaming requests. ## Dependencies - Spring Boot 3.3.0 - OkHttp HTTP client - Java 17+