Flex Gateway新着情報
Governance新着情報
Monitoring API Manager既存の API を使用して、MCP Connector を使用してエージェントを作成する方法の例を次にいくつか示します。
これらの例は、Mule アプリケーション内で MCP サーバーを作成し、MCP サーバーで公開される 2 つの個別のツールを定義するプロセスを示しています。1 つは、承認済みベンダーの動的リストを各ベンダーの商品カテゴリとともに取得するツールで、もう 1 つは、指定された詳細で購入注文の作成を開始するツールです。
これらの例は、MCP ツールの概念を呼び出し可能なリモートプロシージャーコール (RPC) として示しています。
この例は、サーバー送信イベント (SSE) トランスポートを使用して Mule アプリケーション内で MCP サーバーを設定する方法を示しています。この設定は既存の HTTP リスナー設定に基づいて作成されているため、Mule インスタンスでは MCP エンドポイントと従来の HTTP ベース API を同じポートで同時に提供することができます。
<http:listener-config name="HTTP_Listener_config">
<http:listener-connection host="localhost" port="${https.port}" />
</http:listener-config>
<mcp:server-config name="MCP_Server" serverName="Mule MCP Server" serverVersion="1.0.0">
<mcp:sse-server-connection listenerConfig="HTTP_Listener_config" sseEndpointPath="/sse" messagesPath="/message" />
</mcp:server-config>
この例は、外部システム (この例では SAP Concur) から承認済みベンダーの動的リストを取得する MCP ツールを作成する方法を示しています.この例は、<mcp:tool-listener> を使用してコール可能なツールを定義する方法と、データを処理し、Custom19 項目からの割り当て済み商品カテゴリを含め、関連ベンダー情報をエージェントに提供する方法を示しています。
<flow name="vendorsTool" >
<mcp:tool-listener config-ref="MCP_Server" name="get-vendors"> #(1)
<mcp:description>Get all approved vendors</mcp:description> #(2)
<mcp:parameters-schema ><![CDATA[{ #(3)
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {},
"required": []
}]]></mcp:parameters-schema>
<mcp:responses> #(4)
<mcp:text-tool-response-content text="#[payload.^raw]" />
</mcp:responses>
</mcp:tool-listener>
<flow-ref name="getTokenFlow" target="token"/>
<mule-sap-concur-connector:get-vendors config-ref="SAP_Concur_Config"/>
<ee:transform>
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload.Vendor filter ($.Approved == "true") map {
id: $.ID,
name: $.VendorName,
country: $.Country,
city: $.City,
productCategories: $.Custom19
}
]]></ee:set-payload>
</ee:message>
</ee:transform>
</flow>
| 1 | ツールは、<mcp:tool-listener> からトリガーされる Mule フローを介して実装されます。 |
| 2 | <mcp:description> では、ツールの目的についての説明が自然言語で提供されるため、LLM はツールを使用するタイミングを理解することができます。 |
| 3 | <mcp:parameters-schema> では、ツールの入力引数を定義します。この簡単な例では、これは空の JSON スキーマであり、入力パラメーターが不要であることを示しています。 |
| 4 | <mcp:responses> セクションでは、ツールの出力を定義します。ここでは、フローで生成された未加工の JSON ペイロードが含まれるテキスト応答をツールで返すことが指定されています。 |
このフローでは、最初に専用のコネクタを使用して SAP Concur からベンダーのリストを取得します。次に DataWeave を使用してデータを変換して承認済みベンダーを絞り込み、カスタム項目からの商品カテゴリを含め、関連項目をマップします。結果の JSON 出力では、ベンダーを選択するために必要な情報が LLM に提供されます。
この例は、エージェントが SAP Concur で購入注文の作成を開始するために使用できる MCP ツールの作成方法を示しています。この例では、JSON スキーマを使用してツールの入力パラメーターを定義する方法が強調されています。パラメーターごとに自然言語の説明が含まれており、これにより LLM は必要な情報を理解して入力することができます。
<flow name="purchaseOrderTool">
<mcp:tool-listener config-ref="MCP_Server" name="create-concur-purchase-order">
<mcp:description></mcp:description>
<mcp:parameters-schema ><![CDATA[{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Name for the purchase order."
},
"description": {
"type": "string",
"description": "Purchase order description."
},
"vendorCode": {
"type": "string",
"description": "Code that identifies the vendor."
},
"itemDescription": {
"type": "string",
"description": "Description of the item purchased in this order."
},
"price": {
"type": "number",
"description": "Monetary amount of the purchase order."
},
"currency": {
"type": "string",
"description": "Currency code for the purchase order monetary amount."
}
},
"required": ["name", "description", "vendorCode", "itemDescription", "price", "currency"]
}]]></mcp:parameters-schema>
<mcp:responses >
<mcp:text-tool-response-content text="#['Created Order $(payload.PurchaseOrderNumber)']" />
</mcp:responses>
</mcp:tool-listener>
<flow-ref name="getTokenFlow" target="token"/>
<mule-sap-concur-connector:create-purchase-order config-ref="SAP_Concur_Config">
<mule-sap-concur-connector:create-purchase-order-request-data ><![CDATA[#[output application/json
---
{
Name: payload.name,
CurrencyCode: payload.currency,
Description: payload.description,
VendorCode: payload.vendorCode,
LineItem: {
Description: payload.itemDescription,
ApprovedLineItemAmount: payload.price as String,
TotalPrice: payload.price as String
}
}]]]></mule-sap-concur-connector:create-purchase-order-request-data>
</mule-sap-concur-connector:create-purchase-order>
</flow>
その後、フローはコネクタを使用して注文を作成し、注文の ID を含む 1 行のテキストを返します。書式設定された応答は不要です。
前の例では、既存の Anypoint Connector から情報を取得するツールの作成方法が示されました。
すでに実装され、使用準備が整っているサードパーティ MCP サーバーを使用することもできます。これらの例は、MCP クライアントを設定し、Call Tool 操作を使用することで、Mule アプリケーションを既存のサードパーティ MCP サーバーと統合する方法を示しています。
次に、Heroku にデプロイされた Google マップ MCP サーバーを使用して設定された MCP クライアントの例を示します。
<mcp:client-config name="MCP_Client" clientName="Mule MCP Connector" clientVersion="1.0.0">
<mcp:sse-client-connection serverUrl="http://google-maps-mcp-sse-f5ebe64f8456.herokuapp.com">
</mcp:sse-client-connection>
</mcp:client-config>
クライアント接続を設定する機能により、サードパーティ MCP サーバーが解放され、アプリケーションネットワークへの扉が開かれます。
MCP クライアント設定が定義されたら、Call tool (mcp-call-tool) 操作を使用して、MCP サーバーで公開されている特定のツールを呼び出すことができます。Call Tool 操作では、対象 MCP サーバーからメタデータ (使用可能なツールとその引数を含む) を動的に取得して、Mule フロー内で DataSense のオートコンプリートを提供します。
この例では、特定の座標での予報を返す簡単な天気ツールを作成します。
<http:request-config basePath="/v1" name="HTTP_Request_configuration">
<http:request-connection host="api.open-meteo.com" protocol="HTTPS"></http:request-connection>
</http:request-config>
<flow name="getWeatherByCoordinatesToolFlow">
<mcp:tool-listener config-ref="MCP_Server" name="get-weather-by-coordinates">
<mcp:description>Provides the weather at given coordinates expressed as latitude and longitude></mcp:description>
<mcp:parameters-schema><![CDATA[{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"latitude": {
"type": "number",
"description": "The latitude component of a location's coordinates"
},
"longitude": {
"type": "number",
"description": "The longitude component of a location's coordinates"
}
},
"required": ["latitude", "longitude"]
}]]></mcp:parameters-schema>
<mcp:responses>
<mcp:text-tool-response-content text="#['Current temperature at location is $(payload.current.temperature_2m)']" />
</mcp:responses>
</mcp:tool-listener>
<http:request config-ref="HTTP_Request_configuration" method="GET" path="/forecast">
<http:query-params><![CDATA[#[output application/java
---
{
latitude : payload.latitude,
longitude : payload.longitude,
current: 'temperature_2m'
}]]]></http:query-params>
</http:request>
</flow>
このツールでは、OpenMeteo API を使用して、特定の座標での予報を返します。
座標ではなく住所で天気ルックアップを処理するには、Google マップ MCP サーバー (前半に設定済み) を活用して座標を取得した後、get-weather-by-coordinates ツール (内部的に OpenMeteo API をコールする) を使用する新しい MCP ツールを作成します。
<flow name="getWeatherByAddressToolFlow">
<mcp:tool-listener doc:name="Call Tool Listener" config-ref="MCP_Server" name="get-weather-by-address">
<mcp:description>Provides the weather at a specific address</mcp:description>
<mcp:parameters-schema ><![CDATA[{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"address": {
"type": "string",
"description": "The address we want to learn the weather for"
}
},
"required": ["address"]
}]]></mcp:parameters-schema>
<mcp:responses >
<mcp:text-tool-response-content text="#[payload.contents[0].text]" />
</mcp:responses>
</mcp:tool-listener>
<mcp:call-tool config-ref="MCP_GMaps_Client" toolName="maps_geocode">
<mcp:arguments ><![CDATA[#[output application/java
---
{
address: payload.address
}]]]>
</mcp:arguments>
</mcp:call-tool>
<mcp:call-tool config-ref="MCP_Client" toolName="get-weather-by-coordinates">
<mcp:arguments ><![CDATA[#[output application/java
---
{
latitude: read(payload.contents[0].text!, 'json').location.lat as Number,
longitude: read(payload.contents[0].text!, 'json').location.lng as Number
}]]]>
</mcp:arguments>
</mcp:call-tool>
</flow>
この例では、LLM にすべてのツールを個別に提供するのではなく、構成を手動で記述しています。その理由を次に示します。
LLM にはすべての MCP サーバーへのアクセス権が必要です。
LLM はすべての MCP サーバーを安全に認証できる必要があります。
LLM でオーケストレーションを行う場合、ガバナンスやトレースなどが複雑になります。
一部のユースケースでは、LLM でオーケストレーション全体を行うことが理にかなっていますが、それ以外では手動構成が適しています。