Sponsored by Deepsite.site

Spring AI MCP PoC

Created By
shesadri7 months ago
Spring AI integration with GitHub MCP server and LLM model - Proof of Concept
Content

Spring AI MCP PoC

A Proof of Concept demonstrating integration between Spring AI framework, GitHub MCP (Model Context Protocol) server, and LLM models.

Overview

This project showcases how to build an AI-powered application that can:

  • Process natural language prompts using Spring AI
  • Integrate with GitHub through MCP (Model Context Protocol)
  • Leverage OpenAI's GPT models for intelligent responses
  • Provide GitHub-specific functionality through function calling

Architecture

User Request → Spring Boot API → Spring AI → OpenAI LLM
              GitHub MCP Server → GitHub API

Features

  • Spring AI Integration: Leverage Spring AI framework for LLM interactions
  • GitHub MCP Support: Connect to GitHub through Model Context Protocol
  • Function Calling: AI can invoke GitHub operations based on user prompts
  • RESTful API: Clean REST endpoints for prompt processing
  • Configurable: Easy configuration for different environments
  • Error Handling: Robust error handling and logging

Prerequisites

  • Java 17 or higher
  • Gradle 8.6+ (or use the included wrapper)
  • OpenAI API key
  • GitHub MCP server running (optional for basic functionality)

Setup

1. Clone the Repository

git clone https://github.com/shesadri/spring_ai_mcp_poc.git
cd spring_ai_mcp_poc

2. Configure Environment Variables

Create a .env file or set environment variables:

export OPENAI_API_KEY="your-openai-api-key"
export GITHUB_MCP_SERVER_URL="http://localhost:3000"  # Optional
export GITHUB_TOKEN="your-github-token"  # Optional for enhanced features

3. Configure Application Properties

Edit src/main/resources/application.yml or use environment variables:

spring:
  ai:
    openai:
      api-key: ${OPENAI_API_KEY:your-openai-api-key-here}
      
app:
  github:
    mcp:
      server:
        url: ${GITHUB_MCP_SERVER_URL:http://localhost:3000}

4. Build and Run

# Build the project
./gradlew build

# Run the application
./gradlew bootRun

# Or run with specific profile
./gradlew bootRun --args='--spring.profiles.active=dev'

# Alternative: Use custom tasks
./gradlew runDev    # Development profile
./gradlew runProd   # Production profile

The application will start on http://localhost:8080

Usage

Health Check

curl http://localhost:8080/api/v1/health

Process a Prompt

curl -X POST http://localhost:8080/api/v1/prompt \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "Tell me about Spring AI framework",
    "enableMcpTools": true
  }'

GitHub-specific Prompts

curl -X POST http://localhost:8080/api/v1/prompt \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "Show me information about my GitHub repositories",
    "enableMcpTools": true
  }'

Get Available MCP Tools

curl http://localhost:8080/api/v1/mcp/tools

API Endpoints

MethodEndpointDescription
GET/api/v1/healthHealth check
POST/api/v1/promptProcess AI prompt
GET/api/v1/mcp/toolsGet available MCP tools

Request/Response Format

Prompt Request

{
  "prompt": "Your question or instruction",
  "context": "Optional context",
  "enableMcpTools": true,
  "githubToken": "optional-github-token"
}

Prompt Response

{
  "response": "AI generated response",
  "mcpData": {
    "repositories": [...],
    "status": "success"
  },
  "usedMcpTools": true,
  "timestamp": "2024-01-01T12:00:00",
  "status": "success",
  "model": "gpt-4"
}

Configuration

Environment Variables

  • OPENAI_API_KEY: Your OpenAI API key (required)
  • GITHUB_MCP_SERVER_URL: URL of your GitHub MCP server (optional)
  • GITHUB_TOKEN: GitHub personal access token (optional)
  • PORT: Server port (default: 8080)

Application Properties

See application.yml for detailed configuration options including:

  • AI model settings
  • Server configuration
  • CORS settings
  • Logging levels
  • Management endpoints

GitHub MCP Server

This application expects a GitHub MCP server to be running for enhanced GitHub functionality. The MCP server should provide:

  • Repository information endpoints
  • Issue management capabilities
  • Pull request operations
  • Code search functionality

If no MCP server is available, the application will still work but with limited GitHub integration.

Development

Running Tests

./gradlew test

Development Profile

./gradlew runDev
# or
./gradlew bootRun --args='--spring.profiles.active=dev'

Building for Production

./gradlew clean build
java -jar build/libs/spring-ai-mcp-poc-1.0.0-SNAPSHOT.jar

Gradle Commands

# Build project
./gradlew build

# Run application
./gradlew bootRun

# Run tests
./gradlew test

# Clean build
./gradlew clean

# Generate Gradle wrapper (if needed)
gradle wrapper --gradle-version 8.6

# Check dependencies
./gradlew dependencies

# Build info
./gradlew tasks

Project Structure

src/
├── main/
│   ├── java/com/example/springaimcp/
│   │   ├── SpringAiMcpApplication.java     # Main application class
│   │   ├── config/
│   │   │   └── SpringAiConfig.java         # Spring AI configuration
│   │   ├── controller/
│   │   │   └── PromptController.java       # REST API endpoints
│   │   ├── service/
│   │   │   ├── AiMcpService.java          # Main service orchestrating AI and MCP
│   │   │   └── mcp/
│   │   │       └── GitHubMcpClient.java   # GitHub MCP client
│   │   └── model/
│   │       ├── PromptRequest.java         # Request model
│   │       └── PromptResponse.java        # Response model
│   └── resources/
│       ├── application.yml                # Main configuration
│       └── application.properties         # Alternative configuration
└── test/
    └── java/
        └── ... # Test classes

# Gradle files
build.gradle                     # Gradle build script
settings.gradle                  # Gradle settings
gradle/
└── wrapper/
    ├── gradle-wrapper.properties    # Gradle wrapper config
    └── gradle-wrapper.jar          # Gradle wrapper JAR
gradlew                         # Gradle wrapper script (Unix)
gradlew.bat                     # Gradle wrapper script (Windows)

Technologies Used

  • Spring Boot 3.2.5: Application framework
  • Spring AI 1.0.0-M1: AI integration framework
  • OpenAI GPT-4: Large Language Model
  • WebFlux: Reactive web client for MCP communication
  • Jackson: JSON processing
  • Gradle 8.6: Build tool

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

License

This project is licensed under the MIT License.

Troubleshooting

Common Issues

  1. OpenAI API Key Issues

    • Ensure your API key is valid and has sufficient credits
    • Check the environment variable is properly set
  2. MCP Server Connection Issues

    • Verify the MCP server is running
    • Check the server URL configuration
    • Review network connectivity
  3. GitHub Integration Issues

    • Ensure GitHub token has proper permissions
    • Verify MCP server GitHub configuration
  4. Gradle Issues

    • Use ./gradlew --version to check Gradle version
    • Run ./gradlew clean build to clean and rebuild
    • Check Java version with java -version

Logs

Check application logs for detailed error information:

# View logs in development
tail -f logs/spring-ai-mcp-poc.log

# Increase log level for debugging
export LOGGING_LEVEL_COM_EXAMPLE_SPRINGAIMCP=DEBUG

Gradle Wrapper

If you encounter issues with the Gradle wrapper:

# Regenerate wrapper files
gradle wrapper --gradle-version 8.6

# Make gradlew executable on Unix systems
chmod +x gradlew

Support

For issues and questions:

  • Create an issue in this repository
  • Check the Spring AI documentation
  • Review OpenAI API documentation
  • Consult Gradle documentation
Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
Playwright McpPlaywright MCP server
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
DeepChatYour AI Partner on Desktop
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Serper MCP ServerA Serper MCP Server
Amap Maps高德地图官方 MCP Server
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
Tavily Mcp
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
WindsurfThe new purpose-built IDE to harness magic
ChatWiseThe second fastest AI chatbot™
CursorThe AI Code Editor
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.