docs: improve Java SDK documentation and examples (#145)
- Fix typos and update links in quickstart guides - Update artifact names and configuration properties - Add detailed configuration examples and advanced features - Enhance Java SDK client/server documentation - Update architecture diagrams and descriptions - Improve code examples with better comments - Update Spring Boot version requirements Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
This commit is contained in:
parent
ccfc60f57b
commit
e393ebc304
1 changed files with 188 additions and 135 deletions
|
|
@ -404,12 +404,12 @@ If you see:
|
|||
<Tab title="Java">
|
||||
|
||||
<Note>
|
||||
This is a quickstart demo based on Spring AI MCP auto-configuraiton and boot starters.
|
||||
To learn how to create sync and async McpClients programatically consult the [Java SDK Client guid](TODO: add URL)
|
||||
This is a quickstart demo based on Spring AI MCP auto-configuration and boot starters.
|
||||
To learn how to create sync and async MCP Clients manually, consult the [Java SDK Client](/sdk/java/mcp-client) documentation
|
||||
</Note>
|
||||
|
||||
This example demonstrates how to build an interactive chatbot that combines Spring AI's Model Context Protocol (MCP) with the [Brave Search MCP Server](https://github.com/modelcontextprotocol/servers/tree/main/src/brave-search). The application creates a conversational interface powered by Anthropic's Claude AI model that can perform internet searches through Brave Search, enabling natural language interactions with real-time web data.
|
||||
[You can find the complete code for this tutorial here.](https://github.com/spring-projects/spring-ai-examples/tree/main/model-context-protocol/brave-chatbot)
|
||||
[You can find the complete code for this tutorial here.](https://github.com/spring-projects/spring-ai-examples/tree/main/model-context-protocol/web-search/brave-chatbot)
|
||||
|
||||
## System Requirements
|
||||
|
||||
|
|
@ -447,9 +447,9 @@ Before starting, ensure your system meets these requirements:
|
|||
```
|
||||
|
||||
5. Run the application using Maven:
|
||||
```bash
|
||||
./mvnw spring-boot:run
|
||||
```
|
||||
```bash
|
||||
./mvnw spring-boot:run
|
||||
```
|
||||
|
||||
<Warning>
|
||||
Make sure you keep your `ANTHROPIC_API_KEY` and `BRAVE_API_KEY` keys secure!
|
||||
|
|
@ -466,7 +466,7 @@ The application integrates Spring AI with the Brave Search MCP server through se
|
|||
```xml
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-mcp-spring-boot-starter</artifactId>
|
||||
<artifactId>spring-ai-mcp-client-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
|
|
@ -474,16 +474,27 @@ The application integrates Spring AI with the Brave Search MCP server through se
|
|||
</dependency>
|
||||
```
|
||||
|
||||
2. Application properties (application.properties):
|
||||
```properties
|
||||
spring.ai.mcp.client.stdio.enabled=true
|
||||
spring.ai.mcp.client.stdio.servers-configuration=classpath:/mcp-servers-config.json
|
||||
spring.ai.anthropic.api-key=${ANTHROPIC_API_KEY}
|
||||
2. Application properties (application.yml):
|
||||
```yml
|
||||
spring:
|
||||
ai:
|
||||
mcp:
|
||||
client:
|
||||
enabled: true
|
||||
name: brave-search-client
|
||||
version: 1.0.0
|
||||
type: SYNC
|
||||
request-timeout: 20s
|
||||
stdio:
|
||||
root-change-notification: true
|
||||
servers-configuration: classpath:/mcp-servers-config.json
|
||||
anthropic:
|
||||
api-key: ${ANTHROPIC_API_KEY}
|
||||
```
|
||||
|
||||
This acivates the `spring-ai-mcp-spring-boot-starter` to create one or more `McpClient`s based on the provided server configuration.
|
||||
This activates the `spring-ai-mcp-client-spring-boot-starter` to create one or more `McpClient`s based on the provided server configuration.
|
||||
|
||||
3. MCP Server Configuration (mcp-servers-config.json):
|
||||
3. MCP Server Configuration (`mcp-servers-config.json`):
|
||||
```json
|
||||
{
|
||||
"mcpServers": {
|
||||
|
|
@ -513,6 +524,53 @@ var chatClient = chatClientBuilder
|
|||
.build();
|
||||
```
|
||||
|
||||
Key features:
|
||||
- Uses Claude AI model for natural language understanding
|
||||
- Integrates Brave Search through MCP for real-time web search capabilities
|
||||
- Maintains conversation memory using InMemoryChatMemory
|
||||
- Runs as an interactive command-line application
|
||||
|
||||
### Build and run
|
||||
|
||||
```bash
|
||||
./mvnw clean install
|
||||
java -jar ./target/ai-mcp-brave-chatbot-0.0.1-SNAPSHOT.jar
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```bash
|
||||
./mvnw spring-boot:run
|
||||
```
|
||||
|
||||
The application will start an interactive chat session where you can ask questions. The chatbot will use Brave Search when it needs to find information from the internet to answer your queries.
|
||||
|
||||
The chatbot can:
|
||||
- Answer questions using its built-in knowledge
|
||||
- Perform web searches when needed using Brave Search
|
||||
- Remember context from previous messages in the conversation
|
||||
- Combine information from multiple sources to provide comprehensive answers
|
||||
|
||||
### Advanced Configuration
|
||||
|
||||
The MCP client supports additional configuration options:
|
||||
|
||||
- Client customization through `McpSyncClientCustomizer` or `McpAsyncClientCustomizer`
|
||||
- Multiple clients with multiple transport types: `STDIO` and `SSE` (Server-Sent Events)
|
||||
- Integration with Spring AI's tool execution framework
|
||||
- Automatic client initialization and lifecycle management
|
||||
|
||||
For WebFlux-based applications, you can use the WebFlux starter instead:
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-mcp-client-webflux-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
This provides similar functionality but uses a WebFlux-based SSE transport implementation, recommended for production deployments.
|
||||
|
||||
</Tab>
|
||||
|
||||
</Tabs>
|
||||
|
|
|
|||
Loading…
Reference in a new issue