Below is a simple example MCP (Model Context Protocol) server that accepts:
Product pricing factors
Manufacturing cost factors
Returns a Make vs Buy decision
I’ll show:
Architecture
Data model
Example MCP server (Node.js)
Example MCP client call
How decision logic works
🧠 What this MCP server does
The MCP server exposes a tool called:
make_vs_buy_decision
It evaluates:
Manufacturing cost
Supplier cost
Demand
Overheads
Risk margin
Target profit
Then returns:
Recommendation: MAKE or BUY
Cost breakdown
Reasoning
🏗️ Architecture
+-------------------+
| MCP Client |
| (AI agent/app) |
+---------+---------+
|
| MCP (JSON-RPC over stdio/http)
|
+---------v---------+
| MCP Server |
|-------------------|
| Tools: |
| make_vs_buy |
|-------------------|
| Decision Engine |
| Cost calculator |
| Pricing logic |
+---------+---------+
|
v
+-------------------+
| Cost Models |
| Pricing models |
| Supplier DB (opt) |
+-------------------+
📦 Input Schema
Pricing factors
selling_price
target_margin
expected_demand
Manufacturing factors
raw_material_cost
labor_cost
overhead_cost
setup_cost
capacity_limit
Buy factors
supplier_unit_price
logistics_cost
import_duty
supplier_risk_factor
⚙️ Decision Logic (example)
Make cost per unit
(raw + labor + overhead) + setup/demand
Buy cost per unit
supplier price + logistics + duty + risk buffer
Decision:
If make_cost < buy_cost → MAKE
Else → BUY
🖥️ Example MCP Server (Node.js)
This uses MCP-style JSON-RPC tool exposure.
// mcp-server.js
import { createServer } from "@modelcontextprotocol/sdk/server/index.js";
const server = createServer({
name: "make-vs-buy-server",
version: "1.0.0"
});
// Tool definition
server.tool(
"make_vs_buy_decision",
"Evaluate whether to manufacture in-house or buy from supplier",
{
selling_price: "number",
target_margin: "number",
expected_demand: "number",
raw_material_cost: "number",
labor_cost: "number",
overhead_cost: "number",
setup_cost: "number",
supplier_unit_price: "number",
logistics_cost: "number",
import_duty: "number",
supplier_risk_factor: "number"
},
async (input) => {
const {
selling_price,
target_margin,
expected_demand,
raw_material_cost,
labor_cost,
overhead_cost,
setup_cost,
supplier_unit_price,
logistics_cost,
import_duty,
supplier_risk_factor
} = input;
// ---- MAKE COST ----
const variableMakeCost =
raw_material_cost + labor_cost + overhead_cost;
const setupPerUnit = setup_cost / expected_demand;
const makeCostPerUnit = variableMakeCost + setupPerUnit;
// ---- BUY COST ----
const riskBuffer = supplier_unit_price * supplier_risk_factor;
const buyCostPerUnit =
supplier_unit_price +
logistics_cost +
import_duty +
riskBuffer;
// ---- PROFIT CHECK ----
const makeMargin = selling_price - makeCostPerUnit;
const buyMargin = selling_price - buyCostPerUnit;
let decision = "";
let reason = "";
if (makeCostPerUnit < buyCostPerUnit) {
decision = "MAKE";
reason = "Manufacturing cost is lower than supplier cost";
} else {
decision = "BUY";
reason = "Supplier cost is more economical";
}
return {
decision,
make_cost_per_unit: makeCostPerUnit,
buy_cost_per_unit: buyCostPerUnit,
make_margin: makeMargin,
buy_margin: buyMargin,
reasoning: reason
};
}
);
server.start();
💻 Example MCP Client
Client sends pricing + manufacturing factors.
import { MCPClient } from "@modelcontextprotocol/sdk/client/index.js";
const client = new MCPClient({
serverCommand: "node",
serverArgs: ["mcp-server.js"]
});
await client.connect();
const result = await client.callTool("make_vs_buy_decision", {
selling_price: 120,
target_margin: 0.25,
expected_demand: 1000,
raw_material_cost: 40,
labor_cost: 20,
overhead_cost: 15,
setup_cost: 10000,
supplier_unit_price: 95,
logistics_cost: 5,
import_duty: 3,
supplier_risk_factor: 0.05
});
console.log(result);
📊 Example Response
{
"decision": "MAKE",
"make_cost_per_unit": 85,
"buy_cost_per_unit": 103.75,
"make_margin": 35,
"buy_margin": 16.25,
"reasoning": "Manufacturing cost is lower than supplier cost"
}
🧱 Production Architecture (Enterprise)
+----------------------+
| AI Agent (LLM) |
| Supply Chain Bot |
+----------+-----------+
|
v
+----------------------+
| MCP Client Layer |
| (tool orchestration)|
+----------+-----------+
|
MCP Protocol (stdio/ws/http)
|
+--------------v--------------+
| MCP Server |
|-----------------------------|
| Make vs Buy Tool |
| Cost Modeling Engine |
| Pricing Engine |
| Risk Engine |
+--------------+--------------+
|
+-------------v--------------+
| ERP / SAP / Cost DB |
| Supplier APIs |
| Demand Forecast Model |
+---------------------------+
🚀 Real-world extensions
You can upgrade this MCP server to:
Smart decision engine
NPV calculation
Capacity constraints
Multi-country sourcing
MOQ constraints
Currency fluctuation
AI-enhanced
Supplier risk scoring (LLM)
Negotiation suggestions
What-if simulation
Cost optimization
No comments:
Post a Comment