dfernand90/mcp-server
If you are the rightful owner of mcp-server 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.
A Model Context Protocol (MCP) server implementation in Python, designed for deployment to Azure Web App with GitHub Actions integration.
echo
Echo back the input message.
get_time
Get current server time.
placeholder_tool
A placeholder for your custom implementation.
MCP Server - Placeholder Implementation
A Model Context Protocol (MCP) server implementation in Python, ready for deployment to Azure Web App via GitHub Actions.
Features
- MCP Protocol Support: Implements the Model Context Protocol specification
- Placeholder Tools: Includes sample tools that you can replace with your own implementations
- Azure Web App Ready: Configured for deployment to Azure Web App
- GitHub Actions CI/CD: Automated testing and deployment
- Multiple Interfaces:
- STDIO for local development
- HTTP REST API for web access
- WebSocket for real-time communication
- Docker Support: Containerized deployment option
- Health Checks: Built-in health monitoring for Azure
Project Structure
mcp-server/
āāā main.py # Core MCP server implementation
āāā app.py # FastAPI wrapper for web deployment
āāā requirements.txt # Python dependencies
āāā startup.sh # Azure startup script
āāā web.config # Azure Web App configuration
āāā Dockerfile # Container configuration
āāā test_mcp_server.py # Unit tests
āāā .github/workflows/ # GitHub Actions CI/CD
āāā README.md # This file
Quick Start
Local Development
-
Clone the repository
git clone <your-repo-url> cd mcp-server
-
Install dependencies
pip install -r requirements.txt
-
Run the server locally
# STDIO mode (for MCP clients) python main.py # Web mode (for HTTP access) python app.py
-
Test the server
python -m pytest test_mcp_server.py -v
Azure Deployment
-
Create Azure Web App
- Go to Azure Portal
- Create a new Web App with Python runtime
- Note the app name and get the publish profile
-
Configure GitHub Secrets
AZURE_WEBAPP_NAME
: Your Azure Web App nameAZURE_WEBAPP_PUBLISH_PROFILE
: Download from Azure Portal
-
Deploy
- Push to main branch
- GitHub Actions will automatically build and deploy
Available Tools (Placeholders)
The server includes three placeholder tools that you can replace with your own implementations:
1. Echo Tool
- Name:
echo
- Description: Echo back the input message
- Parameters:
message
(string)
2. Get Time Tool
- Name:
get_time
- Description: Get current server time
- Parameters: None
3. Placeholder Tool
- Name:
placeholder_tool
- Description: A placeholder for your custom implementation
- Parameters:
input
(string)
API Endpoints
When deployed as a web app, the server provides these endpoints:
GET /
- Server informationGET /health
- Health checkGET /tools
- List available toolsPOST /mcp
- MCP protocol requestsPOST /tools/call
- Direct tool executionWebSocket /ws
- Real-time MCP communication
Customization
Adding Your Own Tools
-
Update
_setup_default_tools()
inmain.py
:def _setup_default_tools(self): self.tools = { "your_tool": { "name": "your_tool", "description": "Description of your tool", "inputSchema": { "type": "object", "properties": { "param1": { "type": "string", "description": "Parameter description" } }, "required": ["param1"] } } }
-
Implement tool logic in
_execute_tool()
method:async def _execute_tool(self, tool_name: str, arguments: Dict[str, Any]) -> str: if tool_name == "your_tool": # Your custom implementation here param1 = arguments.get('param1') result = your_custom_logic(param1) return f"Result: {result}"
Adding Resources
Resources are static or dynamic content that tools can access:
def __init__(self):
self.resources = {
"your_resource": {
"uri": "resource://your_resource",
"name": "Your Resource",
"description": "Description of your resource",
"mimeType": "text/plain"
}
}
Adding Prompts
Prompts are reusable templates for AI interactions:
def __init__(self):
self.prompts = {
"your_prompt": {
"name": "your_prompt",
"description": "Description of your prompt",
"arguments": [
{
"name": "context",
"description": "Context for the prompt",
"required": True
}
]
}
}
Testing
Run the test suite:
# Run all tests
python -m pytest test_mcp_server.py -v
# Run specific test
python -m pytest test_mcp_server.py::TestMCPServer::test_echo_tool -v
# Run with coverage
pip install pytest-cov
python -m pytest test_mcp_server.py --cov=main --cov-report=html
Environment Variables
Configure these environment variables for deployment:
PORT
: Server port (default: 8000)PYTHONUNBUFFERED
: Set to 1 for AzurePYTHONDONTWRITEBYTECODE
: Set to 1 for Azure
Docker Deployment
Build and run with Docker:
# Build image
docker build -t mcp-server .
# Run container
docker run -p 8000:8000 mcp-server
# Run with environment variables
docker run -p 8000:8000 -e PORT=8000 mcp-server
Monitoring and Logging
The server includes comprehensive logging:
- Application logs: All requests and responses
- Error logs: Detailed error information
- Health checks: Available at
/health
endpoint - Azure logs: Check Azure portal for deployment logs
Security Considerations
- CORS: Configured for web deployment
- Input validation: Validate all tool parameters
- Error handling: Graceful error responses
- Rate limiting: Consider implementing for production
- Authentication: Add authentication for sensitive operations
Performance Optimization
For production deployment:
- Use Gunicorn: Pre-configured in startup script
- Configure workers: Adjust based on your needs
- Enable caching: Implement caching for expensive operations
- Monitor resources: Use Azure Application Insights
- Scale horizontally: Use Azure App Service scaling
Troubleshooting
Common Issues
-
Deployment fails:
- Check Azure publish profile
- Verify GitHub secrets
- Review deployment logs
-
Tools not responding:
- Check tool implementation
- Verify parameter schemas
- Review server logs
-
Performance issues:
- Check worker configuration
- Monitor memory usage
- Review database connections
Debug Mode
Enable debug mode for development:
# In app.py
app = FastAPI(debug=True)
# In main.py
logging.basicConfig(level=logging.DEBUG)
Contributing
- Fork the repository
- Create a feature branch
- Add your implementation
- Write tests
- Submit a pull request
License
This project is open source and available under the MIT License.
Support
For issues and questions:
- Check the troubleshooting section
- Review Azure Web App documentation
- Open an issue on GitHub
Next Steps
- Replace placeholder tools with your actual implementations
- Add authentication if needed
- Implement caching for better performance
- Add monitoring and alerting
- Scale based on usage patterns
Note: This is a placeholder implementation. Replace the example tools with your actual business logic and add proper error handling, validation, and security measures for production use.