AlandeXiong/chat_mcp_server
If you are the rightful owner of chat_mcp_server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
The Model Context Protocol (MCP) server is designed to facilitate communication between clients and language models, providing a structured and efficient way to manage interactions.
Campaign Journey MCP Server with Spring AI
A Spring Boot application that provides a complete MCP (Model Context Protocol) implementation with both client and server components, integrated with Spring AI for creating comprehensive marketing campaigns through chat-based interactions.
Architecture
The application is now structured with two main components:
1. MCP Server (McpServerConfig.java
)
- Provides MCP server functionality
- Integrates with Spring AI ChatClient
- Handles marketing campaign requests
- Manages server properties and configuration
2. MCP Client (McpClientConfig.java
)
- Connects to MCP servers via SSE transport
- Supports both synchronous and asynchronous clients
- Provides tool callback integration
- Customizable client behavior
Features
- MCP Server Integration: Full MCP server implementation
- MCP Client Support: Multiple client connections with customization
- Spring AI Integration: Powered by Spring AI framework
- Marketing Campaign Creation: Generate complete marketing campaigns
- Target Audience Segmentation: Define and analyze target audiences
- Channel Strategy Development: Create multi-channel marketing strategies
- Email Template Generation: Generate email templates and content
- WebSocket Communication: Real-time chat interface
- REST API: HTTP endpoints for all operations
- Tool Callbacks: MCP tool integration with Spring AI
Prerequisites
- Java 17 or higher
- Maven 3.6 or higher
- OpenAI API key or Azure OpenAI credentials
Setup
-
Clone the repository
git clone <repository-url> cd campaign-journey-backend
-
Set up your AI credentials
Option 1: OpenAI
export OPENAI_API_KEY=your-openai-api-key-here export OPENAI_MODEL=gpt-4
Option 2: Azure OpenAI
export AZURE_OPENAI_API_KEY=your-azure-api-key-here export AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com export AZURE_OPENAI_DEPLOYMENT_NAME=gpt-4
-
Build the application
mvn clean install
-
Run the application
mvn spring-boot:run
Configuration
MCP Server Configuration
spring:
ai:
mcp:
server:
enabled: true
name: "Campaign Journey MCP Server"
version: "1.0.0"
description: "MCP Server for marketing campaign journey management using Spring AI"
MCP Client Configuration
spring:
ai:
mcp:
client:
enabled: true
name: "campaign-journey-mcp-client"
version: "1.0.0"
type: SYNC # or ASYNC
request-timeout: 30s
initialized: true
root-change-notification: true
toolcallback:
enabled: true
# SSE Transport
sse:
connections:
local-server:
url: http://localhost:8080
sse-endpoint: /sse
Usage
WebSocket Connection
Connect to the WebSocket endpoint:
ws://localhost:8080/chat
MCP Commands
The WebSocket interface supports MCP-specific commands:
/mcp/status - Check MCP server status
/mcp/tools - Get available MCP tools
/mcp/health - Check MCP health
Marketing Commands
"Create a marketing campaign for life insurance products"
"Define target audience for our insurance products"
"Develop a multi-channel marketing strategy"
"Generate an email template for promotion"
"Analyze campaign performance metrics"
"Optimize budget allocation across channels"
REST API Endpoints
Marketing Operations
POST /api/marketing/campaign
- Create campaignPOST /api/marketing/audience
- Define audiencePOST /api/marketing/strategy
- Develop strategyPOST /api/marketing/template
- Generate templatePOST /api/marketing/performance
- Analyze performancePOST /api/marketing/optimization
- Optimize budget
MCP Operations
GET /api/mcp/server/info
- Get MCP server infoGET /api/mcp/server/health
- Check MCP healthGET /api/mcp/clients
- Get MCP client infoPOST /api/mcp/request
- Send MCP request
General
GET /api/capabilities
- Get all capabilities
MCP Client Customization
The application provides customizable MCP clients:
Sync Client Customizer
@Component
public class CustomMcpSyncClientCustomizer implements McpSyncClientCustomizer {
@Override
public void customize(String serverConfigurationName, McpClient.SyncSpec spec) {
spec.requestTimeout(Duration.ofSeconds(30));
spec.toolsChangeConsumer((tools) -> {
// Handle tools change
});
// ... more customization options
}
}
Async Client Customizer
@Component
public class CustomMcpAsyncClientCustomizer implements McpAsyncClientCustomizer {
@Override
public void customize(String serverConfigurationName, McpClient.AsyncSpec spec) {
spec.requestTimeout(Duration.ofSeconds(30));
}
}
Transport Support
- SSE (Server-Sent Events): HTTP-based transport for remote MCP servers
- Stdio: Standard I/O transport for local MCP servers
- WebFlux: Reactive transport support (optional)
Tool Callback Integration
The MCP client automatically integrates with Spring AI's tool execution framework:
@Autowired
private SyncMcpToolCallbackProvider toolCallbackProvider;
ToolCallback[] toolCallbacks = toolCallbackProvider.getToolCallbacks();
Response Structure
All responses include:
type
: Response type (campaign, segment, strategy, etc.)content
: AI-generated contentstatus
: Success/error statustimestamp
: Response timestamp- Additional fields based on response type
Troubleshooting
Common Issues
- MCP Client Connection: Check SSE endpoint configuration
- AI Model Access: Verify API keys and model configuration
- Transport Issues: Ensure proper transport configuration
Logs
Enable debug logging:
logging:
level:
org.springframework.ai: DEBUG
com.example.mcp: DEBUG
org.springframework.ai.mcp: DEBUG
Development
Project Structure
src/main/java/com/example/mcp/
āāā McpServerConfig.java # MCP Server configuration
āāā McpClientConfig.java # MCP Client configuration
āāā MarketingCampaignService.java # Marketing business logic
āāā MCPClientService.java # MCP client operations
āāā MCPWebSocketHandler.java # WebSocket message handler
āāā WebSocketConfig.java # WebSocket configuration
āāā MarketingCampaignController.java # REST API controller
āāā McpServerApplication.java # Spring Boot main class
Adding New Features
- New MCP Tools: Extend the MCP server with new tool definitions
- Client Customization: Add new client customizers for specific behavior
- Transport Support: Implement new transport mechanisms
License
This project is licensed under the MIT License.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request