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:

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

Enroll to continue this lesson.

The preview above shows the lesson objectives and opening lesson content. Enroll to view the full lesson, complete the practice work, and take the lesson quiz.

Log In / Create Account
Back to Course