MCP模版配置手册
Nacos MCP 存量服务模版配置
通过Nacos控制台MCP管理创建一个基于存量服务的MCP服务,创建完成之后,编辑服务,增加新的Tool,配置Tool的参数信息以及模版信息。
模版信息配置。模版信息包含模版名称以及模版内容,当前仅支持Higress提供的json-go-template
模版。配置方法:
- 点击要配置模版的Tool,点击编辑
- 找到模版,点击新增,在key中填写
json-go-template
, value 中填写模版配置。
模版配置说明
模版是一个JSON配置,有如下的字段
- requestTemplate 请求参数模版
- responseTemplate 返回体模版
- argsPosition 参数位置映射信息
请求参数以及返回体模版
requestTemplate 和 responseTemplate 和 Higress定义的模版参数一致,可以参考文档配置
参数位置信息配置
Higress 支持配置参数的位置信息,我们通过通过argsPosition支持,argsPosition指定参数的位置,支持的值为
- query
- path
- header
- cookie
- body
这个字段的值对应于Higress的
tools[].args[].position
示例
{ "requestTemplate": { "url": "/v3/weather/weatherInfo", "argsToUrlParam": true, "method": "GET" }, "responseTemplate": { "body": "weather info {{ .weather }}" }, "argsPosition": { "city": "query" }}
引用服务绑定的Credential
创建和编辑的服务的时候允许选择可用的Credential的集合,这些Credential将会被Higress渲染到MCP服务信息的字段中,可供模版中进行值引用。
Credential的集合将会被渲染到Higress REST-to-MCP插件的 server.config.credentials
字段中,key 为 credential的 id, value为credential的内容。
例如一个 credential id 为 api_key
的credential, 内容为 {"data": "keyxxxxx"}
,并且在MCP服务中引用的这个credential,最终在 Higress 中 Server 的配置中会有以下内容
server: config: credentials: api_key: data: keyxxxxx
在模版中引用Credential中的值
{ "requestTemplate": { "url": "/v3/weather/weatherInfo?key={{ .config.credentials.api_key.data }}", "argsToUrlParam": true, "method": "GET" }, "responseTemplate": { "body": "response value {{ .value }}" }}