4. MCPサーバの作成方法¶
項目
4.1. 全体の作業の流れ¶
- MCPサーバクラスの作成
@MCPServer を付与したクラスを作成し、エンドポイントパスと認可権限スコープを決定します。
- 機能の実装
MCPサーバクラスのメソッドに @Tool 、 @Prompt 、 @Resource 、 @Completion を付与し、提供する機能を実装します。
- MCPサーバの検出設定
作成したMCPサーバクラスが intra-mart Accel Platform の起動時に検出されるように設定を行います。
4.2. 前提条件¶
MCPサーバクラス、および、ツールの入出力に利用するモデルクラスはすべてpublicである必要があります。
MCPサーバクラスは、publicかつ引数無しのコンストラクタを提供する必要があります。
MCPの機能として公開するメソッドはpublicである必要があります。
モデルクラスは引数無しのコンストラクタを提供する必要があります。
モデルクラスで有効となるプロパティは、対となる getter, setter があるメンバのみです。
ツールの入出力に利用するモデルクラスのフィールドには、JSONスキーマを生成するためのスキーマアノテーションを付与する必要があります。
注意
MCPサーバクラスのインスタンスは、MCPクライアントとの接続(MCPセッション)ごとに生成され、そのセッション内のすべてのリクエストで共有されます。同一セッション内のリクエストは並行して処理される場合があるため、MCPサーバクラスのインスタンスフィールドにリクエストごとに変化する状態を保持しないでください。注意
MCPサーバクラスにpublicかつ引数無しのコンストラクタが存在しない場合、MCPクライアントからの接続時にエラーが発生します。
4.3. MCPサーバクラスの作成¶
package com.example.mcp; import jp.co.intra_mart.foundation.copilot.mcp.annotation.MCPServer; @MCPServer( name = "document-server", path = "/documents", scope = "DOCUMENT_MCP", title = "ドキュメント MCP サーバ", version = "1.0.0", description = "ドキュメント管理機能を提供する MCP サーバです", instructions = "ドキュメントの検索・取得・要約に使用できます" ) public class DocumentMcpServer { // 各機能をメソッドとして実装します。 }
@MCPServer の属性一覧 属性 型 必須 多言語 説明 name String ○ MCPサーバの識別子です。 path String ○ HTTPのエンドポイントパスです。「/copilot/mcp」のプレフィックスを付けたパスでMCPサーバが公開されます。先頭が「/」でない場合は、「/」が付加されます。 scope String ○ MCPサーバへのアクセスを許可する認可権限スコープです。 title String ○ MCPクライアント上での表示に利用されるタイトルです。 version String MCPサーバのバージョン文字列です。 description String ○ MCPサーバの説明です。 instructions String ○ MCPサーバの利用方法をAIモデルに指示する文字列です。 websiteUrl String MCPサーバに関するWebサイトのURLです。 icons Icon[] MCPサーバのアイコン情報です。コラム
多言語の列が「○」の属性は、値にメッセージコードを指定することで多言語化できます。詳細は 表示文言の多言語化 を参照してください。注意
path 属性の値は intra-mart Accel Platform 内で一意である必要があります。同一の path を持つMCPサーバが複数存在する場合、いずれか1つのみが公開されます。どのMCPサーバが公開されるかは不定です。この場合、 intra-mart Accel Platform の起動時にログへエラーが出力されます。
4.4. MCPサーバの検出設定¶
package com.example.mcp; import java.util.Collection; import java.util.List; import jp.co.intra_mart.system.copilot.mcp.annotation.McpScanPackageFactory; public class DocumentMcpScanPackageFactory implements McpScanPackageFactory { @Override public Collection<String> getTargetPackages() { return List.of("com.example.mcp"); } }
src/main/resources/META-INF/services/jp.co.intra_mart.system.copilot.mcp.annotation.McpScanPackageFactory
com.example.mcp.DocumentMcpScanPackageFactory
注意
パッケージスキャンはクラスパス上のクラスを走査するため、対象パッケージの範囲によっては起動に時間がかかります。getTargetPackages() では、MCPサーバクラスが属するパッケージのみを指定してください。
4.5. ツールの実装¶
4.5.1. 基本実装¶
package com.example.mcp; import jp.co.intra_mart.foundation.copilot.mcp.annotation.MCPServer; import jp.co.intra_mart.foundation.copilot.mcp.annotation.Tool; import jp.co.intra_mart.foundation.copilot.tool.annotation.SchemaProperties.IntegerProperty; import jp.co.intra_mart.foundation.copilot.tool.annotation.SchemaProperties.StringProperty; @MCPServer(name = "document-server", path = "/documents", scope = "DOCUMENT_MCP") public class DocumentMcpServer { @Tool( name = "search-documents", title = "ドキュメント検索", description = "キーワードでドキュメントを検索します" ) public String searchDocuments(final SearchInput input) { return performSearch(input.getKeyword(), input.getMaxResults()); } public static class SearchInput { @StringProperty(description = "検索キーワード", required = true) private String keyword; @IntegerProperty(description = "最大件数", minimum = 1, maximum = 100) private int maxResults = 10; public String getKeyword() { return this.keyword; } public void setKeyword(final String keyword) { this.keyword = keyword; } public int getMaxResults() { return this.maxResults; } public void setMaxResults(final int maxResults) { this.maxResults = maxResults; } } }
@Tool の属性一覧 属性 型 必須 多言語 説明 name String ○ ツールの識別子です。 title String ○ MCPクライアント上での表示に利用されるタイトルです。 description String ○ ツールの説明です。AIが用途を判断するために利用されます。 outputSchema Class 構造化出力を返却する場合に、出力のモデルクラスを指定します。 taskSupport TaskSupportMode ツールのタスク実行のサポート有無を指定します。 icons Icon[] ツールのアイコン情報です。
4.5.2. 入力スキーマの定義¶
スキーマアノテーションの種類 アノテーション 対応するJavaの型 説明 @StringProperty String 文字列型のプロパティを定義します。 @IntegerProperty int / Integer / long / Long 整数型のプロパティを定義します。 @NumberProperty double / Double / float / Float 数値型のプロパティを定義します。 @BooleanProperty boolean / Boolean 真偽値型のプロパティを定義します。 @ArrayProperty List / 配列 配列型のプロパティを定義します。 @ObjectProperty ネストしたモデルクラス オブジェクト型のプロパティを定義します。 @EnumProperty 列挙型 列挙型のプロパティを定義します。
import jp.co.intra_mart.foundation.copilot.tool.annotation.SchemaProperties.ArrayProperty; import jp.co.intra_mart.foundation.copilot.tool.annotation.SchemaProperties.BooleanProperty; import jp.co.intra_mart.foundation.copilot.tool.annotation.SchemaProperties.EnumProperty; import jp.co.intra_mart.foundation.copilot.tool.annotation.SchemaProperties.IntegerProperty; import jp.co.intra_mart.foundation.copilot.tool.annotation.SchemaProperties.NumberProperty; import jp.co.intra_mart.foundation.copilot.tool.annotation.SchemaProperties.ObjectProperty; import jp.co.intra_mart.foundation.copilot.tool.annotation.SchemaProperties.StringProperty;
4.5.2.1. 共通の属性¶
共通の属性 属性 型 説明 name String プロパティ名です。省略した場合はフィールド名が利用されます。 description String プロパティの説明です。AIが値を決定するために利用されます。 required boolean 必須かどうかを指定します。(デフォルト: false)
4.5.2.2. 各アノテーション固有の属性¶
@StringProperty 固有の属性 属性 型 説明 enumValues String[] 許容する値を列挙します。 format String 値のフォーマットです。(例: date、email) minLength int 最小文字数です。 maxLength int 最大文字数です。 pattern String 値が満たすべき正規表現パターンです。
@IntegerProperty / @NumberProperty 固有の属性 属性 型 説明 enumValues int[] / double[] 許容する値を列挙します。 minimum double 最小値です。(指定した値を含みます) maximum double 最大値です。(指定した値を含みます) exclusiveMinimum double 最小値です。(指定した値を含みません) exclusiveMaximum double 最大値です。(指定した値を含みません)
@ArrayProperty 固有の属性 属性 型 説明 minItems int 最小要素数です。 maxItems int 最大要素数です。 stringItems @ItemStringProperty 文字列要素に対する制約です。 integerItems @ItemIntegerProperty 整数要素に対する制約です。 numberItems @ItemNumberProperty 数値要素に対する制約です。 arrayItems @ItemArrayProperty 配列要素に対する制約です。コラム
@ArrayProperty の要素に対する制約を指定するアノテーションは、 SchemaProperties ではなく SchemaArrayItemProperties で提供されています。import jp.co.intra_mart.foundation.copilot.tool.annotation.SchemaArrayItemProperties.ItemStringProperty;
4.5.2.3. 使用例¶
public static class SearchInput { @StringProperty(description = "検索キーワード", required = true) private String keyword; @IntegerProperty(description = "最大件数", minimum = 1, maximum = 100) private int maxResults = 10; @StringProperty(description = "検索対象カテゴリ", enumValues = { "技術仕様", "業務フロー", "FAQ" }) private String category; @ArrayProperty(description = "除外するドキュメントID", maxItems = 10, stringItems = @ItemStringProperty) private List<String> excludeIds; @BooleanProperty(description = "全文検索を行うか") private boolean fullText = false; // getter・setter は省略 }注意
スキーマアノテーションで指定した制約は、MCPクライアントへ公開される入力スキーマに反映されますが、制約が実際に適用されるかどうかは利用するAIサービス・AIモデルによって異なります。値の妥当性はツールの実装内でも必ず確認してください。
4.5.3. 戻り値¶
戻り値の変換ルール 戻り値の型 変換内容 CallToolResult 指定された内容がそのまま返却されます。 Collection / 配列 要素ごとに以下のルールで変換され、複数のコンテンツとして返却されます。 String テキストのコンテンツとして返却されます。 Content 指定されたコンテンツがそのまま返却されます。 上記以外(モデルクラスなど) JSON形式の文字列に変換され、テキストのコンテンツとして返却されます。
コラム
Collectionや配列を返却した場合、要素ごとに個別のコンテンツが生成されます。1つのJSON配列にはまとめられません。検索結果などを1つのJSONとしてまとめて返却したい場合は、モデルクラスに格納して返却するか、構造化出力を利用してください。なお、要素にCollectionや配列を指定した場合、その要素はJSON形式の文字列に変換され、1つのコンテンツとして返却されます。注意
日付・時刻を表す型( java.util.Date 、 java.time.LocalDateTime など)や、ファイル操作を行う型( Storage など)は、AIが解釈可能なJSONへ変換できないため、ツールの戻り値として利用しないでください。これらの型を指定した場合、ツールが公開されないか、呼び出し時に意図しない値やエラーが返却されます。日付・時刻を返却する場合は、ISO 8601形式の文字列に変換するなど、JSONで表現可能な形にしたうえで返却してください。Collectionや配列の要素、モデルクラスのプロパティについても同様です。注意
モデルクラスを戻り値とする場合は、JSONへ変換可能である必要があります。JSONへの変換に失敗した場合、そのツールの呼び出しはエラーとして扱われ、MCPクライアントへエラーが返却されます。コラム
JSONへの変換は、getter または public フィールドをもとに行われます。 java.io.Serializable を実装している必要はありません。公開されているプロパティが1つも無い場合や、循環参照を含む場合は変換に失敗します。
4.5.4. 構造化出力を返却する¶
@Tool( name = "search-structured", description = "キーワードでドキュメントを検索し、構造化データで返します", outputSchema = SearchResult.class ) public CallToolResult searchStructured(final SearchInput input) { final SearchResult result = performSearchStructured(input.getKeyword(), input.getMaxResults()); return CallToolResult.builder() .addTextContent("検索結果: " + result.getTotalCount() + " 件") .structuredContent(result) .build(); } public static class SearchResult { @ArrayProperty(description = "検索結果のドキュメントID一覧", stringItems = @ItemStringProperty) private List<String> items; @IntegerProperty(description = "総件数") private int totalCount; // getter・setter は省略 }コラム
outputSchema に指定したモデルクラスのJSONスキーマが、ツールの出力スキーマとしてMCPクライアントへ公開されます。注意
返却した構造化データが outputSchema のスキーマに適合しない場合、ツールの呼び出しはエラーとして扱われ、処理結果はMCPクライアントへ返却されません。出力のモデルクラスに付与したスキーマアノテーションと、実際に設定する値が一致していることを確認してください。注意
構造化データをどのように扱うかは、MCPクライアントの実装に依存します。構造化出力に対応していないMCPクライアントも存在します。構造化データを返却する場合も、 addTextContent() で結果の内容が分かるテキストを併せて返却してください。
4.5.5. エラーを返却する¶
@Tool(name = "get-document", description = "指定されたIDのドキュメントを取得します") public CallToolResult getDocument(final DocumentInput input) { final String content = loadDocument(input.getDocId()); if (content == null) { return CallToolResult.error("ドキュメントが見つかりません: " + input.getDocId()); } return CallToolResult.builder().addTextContent(content).build(); }コラム
AIに内容を判断させたいエラー(対象が存在しない、入力値が不正など)は CallToolResult.error() で返却してください。メソッドから例外を送出した場合の動作は 例外処理 を参照してください。
4.5.6. ツールをタスクとして実行する¶
TaskSupportMode の値 値 説明 FORBIDDEN タスクとしての実行をサポートしません。(デフォルト) OPTIONAL タスクとしての実行と、通常のツール呼び出しの両方をサポートします。 REQUIRED タスクとしての実行のみをサポートします。import jp.co.intra_mart.foundation.copilot.mcp.model.task.TaskSupportMode; @Tool( name = "bulk-import", description = "ドキュメントを一括で取り込みます", taskSupport = TaskSupportMode.OPTIONAL ) public String bulkImport(final ImportInput input) { return executeBulkImport(input); }注意
タスクはMCPプロトコルバージョン 2025-11-25 以降で利用可能です。MCPクライアントがそれより前のバージョンで接続した場合、タスクの機能は公開されません。 TaskSupportMode.REQUIRED を指定したツールは呼び出せない点に注意してください。注意
タスクはMCPの仕様上、実験的な機能として位置づけられており、対応するMCPクライアントは限られます。利用する場合は、あらかじめ対象のMCPクライアントがタスクに対応していることを確認してください。特別な理由がない限り、 taskSupport は指定せず( TaskSupportMode.FORBIDDEN のまま)、通常のツールとして実装することを推奨します。
4.5.7. ツール名の制約¶
128文字以内であること
半角英数字、アンダースコア(_)、ハイフン(-)、ピリオド(.)のみで構成されていること
注意
制約を満たさない name を指定したツールは公開されません。
4.6. プロンプトの実装¶
import java.util.Arrays; import java.util.List; import jp.co.intra_mart.foundation.copilot.mcp.annotation.Prompt; import jp.co.intra_mart.foundation.copilot.mcp.model.prompt.PromptMessage; @Prompt( name = "greeting", title = "挨拶プロンプト", description = "ユーザへの挨拶メッセージを生成します" ) public List<PromptMessage> greeting() { return Arrays.asList( PromptMessage.user("こんにちは!"), PromptMessage.assistant("何かお手伝いできることはありますか?")); }
4.6.1. 引数を持つプロンプト¶
import java.util.Map; import jp.co.intra_mart.foundation.copilot.mcp.annotation.PromptArgument; @Prompt( name = "code-review", title = "コードレビュー", description = "指定された言語でコードレビューを行います", arguments = { @PromptArgument(name = "language", title = "プログラミング言語", required = true), @PromptArgument(name = "focus", title = "レビュー観点", description = "例: セキュリティ、パフォーマンス") } ) public List<PromptMessage> codeReview(final Map<String, String> args) { final String language = args.get("language"); final String focus = args.get("focus"); final String resolvedFocus = (focus != null) ? focus : "全般"; return Arrays.asList( PromptMessage.user(language + " のコードを " + resolvedFocus + " の観点でレビューしてください。")); }注意
任意の引数が指定されずに呼び出された場合、キーに対応する値として null が渡されます。値を利用する前に必ずnullチェックを行ってください。
@Prompt の属性一覧 属性 型 必須 多言語 説明 name String ○ プロンプトの識別子です。 title String ○ MCPクライアント上での表示に利用されるタイトルです。 description String ○ プロンプトの説明です。 arguments PromptArgument[] プロンプトの引数の定義です。 icons Icon[] プロンプトのアイコン情報です。
@PromptArgument の属性一覧 属性 型 必須 多言語 説明 name String ○ 引数の識別子です。 title String ○ MCPクライアント上での表示に利用されるタイトルです。 description String ○ 引数の説明です。 required boolean 必須かどうかを指定します。(デフォルト: false)
4.7. リソースの実装¶
4.7.1. 静的リソース¶
import java.util.Arrays; import java.util.List; import jp.co.intra_mart.foundation.copilot.mcp.annotation.Resource; import jp.co.intra_mart.foundation.copilot.mcp.model.resource.ResourceContents; import jp.co.intra_mart.foundation.copilot.mcp.model.resource.TextResourceContents; @Resource( name = "categories", uri = "resource://documents/categories", title = "カテゴリ一覧", description = "利用可能なドキュメントカテゴリの一覧を返します", mimeType = "application/json" ) public List<? extends ResourceContents> getCategories() { final String json = "[\"技術仕様\",\"業務フロー\",\"FAQ\"]"; return Arrays.asList( new TextResourceContents("resource://documents/categories", "application/json", json)); }
4.7.2. バイナリリソース¶
import java.util.Base64; import jp.co.intra_mart.foundation.copilot.mcp.model.resource.BlobResourceContents; @Resource( name = "logo-image", uri = "resource://assets/logo.png", mimeType = "image/png" ) public List<? extends ResourceContents> getLogo() { final byte[] imageBytes = loadImageBytes(); final String base64 = Base64.getEncoder().encodeToString(imageBytes); return Arrays.asList( new BlobResourceContents("resource://assets/logo.png", "image/png", base64)); }
4.7.3. リソーステンプレート¶
@Resource( name = "document-content", uri = "resource://documents/{docId}", title = "ドキュメント本文", description = "指定されたIDのドキュメントの本文を返します", mimeType = "text/plain" ) public List<? extends ResourceContents> getDocument(final Map<String, String> vars) { final String docId = vars.get("docId"); final String content = loadDocument(docId); return Arrays.asList( new TextResourceContents("resource://documents/" + docId, "text/plain", content)); }
@Resource( name = "project-file", uri = "resource://projects/{projectId}/files/{fileId}" ) public List<? extends ResourceContents> getProjectFile(final Map<String, String> vars) { final String projectId = vars.get("projectId"); final String fileId = vars.get("fileId"); // 省略 }
4.7.4. リソースのヒント情報¶
import jp.co.intra_mart.foundation.copilot.mcp.annotation.Annotations; import jp.co.intra_mart.foundation.copilot.mcp.model.Role; @Resource( name = "ai-context", uri = "resource://context/ai-hints", annotations = @Annotations( audience = Role.ASSISTANT, priority = 0.8, lastModified = "2026-04-01T00:00:00Z" ) ) public List<? extends ResourceContents> getAiContext() { // 省略 }
@Annotations の属性一覧 属性 型 説明 audience Role[] 対象読者です。(USER、ASSISTANT) priority double 重要度です。0.0から1.0の範囲で指定します。値が大きいほど重要であることを示します。annotations を指定する場合は必ず指定してください。 lastModified String 最終更新日時です。ISO 8601形式で指定します。注意
annotations を指定する場合、 priority は必ず 0.0 から 1.0 の範囲で指定してください。priority を省略した場合、および範囲外の値を指定した場合、そのリソースは公開されません。また、 annotations 属性に複数の @Annotations を指定することはできません。
@Resource の属性一覧 属性 型 必須 多言語 説明 name String ○ リソースの識別子です。 uri String ○ リソースのURIです。パスパラメータを含む場合はリソーステンプレートとして扱われます。 title String ○ MCPクライアント上での表示に利用されるタイトルです。 description String ○ リソースの説明です。 mimeType String リソースのMIMEタイプです。 size long リソースのサイズ(バイト)です。 icons Icon[] リソースのアイコン情報です。 annotations Annotations[] リソースの対象読者や重要度などのヒント情報です。
4.8. 自動補完の実装¶
4.8.1. 補完メソッドの引数¶
4.8.1.1. CompleteArgument¶
CompleteArgument のメソッド メソッド 型 説明 name() String 補完対象の名前です。プロンプトの補完の場合は @PromptArgument の name 、リソーステンプレートの補完の場合はURIテンプレートのパラメータ名が設定されます。 value() String 利用者が入力中の値です。入力途中の文字列が設定されるため、通常はこの値を前方一致の条件として候補を絞り込みます。注意
value() には、利用者が何も入力していない状態では空文字が設定されます。また、MCPクライアントの実装によっては CompleteArgument 自体や value() が null となる場合があります。値を利用する前に必ずnullチェックを行ってください。
4.8.1.2. CompleteContext¶
CompleteContext のメソッド メソッド 型 説明 arguments() Map<String, String> 入力済みの引数の値です。引数の名前をキーとして値を取得します。注意
CompleteContext はMCPの仕様上、任意の情報です。MCPクライアントが送信しない場合は CompleteContext 自体や arguments() に null が渡されます。値を利用する前に必ずnullチェックを行ってください。
4.8.2. 補完メソッドの戻り値¶
補完メソッドの戻り値 戻り値の型 変換内容 List<String> などのCollection 補完候補の一覧として返却されます。候補の総数には要素数が設定されます。 CompleteCompletion 候補の一覧に加えて、候補の総数(total)と、返却した候補以外にも候補が存在するか(hasMore)を指定できます。 CompleteResult 指定された内容がそのまま返却されます。 null 候補なしとして返却されます。コラム
候補が多数存在する場合は、返却する件数を制限したうえで CompleteCompletion で hasMore に true を設定してください。final List<String> values = searchDocumentIds(prefix, 100); return new CompleteCompletion(values, values.size(), true);注意
上記以外の型を返却した場合、補完の呼び出しでエラーが発生します。
4.8.3. プロンプトの引数を補完する¶
import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; import jp.co.intra_mart.foundation.copilot.mcp.annotation.Completion; import jp.co.intra_mart.foundation.copilot.mcp.model.completion.CompleteArgument; import jp.co.intra_mart.foundation.copilot.mcp.model.completion.CompleteContext; @Completion(prompt = "code-review") public List<String> completeLanguage(final CompleteArgument argument, final CompleteContext context) { if (argument == null || !"language".equals(argument.name())) { return Arrays.asList(); } final String prefix = (argument.value() != null) ? argument.value() : ""; return Arrays.asList("Java", "JavaScript", "TypeScript", "Python", "Go").stream() .filter(lang -> lang.toLowerCase().startsWith(prefix.toLowerCase())) .collect(Collectors.toList()); }コラム
1つのプロンプトが複数の引数を持つ場合でも、補完メソッドは引数ごとには分かれません。CompleteArgument#name() で補完対象の引数を判別して候補を返却してください。なお、同一のプロンプトに対して @Completion を複数指定した場合、いずれか1つのみが利用されます。
4.8.4. リソーステンプレートのパラメータを補完する¶
@Completion(resource = "resource://documents/{docId}") public List<String> completeDocId(final CompleteArgument argument, final CompleteContext context) { final String prefix = (argument != null && argument.value() != null) ? argument.value() : ""; return searchDocumentIds(prefix); }
@Completion(resource = "resource://projects/{projectId}/files/{fileId}") public List<String> completeProjectFile(final CompleteArgument argument, final CompleteContext context) { if (argument == null || !"fileId".equals(argument.name())) { return Arrays.asList(); } final String prefix = (argument.value() != null) ? argument.value() : ""; // 入力済みの projectId を取得する final String projectId = (context != null && context.arguments() != null) ? context.arguments().get("projectId") : null; if (projectId == null) { // projectId が未入力の場合は候補を返却しない return Arrays.asList(); } return searchFileIds(projectId, prefix); }
@Completion の属性一覧 属性 型 必須 説明 prompt String ※ 補完対象のプロンプトの name です。 resource String ※ 補完対象のリソーステンプレートのURIです。コラム
「※」の属性は、いずれか一方を必ず指定する必要があります。
4.9. アイコンの指定¶
import jp.co.intra_mart.foundation.copilot.mcp.annotation.Icon; @MCPServer( name = "document-server", path = "/documents", scope = "DOCUMENT_MCP", icons = { @Icon(src = "https://example.com/icon-32.png", mimeType = "image/png", sizes = { "32x32" }), @Icon(src = "https://example.com/icon.svg", mimeType = "image/svg+xml", sizes = { "any" }) } ) public class DocumentMcpServer { // 省略 }
@Icon の属性一覧 属性 型 必須 説明 src String ○ アイコンのURLです。HTTP/HTTPSのURLまたは data: URI を指定します。 mimeType String アイコンのMIMEタイプです。 sizes String[] アイコンのサイズです。(例: “32x32”、”any”)
4.10. 表示文言の多言語化¶
多言語化が可能な属性 アノテーション 多言語化が可能な属性 @MCPServer title、description、instructions @Tool title、description @Prompt title、description @PromptArgument title、description @Resource title、description
CAP.L.SAMPLE.MCP.TOOL.SEARCH.TITLE=ドキュメント検索 CAP.L.SAMPLE.MCP.TOOL.SEARCH.DESCRIPTION=キーワードでドキュメントを検索します@Tool( name = "search-documents", title = "CAP.L.SAMPLE.MCP.TOOL.SEARCH.TITLE", description = "CAP.L.SAMPLE.MCP.TOOL.SEARCH.DESCRIPTION" ) public String searchDocuments(final SearchInput input) { // 省略 }コラム
指定した値に対応するメッセージが存在しない場合は、指定した値がそのまま利用されます。注意
スキーマアノテーション( @StringProperty など)の description は、メッセージコードによる多言語化に対応していません。
4.11. メソッドシグネチャと戻り値の規約¶
メソッドシグネチャの規約 アノテーション 引数 戻り値 @Tool 引数なし、または第1引数に入力のモデルクラスを指定します。プリミティブ型、配列、Collection、String は指定できません。 CallToolResultプリミティブ型、String、Content、JSONへ変換可能なモデルクラスCollection・配列(要素ごとに変換されます) @Prompt 引数なし、または Map<String, String> List<PromptMessage> @Resource(静的リソース) 引数なし Collection<? extends ResourceContents>、または ResourceContents @Resource(リソーステンプレート) Map<String, String> Collection<? extends ResourceContents>、または ResourceContents @Completion CompleteArgument、CompleteContext の2つ(順序も固定) List<String> などのCollection、CompleteCompletion、CompleteResult注意
規約を満たさないメソッドは、MCPの機能として公開されません。また、 @MCPServer の必須属性が指定されていない場合、そのクラスはMCPサーバとして公開されません。いずれの場合も intra-mart Accel Platform の起動は継続され、ログにエラーが出力されます。MCPサーバやツールがMCPクライアントから参照できない場合は、ログを確認してください。
4.12. 例外処理¶
import jp.co.intra_mart.foundation.copilot.mcp.exception.McpServerException; @Resource(name = "document-content", uri = "resource://documents/{docId}") public List<? extends ResourceContents> getDocument(final Map<String, String> vars) throws McpServerException { final String docId = vars.get("docId"); final String content = loadDocument(docId); if (content == null) { throw new McpServerException("ドキュメントが見つかりません: " + docId); } return Arrays.asList( new TextResourceContents("resource://documents/" + docId, "text/plain", content)); }コラム
ツールの場合、エラーの内容をAIに伝えて処理を継続させたいときは、例外を送出するのではなく CallToolResult.error() で返却してください。JSON-RPCのエラーレスポンスはプロトコルレベルのエラーとして扱われるため、AIがエラーの内容をもとに処理を継続することはできません。