mcp-spring-kotlin-server

patricklenert/mcp-spring-kotlin-server

3.2

If you are the rightful owner of mcp-spring-kotlin-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 MCP Spring Server is a comprehensive Model Context Protocol (MCP) Server built with Spring Boot and Kotlin, showcasing video memory management functionality.

Tools
  1. create_video_memory

    Create new video memories

  2. add_chunks

    Add text chunks to video memories

  3. build_video

    Build searchable indexes

  4. chat_with_memory

    Chat with video memory content

  5. list_video_memories

    List all video memories

  6. get_memory_details

    Get detailed information

  7. search_memories

    Search by title/description

  8. get_memory_status

    System status overview

  9. delete_memory

    Remove video memories

MCP Spring Server

A comprehensive Model Context Protocol (MCP) Server built with Spring Boot and Kotlin that demonstrates video memory management functionality similar to the memvid concept. This project showcases key Spring Boot concepts including JPA, WebMVC, Repositories, GraphQL, and MCP integration using the official Spring AI MCP library.

๐Ÿš€ Features

Core Technologies

  • Spring Boot 3.3.0 with Kotlin
  • Spring AI MCP Integration (Official MCP Library)
  • JPA with Hibernate for data persistence
  • Spring WebMVC for REST APIs
  • GraphQL for flexible query interface
  • H2 Database for demonstration
  • Spring Actuator for monitoring

MCP Tools Available

  • create_video_memory - Create new video memories
  • add_chunks - Add text chunks to video memories
  • build_video - Build searchable indexes
  • chat_with_memory - Chat with video memory content
  • list_video_memories - List all video memories
  • get_memory_details - Get detailed information
  • search_memories - Search by title/description
  • get_memory_status - System status overview
  • delete_memory - Remove video memories

API Endpoints

  • MCP Server: /mcp (Server-Sent Events)
  • REST API: /api/v1/memvid/**
  • GraphQL: /graphql
  • GraphiQL: /graphiql (Interactive GraphQL playground)
  • H2 Console: /h2-console
  • Health Check: /actuator/health

๐Ÿ—๏ธ Architecture

The application follows a layered architecture demonstrating Spring Boot best practices:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   MCP Tools Layer   โ”‚  โ† @McpServerTool annotations
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Controllers/GraphQL โ”‚  โ† @RestController, @Controller
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚   Service Layer     โ”‚  โ† @Service, @Transactional
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Repository Layer    โ”‚  โ† @Repository, Spring Data JPA
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚   Domain Layer      โ”‚  โ† @Entity, JPA annotations
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ› ๏ธ Setup & Installation

Prerequisites

  • Java 17+
  • Maven 3.6+

Run the Application

  1. Clone and build:
git clone <repository-url>
cd mcp-spring-server
mvn clean install
  1. Start the server:
mvn spring-boot:run
  1. Access the application:

๐Ÿ“ Usage Examples

Using as MCP Server

Connect any MCP client to: http://localhost:8080/mcp

Example MCP client usage (Python):

# This is how the MCP tools would be used from a client

# Create video memory
create_video_memory(title="Important Lecture", description="AI and Machine Learning basics")

# Add text chunks  
add_chunks(video_memory_id=1, chunks=[
    "Introduction to artificial intelligence and its applications",
    "Machine learning algorithms and their use cases", 
    "Deep learning and neural networks overview"
])

# Build the video index
build_video(video_memory_id=1)

# Chat with the memory
chat_with_memory(video_memory_id=1, question="What are the main AI applications discussed?")

REST API Examples

# Create a video memory
curl -X POST http://localhost:8080/api/v1/memvid/memories \
  -H "Content-Type: application/json" \
  -d '{"title": "Spring Boot Tutorial", "description": "Comprehensive Spring Boot guide"}'

# Add text chunks
curl -X POST http://localhost:8080/api/v1/memvid/memories/1/chunks \
  -H "Content-Type: application/json" \
  -d '{"chunks": ["Spring Boot basics", "Dependency injection", "Data JPA usage"]}'

# Build video index
curl -X POST http://localhost:8080/api/v1/memvid/memories/1/build

# Chat with memory
curl -X POST http://localhost:8080/api/v1/memvid/memories/1/chat \
  -H "Content-Type: application/json" \
  -d '{"question": "What is dependency injection?"}'

# List all memories
curl http://localhost:8080/api/v1/memvid/memories

# Search memories
curl "http://localhost:8080/api/v1/memvid/memories/search?query=Spring"

GraphQL Examples

Access GraphiQL at http://localhost:8080/graphiql

# Create a video memory
mutation {
  createVideoMemory(title: "GraphQL Tutorial", description: "Learning GraphQL with Spring") {
    id
    title
    status
    videoFilename
  }
}

# Query video memories with pagination
query {
  videoMemories(page: 0, size: 10) {
    content {
      id
      title
      status
      totalChunks
    }
    totalElements
    totalPages
  }
}

# Get detailed memory information
query {
  videoMemory(id: "1") {
    id
    title
    description
    status
    textChunks {
      content
      wordCount
      summary
    }
    memoryIndex {
      totalWords
      keywords
      topics
    }
  }
}

# Chat with memory
mutation {
  chatWithMemory(videoMemoryId: "1", question: "Explain GraphQL benefits") {
    response
  }
}

# System status
query {
  systemStatus {
    totalMemories
    readyForChat
    processing
    statusCounts {
      CREATED
      BUILT
      PROCESSING
      ERROR
    }
  }
}

๐Ÿ›๏ธ Spring Boot Concepts Demonstrated

1. JPA & Repositories

  • Entity relationships (@OneToMany, @OneToOne)
  • Custom query methods
  • @Query annotations for complex queries
  • Transaction management with @Transactional

2. WebMVC

  • RESTful controllers with @RestController
  • Request/Response DTOs with validation
  • Exception handling with @ExceptionHandler
  • CORS configuration

3. GraphQL Integration

  • Schema-first approach
  • Query and Mutation resolvers
  • Field-level resolvers with @SchemaMapping
  • Pagination support

4. Spring AI MCP

  • @McpServerTool annotations for tool registration
  • Automatic MCP server setup via Spring Boot starter
  • HTTP Server-Sent Events transport
  • Tool parameter validation and error handling

5. Configuration Management

  • application.yml configuration
  • Profile-specific settings
  • Auto-configuration with Spring Boot starters

๐Ÿ”ง Configuration

Application Properties (application.yml)

spring:
  ai:
    mcp:
      server:
        enabled: true
        name: memvid-server
        capabilities:
          tools: true
          resources: true
          prompts: true
        webmvc:
          enabled: true
          endpoint: "/mcp"

Key Dependencies

<!-- Spring AI MCP Integration -->
<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-mcp-server-spring-boot-starter</artifactId>
</dependency>

<!-- GraphQL Support -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-graphql</artifactId>
</dependency>

<!-- JPA & Database -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

๐Ÿ“Š Database Schema

The application uses three main entities:

  • VideoMemory: Main entity storing video memory metadata
  • TextChunk: Individual text segments with indexing
  • MemoryIndex: Built indexes for efficient searching

๐Ÿงช Testing

Access the H2 console at http://localhost:8080/h2-console:

  • JDBC URL: jdbc:h2:mem:memvid
  • Username: sa
  • Password: password

๐Ÿ” Monitoring

Spring Actuator endpoints available:

  • /actuator/health - Application health
  • /actuator/info - Application information
  • /actuator/metrics - Application metrics

๐Ÿค MCP Integration

This server implements the Model Context Protocol (MCP) specification using Spring AI's official MCP library. It can be used with any MCP-compatible client, including:

  • Claude Desktop
  • Custom MCP clients
  • AI development tools
  • Chat applications

The server exposes its functionality through MCP tools, making it easy for AI models to interact with video memory management capabilities.

๐Ÿ“š Learning Outcomes

This project demonstrates:

  1. Modern Spring Boot Architecture: Clean separation of concerns
  2. MCP Integration: Official Spring AI MCP library usage
  3. Multi-API Support: REST, GraphQL, and MCP in one application
  4. JPA Best Practices: Entity modeling and repository patterns
  5. Kotlin with Spring: Leveraging Kotlin's features with Spring Framework
  6. API Design: RESTful principles and GraphQL schema design
  7. Configuration Management: Spring Boot auto-configuration and properties

๐Ÿ“„ License

This project is created for educational purposes to demonstrate Spring Boot and MCP integration concepts.