- MCP Server for Smithery Integration
MCP Server for Smithery Integration
MCP Server for Smithery Integration
This project implements a FastAPI-based MCP (Model Context Protocol) server that integrates the Greptile API with the Smithery Framework, enabling AI agents to comprehend and interact with codebases.
Project Overview
The MCP Server acts as a critical intermediary between Smithery's AI agents and the Greptile API, providing:
- Standardized MCP-compliant endpoints
- Robust rate limiting
- Authentication and security mechanisms
- Error handling and data transformation
- Consistent response formatting
Rate Limiter Implementation
The rate limiter implementation is defined in app/core/rate_limit.py and has the following components:
Core Components
-
RateLimitStorage (ABC): Abstract base class for storage backends
- Defines interface with
increment,reset, andget_countmethods - Allows for different storage implementations
- Defines interface with
-
InMemoryRateLimitStorage: Default implementation
- Stores counters in memory using Python dictionaries
- Tracks both counts and window expiry times
- Not suitable for distributed environments
-
RateLimiter: Main service class
- Configurable via environment variables
- Provides
check_rate_limitandreset_rate_limitmethods - Returns detailed limit information
-
FastAPI Integration:
- Middleware implementation (
RateLimitMiddleware) - Dependency function (
rate_limiter()) - Standard rate limit headers
- Middleware implementation (
Configuration Options
# Settings for rate limiting
RATE_LIMIT_ENABLED: bool = True
RATE_LIMIT_REQUESTS: int = 60
RATE_LIMIT_PERIOD_SECONDS: int = 60
Limitations & Future Enhancements
-
Scalability: Current implementation uses in-memory storage, which doesn't scale across multiple instances. Future implementation should use Redis or similar distributed cache.
-
External API Awareness: Should track Greptile API quotas and adapt rate limits accordingly.
-
Per-Service Limits: Implement separate rate limits for different services and endpoints.
-
Advanced Strategies: Consider implementing token bucket or sliding window algorithms for more sophisticated rate limiting.
Integration with Smithery
This MCP server follows the requirements for integration with the Smithery Framework by:
- Providing standardized endpoints that map to Greptile functionality
- Implementing proper authentication and security mechanisms
- Transforming data between Greptile API format and MCP format
- Abstracting complex logic into a standardized interface
Development
To run the server locally:
# Set up environment
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
# Configure environment variables
cp .env.example .env
# Edit .env with your Greptile API key
# Run server
uvicorn app.main:app --reload
License
MIT License