imageSearchPic
Retrieve visually similar images from a dataset based on an input image. Operates on the Tencent Cloud COS MCP Server, enabling direct access to object storage and image processing without coding.
Instructions
根据输入的图片,从数据集中检索出与输入的图片内容相似的图片
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| uri | Yes | 图片地址 |
Implementation Reference
- The core handler function implementing the imageSearchPic tool logic, validating input and making a POST request to Tencent Cloud COS for image search using picture URI.
async imageSearchPic(params: ImageSearchPicParams) { // 验证并解析参数 const validParams = ImageSearchPicParamsSchema.parse(params); const { uri } = 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: 'pic', URI: uri, }); 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 { success: true, message: '图像检索成功', // data: result.Body.toString() data: result, }; } catch (error) { return { isSuccess: false, message: '图像检索失败', data: error, }; } } - src/server.ts:491-509 (registration)MCP server tool registration for 'imageSearchPic', defining input schema and delegating to the service instance handler.
server.tool( 'imageSearchPic', '根据输入的图片,从数据集中检索出与输入的图片内容相似的图片', { uri: z.string().describe('图片地址'), }, async ({ uri }) => { const res = await CIMateInsightInstance.imageSearchPic({ uri }); return { content: [ { type: 'text', text: JSON.stringify(res.data, null, 2), }, ], isError: !res.isSuccess, }; }, ); - Zod schema definition for ImageSearchPic parameters (uri: string) and inferred TypeScript type, used for input validation in the handler.
export const ImageSearchPicParamsSchema = z.object({ uri: z.string(), }); export type ImageSearchPicParams = z.infer<typeof ImageSearchPicParamsSchema>;