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로 등록
실행 방법
- Spring Boot 애플리케이션 실행
./gradlew bootRun - Claude Desktop 애플리케이션 실행
- Claude Desktop 설정에서 MCP 서버 추가
{ "mcpServers": { "spring-ai-mcp-weather": { "command": "npx", "args": ["-y", "mcp-remote", "http://localhost:8080/mcp", "--allow-http"] } } } - Claude Desktop 재시작
- Claude AI와 대화 시작
- 예: "오늘 서울의 날씨는 어때?"
커밋 로그
- Spring Initializr로 프로젝트 생성
- Model Context Protocol Server
- Spring Web
- Spring AI Version을 1.1.0-M1으로 변경
- 현재 1.0.3버전에서는 Streamable HTTP를 지원안함
// build.gradle.kts extra["springAiVersion"] = "1.1.0-M1" - application.yml 설정
#application.yml spring: ai: mcp: server: protocol: STREAMABLE enabled: true - Tool 작성
//MyTool.kt class MyTool { private val weathers = arrayOf("Sunny","Rainy","Cloudy") @Tool fun getWeather(location:String) = weathers.random() } - Tool을 Bean으로 등록
@Configuration class McpConfig { @Bean fun myTools(): ToolCallbackProvider = MethodToolCallbackProvider.builder().toolObjects(MyTool()).build() } - claude_desktop_config.json 수정
{ "mcpServers": { "spring-ai-mcp-weather": { "command": "npx", "args": ["-y", "mcp-remote", "http://localhost:8080/mcp", "--allow-http"] } } } - SpringBoot 실행 후 Claude Desktop 재시작