daBongo LMS AI Training Courses

Model Context Protocol – Advanced Patterns for Production

Lesson 5: Production Deployment – Testing, Monitoring, and Maintenance

Lesson Objectives

By the end of this lesson, students should be able to:

  • Design a testing strategy for an MCP server
  • Implement observability for production MCP servers
  • Apply versioning strategies for MCP server updates
  • Build a maintenance workflow for production MCP deployments

Lesson Content

Testing strategy for MCP servers.

Three testing layers for production MCP servers:

Unit tests: Test tool handler logic independently of the MCP protocol layer. Mock the external dependencies (API calls, database queries) and verify handler behavior for valid inputs, invalid inputs, and error cases.

Integration tests: Test the full MCP server using the SDK's test client utilities. Verify tool discovery (list_tools returns expected tools), tool execution (call_tool returns expected results for representative inputs), and error handling (call_tool returns correct errors for invalid inputs).

End-to-end tests: Connect a real Claude Code or test MCP client to the server and verify behavior from the AI perspective – "Can Claude successfully use this tool to accomplish the task it was designed for?"

The end-to-end test is where prompt injection vulnerabilities and tool description quality issues surface.

Observability for MCP servers.

Minimum production observability:

“`python import logging, time

logger = logging.getLogger(__name__)

@app.call_tool() async def call_tool(name: str, arguments: dict): start = time.time() try: result = await _execute_tool(name, arguments) logger.info({ "event": "tool_call", "tool": name, "latency_ms": int((time.time() – start) * 1000), "result": "success" }) return result except Exception as e: logger.error({ "event": "tool_call", "tool": name, "latency_ms": int((time.time() – start) * 1000), "result": "error", "error": str(e) }) return [types.TextContent(type="text", text=f"Tool error: {str(e)}")] “`

Versioning and updates.

MCP servers do not have a built-in versioning mechanism – clients connect and get the current tool list. For breaking changes (removing a tool, changing a tool's parameter schema):

  • Deploy the new version to a staging environment first
  • Test with all client applications that depend on the server
  • Coordinate client updates if tool schemas change (clients may break if they call a tool with an outdated schema)
  • For major changes, consider running old and new versions in parallel during the migration period

Maintenance workflow.

Regular maintenance tasks for production MCP servers:

  • Monitor error rates and latency in observability dashboards
  • Review authentication logs for unusual access patterns
  • Test tool descriptions against current model behavior periodically – model updates can change how Claude interprets descriptions
  • Update external API clients when dependent services update their interfaces
  • Review and update path restrictions and permissions as the server's scope changes

Practical Example

A developer's production MCP server handles 5,000 tool calls per day.

His observability shows: 98% success rate, average latency 180ms, one tool (bulk_export) showing 2× average latency and 5% error rate.

He investigates the bulk_export error logs – the external API it calls has a rate limit that is being hit for large exports.

He implements request chunking in the bulk_export handler and adds retry logic.

Error rate drops to 0.3%, latency drops to 160ms.

Observability identified the issue; the fix was targeted.

Safety Notes

MCP server logs may contain tool arguments and results that include sensitive data – user queries, document contents, query results. Apply the same log data governance to MCP server logs as to any other application log containing user data: appropriate retention policies, access controls, and sensitive field masking where applicable.

Log in and enroll to access lesson quizzes.

Scroll to Top