সাকিব ভাই (১১:০০)
রুমি (১১:০২)
সাকিব ভাই (১১:০৩)
রুমি (১১:০৩)
এই পাঠ ঐচ্ছিক, হাতে-কলমের। কোড পড়তে পারলেই চলবে। আগে টুল ও MCP আর MCP সার্ভারের ধরন পাঠ দুটি দেখে নিন। আমরা বানাব টেস্ট-ম্যানেজমেন্ট ধরনের একটি ছোট সার্ভার: একটি টুল, যা টিকিটবাসের কাল্পনিক টেস্ট কেস খুঁজে দেয়। কোডটি লেখার সময় (নভেম্বর ২০২৬) আসলেই চালিয়ে দেখা হয়েছে। SDK বদলায়। এখানকার কোড আপনার সংস্করণে না মিললে অফিসিয়াল SDK ডকুমেন্টেশন অনুসরণ করুন। পাইথনের জন্যও অফিসিয়াল SDK আছে, এখানে তা দেখানো হয়নি।
কে কার সঙ্গে কথা বলে(Who Talks to Whom)
পাঁচ ধাপ(Five Steps)
বানান (Build)
প্রজেক্ট ফোল্ডার, তিনটি ফাইল, একটি কমান্ডে কম্পাইল।চালান (Run)
সার্ভার stdio-তে অপেক্ষা করে। তাকে সরাসরি চালানোর দরকার নেই, Inspector নিজেই চালিয়ে নেয়।পরীক্ষা করুন (Inspect)
Inspector দিয়ে টুল-তালিকা দেখুন, একটি ঠিক ও একটি ভুল ইনপুটে ডাকুন।জুড়ুন (Connect)
ক্লায়েন্টের কনফিগে সার্ভারটির নাম ও পথ বসান।নিরাপদ করুন (Secure)
অনুমতি ছোট রাখুন, ইনপুট যাচাই করুন, গোপন তথ্য রাখবেন না।
ধাপ ১: বানান(Step 1: Build)
ফোল্ডারে তিনটি ফাইল: package.json, tsconfig.json, src/server.ts। মনে রাখুন, build/server.js ফাইলটি কম্পাইলের পরে তৈরি হবে। সার্ভারটির জন্য Node 20 বা নতুন লাগে।
{
"name": "bus-ticket-testcases",
"version": "1.0.0",
"private": true,
"type": "module",
"scripts": {
"build": "tsc"
},
"dependencies": {
"@modelcontextprotocol/server": "2.4.0",
"zod": "4.6.7"
},
"devDependencies": {
"@types/node": "22.20.5",
"typescript": "7.0.2"
}
}
{
"compilerOptions": {
"target": "ES2022",
"module": "Node16",
"moduleResolution": "Node16",
"types": ["node"],
"outDir": "./build",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}
এবার সার্ভারের কোড। প্রতিটি অংশ ইচ্ছা করেই ছোট: একটি টুল, একটি ইনপুট feature, যার মান শুধু চারটির একটি।
// Tested with @modelcontextprotocol/server 2.4.0 and zod 4.6.7, November 2026.
import { McpServer } from "@modelcontextprotocol/server";
import { serveStdio } from "@modelcontextprotocol/server/stdio";
import { z } from "zod";
// Fictional data, kept in the same file. No file, no network, no secrets.
const FEATURES = ["login", "search", "seat", "payment"] as const;
type TestCase = {
id: string;
feature: (typeof FEATURES)[number];
title: string;
steps: string[];
expected: string;
};
const TEST_CASES: TestCase[] = [
{
id: "TC-LOGIN-01",
feature: "login",
title: "Login with a valid phone number and PIN",
steps: ["Open the app", "Enter a valid phone number and PIN", "Tap Login"],
expected: "The home screen opens",
},
{
id: "TC-LOGIN-02",
feature: "login",
title: "Login with a wrong PIN",
steps: ["Open the app", "Enter a valid phone number and a wrong PIN", "Tap Login"],
expected: "An error message shows and the user stays on the login screen",
},
{
id: "TC-SEARCH-01",
feature: "search",
title: "Search a bus from Dhaka to Chattogram",
steps: ["Choose From: Dhaka", "Choose To: Chattogram", "Pick tomorrow's date", "Tap Search"],
expected: "A list of buses for that route and date shows",
},
{
id: "TC-SEARCH-02",
feature: "search",
title: "Search with the same From and To city",
steps: ["Choose From: Dhaka", "Choose To: Dhaka", "Tap Search"],
expected: "The app says the two cities must be different",
},
{
id: "TC-SEAT-01",
feature: "seat",
title: "Select one free seat",
steps: ["Open a bus from the result list", "Tap a free seat"],
expected: "The seat is marked as selected and the fare total updates",
},
{
id: "TC-SEAT-02",
feature: "seat",
title: "Try to select a seat that is already sold",
steps: ["Open a bus from the result list", "Tap a sold seat"],
expected: "The seat cannot be selected",
},
{
id: "TC-PAY-01",
feature: "payment",
title: "Pay with the test wallet",
steps: ["Select a seat", "Go to Payment", "Choose the test wallet", "Confirm"],
expected: "The ticket shows with status Paid",
},
{
id: "TC-PAY-02",
feature: "payment",
title: "Payment is cancelled by the user",
steps: ["Select a seat", "Go to Payment", "Choose the test wallet", "Tap Cancel"],
expected: "No ticket is issued and the seat is released",
},
];
function formatCase(tc: TestCase): string {
return [
`${tc.id}: ${tc.title}`,
...tc.steps.map((step, i) => ` ${i + 1}. ${step}`),
` Expected: ${tc.expected}`,
].join("\n");
}
// serveStdio calls this whenever it needs an instance, so each call returns a new server.
function createServer() {
const server = new McpServer({
name: "bus-ticket-testcases",
version: "1.0.0",
});
server.registerTool(
"find_test_cases",
{
description:
"Find fictional test cases for one feature of a bus ticket app. Read only.",
inputSchema: z.object({
feature: z
.enum(FEATURES)
.describe("The feature: login, search, seat or payment"),
}),
// Hints only. They are not protection.
annotations: { readOnlyHint: true, openWorldHint: false },
},
async ({ feature }) => {
const found = TEST_CASES.filter((tc) => tc.feature === feature);
if (found.length === 0) {
return {
content: [{ type: "text", text: `No test cases for ${feature}` }],
isError: true,
};
}
return {
content: [
{
type: "text",
text: `Test cases for ${feature}:\n\n${found.map(formatCase).join("\n\n")}`,
},
],
};
},
);
return server;
}
serveStdio(createServer, {
onerror: (error) => console.error("bus-ticket-testcases error:", error),
});
console.error("bus-ticket-testcases running on stdio");
কোডের কয়েকটি জায়গা লক্ষ করুন। z.enum(FEATURES) অন্য যেকোনো মান ফিরিয়ে দেয়। annotations শুধু ইঙ্গিত, সুরক্ষা নয়। আর লগ ছাপা হচ্ছে console.error দিয়ে, console.log দিয়ে নয়, কারণ stdout-এ বাড়তি লেখা পাঠালে stdio-র বার্তা নষ্ট হয়ে যায়।
npm install
npm run build
ধাপ ২ ও ৩: চালান ও পরীক্ষা করুন(Steps 2 and 3: Run and Inspect)
MCP Inspector একটি অফিসিয়াল পরীক্ষার টুল। আমরা তার কমান্ড-লাইন রূপ (--cli) ব্যবহার করছি, কারণ তার আউটপুট লেখা হিসেবে এখানে রাখা যায়। এতে ওয়েব ইউআইও আছে, কিন্তু সেটা এই পাঠে পরীক্ষা করা হয়নি।
দুটি সতর্কতা। প্রথমত, Inspector-এর নতুন সংস্করণের জন্য নতুন Node লাগে (লেখার সময় 22.23.4 বা নতুন, বা 24.22.1 বা নতুন, বা 26.12.1 বা নতুন)। পুরনো Node-এ সংস্করণ না আটকালে npx চুপচাপ পুরনো 1.x Inspector নামিয়ে আনতে পারে, আর আমরা সেটাই দেখেছি, তাই @2.16.0 লেখা আছে। node --version দেখে নিন, আর দরকারে আপনার ভার্সন-ম্যানেজারে একটি নতুন Node ব্যবহার করুন। সিস্টেমের কিছু বদলানোর কোনো দরকার নেই। দ্বিতীয়ত, কমান্ড স্ক্রিপ্টের ভেতরে চালালে শেষে </dev/null যোগ করুন, নইলে Inspector স্ক্রিপ্টের stdin পড়ে ফেলে। Inspector-এর বিস্তারিত দেখুন তার অফিসিয়াল ডকুমেন্টেশনে।
প্রথম কমান্ড, টুলের তালিকা:
npx @modelcontextprotocol/inspector@2.16.0 --cli node build/server.js --protocol-era modern --method tools/list
আউটপুট:
bus-ticket-testcases running on stdio
{
"tools": [
{
"name": "find_test_cases",
"description": "Find fictional test cases for one feature of a bus ticket app. Read only.",
"inputSchema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"feature": {
"type": "string",
"enum": [
"login",
"search",
"seat",
"payment"
],
"description": "The feature: login, search, seat or payment"
}
},
"required": [
"feature"
]
},
"annotations": {
"readOnlyHint": true,
"openWorldHint": false
}
}
]
}
দ্বিতীয় কমান্ড একই তালিকা পুরনো প্রটোকল-যুগে চায়। কমান্ডটি --protocol-era modern-এর জায়গায় legacy দিয়ে চলে।
npx @modelcontextprotocol/inspector@2.16.0 --cli node build/server.js --protocol-era legacy --method tools/list
আমাদের চালানোয় তালিকার বিষয়বস্তু একই এসেছিল, শুধু $schema ফিল্ডটি inputSchema-র শেষে ছিল, শুরুতে নয়। এবার একটি ঠিক ডাক:
npx @modelcontextprotocol/inspector@2.16.0 --cli node build/server.js --protocol-era modern --method tools/call --tool-name find_test_cases --tool-arg feature=seat
bus-ticket-testcases running on stdio
{
"_meta": {
"io.modelcontextprotocol/serverInfo": {
"name": "bus-ticket-testcases",
"version": "1.0.0"
}
},
"content": [
{
"type": "text",
"text": "Test cases for seat:\n\nTC-SEAT-01: Select one free seat\n 1. Open a bus from the result list\n 2. Tap a free seat\n Expected: The seat is marked as selected and the fare total updates\n\nTC-SEAT-02: Try to select a seat that is already sold\n 1. Open a bus from the result list\n 2. Tap a sold seat\n Expected: The seat cannot be selected"
}
]
}
আর একটি ভুল ইনপুট, যা এই পাঠের আসল কথা। refund চারটি মানের কোনোটি নয়:
npx @modelcontextprotocol/inspector@2.16.0 --cli node build/server.js --protocol-era modern --method tools/call --tool-name find_test_cases --tool-arg feature=refund
bus-ticket-testcases running on stdio
{
"_meta": {
"io.modelcontextprotocol/serverInfo": {
"name": "bus-ticket-testcases",
"version": "1.0.0"
}
},
"content": [
{
"type": "text",
"text": "Input validation error: Invalid arguments for tool find_test_cases: feature: Invalid option: expected one of \"login\"|\"search\"|\"seat\"|\"payment\""
}
],
"isError": true
}
{"error":{"code":"tool_is_error","message":"Tool 'find_test_cases' returned isError:true."}}
লক্ষ করুন, আমাদের হ্যান্ডলারের কোড চলার আগেই স্কিমা অনুরোধটি ফিরিয়ে দিয়েছে। Inspector এই চালানোয় exit কোড 5 দিয়েছিল (tool_is_error), তাই স্ক্রিপ্টে ব্যবহার করলে এটি ব্যর্থতা বলে ধরা পড়বে।
ধাপ ৪: জুড়ুন(Step 4: Connect)
প্রতিটি ক্লায়েন্টে একটি কনফিগ-ফাইল থাকে, যাতে সার্ভারের নাম ও চালানোর কমান্ড লেখা হয়। ফাইলটি কোথায় থাকে তা ক্লায়েন্টভেদে আলাদা, তাই আপনার ক্লায়েন্টের ডকুমেন্টেশন দেখুন। সাধারণ আকার এমন, পথটি আপনার ফোল্ডারের পূর্ণ পথ বসিয়ে:
{
"mcpServers": {
"bus-ticket-testcases": {
"command": "node",
"args": ["/ABSOLUTE/PATH/TO/build/server.js"]
}
}
}
ধাপ ৫: নিরাপদ করুন(Step 5: Secure)
ছোট সার্ভারেও এই নিয়মগুলো
০/৯
এই পাঠে যা পরীক্ষা হয়নি(What Was Not Tested)
আমরা সার্ভার বানিয়েছি, তালিকা দেখেছি, একটি ঠিক ও একটি ভুল ডাক দিয়েছি। কিন্তু একটি আসল ক্লায়েন্ট কনফিগ ফাইল থেকে সার্ভারটি তুলে নিচ্ছে কি না, তা পরীক্ষা করা হয়নি। Inspector-এর ওয়েব ইউআই আর --tui রূপও দেখা হয়নি। স্কিমার বাইরে কোনো নিরাপত্তা-পরীক্ষাও হয়নি। তাই জুড়ে দেওয়ার ধাপ আপনার নিজের পরীক্ষা, আর এই পাঠকে প্রমাণ নয়, শুরুর জায়গা ভাবুন।
নিজেকে যাচাই করুন
Inspector-এ feature=refund দিয়ে ডাকলে কী হলো, আর এর মানে কী?