imageSearchText
Retrieve images matching input text from a dataset stored on Tencent Cloud COS MCP Server, enabling efficient visual content search and retrieval.
Instructions
根据输入的文本内容,从数据集中检索出与输入的文本内容相符的图片
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | 检索的文本 |
Implementation Reference
- The main handler function implementing the imageSearchText tool logic. It validates input using Zod schema, constructs a request to Tencent Cloud CI datasetquery/imagesearch endpoint with Mode: 'text', and returns search results or error.async imageSearchText(params: ImageSearchTextParams) { // 验证并解析参数 const validParams = ImageSearchTextParamsSchema.parse(params); const { text } = validParams; try { const key = 'datasetquery/imagesearch'; // 固定值 const appid = this.bucket.split('-').pop(); const host = `${appid}.ci.${this.region}.myqcloud.com`; const url = `https://${host}/${key}`; const body = JSON.stringify({ DatasetName: this.datasetName, Mode: 'text', Text: text, }); const result = await this.cos.request({ Method: 'POST', // 固定值,必须 Key: key, // 必须 Url: url, // 请求的url,必须 Body: body, // 请求体参数,必须 Headers: { // 设置请求体为 json,固定值,必须 'Content-Type': 'application/json', // 设置响应体为json,固定值,必须 Accept: 'application/json', }, }); return { isSuccess: true, message: '图像检索成功', data: result, }; } catch (error) { return { isSuccess: false, message: '请求异常: ${error.message}', data: error, }; } }
- Zod schema defining input parameters for the imageSearchText handler: expects a 'text' string.export const ImageSearchTextParamsSchema = z.object({ text: z.string(), }); export type ImageSearchTextParams = z.infer<typeof ImageSearchTextParamsSchema>;
- src/server.ts:511-529 (registration)MCP server tool registration. Defines the tool name 'imageSearchText', description in Chinese, inline Zod input schema for 'text', and async handler that calls the service method and formats response for MCP.server.tool( 'imageSearchText', '根据输入的文本内容,从数据集中检索出与输入的文本内容相符的图片', { text: z.string().describe('检索的文本'), }, async ({ text }) => { const res = await CIMateInsightInstance.imageSearchText({ text }); return { content: [ { type: 'text', text: JSON.stringify(res.data, null, 2), }, ], isError: !res.isSuccess, }; }, );