Server inspector — Debug UI cho MCP

8 — MCPTrung cấp10 phút

Build server → test end-to-end qua chatbot = slow loop: - Edit server - Restart app - Chat với Claude - Observe behavior

Bạn sẽ học được
  • Start MCP Inspector để test server
  • Verify tools, prompts, resources qua UI
  • Development workflow hiệu quả

Start Inspector

Output:

mcp dev mcp_server.py

Start Inspector (tiếp)

Open browser → see dashboard.

MCP Inspector starting on http://localhost:6277
Connected to mcp_server.py

Interface

┌────────────────────────────────────────────────┐
│  MCP Inspector                                 │
│                                                │
│  Server: mcp_server.py  [Connected ✓]          │
│                                                │
│  ┌──────────────────────────────────────────┐  │
│  │  Tabs:                                   │  │
│  │  [Resources] [Prompts] [Tools] [Logs]    │  │
│  └──────────────────────────────────────────┘  │
│                                                │
│  Tools:                                        │
│    - hello                                     │
│    - read_doc_contents                         │
│    - edit_document                             │
│                                                │
│  Click tool → see schema, test with params     │
│                                                │
└────────────────────────────────────────────────┘

Test tool

Rapid iteration.

  • Click Tools tab
  • Click List Tools (refresh)
  • Select tool, e.g., read_doc_contents
  • Enter params: doc_id: "report.pdf"
  • Click Run Tool
  • See result
Result:
[TextContent type="text" text="This report describes Q3 performance..."]

Duration: 25ms

Test prompts

Similar flow trong Prompts tab:

Verify interpolation correct.

  • Select prompt
  • Fill params (e.g., doc_id: "report.pdf")
  • View generated messages

Test resources

Resources tab:

  • Click List Resources
  • See resource URIs
  • Click resource → read content

Logs

Logs tab:

Helpful when tool fails — see exception trace.

  • Shows server log output
  • Debug errors

Dev workflow

Much faster than full chatbot loop.

1. Edit mcp_server.py
2. Save (auto-reload if supported)
3. Refresh Inspector → List Tools
4. Test tool qua Inspector
5. Check log for errors
6. Iterate

Testing complex scenarios

Sequence

Test tool chaining:

Inspector show both results → confirm end-to-end.

Edge cases

Inspector catch these without chatbot complexity.

  • edit_document(doc_id="report.pdf", old_str="Q3", new_str="Q4")
  • read_doc_contents(doc_id="report.pdf") — verify change applied
  • Empty string input
  • Very long input
  • Invalid doc_id → verify error handling

When NOT to use Inspector

Real agent behavior

Inspector is manual. To test "Claude uses tools correctly" — need chatbot.

Inspector = unit test. Chatbot = integration test.

Multi-tool chains

Claude decides dispatch. Inspector sequential manual. Chatbot shows emergent behavior.

Inspector caveat: UI changes

MCP Inspector under active dev. UI may differ screenshots. Core functionality (list/call) stable.

Anti-patterns

❌ Only test via chatbot

Slow feedback loop.

Fix: Inspector first cho unit tests.

❌ Inspector only

Miss emergent agent behavior (Claude choice of tools).

Fix: Both. Inspector + real chatbot.

❌ Not checking logs

Tool fail silently, Inspector show "undefined behavior".

Fix: Check Logs tab when issue arise.

Áp dụng ngay

Bài tập: Test toàn bộ server (15 phút)

Start Inspector. For each tool bạn đã define:

Goal: confident server robust trước khi integrate.

  • List tools — verify name, description
  • Run tool với normal params
  • Run tool với edge case (empty, invalid)
  • Check Logs for any error

Tóm tắt

🎯 Inspector = browser UI test MCP server standalone.

🎯 mcp dev server.py to start.

🎯 Tabs: Tools, Prompts, Resources, Logs.

🎯 Fast dev loop: edit → reload → test in seconds.

🎯 Complement chatbot testing, không thay thế.

Nội dung này có hữu ích không?