注册 MCP 工具
3.0 版本引入
这是一项实验性功能,不建议在生产环境中使用。有关该功能进展的更新或如果您想留下反馈,请加入 OpenSearch 论坛上的讨论。
使用此 API 注册一个或多个基于模型上下文协议 (MCP) 的工具。有关支持工具的更多信息,请参阅工具。
端点
POST /_plugins/_ml/mcp/tools/_register
请求正文字段
下表列出了可用的请求字段。
字段 | 数据类型 | 必需/可选 | 描述 |
---|---|---|---|
工具 | 数组 | 必需 | 工具列表。 |
tools
数组包含一个工具列表。每个工具都包含以下字段。
字段 | 数据类型 | 必需/可选 | 描述 |
---|---|---|---|
名称 | 字符串 | 可选 | 工具名称。工具名称默认为 type 参数值。如果需要在 MCP 服务器中包含多个相同类型的工具,请为这些工具指定不同的名称。 |
type | 字符串 | 必需 | 工具类型。有关支持的工具列表,请参阅 工具。 |
description | 字符串 | 可选 | 工具的描述。 |
parameters | 对象 | 可选 | 工具的参数。参数取决于工具类型。有关特定工具类型的信息,请参阅工具。 |
attributes | 对象 | 可选 | 工具的配置属性。此字段中最重要的属性是工具的 input_schema ,它定义了工具的预期参数格式。此 schema 会发送给大型语言模型 (LLM),以便在执行工具时能够正确格式化参数。 |
示例请求
内置工具分为零配置工具(无需参数)和参数化工具(需要参数)。零配置工具使用标准的初始化过程,因此具有相同的请求体,因为无需参数。相比之下,对于参数化工具,您必须提供正确的初始化参数以确保工具按预期运行。
示例请求:零配置工具
请求示例
{
"tools": [
{
"name": "ListIndexTool",
"type": "ListIndexTool",
"description": "This tool gets index information from the OpenSearch cluster. It takes 2 optional arguments named `indices` which is a comma-delimited list of one or more indices to get information from (default is an empty list meaning all indices), and `local` which means whether to return information from the local node only instead of the cluster manager node (default is false). The tool returns the indices information, including `health`, `status`, `index`, `uuid`, `pri`, `rep`, `docs.count`, `docs.deleted`, `store.size`, `pri.store. size `, `pri.store.size`, `pri.store`.",
"attributes": {
"input_schema": {
"type": "object",
"properties": {
"indices": {
"type": "array",
"items": {
"type": "string"
},
"description": "OpenSearch index name list, separated by comma. for example: [\"index1\", \"index2\"], use empty array [] to list all indices in the cluster"
}
},
"additionalProperties": false
}
}
},
{
"name": "SearchIndexTool",
"type": "SearchIndexTool",
"description": "Use this tool to search an index by providing two parameters: 'index' for the index name, and 'query' for the OpenSearch DSL formatted query. Only use this tool when both index name and DSL query is available.",
"attributes": {
"input_schema": {
"type": "object",
"properties": {
"index": {
"type": "string"
},
"query": {
"type": "string"
}
},
"additionalProperties": false
}
}
},
{
"name": "IndexMappingTool",
"type": "IndexMappingTool",
"description": "This tool gets index mapping information from a certain index. It takes 1 required argument named 'index' which is a comma-delimited list of one or more indices to get mapping information from, which expands wildcards. It takes 1 optional argument named 'local' which means whether to return information from the local node only instead of the cluster manager node (Default is false). The tool returns a list of index mappings and settings for each index. The mappings are in JSON format under the key 'properties' which includes the field name as a key and a JSON object with field type under the key 'type'. The settings are in flattened map with 'index' as the top element and key-value pairs for each setting.",
"attributes": {
"input_schema": {
"type": "object",
"properties": {
"index": {
"type": "array",
"description": "OpenSearch index name list, separated by comma. for example: [\"index1\", \"index2\"]",
"items": {
"type": "string"
}
}
},
"required": [
"index"
],
"additionalProperties": false
}
}
},
{
"name": "SearchAlertsTool",
"type": "SearchAlertsTool",
"description": "Use this tool to search an index by providing two parameters: 'index' for the index name, and 'query' for the OpenSearch DSL formatted query. Only use this tool when both index name and DSL query is available.",
"attributes": {
"input_schema": {
"type": "object",
"properties": {
"index": {
"type": "string",
"description": "OpenSearch index name. for example: index1"
},
"query": {
"type": "object",
"description": "OpenSearch search index query. You need to get index mapping to write correct search query. It must be a valid OpenSearch query. Valid value:\n{\"query\":{\"match\":{\"population_description\":\"seattle 2023 population\"}},\"size\":2,\"_source\":\"population_description\"}\nInvalid value: \n{\"match\":{\"population_description\":\"seattle 2023 population\"}}\nThe value is invalid because the match not wrapped by \"query\".",
"additionalProperties": false
}
},
"required": ["index", "query"],
"additionalProperties": false
}
}
},
{
"name": "SearchAnomalyDetectorsTool",
"type": "SearchAnomalyDetectorsTool",
"description": "This is a tool that searches anomaly detectors. It takes 12 optional arguments named detectorName which is the explicit name of the detector (default is null), and detectorNamePattern which is a wildcard query to match detector name (default is null), and indices which defines the index or index pattern the detector is detecting over (default is null), and highCardinality which defines whether the anomaly detector is high cardinality (synonymous with multi-entity) of non-high-cardinality (synonymous with single-entity) (default is null, indicating both), and lastUpdateTime which defines the latest update time of the anomaly detector in epoch milliseconds (default is null), and sortOrder which defines the order of the results (options are asc or desc, and default is asc), and sortString which defines how to sort the results (default is name.keyword), and size which defines the size of the request to be returned (default is 20), and startIndex which defines the paginated index to start from (default is 0), and running which defines whether the anomaly detector is running (default is null, indicating both), and failed which defines whether the anomaly detector has failed (default is null, indicating both). The tool returns 2 values: a list of anomaly detectors (each containing the detector id, detector name, detector type indicating multi-entity or single-entity (where multi-entity also means high-cardinality), detector description, name of the configured index, last update time in epoch milliseconds), and the total number of anomaly detectors.",
"attributes": {
"input_schema": {
"type": "object",
"properties": {
"detectorName": {
"type": "string",
"description": "Anomaly detector name"
},
"detectorNamePattern": {
"type": "string",
"description": "Anomaly detector name pattern"
},
"indices": {
"type": "string",
"description": "The index name that anomaly detector uses"
},
"highCardinality": {
"type": "string",
"description": "The value is true of false, the detector type will be set to MULTI_ENTITY if it's value is true, otherwise SINGLE_ENTITY if it's false"
},
"lastUpdateTime": {
"type": "string",
"description": "The last update time of the anomaly detector"
},
"sortString": {
"type": "string",
"description": "The sort key of the search result, default value is `name.keyword` which means the sorting is based on the detector name"
},
"sortOrder": {
"type": "string",
"description": "The search result order is based on this value, default is asc which means the sorting is in ascending manner."
},
"size": {
"type": "string",
"description": "This value controls how many search results will be fetched, default value is 20 which means at most 20 anomaly detecotrs can return"
},
"startIndex": {
"type": "string",
"description": "The start index of the search, default value is 0 which means starts from the beginning"
},
"running": {
"type": "string",
"description": "The running status of the anomaly detector, valid values are true and false, default is null"
},
"failed": {
"type": "string",
"description": "The failed status of the anomaly detector, valid values are true and false, default is null"
}
},
"additionalProperties": false
}
}
},
{
"name": "SearchAnomalyResultsTool",
"type": "SearchAnomalyResultsTool",
"description": "This is a tool that searches anomaly results. It takes 9 arguments named detectorId which defines the detector ID to filter for (default is null), and realtime which defines whether the anomaly results are from a realtime detector (set to false to only get results from historical analyses) (default is null), and anomalyGradeThreshold which defines the threshold for anomaly grade (a number between 0 and 1 that indicates how anomalous a data point is) (default is greater than 0), and dataStartTime which defines the start time of the anomaly data in epoch milliseconds (default is null), and dataEndTime which defines the end time of the anomaly data in epoch milliseconds (default is null), and sortOrder which defines the order of the results (options are asc or desc, and default is desc), and sortString which defines how to sort the results (default is data_start_time), and size which defines the number of anomalies to be returned (default is 20), and startIndex which defines the paginated index to start from (default is 0). The tool returns 2 values: a list of anomaly results (where each result contains the detector ID, the anomaly grade, and the confidence), and the total number of anomaly results.",
"attributes": {
"input_schema": {
"type": "object",
"properties": {
"detectorId": {
"type": "string",
"description": "Anomaly detector id"
},
"realTime": {
"type": "string",
"description": "If the anomaly detector a real time one, valid values are true and false, default is null"
},
"anomalyGradeThreshold": {
"type": "string",
"description": "A float number to indicate the anomaly grade"
},
"dataStartTime": {
"type": "string",
"description": "Start time of the data in the anomaly detector"
},
"dataEndTime": {
"type": "string",
"description": "End time of the data in the anomaly detector"
},
"sortString": {
"type": "string",
"description": "The sort key of the search result, default value is `name.keyword` which means the sorting is based on the detector name"
},
"sortOrder": {
"type": "string",
"description": "The search result order is based on this value, default is asc which means the sorting is in ascending manner."
},
"size": {
"type": "string",
"description": "This value controls how many search results will be fetched, default value is 20 which means at most 20 anomaly detecotrs can return"
},
"startIndex": {
"type": "string",
"description": "The start index of the search, default value is 0 which means starts from the beginning"
}
},
"additionalProperties": false
}
}
},
{
"name": "SearchMonitorsTool",
"type": "SearchMonitorsTool",
"description": "This is a tool that searches alerting monitors. It takes 10 optional arguments named monitorId which defines the monitor ID to filter for (default is null), and monitorName which defines explicit name of the monitor (default is null), and monitorNamePattern which is a wildcard query to match monitor name (default is null), and enabled which defines whether the monitor is enabled (default is null, indicating both enabled and disabled), and hasTriggers which defines whether the monitor has triggers enabled (default is null, indicating both), and indices which defines the index being monitored (default is null), and sortOrder which defines the order of the results (options are asc or desc, and default is asc), and sortString which defines how to sort the results (default is name.keyword), and size which defines the size of the request to be returned (default is 20), and startIndex which defines the paginated index to start from (default is 0). The tool returns 2 values: a list of alerting monitors (each containining monitor ID, monitor name, monitor type (indicating query-level, document-level, or bucket-level monitor types), enabled, enabled time in epoch milliseconds, last update time in epoch milliseconds), and the total number of alerting monitors.",
"attributes": {
"input_schema": {
"type": "object",
"properties": {
"monitorId": {
"type": "string",
"description": "Alerting monitor id"
},
"monitorName": {
"type": "string",
"description": "Alerting monitor name"
},
"monitorNamePattern": {
"type": "string",
"description": "Alerting monitor name pattern"
},
"enabled": {
"type": "string",
"description": "If the alerting monitor enabled or not, valid values are true and false, default is null"
},
"hasTriggers": {
"type": "string",
"description": "If the alerting monitor has triggers, valid values are true and false, default is null"
},
"indices": {
"type": "string",
"description": "The index names that alerting monitor uses"
},
"sortString": {
"type": "string",
"description": "The sort key of the search result, default value is `name.keyword` which means the sorting is based on the detector name"
},
"sortOrder": {
"type": "string",
"description": "The search result order is based on this value, default is asc which means the sorting is in ascending manner."
},
"size": {
"type": "string",
"description": "This value controls how many search results will be fetched, default value is 20 which means at most 20 alerting monitors can return"
},
"startIndex": {
"type": "string",
"description": "The start index of the search, default value is 0 which means starts from the beginning"
}
},
"additionalProperties": false
}
}
}
]
}
示例请求:参数化工具
以下部分提供了注册参数化工具的示例请求。有关工具特定参数的信息,请参阅相应的工具文档。
WebSearchTool
POST /_plugins/_ml/mcp/tools/_register
{
"tools": [
{
"type": "WebSearchTool",
"name": "GoogleSearchTool",
"attributes": {
"input_schema": {
"type": "object",
"properties": {
"engine": {
"type": "string",
"description": "The search engine that will be used by the tool."
},
"query": {
"type": "string",
"description": "The search query parameter that will be used by the engine to perform the search."
},
"next_page": {
"type": "string",
"description": "The search result's next page link. If this is provided, the WebSearchTool will fetch the next page results using this link and crawl the links on the page."
}
},
"required": [
"engine",
"query"
]
},
"strict": false
}
}
]
}
PPLTool
POST /_plugins/_ml/mcp/tools/_register
{
"type": "PPLTool",
"name": "TransferQuestionToPPLAndExecuteTool",
"description": "Use this tool to convert natural language into PPL queries and execute them. Use this tool after you know the index name; otherwise, call IndexRoutingTool first. The input parameters are: {index: IndexName, question: UserQuestion}",
"parameters": {
"model_id": "${your_model_id}",
"model_type": "FINETUNE"
},
"attributes": {
"input_schema": {
"type": "object",
"properties": {
"question": {
"type": "string",
"description": "The user's natural language question that needs to be converted to PPL."
},
"index": {
"type": "string",
"description": "The index on which the generated PPL query will be executed."
}
}
}
}
}
示例响应
OpenSearch 返回节点 ID 和每个节点上所有工具的创建状态
{
"_ZNV5BrNTVm6ilcM7Jn1pw": {
"created": true
},
"NZ9aiUCrSp2b5KBqdJGJKw": {
"created": true
}
}