spring-mcp-server-claude-desktop-example

farrar142-examples/spring-mcp-server-claude-desktop-example

3.2

If you are the rightful owner of spring-mcp-server-claude-desktop-example and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.

The Model Context Protocol (MCP) server is a framework designed to facilitate communication between AI models and applications using a standardized protocol.

Tools
1
Resources
0
Prompts
0

개요

이 예제는 Spring AI의 Model Context Protocol(MCP) 기능을 활용하여 Claude AI에서 외부 툴(도구)을 호출하는 방법을 보여줍니다.

핵심 기능

MyTool.getWeather: 임의의 날씨 정보를 반환하는 도구 메서드 McpConfig.myTools: MyTool을 ToolCallbackProvider로 등록

실행 방법

  1. Spring Boot 애플리케이션 실행
    ./gradlew bootRun
    
  2. Claude Desktop 애플리케이션 실행
  3. Claude Desktop 설정에서 MCP 서버 추가
    {
       "mcpServers": {
          "spring-ai-mcp-weather": {
             "command": "npx",
             "args": ["-y", "mcp-remote", "http://localhost:8080/mcp", "--allow-http"]
          }
       }
    }
    
  4. Claude Desktop 재시작
  5. Claude AI와 대화 시작
    • 예: "오늘 서울의 날씨는 어때?"

커밋 로그

  1. Spring Initializr로 프로젝트 생성
    • Model Context Protocol Server
    • Spring Web
  2. Spring AI Version을 1.1.0-M1으로 변경
    • 현재 1.0.3버전에서는 Streamable HTTP를 지원안함
    // build.gradle.kts
    extra["springAiVersion"] = "1.1.0-M1"
    
  3. application.yml 설정
    #application.yml
    spring:
     ai:
       mcp:
          server:
             protocol: STREAMABLE
             enabled: true
    
  4. Tool 작성
    //MyTool.kt
    class MyTool {
       private val weathers = arrayOf("Sunny","Rainy","Cloudy")
       @Tool
       fun getWeather(location:String) = weathers.random()
    }
    
  5. Tool을 Bean으로 등록
    @Configuration
    class McpConfig {
        @Bean
        fun myTools(): ToolCallbackProvider = MethodToolCallbackProvider.builder().toolObjects(MyTool()).build()
    }
    
  6. claude_desktop_config.json 수정
    {
       "mcpServers": {
          "spring-ai-mcp-weather": {
             "command": "npx",
             "args": ["-y", "mcp-remote", "http://localhost:8080/mcp", "--allow-http"]
          }
       }
    }
    
    
  7. SpringBoot 실행 후 Claude Desktop 재시작