qiscrm-mcp
Version:
MCP server for QISCRM
570 lines (569 loc) • 30.5 kB
JavaScript
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { McpError, ErrorCode, } from "@modelcontextprotocol/sdk/types.js";
import { log, formatError } from "./utils.js";
import { z } from "zod";
import { ORG_ID } from "./config.js";
import { makePostRequest, makeGetRequest } from "./api.js";
import { handleCountReturn, handleSearchReturn, handleUpdateReturn, handlePostReturn } from "./tools/handlers.js";
/**
* Create and configure MCP server
*/
export function createServer() {
log("Creating Qiscrm MCP server");
// Create server instance
const server = new McpServer({
name: "qiscrm-mcp",
version: "0.0.1",
});
server.prompt("getCurrentTime", "获取当前时间,返回的数据格式是 YYMMDD:HH:SS:mm", {}, () => ({
messages: [{
role: "assistant",
content: {
type: "text",
text: "help you get current time."
}
}]
}));
server.tool("getCurrentTime", "获取当前时间", {}, async ({}) => {
const now = new Date();
const year = now.getFullYear();
const month = now.getMonth() + 1; // 月份是从0开始的
const date = now.getDate();
const hours = now.getHours();
const minutes = now.getMinutes();
const seconds = now.getSeconds();
return {
content: [
{
type: "text",
text: `当前时间:${year}-${month}-${date} ${hours}:${minutes}:${seconds}`,
},
],
};
});
server.prompt('count_friend', '搜索企微好友数量', {
like: z.string().max(64).optional().describe("好友的昵称或者备注"),
includeLabels: z.string().max(64).optional().describe("好友的标签"),
startTime: z.string().max(64).optional().describe("好友的添加时间(开始),格式为yyyy-MM-dd HH:mm:ss"),
endTime: z.string().max(64).optional().describe("好友的添加时间(结束),格式为yyyy-MM-dd HH:mm:ss"),
}, ({ like = '名字或者昵称包含关键字', includeLabels = '客户身上存在的标签', startTime = '添加时间(开始)', endTime = '添加时间(结束)' }) => {
return {
messages: [{
role: 'assistant',
content: {
type: 'text',
text: `可以通过以下条件 %{like}, %{includeLabels}, %{startTime}, %{endTime}, 来查询符合条件好友数量`
}
}]
};
});
// 搜企微外部联系人
server.tool("count_friend", "搜索企微好友数量", {
like: z.string().max(64).optional().describe("好友的昵称或者备注"),
includeLabels: z.string().max(64).optional().describe("好友的标签"),
startTime: z.string().max(64).optional().describe("好友的添加时间(开始),格式为yyyy-MM-dd HH:mm:ss"),
endTime: z.string().max(64).optional().describe("好友的添加时间(结束),格式为yyyy-MM-dd HH:mm:ss"),
}, async ({ like, includeLabels, startTime, endTime }) => {
const query = {
ORG_ID,
like: like ? like : '',
includeLabels: includeLabels ? includeLabels : '',
startTime: startTime ? startTime : '',
endTime: endTime ? endTime : '',
};
const searchResult = await makeGetRequest('/wxAPI/wxCampaign/v2/externalContact/count', query);
const t = handleCountReturn(searchResult);
return {
content: [{
type: "text",
text: `${t}`,
}],
};
});
server.prompt('searchFriend', '搜索企微好友数量', {
like: z.string().max(64).optional().describe("好友的昵称或者备注"),
includeLabels: z.string().max(64).optional().describe("好友的标签"),
startTime: z.string().max(64).optional().describe("好友的添加时间(开始),格式为yyyy-MM-dd HH:mm:ss"),
endTime: z.string().max(64).optional().describe("好友的添加时间(结束),格式为yyyy-MM-dd HH:mm:ss"),
}, ({ like = '名字或者昵称包含关键字', includeLabels = '客户身上存在的标签', startTime = '添加时间(开始)', endTime = '添加时间(结束)' }) => {
return {
messages: [{
role: 'assistant',
content: {
type: 'text',
text: `可以通过以下条件 %{like}, %{includeLabels}, %{startTime}, %{endTime}, 来查询符合条件好友列表`
}
}]
};
});
// 搜企微外部联系人
server.tool("searchFriend", "搜索企微好友,当有数据时,返回一个list,数据结构为:" +
"id: 逻辑id, corpId: 企业id, externalAvatar: 好友头像,externalName: 好友名字,externalUnionId:unionid," +
"externalUserId: 好友id,followCreateTime:添加好友时间,poolId:好友公海id,followUserId:添加的企业成员id,followUserName:添加的企业成员名字,", {
like: z.string().max(64).optional().describe("好友的昵称或者备注,非必填"),
includeLabels: z.string().max(64).optional().describe("好友的标签,非必填"),
startTime: z.string().max(64).optional().describe("好友的添加时间(开始),格式为yyyy-MM-dd HH:mm:ss,非必填"),
endTime: z.string().max(64).optional().describe("好友的添加时间(结束),格式为yyyy-MM-dd HH:mm:ss,非必填"),
pageFrom: z.number().optional().default(1).describe("分页开始的页码,非必填"),
pageSize: z.number().max(100).default(10).describe("每页显示的条数,非必填"),
}, async ({ like, includeLabels, startTime, endTime, pageFrom, pageSize }) => {
const query = {
ORG_ID,
like: like ? like : '',
includeLabels: includeLabels ? includeLabels : '',
startTime: startTime ? startTime : '',
endTime: endTime ? endTime : '',
pageSize: pageSize ? pageSize : 10,
pageFrom: pageFrom ? pageFrom : 1,
};
const searchResult = await makeGetRequest('/wxAPI/wxCampaign/v2/externalContact/search', query);
const t = handleSearchReturn(searchResult);
return {
content: [{
type: "text",
text: `${t}`,
}],
};
});
// 给一个好友添加标签
server.tool("addFriendTag", "给好友添加标签", {
tag: z.string().min(1).max(64).describe("要打上的标签,必填"),
poolId: z.string().min(1).max(64).describe("好友公海id,必填,可以从searchFriend的返回结果的poolId中找到"),
}, async ({ tag, poolId }) => {
const bodyParam = {
orgid: ORG_ID,
id: poolId,
addLabels: [tag],
};
const updateResult = await makePostRequest('/wxCustomerAPI/wxCustomer/v1/customerPool/updateDetail', bodyParam);
const t = handleUpdateReturn(updateResult);
return {
content: [{
type: "text",
text: `${t}`,
}],
};
});
// 搜索已经创建好的旅程配置
server.tool("searchDealStageEnum", "搜索旅程配置,返回的数据结构为" +
"name: 旅程的名字, type: 这个旅程的类型", {
like: z.string().max(64).optional().describe("旅程的名称,非必填"),
pageFrom: z.number().optional().default(1).describe("分页开始的页码,非必填"),
pageSize: z.number().max(100).default(10).describe("每页显示的条数,非必填"),
}, async ({ like, pageSize, pageFrom }) => {
const query = {
orgId: ORG_ID,
refType: '1',
like: like ? like : '',
pageSize: pageSize ? pageSize : 10,
pageFrom: pageFrom ? pageFrom : 1,
};
const updateResult = await makeGetRequest('/wxCustomerAPI/wxCustomer/v1/custome/search', query);
const t = handleSearchReturn(updateResult);
return {
content: [{
type: "text",
text: `${t}`,
}],
};
});
// 将好友加入旅程配置
server.tool("changeOrCreateNewDealStage", "加好友加入旅程", {
customerPoolId: z.string().max(64).describe("好友公海id,必填,可以从searchFriend的返回结果的poolId中找到"),
type: z.number().describe("旅程的类型,必填,可以从searchDealStageEnum的返回结果的type中找到"),
}, async ({ customerPoolId, type }) => {
const bodyParam = {
orgId: ORG_ID,
refType: 1,
customerPoolId,
fieldBaseId: 'SalesPipeline',
note: 'mcp修改旅程',
type,
};
const updateResult = await makePostRequest('/wxCustomerAPI/wxCustomer/v1/customerPool/changeOrNewDeal', bodyParam);
const t = handleUpdateReturn(updateResult);
return {
content: [{
type: "text",
text: `${t}`,
}],
};
});
// 将好友加入旅程配置
server.tool("查询好友的旅程信息", "在指定的旅程中查找好友, 如果存在,则返回好友信息,数据结构为" +
"dealid: 旅程id, stagedisplayvalue: 当前所处的旅程阶段, dealdays: 在旅程中的天数, staydays: 在旅程阶段中的天数", {
like: z.string().max(64).describe("好友的名字"),
type: z.number().describe("旅程的类型,必填,可以从searchDealStageEnum的返回结果的type中找到"),
pageFrom: z.number().optional().default(1).describe("分页开始的页码,非必填"),
pageSize: z.number().max(100).default(10).describe("每页显示的条数,非必填"),
}, async ({ like, type, pageSize, pageFrom }) => {
const query = {
orgId: ORG_ID,
like,
type,
pageSize: pageSize ? pageSize : 10,
pageFrom: pageFrom ? pageFrom : 1,
};
const getResult = await makeGetRequest('/wxCustomerAPI/wxCustomer/v1/field/searchDealStage', query);
const t = handleSearchReturn(getResult);
return {
content: [{
type: "text",
text: `${t}`,
}],
};
});
// 自主执行智能体
server.tool("searchExecuteAgent", "搜索自主执行智能体,返回的数据结果为:" +
"entityid: 自主执行智能体的id,updateByUsername: 更新者,entityname: 自主执行智能体的名字,config:自主执行智能体的配置," +
"{ entityid: d4d6a504603b446b8152aa5acaba37f4 // 自主执行智能体的id, " +
" status: 0, // 自主执行智能体的状态,0:待配置, 2:运行中, 3:完成 4:暂停 " +
" config: {autoPick: true, pickConfig: {deal: [{type: 959, stage: 57188a3a-2fca-498e-88c9-f61cd6f61859}], template: 旅程}, sendRepeat: 2, sourceType: 4}" +
" config是执行智能体的配置,其中 sendRepeat表示是否可以重复发送内容, sourceType表示好友的来源类型: 1.个微好友,4.企微好友,7.企微成员好友" +
" autoPick:是否自动进入,true 表示符合条件的对象自动进入,false表示需要手动操作对象, pickConfig: 自动进入的条件是什么, " +
" 例如 {deal: [{type: 959, stage: 57188a3a-2fca-498e-88c9-f61cd6f61859}], template: 旅程} 表示 进入条件是好友所处的旅程(template字段),旅程类型是959(type字段),旅程阶段是57188a3a-2fca-498e-88c9-f61cd6f61859(stage字段)," +
" {tag:[需要跟进],template:标签} 表示 进入条件是好友有特定标签(template字段),标签是需要跟进(tag字段)," +
" createtime: 1750256457819 // 创建时间, updatetime: 1750256457819 // 更新时间, updateByUsername: 陈健 // 最后更新者", {
entityName: z.string().max(64).optional().describe("自主执行智能体的名字,非必填"),
pageFrom: z.number().optional().default(1).describe("分页开始的页码,非必填"),
pageSize: z.number().max(100).default(10).describe("每页显示的条数,非必填"),
}, async ({ entityName, pageFrom, pageSize }) => {
const query = {
orgId: ORG_ID,
templateIds: 'ExecuteAgent',
entityName: entityName ? entityName : '',
pageSize: pageSize ? pageSize : 10,
pageFrom: pageFrom ? pageFrom : 1,
};
const searchResult = await makeGetRequest('/wxAPI/wxCampaign/v1/strategyConfigInfo/searchHead', query);
const t = handleSearchReturn(searchResult);
return {
content: [{
type: "text",
text: `${t}`,
}],
};
});
// 将好友加入执行智能体
server.tool("addFriend2ExecuteAgent", "将好友加入执行智能体", {
id: z.string().min(1).max(64).describe("好友的逻辑id,必填,可以从searchFriend的返回结果的逻辑id中找到"),
entityId: z.string().min(1).describe("执行智能体的id,必填,可以从searchExecuteAgent的返回结果的entityid中找到"),
corpId: z.string().min(1).max(64).describe("好友的企业id,必填,可以从searchFriend的返回结果的corpId中找到"),
}, async ({ id, corpId, entityId }) => {
const bodyParam = {
orgId: ORG_ID,
corpId,
ids: [id],
sopId: entityId,
};
const updateResult = await makePostRequest('/wxAPI/wxCampaign/v1/contentSeq/batchAdd', bodyParam);
const t = handleUpdateReturn(updateResult);
return {
content: [{
type: "text",
text: `${t}`,
}],
};
});
server.tool("updateExecuteAgentStatus", "修改执行智能体的运行状态, 可以修改的状态为: 2:运行中, 4:暂停 ", {
id: z.string().min(1).max(64).describe("执行智能体id,必填,可以从searchExecuteAgent的返回结果的entityid中找到"),
status: z.number().describe("更新的执行智能体的状态,必填,可以修改的状态为: 2:运行中, 4:暂停 "),
}, async ({ id, status }) => {
const bodyParam = {
orgId: ORG_ID,
id,
status: status,
};
const updateResult = await makePostRequest('/wxAPI/wxCampaign/v1/strategyConfigInfo/updateEntity', bodyParam);
const t = handleUpdateReturn(updateResult);
return {
content: [{
type: "text",
text: `${t}`,
}],
};
});
server.tool("searchFriendsInExecuteAgent", "搜索执行智能体中的好友,返回的数据结果为:" +
"sopid: 执行智能体的id,friendname: 好友名字,poolid: 好友公海id, followusername: 跟进的企微成员名字, followuserid: 跟进的企微成员id" +
"staydays: 在执行智能体中的经过的时间", {
entityId: z.string().max(64).optional().describe("执行智能体的id,必填,可以从searchExecuteAgent的返回结果的entityid中找到"),
friendName: z.string().max(64).optional().describe("执行智能体的中的好友名字(包含),非必填"),
pageFrom: z.number().optional().default(1).describe("分页开始的页码,非必填"),
pageSize: z.number().max(100).default(10).describe("每页显示的条数,非必填"),
}, async ({ entityId, friendName, pageFrom, pageSize }) => {
const query = {
orgId: ORG_ID,
sopId: entityId,
friendName: friendName ? friendName : '',
pageSize: pageSize ? pageSize : 10,
pageFrom: pageFrom ? pageFrom : 1,
};
const searchResult = await makeGetRequest('/wxAPI/wxCampaign/v1/contentSeq/searchFriend', query);
const t = handleSearchReturn(searchResult);
return {
content: [{
type: "text",
text: `${t}`,
}],
};
});
server.tool("removeExecuteAgentFriend", "将执行智能体中的好友移除", {
id: z.string().min(1).max(64).describe("好友的逻辑id,必填,可以从searchFriendsInExecuteAgent的返回结果的逻辑id中找到"),
}, async ({ id }) => {
const bodyParam = {
orgId: ORG_ID,
id,
};
const updateResult = await makePostRequest('/wxAPI/wxCampaign/v1/contentSeq/deleteFriend', bodyParam);
const t = handleUpdateReturn(updateResult);
return {
content: [{
type: "text",
text: `${t}`,
}],
};
});
// 内容序列
server.tool("searchContentSeq", "搜索内容序列,返回的数据结果为:" +
"entityid: 内容序列的id,updateByUsername: 更新者,entityname: 自主执行智能体的名字" +
"{ entityid: d4d6a504603b446b8152aa5acaba37f4 // 内容序列的id, " +
" status: 0, // 内容序列的状态,0:待配置, 2:运行中, 3:完成 4:暂停 " +
" createtime: 1750256457819 // 创建时间, updatetime: 1750256457819 // 更新时间, updateByUsername: 陈健 // 最后更新者", {
entityName: z.string().max(64).optional().describe("自主执行智能体的名字,非必填"),
pageFrom: z.number().optional().default(1).describe("分页开始的页码,非必填"),
pageSize: z.number().max(100).default(10).describe("每页显示的条数,非必填"),
}, async ({ entityName, pageFrom, pageSize }) => {
const query = {
orgId: ORG_ID,
templateIds: 'SOPContentSequence',
entityName: entityName ? entityName : '',
pageSize: pageSize ? pageSize : 10,
pageFrom: pageFrom ? pageFrom : 1,
};
const searchResult = await makeGetRequest('/wxAPI/wxCampaign/v1/strategyConfigInfo/searchHead', query);
const t = handleSearchReturn(searchResult);
return {
content: [{
type: "text",
text: `${t}`,
}],
};
});
// 将好友加入内容序列
server.tool("addFriend2ContentSeq", "将好友加入内容序列", {
id: z.string().min(1).max(64).describe("好友的逻辑id,必填,可以从searchFriend的返回结果的逻辑id中找到"),
entityId: z.string().min(1).describe("内容序列的id,必填,可以从searchContentSeq的返回结果的entityid中找到"),
corpId: z.string().min(1).max(64).describe("好友的企业id,必填,可以从searchFriend的返回结果的corpId中找到"),
}, async ({ id, corpId, entityId }) => {
const bodyParam = {
orgId: ORG_ID,
corpId,
ids: [id],
sopId: entityId,
};
const updateResult = await makePostRequest('/wxAPI/wxCampaign/v1/contentSeq/batchAdd', bodyParam);
const t = handleUpdateReturn(updateResult);
return {
content: [{
type: "text",
text: `${t}`,
}],
};
});
server.tool("updateContentSeqStatus", "修改内容序列的运行状态, 可以修改的状态为: 2:运行中, 4:暂停 ", {
id: z.string().min(1).max(64).describe("内容序列id,必填,可以从searchContentSeq的返回结果的entityid中找到"),
status: z.number().describe("更新的内容序列的状态,必填,可以修改的状态为: 2:运行中, 4:暂停 "),
}, async ({ id, status }) => {
const bodyParam = {
orgId: ORG_ID,
id,
status: status,
};
const updateResult = await makePostRequest('/wxAPI/wxCampaign/v1/strategyConfigInfo/updateEntity', bodyParam);
const t = handleUpdateReturn(updateResult);
return {
content: [{
type: "text",
text: `${t}`,
}],
};
});
server.tool("searchFriendsInContentSeq", "搜索内容序列中的好友,返回的数据结果为:" +
"id: 这条记录的逻辑id, sopid: 内容序列的id,friendname: 好友名字,poolid: 好友公海id, followusername: 跟进的企微成员名字, followuserid: 跟进的企微成员id" +
"staydays: 在内容序列中的经过的时间", {
entityId: z.string().max(64).optional().describe("内容序列的id,必填,可以从searchContentSeq的返回结果的entityid中找到"),
friendName: z.string().max(64).optional().describe("内容序列的中的好友名字(包含),非必填"),
pageFrom: z.number().optional().default(1).describe("分页开始的页码,非必填"),
pageSize: z.number().max(100).default(10).describe("每页显示的条数,非必填"),
}, async ({ entityId, friendName, pageFrom, pageSize }) => {
const query = {
orgId: ORG_ID,
sopId: entityId,
friendName: friendName ? friendName : '',
pageSize: pageSize ? pageSize : 10,
pageFrom: pageFrom ? pageFrom : 1,
};
const searchResult = await makeGetRequest('/wxAPI/wxCampaign/v1/contentSeq/searchFriend', query);
const t = handleSearchReturn(searchResult);
return {
content: [{
type: "text",
text: `${t}`,
}],
};
});
server.tool("removeContentSeqFriend", "将内容序列中的好友移除", {
id: z.string().min(1).max(64).describe("好友的逻辑id,必填,可以从searchFriendsInContentSeq的返回结果的逻辑id中找到"),
}, async ({ id }) => {
const bodyParam = {
orgId: ORG_ID,
id,
};
const updateResult = await makePostRequest('/wxAPI/wxCampaign/v1/contentSeq/deleteFriend', bodyParam);
const t = handleUpdateReturn(updateResult);
return {
content: [{
type: "text",
text: `${t}`,
}],
};
});
// 内容序列和执行智能体的天数配置
server.tool("searchDayConfig", "搜索内容序列和执行智能体中的天数信息,返回的数据结果为:" +
"entityid: 天数配置的id,updateByUsername: 更新者,entityname: 自主执行智能体的名字" +
"config: {\"发送时间\": \"09:00\", \"好友通过天数\": 3} // config中是第几天的几点" +
" configcount: 这个配置下有多少条内容 , " +
" status: 0, // 内容序列的状态,0:待配置, 2:运行中, 3:完成 4:暂停 " +
" createtime: 1750256457819 // 创建时间, updatetime: 1750256457819 // 更新时间, updateByUsername: 陈健 // 最后更新者" +
"其他返回值不需要分析", {
parentEntitiyId: z.string().max(64).optional().describe("内容序列或者执行智能体的id,必填,通过searchContentSeq或者searchExecuteAgent获取"),
pageFrom: z.number().optional().default(1).describe("分页开始的页码,非必填"),
pageSize: z.number().max(100).default(10).describe("每页显示的条数,非必填"),
}, async ({ parentEntitiyId, pageFrom, pageSize }) => {
const query = {
orgId: ORG_ID,
templateIds: 'SOPScheduleMessageSendRunTask,SOPDeleteDealStageRunTask,SOPChangeDealStageRunTask,SOPScheduleQYExtUserMsgRunTask,SOPQYExtUserMsgNoticeRunTask,SOPScheduleMomentSendRunTask,SOPScheduleSendQyMomentMessageRunTask,SOPQYMomentSendNoticeRunTask,SOPScheduleFollowUpNoticeRunTask,SOPQYFollowUpNoticeRunTask,SOPScheduleAliRPASendQiYeFriendMessageRunTask,SOPScheduleAliRPASendQiYeRoomMMessageRunTask,SOPScheduleChatroomMessageSendRunTask,SOPScheduleSendQiYeRoomMessageRunTask',
configTemplateIds: 'SOPScheduleMessageSendRunTask,SOPDeleteDealStageRunTask,SOPChangeDealStageRunTask,SOPScheduleQYExtUserMsgRunTask,SOPQYExtUserMsgNoticeRunTask,SOPScheduleMomentSendRunTask,SOPScheduleSendQyMomentMessageRunTask,SOPQYMomentSendNoticeRunTask,SOPScheduleFollowUpNoticeRunTask,SOPQYFollowUpNoticeRunTask,SOPScheduleAliRPASendQiYeFriendMessageRunTask,SOPScheduleAliRPASendQiYeRoomMMessageRunTask,SOPScheduleChatroomMessageSendRunTask,SOPScheduleSendQiYeRoomMessageRunTask',
parentEntitiyids: parentEntitiyId,
excludeMember: 1,
pageSize: pageSize ? pageSize : 10,
pageFrom: pageFrom ? pageFrom : 1,
};
const searchResult = await makeGetRequest('/wxAPI/wxCampaign/v1/strategyConfigInfo/searchHead', query);
const t = handleSearchReturn(searchResult);
return {
content: [{
type: "text",
text: `${t}`,
}],
};
});
// 内容序列和执行智能体的天数配置
server.tool("searchDayDetailConfig", "搜索内容序列和执行智能体中的指定天数的具体发送内容,返回的数据结果为:" +
"configid: 发送内容配置的id," +
"contentType: 表示发送内容的类型,1010:文字,1020:图片,1030:链接,1031:链接,3000:朋友圈,3009:修改旅程阶段,3024:移除旅程" +
"content: 表示具体的内容" +
"其他返回值不需要分析", {
entityIds: z.string().max(64).describe("天数配置的id,必填,通过searchDayConfig获取"),
pageFrom: z.number().optional().default(1).describe("分页开始的页码,非必填"),
pageSize: z.number().max(100).default(10).describe("每页显示的条数,非必填"),
}, async ({ entityIds, pageFrom, pageSize }) => {
const query = {
orgId: ORG_ID,
templateIds: 'SOPScheduleMessageSendRunTask,SOPDeleteDealStageRunTask,SOPChangeDealStageRunTask,SOPScheduleQYExtUserMsgRunTask,SOPQYExtUserMsgNoticeRunTask,SOPScheduleMomentSendRunTask,SOPScheduleSendQyMomentMessageRunTask,SOPQYMomentSendNoticeRunTask,SOPScheduleFollowUpNoticeRunTask,SOPQYFollowUpNoticeRunTask,SOPScheduleAliRPASendQiYeFriendMessageRunTask,SOPScheduleAliRPASendQiYeRoomMMessageRunTask,SOPScheduleChatroomMessageSendRunTask,SOPScheduleSendQiYeRoomMessageRunTask',
entityIds,
pageSize: pageSize ? pageSize : 10,
pageFrom: pageFrom ? pageFrom : 1,
};
const searchResult = await makeGetRequest('/wxAPI/wxCampaign/v1/strategyConfigInfo/search', query);
const t = handleSearchReturn(searchResult);
return {
content: [{
type: "text",
text: `${t}`,
}],
};
});
// 内容生成智能体
server.tool("splitContent", "拆分一段长文字:" +
"blocks: 要拆分的段落数" +
"contentType: 表示发送内容的类型,1010:文字,1020:图片,1030:链接,1031:链接,3000:朋友圈,3009:修改旅程阶段,3024:移除旅程" +
"content: 表示具体的内容" +
"其他返回值不需要分析", {
blocks: z.number().optional().default(1).describe("要拆分的段落数,必填"),
longText: z.string().describe("需要拆分的文字内容,必填"),
}, async ({ blocks, longText }) => {
const bodyParam = {
orgId: ORG_ID,
model: 'moonshot-v1-auto',
days: blocks,
prompt: longText,
topicId: 'content_split',
};
const updateResult = await makePostRequest('cloudmobileapi/cloudmobile/v1/gpt/split', bodyParam);
const t = handlePostReturn(updateResult);
return {
content: [{
type: "text",
text: `${t}`,
}],
};
});
server.tool("generateContent", "根据输入的业务信息,生成有吸引力的内容", {
longText: z.string().max(64).optional().describe("输入的业务信息,必填"),
model: z.string().optional().default('GLM-4-Air').describe("选择模型,可以是 GLM-4-Air, deepseek-chat, moonshot-v1-auto"),
category: z.string().default('邀约').describe("生成的内容的偏向性,非必填,可以是 邀约,交付,发售,培育"),
num: z.number().max(10).default(3).describe("生成的内容条数,非必填,默认值是3条"),
}, async ({ longText, model, category, num }) => {
const bodyParam = {
orgId: ORG_ID,
longText,
model,
category,
num,
};
const updateResult = await makePostRequest('cloudmobileapi/cloudmobile/v1/llm/contentagent/generateBySummary', bodyParam);
const t = handlePostReturn(updateResult);
return {
content: [{
type: "text",
text: `${t}`,
}],
};
});
server.tool("addDayConfig", "在执行智能体或者内功序列中添加一个文本内容", {
parentEntity: z.string().max(64).optional().describe("执行智能体或者内功序列的id,必填"),
passday: z.number().optional().default(3).describe("内容在第几天发送"),
deliverytime: z.string().default('09:00').describe("内容在几点发送, 数据格式需要整理成 09:00 这样"),
content: z.string().describe("具体内容,必填"),
}, async ({ parentEntity, passday, deliverytime, content }) => {
const bodyParam = {
orgId: ORG_ID,
parentEntity,
passday,
deliverytime,
templateid: 'SOPScheduleQYExtUserMsgRunTask',
contenttype: '1010',
content,
};
const updateResult = await makePostRequest('/wxAPI/wxCampaign/v1/contentSeq/addDayConfig', bodyParam);
const t = handlePostReturn(updateResult);
return {
content: [{
type: "text",
text: `${t}`,
}],
};
});
return server;
}
/**
* Helper function to handle errors uniformly
*/
function handleError(context, error) {
log(`Error ${context}:`, error);
if (error instanceof McpError) {
throw error;
}
throw new McpError(ErrorCode.InternalError, `${context}: ${formatError(error)}`);
}