From cf529d6940f2bdcf8ddae3c03b8c7b96510dcc70 Mon Sep 17 00:00:00 2001 From: Christian Tzolov Date: Mon, 10 Feb 2025 11:40:37 +0100 Subject: [PATCH] move the brave client starters under the web-search folder Signed-off-by: Christian Tzolov --- .../.mvn/wrapper/maven-wrapper.jar | Bin .../.mvn/wrapper/maven-wrapper.properties | 0 .../{ => web-search}/brave-chatbot/README.md | 54 +++++++++++++++--- .../{ => web-search}/brave-chatbot/mvnw | 0 .../{ => web-search}/brave-chatbot/mvnw.cmd | 0 .../{ => web-search}/brave-chatbot/pom.xml | 0 .../brave-chatbot/spring-ai-mcp-brave.jpg | Bin .../ai/mcp/samples/brave/Application.java | 0 .../src/main/resources/application.properties | 0 .../main/resources/mcp-servers-config.json | 0 .../.mvn/wrapper/maven-wrapper.jar | Bin .../.mvn/wrapper/maven-wrapper.properties | 0 .../{ => web-search}/brave-starter/README.md | 0 .../{ => web-search}/brave-starter/mvnw | 0 .../{ => web-search}/brave-starter/mvnw.cmd | 0 .../{ => web-search}/brave-starter/pom.xml | 0 .../brave-starter/spring-ai-mcp-brave.jpg | Bin .../ai/mcp/samples/brave/Application.java | 0 .../src/main/resources/application.properties | 0 .../main/resources/mcp-servers-config.json | 0 pom.xml | 4 +- 21 files changed, 49 insertions(+), 9 deletions(-) rename model-context-protocol/{ => web-search}/brave-chatbot/.mvn/wrapper/maven-wrapper.jar (100%) rename model-context-protocol/{ => web-search}/brave-chatbot/.mvn/wrapper/maven-wrapper.properties (100%) rename model-context-protocol/{ => web-search}/brave-chatbot/README.md (65%) rename model-context-protocol/{ => web-search}/brave-chatbot/mvnw (100%) rename model-context-protocol/{ => web-search}/brave-chatbot/mvnw.cmd (100%) rename model-context-protocol/{ => web-search}/brave-chatbot/pom.xml (100%) rename model-context-protocol/{ => web-search}/brave-chatbot/spring-ai-mcp-brave.jpg (100%) rename model-context-protocol/{ => web-search}/brave-chatbot/src/main/java/org/springframework/ai/mcp/samples/brave/Application.java (100%) rename model-context-protocol/{ => web-search}/brave-chatbot/src/main/resources/application.properties (100%) rename model-context-protocol/{ => web-search}/brave-chatbot/src/main/resources/mcp-servers-config.json (100%) rename model-context-protocol/{ => web-search}/brave-starter/.mvn/wrapper/maven-wrapper.jar (100%) rename model-context-protocol/{ => web-search}/brave-starter/.mvn/wrapper/maven-wrapper.properties (100%) rename model-context-protocol/{ => web-search}/brave-starter/README.md (100%) rename model-context-protocol/{ => web-search}/brave-starter/mvnw (100%) rename model-context-protocol/{ => web-search}/brave-starter/mvnw.cmd (100%) rename model-context-protocol/{ => web-search}/brave-starter/pom.xml (100%) rename model-context-protocol/{ => web-search}/brave-starter/spring-ai-mcp-brave.jpg (100%) rename model-context-protocol/{ => web-search}/brave-starter/src/main/java/org/springframework/ai/mcp/samples/brave/Application.java (100%) rename model-context-protocol/{ => web-search}/brave-starter/src/main/resources/application.properties (100%) rename model-context-protocol/{ => web-search}/brave-starter/src/main/resources/mcp-servers-config.json (100%) diff --git a/model-context-protocol/brave-chatbot/.mvn/wrapper/maven-wrapper.jar b/model-context-protocol/web-search/brave-chatbot/.mvn/wrapper/maven-wrapper.jar similarity index 100% rename from model-context-protocol/brave-chatbot/.mvn/wrapper/maven-wrapper.jar rename to model-context-protocol/web-search/brave-chatbot/.mvn/wrapper/maven-wrapper.jar diff --git a/model-context-protocol/brave-chatbot/.mvn/wrapper/maven-wrapper.properties b/model-context-protocol/web-search/brave-chatbot/.mvn/wrapper/maven-wrapper.properties similarity index 100% rename from model-context-protocol/brave-chatbot/.mvn/wrapper/maven-wrapper.properties rename to model-context-protocol/web-search/brave-chatbot/.mvn/wrapper/maven-wrapper.properties diff --git a/model-context-protocol/brave-chatbot/README.md b/model-context-protocol/web-search/brave-chatbot/README.md similarity index 65% rename from model-context-protocol/brave-chatbot/README.md rename to model-context-protocol/web-search/brave-chatbot/README.md index 512d221..17e607e 100644 --- a/model-context-protocol/brave-chatbot/README.md +++ b/model-context-protocol/web-search/brave-chatbot/README.md @@ -24,7 +24,7 @@ This example demonstrates how to build an interactive chatbot that combines Spri 2. Clone the repository: ```bash git clone https://github.com/spring-projects/spring-ai-examples.git - cd model-context-protocol/brave-chatbot + cd model-context-protocol/web-search/brave-chatbot ``` 3. Set up your API keys: @@ -57,7 +57,7 @@ The application integrates Spring AI with the Brave Search MCP server through se ```xml org.springframework.ai - spring-ai-mcp-spring-boot-starter + spring-ai-mcp-client-spring-boot-starter org.springframework.ai @@ -65,11 +65,22 @@ The application integrates Spring AI with the Brave Search MCP server through se ``` -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): +```yaml +spring: + ai: + mcp: + client: + enabled: true + name: brave-search-client + version: 1.0.0 + type: SYNC # or ASYNC for reactive applications + request-timeout: 20s + stdio: + root-change-notification: true + servers-configuration: classpath:/mcp-servers-config.json + anthropic: + api-key: ${ANTHROPIC_API_KEY} ``` 3. MCP Server Configuration (mcp-servers-config.json): @@ -90,6 +101,15 @@ spring.ai.anthropic.api-key=${ANTHROPIC_API_KEY} } ``` +### Client Types + +The MCP client supports two types of implementations: + +- **Synchronous (default)**: Uses blocking operations, suitable for traditional request-response patterns +- **Asynchronous**: Uses non-blocking operations, suitable for reactive applications + +You can switch between these types using the `spring.ai.mcp.client.type` property (SYNC or ASYNC). + ### Chat Implementation The chatbot is implemented using Spring AI's ChatClient with MCP tool integration: @@ -113,3 +133,23 @@ The chatbot can: - 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 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 + + org.springframework.ai + spring-ai-mcp-client-webflux-spring-boot-starter + +``` + +This provides similar functionality but uses a WebFlux-based SSE transport implementation, recommended for production deployments. diff --git a/model-context-protocol/brave-chatbot/mvnw b/model-context-protocol/web-search/brave-chatbot/mvnw similarity index 100% rename from model-context-protocol/brave-chatbot/mvnw rename to model-context-protocol/web-search/brave-chatbot/mvnw diff --git a/model-context-protocol/brave-chatbot/mvnw.cmd b/model-context-protocol/web-search/brave-chatbot/mvnw.cmd similarity index 100% rename from model-context-protocol/brave-chatbot/mvnw.cmd rename to model-context-protocol/web-search/brave-chatbot/mvnw.cmd diff --git a/model-context-protocol/brave-chatbot/pom.xml b/model-context-protocol/web-search/brave-chatbot/pom.xml similarity index 100% rename from model-context-protocol/brave-chatbot/pom.xml rename to model-context-protocol/web-search/brave-chatbot/pom.xml diff --git a/model-context-protocol/brave-chatbot/spring-ai-mcp-brave.jpg b/model-context-protocol/web-search/brave-chatbot/spring-ai-mcp-brave.jpg similarity index 100% rename from model-context-protocol/brave-chatbot/spring-ai-mcp-brave.jpg rename to model-context-protocol/web-search/brave-chatbot/spring-ai-mcp-brave.jpg diff --git a/model-context-protocol/brave-chatbot/src/main/java/org/springframework/ai/mcp/samples/brave/Application.java b/model-context-protocol/web-search/brave-chatbot/src/main/java/org/springframework/ai/mcp/samples/brave/Application.java similarity index 100% rename from model-context-protocol/brave-chatbot/src/main/java/org/springframework/ai/mcp/samples/brave/Application.java rename to model-context-protocol/web-search/brave-chatbot/src/main/java/org/springframework/ai/mcp/samples/brave/Application.java diff --git a/model-context-protocol/brave-chatbot/src/main/resources/application.properties b/model-context-protocol/web-search/brave-chatbot/src/main/resources/application.properties similarity index 100% rename from model-context-protocol/brave-chatbot/src/main/resources/application.properties rename to model-context-protocol/web-search/brave-chatbot/src/main/resources/application.properties diff --git a/model-context-protocol/brave-chatbot/src/main/resources/mcp-servers-config.json b/model-context-protocol/web-search/brave-chatbot/src/main/resources/mcp-servers-config.json similarity index 100% rename from model-context-protocol/brave-chatbot/src/main/resources/mcp-servers-config.json rename to model-context-protocol/web-search/brave-chatbot/src/main/resources/mcp-servers-config.json diff --git a/model-context-protocol/brave-starter/.mvn/wrapper/maven-wrapper.jar b/model-context-protocol/web-search/brave-starter/.mvn/wrapper/maven-wrapper.jar similarity index 100% rename from model-context-protocol/brave-starter/.mvn/wrapper/maven-wrapper.jar rename to model-context-protocol/web-search/brave-starter/.mvn/wrapper/maven-wrapper.jar diff --git a/model-context-protocol/brave-starter/.mvn/wrapper/maven-wrapper.properties b/model-context-protocol/web-search/brave-starter/.mvn/wrapper/maven-wrapper.properties similarity index 100% rename from model-context-protocol/brave-starter/.mvn/wrapper/maven-wrapper.properties rename to model-context-protocol/web-search/brave-starter/.mvn/wrapper/maven-wrapper.properties diff --git a/model-context-protocol/brave-starter/README.md b/model-context-protocol/web-search/brave-starter/README.md similarity index 100% rename from model-context-protocol/brave-starter/README.md rename to model-context-protocol/web-search/brave-starter/README.md diff --git a/model-context-protocol/brave-starter/mvnw b/model-context-protocol/web-search/brave-starter/mvnw similarity index 100% rename from model-context-protocol/brave-starter/mvnw rename to model-context-protocol/web-search/brave-starter/mvnw diff --git a/model-context-protocol/brave-starter/mvnw.cmd b/model-context-protocol/web-search/brave-starter/mvnw.cmd similarity index 100% rename from model-context-protocol/brave-starter/mvnw.cmd rename to model-context-protocol/web-search/brave-starter/mvnw.cmd diff --git a/model-context-protocol/brave-starter/pom.xml b/model-context-protocol/web-search/brave-starter/pom.xml similarity index 100% rename from model-context-protocol/brave-starter/pom.xml rename to model-context-protocol/web-search/brave-starter/pom.xml diff --git a/model-context-protocol/brave-starter/spring-ai-mcp-brave.jpg b/model-context-protocol/web-search/brave-starter/spring-ai-mcp-brave.jpg similarity index 100% rename from model-context-protocol/brave-starter/spring-ai-mcp-brave.jpg rename to model-context-protocol/web-search/brave-starter/spring-ai-mcp-brave.jpg diff --git a/model-context-protocol/brave-starter/src/main/java/org/springframework/ai/mcp/samples/brave/Application.java b/model-context-protocol/web-search/brave-starter/src/main/java/org/springframework/ai/mcp/samples/brave/Application.java similarity index 100% rename from model-context-protocol/brave-starter/src/main/java/org/springframework/ai/mcp/samples/brave/Application.java rename to model-context-protocol/web-search/brave-starter/src/main/java/org/springframework/ai/mcp/samples/brave/Application.java diff --git a/model-context-protocol/brave-starter/src/main/resources/application.properties b/model-context-protocol/web-search/brave-starter/src/main/resources/application.properties similarity index 100% rename from model-context-protocol/brave-starter/src/main/resources/application.properties rename to model-context-protocol/web-search/brave-starter/src/main/resources/application.properties diff --git a/model-context-protocol/brave-starter/src/main/resources/mcp-servers-config.json b/model-context-protocol/web-search/brave-starter/src/main/resources/mcp-servers-config.json similarity index 100% rename from model-context-protocol/brave-starter/src/main/resources/mcp-servers-config.json rename to model-context-protocol/web-search/brave-starter/src/main/resources/mcp-servers-config.json diff --git a/pom.xml b/pom.xml index 9b30a73..9d3f586 100644 --- a/pom.xml +++ b/pom.xml @@ -27,8 +27,8 @@ model-context-protocol/filesystem model-context-protocol/brave - model-context-protocol/brave-starter - model-context-protocol/brave-chatbot + model-context-protocol/web-search/brave-starter + model-context-protocol/web-search/brave-chatbot model-context-protocol/book-library/manual-webmvc-server model-context-protocol/book-library/manual-webflux-server