Dealx

Dealx

🚀 @模型上下文协议/SDK 的 MCP 服务器实现

本项目提供了 @模型上下文协议/SDK 的 MCP 服务器实现,能够帮助你轻松配置和使用相关工具,实现广告搜索等功能。

🚀 快速开始

在开始使用 @模型上下文协议/SDK 的 MCP 服务器之前,你可以通过以下步骤进行安装和配置。

📦 安装指南

你可以使用 npm 进行安装:

npm install @模型上下文协议/mcp-server

然后将其作为命令使用:

npx @模型上下文协议/mcp-server

或者在你的代码中引入并使用:

import { McpServer } from "@模型上下文协议/mcp-server";
const server = new McpServer();
server.start(1234);

🔧 配置

编辑 config.json 文件:

{
"apiEndpoint": "http://localhost:3000",
"allowedOrigins": ["*"]
}

然后启动服务器:

npm start

💻 使用示例

基础用法

工具列表

获取所有可用工具的列表:

server.setRequestHandler(ListToolsRequestSchema, () => ({
tools: [
{
name: SEARCH_ADS,
description: "搜索广告",
inputSchema: SearchAdsInputSchema
}
]
}));

调用工具

调用具体的工具:

server.setRequestHandler(CallToolRequestSchema, async (request) => {
const { name, arguments: args } = request.params;
switch (name) {
case SEARCH_ADS:
return await searchAds(args);
default:
throw new McpError(ErrorCode.MethodNotFound, `未知工具:${name}`);
}
});

高级用法

搜索广告

搜索平台上的广告:

interface SearchAdsParams {
keyword?: string;
filters: {
priceRange?: [number, number];
category?: string;
};
}

export async function searchAds(params: SearchAdsParams) {
try {
const result = await fetch(`${config.apiEndpoint}/search`, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(params)
});

if (!result.ok) throw new Error("搜索广告失败");

const data = await result.json();
return {
content: [
{
type: "text",
text: JSON.stringify(data, null, 2),
}
],
};
} catch (error) {
throw new McpError(ErrorCode.InternalError, error instanceof Error ? error.message : String(error));
}
}

📚 详细文档

环境变量

在项目根目录创建 .env 文件:

DEALX_API_URL=http://localhost:3000
PORT=1234

然后加载环境变量:

import { config } from "dotenv";
config();

计划中的未来工具

  • create_ad: 创建新广告
  • edit_ad: 编辑现有广告
  • delete_ad: 删除广告
  • get_threads: 获取广告的讨论线程
  • create_thread: 创建新的讨论线程

项目结构

src/
├── config.ts
├── server.ts
└── tools/
└── searchAds.ts

👥 贡献者

  • [你的名字] - 初始实现
  • [其他贡献者的姓名]

📄 许可证

[插入许可证内容]

  • 0 关注
  • 0 收藏,26 浏览
  • system 提出于 2025-10-04 04:57

相似服务问题

相关AI产品