cos-mcp
Version:
基于MCP协议的腾讯云COS MCP Server,无需编码即可让大模型快速接入腾讯云存储(COS)和数据万象(CI)能力
101 lines • 3.52 kB
JavaScript
import { z } from 'zod';
export const ImageSearchPicParamsSchema = z.object({
uri: z.string(),
});
export const ImageSearchTextParamsSchema = z.object({
text: z.string(),
});
export class CIMateInsightService {
bucket;
region;
cos;
datasetName;
constructor(bucket, region, datasetName, cos) {
this.bucket = bucket;
this.region = region;
this.datasetName = datasetName;
this.cos = cos;
}
async imageSearchPic(params) {
// 验证并解析参数
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,
};
}
}
async imageSearchText(params) {
// 验证并解析参数
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,
};
}
}
}
//# sourceMappingURL=mateInsight.service.js.map