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.
# 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}"Before starting the workshop, ensure you have the following installed:
-
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
- Git for version control
- VS Code or your preferred IDE
- Docker (for containerized deployment)
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 β
βββββββββββββββββββ βββββββββββββββββββ
-
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
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']}")# Start server (listens on stdin/stdout)
poetry run workshop-mcp-server
# Or use the script entry point
poetry run python -m workshop_mcp.server# Run keyword analysis agent
qodo keyword_analysis --set keyword="{KEYWORD_HERE}"# 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-
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
# 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/# 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 -sagent-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
The project includes comprehensive tests covering:
- 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
- MCP protocol: Server startup and tool execution
- File system: Real directory traversal
- Agent configuration: TOML parsing and validation
- Large codebases: Scalability testing
- Concurrent searches: Multi-directory operations
- Memory usage: Resource consumption monitoring
-
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
Enable detailed logging:
export LOG_LEVEL=DEBUG
poetry run workshop-mcp-serverRun the comprehensive verification:
python3.12 verification.pyThis checks:
- Python version compatibility
- Poetry installation and configuration
- Project structure completeness
- Dependency installation success
- MCP server functionality
- Unit test execution
- Agent configuration validity
- 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
- Follow PEP 8 style guidelines
- Add type hints to all functions
- Write comprehensive docstrings
- Include unit tests for new features
- Update documentation as needed
This project is licensed under the MIT License - see the LICENSE file for details.
- 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
- 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.