nnennandukwe/python-mcp-agent-workshop
If you are the rightful owner of python-mcp-agent-workshop and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
The Model Context Protocol (MCP) server is a framework for building AI agents in Python, enabling seamless integration and communication between AI tools and agents.
Python MCP Agent Workshop
A comprehensive workshop for building AI agents using the Model Context Protocol (MCP) in Python. This project demonstrates how to create MCP servers, implement custom tools, and configure intelligent agents for code analysis.
Link to Presentation Slides
π Quick Start
# Install the repository
git clone <repository-url>
cd agent-mcp-workshop-python
# Install dependencies
poetry install
# Verify setup
python3.12 verification.py
# Start the MCP server
poetry run workshop-mcp-server
# Run tests
poetry run pytest
# Use the agent (requires Qodo)
qodo keyword_analysis --set keyword="{KEYWORD_HERE}"
π Prerequisites
Before starting the workshop, ensure you have the following installed:
Required Software
-
Python 3.11+
- Download from python.org
- Verify:
python --version
-
Poetry (Python dependency management)
- Install:
curl -sSL https://install.python-poetry.org | python3 -
- Or via pip:
pip install poetry
- Verify:
poetry --version
- Install:
-
Qodo Command (for agent execution)
- Install by running command
npm install -g @qodo/command
- Log in with the command
qodo login
- Verify:
qodo --version
- Additional resources: docs.qodo.ai/qodo-documentation/qodo-command
- Install by running command
Optional Tools
- Git for version control
- VS Code or your preferred IDE
- Docker (for containerized deployment)
ποΈ Architecture Overview
This workshop demonstrates a complete MCP ecosystem:
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β AI Agent βββββΆβ MCP Server βββββΆβ Keyword Tool β
β(keyword_analysisβ β (server.py) β β(keyword_search) β
β .toml) β β β β β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β
β β βΌ
β β βββββββββββββββββββ
β β β File System β
β β β (Search) β
β β βββββββββββββββββββ
β β
βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ
β Analysis β β JSON-RPC β
β Results β β Protocol β
βββββββββββββββββββ βββββββββββββββββββ
Components
-
MCP Server (
src/workshop_mcp/server.py
)- Implements MCP protocol
- Exposes keyword search tool
- Handles JSON-RPC communication
-
Keyword Search Tool (
src/workshop_mcp/keyword_search.py
)- Asynchronous file system search
- Multi-format text file support
- Statistical analysis and reporting
-
AI Agent (
agents/keyword_analysis.toml
)- Intelligent keyword analysis
- Pattern recognition
- Refactoring recommendations
π οΈ Usage Examples
Basic Keyword Search
from workshop_mcp.keyword_search import KeywordSearchTool
tool = KeywordSearchTool()
result = await tool.execute("async", ["/path/to/codebase"])
print(f"Found {result['summary']['total_occurrences']} occurrences")
print(f"Most frequent file: {result['summary']['most_frequent_file']}")
Running the MCP Server
# Start server (listens on stdin/stdout)
poetry run workshop-mcp-server
# Or use the script entry point
poetry run python -m workshop_mcp.server
Agent Analysis
# Run keyword analysis agent
qodo keyword_analysis --set keyword="{KEYWORD_HERE}"
Testing
# Run all tests
poetry run pytest
# Run with coverage
poetry run pytest --cov=workshop_mcp
# Run specific test file
poetry run pytest tests/test_keyword_search.py -v
# Run with detailed output
poetry run pytest -v --tb=long
π§ Development Setup
Environment Setup
-
Clone and Install
git clone <repository-url> cd agent-mcp-workshop-python poetry install
-
Verify Installation
python verification.py
-
Development Dependencies
poetry install --with dev
Code Quality Tools
# Format code
poetry run black src/ tests/
# Sort imports
poetry run isort src/ tests/
# Type checking
poetry run mypy src/
# Linting
poetry run flake8 src/ tests/
Running in Development Mode
# Install in editable mode
poetry install
# Run server with debug logging
PYTHONPATH=src poetry run python -m workshop_mcp.server
# Run tests with verbose output
poetry run pytest -v -s
π Project Structure
agent-mcp-workshop-python/
βββ pyproject.toml # Poetry configuration
βββ README.md # This file
βββ verification.py # Setup verification script
βββ .gitignore # Git ignore rules
β
βββ src/workshop_mcp/ # Main package
β βββ __init__.py # Package initialization
β βββ server.py # MCP server implementation
β βββ keyword_search.py # Keyword search tool
β
βββ agents/ # Agent configurations
β βββ keyword_analysis.toml # Keyword analysis agent
β
βββ tests/ # Test suite
βββ __init__.py # Test package init
βββ test_keyword_search.py # Comprehensive tests
π§ͺ Testing Strategy
The project includes comprehensive tests covering:
Unit Tests
- Basic functionality: Keyword search across files
- Edge cases: Empty files, binary files, permission errors
- Concurrency: Async operations and performance
- Error handling: Invalid inputs and system errors
Integration Tests
- MCP protocol: Server startup and tool execution
- File system: Real directory traversal
- Agent configuration: TOML parsing and validation
Performance Tests
- Large codebases: Scalability testing
- Concurrent searches: Multi-directory operations
- Memory usage: Resource consumption monitoring
π¨ Troubleshooting
Common Issues
-
Python Version Error
Error: Python 3.11+ required Solution: Upgrade Python or use pyenv
-
Poetry Not Found
Error: poetry: command not found Solution: Install Poetry from python-poetry.org
-
MCP Import Error
Error: No module named 'mcp' Solution: Run 'poetry install' to install dependencies
-
Permission Denied
Error: Permission denied accessing files Solution: Check file permissions and user access
-
Agent Configuration Error
Error: Invalid TOML configuration Solution: Validate TOML syntax in agents/keyword_analysis.toml
Debug Mode
Enable detailed logging:
export LOG_LEVEL=DEBUG
poetry run workshop-mcp-server
Verification Script
Run the comprehensive verification:
python3.12 verification.py
This checks:
- Python version compatibility
- Poetry installation and configuration
- Project structure completeness
- Dependency installation success
- MCP server functionality
- Unit test execution
- Agent configuration validity
π Learning Resources
MCP Protocol
Python Async Programming
Agent Development
π€ Contributing
- Fork the repository
- Create feature branch:
git checkout -b feature/amazing-feature
- Make changes and test:
poetry run pytest
- Commit changes:
git commit -m 'Add amazing feature'
- Push to branch:
git push origin feature/amazing-feature
- Open Pull Request
Development Guidelines
- Follow PEP 8 style guidelines
- Add type hints to all functions
- Write comprehensive docstrings
- Include unit tests for new features
- Update documentation as needed
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π Acknowledgments
- Model Context Protocol team for the excellent protocol specification
- Poetry team for dependency management
- Qodo team for agent development platform
- Python community for async/await support
π Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: nnenna.n@qodo.ai
- Discord:
Happy coding! π
This workshop provides a solid foundation for building production-ready MCP agents in Python. Extend and customize it for your specific use cases.