Skip to content

Latest commit

 

History

History
408 lines (322 loc) · 14 KB

File metadata and controls

408 lines (322 loc) · 14 KB

MCP Setup Tutorial - Project Creation Documentation

Overview

This document details every step taken to create the MCP Debug Test project, including the rationale behind each decision and the results achieved. This serves as both a learning record and a guide for others to understand the MCP development process.

Project Creation Timeline

Step 1: Initial Project Setup and Environment Configuration

Objective: Create a clean workspace for MCP development and testing

Actions Taken:

  1. Created project directory structure:
    MCPDebugTest/
    ├── simple_mcp_server/     # Core server implementation
    ├── tests/                 # Test scripts and validation
    ├── .vscode/              # VS Code debugging configuration
    ├── config/               # Configuration files
    ├── docs/                 # Documentation
    └── logs/                 # Runtime logs (auto-created)
    

Rationale:

  • Organized structure separates concerns cleanly
  • simple_mcp_server/ contains the core learning implementation
  • tests/ allows for isolated testing without Claude Code dependency
  • .vscode/ provides debugging capabilities essential for learning
  • config/ holds Claude Code integration files
  • docs/ contains all learning materials and guides

Results: Clean project structure that supports both development and learning objectives.

Step 2: Python Environment Setup

Objective: Configure Python environment with MCP dependencies

Actions Taken:

  1. Created virtual environment setup
  2. Installed MCP Python SDK
  3. Created requirements.txt with minimal dependencies
  4. Set up Python environment configuration tools

Code Created:

  • requirements.txt: MCP package dependency
  • setup.bat: Windows setup script for environment
  • install_mcp.py: Helper script for MCP installation with error handling

Rationale:

  • Virtual environment ensures clean dependency management
  • MCP SDK is the only required dependency for basic functionality
  • Setup scripts make the tutorial reproducible for others
  • Installation helper provides debugging for common installation issues

Results:

  • Successfully installed MCP SDK
  • Created reproducible environment setup
  • Validated installation with test imports

Step 3: Core MCP Server Implementation

Objective: Create a minimal but complete MCP server to understand the protocol

Actions Taken:

  1. Implemented main server class (server.py)
  2. Created tool definitions (tools.py)
  3. Implemented tool handlers (handlers.py)
  4. Added comprehensive debugging utilities (debug_utils.py)

File: simple_mcp_server/server.py

Purpose: Main MCP server implementation with protocol handling

Key Components:

  • SimpleMCPServer class: Main server container
  • Protocol handlers for list_tools(), call_tool(), list_prompts(), get_prompt()
  • Comprehensive logging for every MCP interaction
  • Error handling and response formatting

Learning Points Demonstrated:

  • How MCP protocol handlers are structured
  • Request/response flow through the server
  • Error handling patterns
  • Logging for debugging MCP communication

Code Structure:

class SimpleMCPServer:
    def __init__(self):
        self.server = Server("simple-mcp-debug")
        self._setup_handlers()
    
    def _setup_handlers(self):
        @self.server.list_tools()
        async def handle_list_tools() -> List[types.Tool]:
            # Tool discovery implementation
            
        @self.server.call_tool()
        async def handle_call_tool(name: str, arguments: dict) -> List[types.TextContent]:
            # Tool execution implementation

Rationale:

  • Demonstrates core MCP server patterns
  • Shows how to implement required protocol methods
  • Provides debugging hooks at every step
  • Uses proper MCP types and response formats

File: simple_mcp_server/tools.py

Purpose: Tool definitions and schema management

Key Components:

  • get_all_tools(): Returns list of available tools
  • Tool schema definitions with proper validation
  • Helper functions for tool introspection

Tools Implemented:

  1. hello_world: Basic functionality test
  2. echo: Input/output validation
  3. get_time: System interaction
  4. math_add: Parameter validation
  5. debug_info: Server introspection

Learning Points Demonstrated:

  • How MCP tools are defined using types.Tool
  • JSON Schema format for parameter validation
  • Required vs optional parameters
  • Tool discovery mechanism

Rationale:

  • Each tool demonstrates a different aspect of MCP development
  • Progressive complexity from simple to advanced
  • Real-world parameter validation examples
  • Server introspection capabilities for debugging

File: simple_mcp_server/handlers.py

Purpose: Tool execution logic and request processing

Key Components:

  • Individual handler functions for each tool
  • Input validation and error handling
  • Response formatting
  • Logging for debugging

Learning Points Demonstrated:

  • How to implement tool logic
  • Parameter validation patterns
  • Error handling and reporting
  • Response formatting for MCP protocol

Rationale:

  • Shows separation of tool definition from implementation
  • Demonstrates proper error handling patterns
  • Provides examples of different response types
  • Includes debugging and logging best practices

File: simple_mcp_server/debug_utils.py

Purpose: Comprehensive debugging and logging infrastructure

Key Components:

  • Structured logging setup
  • MCP protocol message tracing
  • Performance monitoring
  • Error diagnosis utilities

Learning Points Demonstrated:

  • How to set up effective logging for MCP servers
  • Protocol message inspection techniques
  • Performance monitoring approaches
  • Error diagnosis and reporting

Rationale:

  • Debugging is crucial for MCP development
  • Protocol-level visibility is essential for understanding
  • Performance monitoring helps identify bottlenecks
  • Error diagnosis speeds up development

Results:

  • Complete working MCP server with 5 functional tools
  • Comprehensive logging of all MCP interactions
  • Error handling for common failure scenarios
  • Server introspection capabilities

Step 4: VS Code Debugging Configuration

Objective: Enable step-through debugging of MCP servers

Actions Taken:

  1. Created .vscode/launch.json with multiple debug configurations
  2. Set up proper environment variables and paths
  3. Configured debugging for both server and tests

Configurations Created:

  • Debug MCP Server: Standard debugging mode
  • Debug MCP Server (Verbose): Enhanced logging enabled
  • Test MCP Server Locally: Debug the test suite

Key Settings:

{
    "type": "debugpy",
    "request": "launch",
    "program": "${workspaceFolder}/simple_mcp_server/server.py",
    "console": "integratedTerminal",
    "justMyCode": false,
    "subProcess": true
}

Learning Points Demonstrated:

  • How to configure VS Code for MCP server debugging
  • Environment variable configuration
  • Debugging both server and client code
  • Breakpoint strategies for MCP development

Rationale:

  • Visual debugging is essential for understanding MCP protocol
  • Breakpoints allow inspection of request/response objects
  • Multiple configurations support different debugging scenarios
  • Proper environment setup ensures reproducible debugging

Results:

  • Full VS Code debugging capability
  • Ability to set breakpoints and inspect variables
  • Step-through debugging of MCP protocol interactions
  • Support for debugging both server and test code

Step 5: Test Suite Development

Objective: Create comprehensive testing without Claude Code dependency

Actions Taken:

  1. Implemented tests/test_server.py with full test coverage
  2. Created mock server for testing
  3. Implemented automated validation of all server functions

Test Categories:

  1. Tool Discovery: Validates tool registration and schema
  2. Tool Validation: Tests parameter validation logic
  3. Tool Handlers: Tests actual tool execution
  4. Error Handling: Validates error scenarios and responses

Key Test Functions:

  • test_tool_discovery(): Tool registration validation
  • test_tool_validation(): Parameter validation testing
  • test_tool_handlers(): Handler execution testing
  • test_error_handling(): Error scenario validation

Learning Points Demonstrated:

  • How to test MCP servers independently
  • Mock server creation for testing
  • Automated validation of MCP protocol compliance
  • Error scenario testing strategies

Rationale:

  • Independent testing validates server functionality
  • Automated tests catch regressions during development
  • Mock server allows testing without full MCP setup
  • Error testing ensures robust server behavior

Results:

  • 3/4 tests passing (1 Unicode encoding issue on Windows)
  • Comprehensive validation of server functionality
  • Automated testing pipeline for development
  • Clear error reporting and debugging output

Step 6: Claude Code Integration Configuration

Objective: Provide configuration for integrating with Claude Code

Actions Taken:

  1. Created example Claude Desktop configuration
  2. Documented integration process
  3. Provided troubleshooting guidance

Configuration Created:

{
  "mcpServers": {
    "simple-mcp-debug": {
      "command": "python",
      "args": [
        "c:\\code\\TodoAI\\MCPDebugTest\\simple_mcp_server\\server.py"
      ],
      "cwd": "c:\\code\\TodoAI\\MCPDebugTest"
    }
  }
}

Learning Points Demonstrated:

  • How to configure MCP servers in Claude Desktop
  • Command line arguments and working directory setup
  • Integration troubleshooting approaches
  • Server registration process

Rationale:

  • Integration with Claude Code is the end goal
  • Proper configuration is critical for successful integration
  • Troubleshooting guidance helps with common issues
  • Example configuration reduces setup friction

Results:

  • Complete Claude Code integration configuration
  • Documentation of integration process
  • Troubleshooting guidance for common issues
  • Ready-to-use configuration examples

Step 7: Documentation and Learning Materials

Objective: Create comprehensive learning materials for MCP development

Actions Taken:

  1. Created CLAUDE.md with project overview and learning objectives
  2. Developed README.md with quick start guide
  3. Created docs/debugging_guide.md with detailed debugging information
  4. Documented all creation steps and rationale

Documentation Created:

  • CLAUDE.md: Project overview and learning objectives
  • README.md: Quick start guide and project structure
  • docs/debugging_guide.md: Comprehensive debugging guide
  • docs/project_creation.md: This document

Learning Points Demonstrated:

  • Project organization and structure
  • Step-by-step learning progression
  • Debugging techniques and best practices
  • Integration and troubleshooting guidance

Rationale:

  • Documentation is essential for learning and sharing
  • Step-by-step guides reduce learning curve
  • Debugging documentation enables problem-solving
  • Comprehensive materials support tutorial creation

Results:

  • Complete learning documentation
  • Step-by-step guides for all aspects
  • Debugging and troubleshooting materials
  • Foundation for tutorial project creation

Key Insights and Lessons Learned

MCP Protocol Understanding

  1. Tool Discovery: MCP clients call list_tools() to discover available tools
  2. Tool Execution: Tools are executed via call_tool(name, arguments)
  3. Response Format: All responses must be properly formatted MCP types
  4. Error Handling: Errors should be caught and formatted as MCP responses

Development Best Practices

  1. Logging: Comprehensive logging is essential for debugging
  2. Testing: Independent testing validates functionality without full setup
  3. Structure: Clean separation of concerns improves maintainability
  4. Documentation: Step-by-step documentation enables learning and sharing

Debugging Strategies

  1. Breakpoints: VS Code debugging with breakpoints is invaluable
  2. Protocol Tracing: Logging MCP messages reveals communication issues
  3. Independent Testing: Testing without Claude Code isolates server issues
  4. Error Handling: Proper error handling and reporting speeds debugging

Integration Challenges

  1. Configuration: Claude Code configuration must be precise
  2. Path Issues: Absolute paths and working directories are critical
  3. Environment: Python environment and dependencies must be correct
  4. Unicode: Windows console encoding can cause display issues

Success Metrics

Functionality Achievement

  • ✅ Complete MCP server implementation
  • ✅ 5 functional tools with different complexity levels
  • ✅ VS Code debugging configuration working
  • ✅ Comprehensive test suite (3/4 tests passing)
  • ✅ Complete documentation and learning materials

Learning Objectives Met

  • ✅ Understanding MCP protocol and architecture
  • ✅ Server development best practices
  • ✅ Debugging techniques and tools
  • ✅ Integration and troubleshooting knowledge
  • ✅ Foundation for fixing TodoAI-Todoist issues

Tutorial Preparation

  • ✅ Step-by-step documentation of all processes
  • ✅ Rationale and learning points for each step
  • ✅ Code examples and configurations
  • ✅ Troubleshooting guidance and solutions
  • ✅ Ready for tutorial project creation

Next Steps for Tutorial Creation

  1. Chapter Organization: Create individual markdown files for each learning objective
  2. Code Examples: Provide working code examples for each concept
  3. Interactive Scripts: Create demonstration scripts for each tutorial section
  4. Testing Framework: Provide validation scripts for each tutorial step
  5. GitHub Repository: Organize materials for public tutorial repository

This comprehensive documentation provides the foundation for creating the MCP Setup Tutorial project that will help others learn MCP development from the ground up.


This document serves as both a record of the project creation process and a guide for understanding the decisions and implementations made during development.