This commit is contained in:
Your Name committed 2026-06-28 20:18:07 -04:00
1 parent 6096c727d9
commit 3965f4f4da
38 files changed
+1513 -752

No files matched your search

+21
View File
@@ -130,6 +130,18 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
required: ["id", "lang", "name"]
}
},
{
name: "update_category_image",
description: "Update the image URL for a specific category.",
inputSchema: {
type: "object",
properties: {
id: { type: "number", description: "Category ID" },
imageUrl: { type: ["string", "null"], description: "New image URL, or null/empty string to remove the image" }
},
required: ["id", "imageUrl"]
}
},
{
name: "update_product_brand_translation",
description: "Add or update translations for a specific product brand.",
@@ -868,6 +880,15 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
content: [{ type: "text", text: JSON.stringify(res.data, null, 2) }]
};
}
case "update_category_image": {
const { id, imageUrl } = params as any;
const res = await api.patch(`/categories/${id}/image`, {
imageUrl: imageUrl || null
});
return {
content: [{ type: "text", text: JSON.stringify(res.data, null, 2) }]
};
}
case "update_product_brand_translation": {
const { id, lang, name } = params as any;
const res = await api.patch(`/products/brands/${id}/translations`, {
@@ -0,0 +1,91 @@
import { spawn } from "child_process";
async function test() {
console.log("Starting backend server...");
const backend = spawn("bun", ["src/index.ts"], {
cwd: "../backend",
env: { ...process.env, PORT: "3051" }
});
// Give backend 2 seconds to start
await new Promise(resolve => setTimeout(resolve, 2000));
console.log("Starting MCP server...");
const mcp = spawn("bun", ["index.ts"], {
cwd: ".",
env: { ...process.env, MCP_BACKEND_URL: "http://localhost:3051/api" }
});
mcp.stderr.on("data", (data) => {
console.error(`[MCP STDERR] ${data}`);
});
let responseData = "";
mcp.stdout.on("data", (data) => {
responseData += data.toString();
console.log(`[MCP STDOUT] ${data}`);
});
const send = (msg: any) => {
mcp.stdin.write(JSON.stringify(msg) + "\n");
};
// 1. Send initialize
console.log("Sending initialize request...");
send({
jsonrpc: "2.0",
id: 1,
method: "initialize",
params: {
protocolVersion: "2024-11-05",
capabilities: {},
clientInfo: { name: "test-client", version: "1.0.0" }
}
});
await new Promise(resolve => setTimeout(resolve, 1000));
// 2. Send initialized notification
console.log("Sending initialized notification...");
send({
jsonrpc: "2.0",
method: "notifications/initialized"
});
await new Promise(resolve => setTimeout(resolve, 1000));
// 3. Send callTool request to update_category_image
console.log("Sending callTool request for update_category_image...");
responseData = ""; // Clear response data
send({
jsonrpc: "2.0",
id: 2,
method: "tools/call",
params: {
name: "update_category_image",
arguments: {
id: 1,
imageUrl: "https://example.com/mcp-test.png"
}
}
});
await new Promise(resolve => setTimeout(resolve, 3000));
console.log("Cleaning up servers...");
mcp.kill();
backend.kill();
console.log("Verifying response...");
console.log("Full responseData:", responseData);
if (!responseData.includes("https://example.com/mcp-test.png")) {
throw new Error("MCP response did not contain the updated imageUrl!");
}
console.log("MCP tool test passed successfully!");
}
test().catch(err => {
console.error("Test failed:", err);
process.exit(1);
});