MCP サーバー Boot スターター
Model Context Protocol (MCP) Servers (英語) は、標準化されたプロトコルインターフェースを通じて AI アプリケーションに特定の機能を提供するプログラムです。各サーバーは、特定のドメインに特化した機能を提供します。
Spring AI MCP サーバー Boot スターターは、Spring Boot アプリケーションで MCP サーバー (英語) を設定するための自動構成機能を提供します。MCP サーバー機能と Spring Boot の自動構成システムをシームレスに統合できます。
MCP サーバー Boot スターターは以下を提供します。
ツール、リソース、プロンプトを含む MCP サーバーコンポーネントの自動構成
STDIO、SSE、Streamable-HTTP、ステートレスサーバーなど、さまざまな MCP プロトコルバージョンのサポート
同期と非同期の両方の動作モードをサポート
複数のトランスポート層オプション
柔軟なツール、リソース、迅速な仕様
変更通知機能
自動 Bean スキャンおよび登録機能を備えた Annotation-based server development
MCP サーバー Boot スターター
MCP サーバーは複数のプロトコルとトランスポートメカニズムをサポートしています。専用のスターターと適切な spring.ai.mcp.server.protocol プロパティを使用してサーバーを設定してください。
WebMVC
サーバータイプ | 依存 | プロパティ |
|
|
|
|
| |
|
|
サーバー機能
サーバーおよびトランスポートの種類に応じて、MCP サーバーは次のようなさまざまな機能をサポートできます。
ツール - 言語モデルから呼び出せるツールをサーバーに公開できるようにする
リソース - サーバーがクライアントにリソースを公開するための標準化された方法を提供します
プロンプト - サーバーがプロンプトテンプレートをクライアントに公開するための標準化された方法を提供します
Utility/Completions - サーバーがプロンプトやリソース URI の引数の自動補完候補を提供するための標準化された方法を提供します
Utility/Logging - サーバーが構造化されたログメッセージをクライアントに送信するための標準化された方法を提供します
Utility/Progress - 通知メッセージによる長時間実行操作の進行状況の追跡(オプション)
Utility/Ping - サーバーのステータスを報告するためのオプションのヘルスチェックメカニズム
すべての機能はデフォルトで有効になっています。機能を無効にすると、サーバーは対応する機能を登録してクライアントに公開できなくなります。
サーバープロトコル
MCP は、次のようないくつかのプロトコル型を提供します。
STDIO - インプロセス(例: サーバーがホストアプリケーション内で実行される)プロトコル。通信は標準入力と標準出力を介して行われます。
STDIOを有効にするには、spring.ai.mcp.server.stdio=trueを設定してください。SSE - リアルタイム更新のためのサーバー送信イベントプロトコル。サーバーは複数のクライアント接続を処理できる独立したプロセスとして動作します。
Streamable-HTTP - Streamable HTTP transport (英語) を使用すると、MCP サーバーは独立したプロセスとして動作し、HTTP POST および GET リクエストを使用して複数のクライアント接続を処理できます。オプションで、複数のサーバーメッセージに対応する Server-Sent Events(SSE)ストリーミングも利用できます。これは SSE トランスポートに代わるものです。
STREAMABLEプロトコルを有効にするには、spring.ai.mcp.server.protocol=STREAMABLEを設定します。ステートレス - ステートレス MCP サーバーは、リクエスト間でセッション状態が維持されない、簡素化されたデプロイ向けに設計されています。マイクロサービスアーキテクチャやクラウドネイティブのデプロイに最適です。
STATELESSプロトコルを有効にするには、spring.ai.mcp.server.protocol=STATELESSを設定してください。
同期 / 非同期サーバー API オプション
MCP サーバー API は、命令型 (同期など) およびリアクティブ型 (非同期など) のプログラミングモデルをサポートしています。
同期サーバー -
McpSyncServerを使用して実装されたデフォルトのサーバー型。アプリケーションでの簡単なリクエスト / レスポンスパターン向けに設計されています。このサーバー型を有効にするには、構成でspring.ai.mcp.server.type=SYNCを設定します。有効にすると、同期ツール仕様の構成が自動的に処理されます。
NOTE : SYNC サーバーは、MCP アノテーションが付けられた同期メソッドのみを登録します。非同期メソッドは無視されます。
非同期サーバー - 非同期サーバーの実装は
McpAsyncServerを使用し、ノンブロッキング操作に最適化されています。このサーバー型を有効にするには、アプリケーションをspring.ai.mcp.server.type=ASYNCで構成します。このサーバー型は、組み込みのプロジェクト Reactor サポートを使用して、非同期ツール仕様を自動的に設定します。
NOTE : ASYNC サーバーは、MCP アノテーションが付けられた非同期メソッドのみを登録します。同期メソッドは無視されます。
MCP サーバーアノテーション
MCP サーバー Boot スターターは、アノテーションベースのサーバー開発を包括的にサポートし、手動構成の代わりに宣言型 Java アノテーションを使用して MCP サーバーを作成できるようにします。
主なアノテーション
@McpTool - 自動 JSON スキーマ生成を使用してメソッドを MCP ツールとしてマークします
@McpResource - Provide access to resources via URI templates
@McpPrompt - Generate prompt messages for AI interactions
@McpComplete - Provide auto-completion functionality for prompts
特別なパラメーター
The annotation system supports special parameter types that provide additional context:
McpMeta- Access metadata from MCP requests@McpProgressToken- Receive progress tokens for long-running operationsMcpSyncServerExchange/McpAsyncServerExchange- Full server context for advanced operationsMcpTransportContext- Lightweight context for stateless operationsCallToolRequest- Dynamic schema support for flexible tools
簡単な例
@Component
public class CalculatorTools {
@McpTool(name = "add", description = "Add two numbers together")
public int add(
@McpToolParam(description = "First number", required = true) int a,
@McpToolParam(description = "Second number", required = true) int b) {
return a + b;
}
@McpResource(uri = "config://{key}", name = "Configuration")
public String getConfig(String key) {
return configData.get(key);
}
}自動構成
With Spring Boot auto-configuration, annotated beans are automatically detected and registered:
@SpringBootApplication
public class McpServerApplication {
public static void main(String[] args) {
SpringApplication.run(McpServerApplication.class, args);
}
}The auto-configuration will:
Scan for beans with MCP annotations
Create appropriate specifications
Register them with the MCP server
Handle both sync and async implementations based on configuration
プロパティの構成
Configure the server annotation scanner:
spring:
ai:
mcp:
server:
type: SYNC # or ASYNC
annotation-scanner:
enabled: true追加リソース
Server Annotations Reference - Complete guide to server annotations
特別なパラメーター - Advanced parameter injection
サンプル - Comprehensive examples and use cases
アプリケーション例
天気サーバー (南東 WebFlux) [GitHub] (英語) - Spring AI MCP Server Boot Starter with WebFlux transport
天気サーバー (STDIO) [GitHub] (英語) - Spring AI MCP Server Boot Starter with STDIO transport
天気サーバーの手動設定 [GitHub] (英語) - Spring AI MCP Server Boot Starter that doesn’t use auto-configuration but uses the Java SDK to configure the server manually
Streamable-HTTP WebFlux/WebMVC Example - TODO
Stateless WebFlux/WebMVC Example - TODO
追加リソース
MCP サーバーアノテーション - Declarative server development with annotations
特別なパラメーター - Advanced parameter injection and context access
MCP アノテーションの例 - Comprehensive examples and use cases