पाठ 13 / 31

MCP Servers की Testing और Inspection

Inspector, scripted clients और unit tests से व्यवहार जाँचें।

Contract परखें, मॉडल नहीं

MCP server प्रकाशित contract वाला निश्चित कोड है, इसलिए उसे किसी मॉडल के बिना परखें। (1) अंतर्निहित functions की unit test। (2) scripted client से protocol test, जैसे इस कोर्स में दिखाया कच्चा JSON-RPC session, tools की सूची, उनके schemas, परिणामों और error codes पर assert करके। (3) आधिकारिक MCP Inspector उपयोग करें, जो server से जुड़कर उसके tools, resources और prompts हाथ से बुलाने का interactive औज़ार है। (4) tools/list के snapshot tests जोड़ें ताकि नाम या schemas का कोई भी बदलाव समीक्षा में दिखे, क्योंकि वही आपकी सार्वजनिक API है। (5) अंत में कुछ end-to-end मूल्यांकन असली मॉडल से चलाएँ यह जाँचने को कि वह आपके विवरणों से सही tool चुनता है।

Protocol test (उदाहरण)

ऊपर के कच्चे session के call function जैसा सहायक उपयोग करता है। यहाँ test के रूप में चलाया नहीं गया।

def test_tools_contract():
    tools = call(2, "tools/list")["result"]["tools"]
    assert [t["name"] for t in tools] == ["get_order_status"]
    assert tools[0]["inputSchema"]["required"] == ["order_id"]

def test_invalid_order_id_is_a_clear_error():
    r = call(3, "tools/call", {"name": "get_order_status", "arguments": {"order_id": "12"}})
    assert "6 digits" in r["result"]["content"][0]["text"]

def test_unknown_method_is_a_protocol_error():
    assert call(4, "no/such/method")["error"]["code"] == -32601

त्वरित जाँच: Tests में tools/list का snapshot क्यों?

  • Server memory घटाने के लिए
  • नाम और schemas आपकी सार्वजनिक API हैं; बदलाव दिखने चाहिए
  • Authentication से बचने के लिए
  • मॉडल प्रशिक्षित करने के लिए
Answer

नाम और schemas आपकी सार्वजनिक API हैं; बदलाव दिखने चाहिए — आकस्मिक contract बदलाव clients और prompts को चुपचाप तोड़ सकते हैं।