
tzolov/spring-ai-mcp-blogpost
Developer toolsこのページは AI により自動翻訳されています。技術的な詳細は原文をご確認ください。 原文を見る
Spring AI MCP イントロブログ投稿のコンパニオン例
概要
このリポジトリには、 Spring AI Model Context Protocol (MCP) のブログ投稿のコードが含まれているため、 Spring Boot を使用して MCP Server と Client の両方をビルドする方法を説明します。 モデルコンテキストプロトコル(MCP)は、AIアプリケーションが外部ツールやリソースとどのように相互作用するかを標準化します。 この例のショーケース: - : MCP ツールとして天気予報機能を公開する Spring Boot サーバー - : MCP サーバーに接続し、LM (Anthropic Claude) を使用する Spring Boot AI アプリケーション - : 座標による天気予報検索 - : クライアントに送信された構造化されたログメッセージ - : 業務のリアルタイム進捗更新 - : クライアントのLMからAI生成されたコンテンツをリクエストする - : 複数のMCPサーバーに同時に接続 - : ストリーム可能なHTTPとSTDIOの両方の転送 - : プロセスサーバーの通知とリクエスト - : Anthropic Claudeとのシームレスな統合 - Java 17以降 - Maven 3.6 + - Spring AI 1.1.0-SNAPSHOT - Node.
概要(AI 翻訳)
このリポジトリには、 Spring AI Model Context Protocol (MCP) のブログ投稿のコードが含まれているため、 Spring Boot を使用して MCP Server と Client の両方をビルドする方法を説明します。
概要
モデルコンテキストプロトコル(MCP)は、AIアプリケーションが外部ツールやリソースとどのように相互作用するかを標準化します。 この例のショーケース:
- MCP天気サーバー:MCPツールとして気象予報機能を公開するスプリングブートサーバー
- MCP 天気クライアント: MCP サーバーに接続し、LM (Anthropic Claude) を使用する Spring Boot AI アプリケーション
アーキテクチャ
##特徴 実証済み
MCP サーバーの機能
- ツール: 天候予測 座標による検索
- ログイン:クライアントに送信された構造化されたログメッセージ
- 進捗追跡:運用のリアルタイム進捗更新 -Sampling:クライアントのLMからAI生成されたコンテンツをリクエストする
MCP クライアント機能
- 複数のサーバー関係: 複数のMCPサーバーを同時に接続 -Transport Support: Streamable-HTTPとSTDIOの両方の転送
- ハンドラーアノテーション: サーバの通知とリクエストを処理する -LLMインテグレーション:Anthropic Claudeとのシームレスな統合
前提条件
このページは AI により自動翻訳されています。技術的な詳細は原文をご確認ください。
README
以下は原文 README の抜粋です。原文を見る。
Spring AI MCP Weather Example
This repository contains the example code for the Spring AI Model Context Protocol (MCP) blog post, demonstrating how to build both MCP Servers and Clients using Spring Boot.
Overview
The Model Context Protocol (MCP) standardizes how AI applications interact with external tools and resources. This example showcases:
- MCP Weather Server: A Spring Boot server that exposes weather forecast capabilities as MCP tools
- MCP Weather Client: A Spring Boot AI application that connects to MCP servers and uses an LLM (Anthropic Claude)
Architecture
┌────────────────────────────────────────────────────────────┐
│ MCP Weather Client │
│ ┌─────────────┐ ┌──────────────┐ ┌──────────────────┐ │
│ │ ChatClient │──│ MCP Client │──│ Weather Server │ │
│ │ (Claude) │ │ Transport │ │ (Streamable-HTTP)│ │
│ └─────────────┘ └──────────────┘ └──────────────────┘ │
│ │ │
│ ┌──────────────┐ ┌──────────────────┐ │
│ │ MCP Client │──│ Brave Search │ │
│ │ Transport │ │ (STDIO) │ │
│ └──────────────┘ └──────────────────┘ │
└────────────────────────────────────────────────────────────┘
Features Demonstrated
MCP Server Features
- Tools: Weather forecast retrieval by coordinates
- Logging: Structured log messages sent to clients
- Progress Tracking: Real-time progress updates for operations
- Sampling: Request AI-generated content from the client’s LLM
MCP Client Features
- Multi-Server Connection: Connect to multiple MCP servers simultaneously
- Transport Support: Both Streamable-HTTP and STDIO transports
- Handler Annotations: Process server notifications and requests
- LLM Integration: Seamless integration with Anthropic Claude
Prerequisites
- Java 17 or higher
- Maven 3.6+
- Spring AI 1.1.0-SNAPSHOT
- Node.js and NPM (for optional Brave Search integration)
- Anthropic API key (for the client)
- Brave Search API key (optional, for web search)
Project Structure
spring-ai-mcp-blogpost/
├── mcp-weather-server/ # MCP Server implementation
│ ├── src/main/java/
│ │ └── .../server/
│ │ ├── McpServerApplication.java
│ │ └── WeatherService.java
│ └── pom.xml
├── mcp-weather-client/ # MCP Client implementation
│ ├── src/main/java/
│ │ └── .../client/
│ │ ├── McpClientApplication.java
│ │ └── McpClientHandlers.java
│ └── pom.xml
└── pom.xml # Parent POM
Quick Start
1. Configure Maven Repository
Both projects use Spring AI snapshots. The required repository is already configured in the pom.xml files:
central-portal-snapshots
Central Portal Snapshots
インストール
npx @modelcontextprotocol/inspector設定
{
"mcpServers": {
"spring-ai-mcp-weather": {
"command": "java",
"args": [
"-Dspring.ai.mcp.server.stdio=true",
"-Dspring.main.web-application-type=none",
"-Dlogging.pattern.console=",
"-jar",
"/path/to/mcp-weather-server.jar"
]
}
}
}