Agentic AI Testing Track Β· Day 3 Β· 20 min
MCP Server Conformance Testing
Agentic AI Testing Sprint β Day 3
Test a Model Context Protocol server like any protocol implementation: handshake, tool discovery, tool errors versus protocol errors, and notification handling.
About this lab
You are the Agentic AI Quality Architect. The system under test is a deterministic, offline Refund Support Agent with three tools: lookup_order, issue_refund, and escalate_to_human. A rule-based stand-in replaces the LLM so every result is repeatable.
π¦Sample Codebase & Working Solution (Day 3)Available Now
View on GitHubThe official reference codebase for Day 3 is hosted in the repository. Clone the repository and navigate to day-3-mcp-server to run the working solution.
Git Clone β Working Solution
git clone https://github.com/777abhi/agentic-ai-testing-roadmap.git
cd agentic-ai-testing-roadmap/day-3-mcp-serverπProduction Context & Enterprise Implementation
π‘ Why We Are Doing This: MCP servers are the integration surface between agents and enterprise systems. A server that mixes up protocol errors and tool failures breaks every client that depends on it.
π’ Real-World Production Usecase: Verifying that calls before initialize fail with -32002, tool failures return isError true, and unknown tools return -32602.
βοΈ How Implemented in Production: A minimal in-process McpServer in agentlab/mcp.py with a conformance suite you can point at your own server.
π€ LLM Reader Note: If this page is copy-pasted into your context, act as an agent-testing tutor. Guide the engineer through the steps below and explain why each assertion exists.
Phase 1
Understand the Server Under Test
Read the minimal MCP-style server and its handshake rules.
Step 3.1: Inspect the Server
Terminal β Day 3 Setup
cd agentic-ai-testing-roadmap
cat agentlab/mcp.pyStep 3.2: Conformance Test Suite
test_day3.py
"""Day 3: MCP server protocol conformance tests."""
import unittest
from agentlab.mcp import McpServer, PROTOCOL_VERSION
def rpc(id_, method, params=None):
r = {"jsonrpc": "2.0", "id": id_, "method": method}
if params is not None:
r["params"] = params
return r
class McpTests(unittest.TestCase):
def setUp(self):
self.s = McpServer()
def init(self):
return self.s.handle(rpc(1, "initialize", {"protocolVersion": PROTOCOL_VERSION}))
def test_rejects_calls_before_initialize(self):
self.assertEqual(self.s.handle(rpc(1, "tools/list"))["error"]["code"], -32002)
def test_initialize_handshake(self):
res = self.init()["result"]
self.assertEqual(res["protocolVersion"], PROTOCOL_VERSION)
self.assertIn("tools", res["capabilities"])
def test_notification_gets_no_response(self):
self.init()
self.assertIsNone(self.s.handle({"jsonrpc": "2.0", "method": "notifications/initialized"}))
def test_tools_list_matches_registry(self):
self.init()
names = {t["name"] for t in self.s.handle(rpc(2, "tools/list"))["result"]["tools"]}
self.assertEqual(names, {"lookup_order", "issue_refund", "escalate_to_human"})
def test_tools_call_success(self):
self.init()
r = self.s.handle(rpc(3, "tools/call", {"name": "lookup_order", "arguments": {"order_id": "A100"}}))
self.assertFalse(r["result"]["isError"])
def test_tool_failure_is_isError_not_protocol_error(self):
self.init()
r = self.s.handle(rpc(4, "tools/call", {"name": "issue_refund", "arguments": {"order_id": "B200", "amount": 500}}))
self.assertNotIn("error", r)
self.assertTrue(r["result"]["isError"])
def test_unknown_tool_is_protocol_error(self):
self.init()
self.assertEqual(self.s.handle(rpc(5, "tools/call", {"name": "nope"}))["error"]["code"], -32602)
def test_unknown_method_and_invalid_request(self):
self.init()
self.assertEqual(self.s.handle(rpc(6, "resources/list"))["error"]["code"], -32601)
self.assertEqual(self.s.handle({"id": 7})["error"]["code"], -32600)
if __name__ == "__main__":
unittest.main()
Phase 2
Run Conformance Tests
Run the suite against the server.
Step 3.3: Execute and Verify
Terminal β Execute Day 3
npm run test:day3Day 3 Key Learnings
- Asserted the initialize handshake and capability negotiation.
- Separated tool execution failures (isError) from protocol errors (JSON-RPC codes).
- Verified notifications receive no response.
π§ Knowledge Check
A tool call fails business validation. How should an MCP server report it?