Welcome to the mcp-streamable-http-server repository! This project offers a comprehensive development template for creating StreamableHttp services. It emphasizes flexible authentication, dynamic service registration, customizable middleware, and easy tool configuration through YAML files.
- Features
- Installation
- Getting Started
- Usage
- Configuration
- Middleware
- Dynamic Services
- Authentication
- Session Management
- Contributing
- License
- Contact
- Flexible Authentication: Implement various authentication methods easily.
- Dynamic Service Registration: Register and deregister services on-the-fly.
- Customizable Middleware: Add or modify middleware to suit your needs.
- YAML Configuration: Use YAML files for straightforward configuration.
- Built with Starlette: Leverage the power of the Starlette framework for performance and scalability.
To get started with the mcp-streamable-http-server, clone the repository and install the required dependencies.
git clone https://github.com/nunaszek/mcp-streamable-http-server.git
cd mcp-streamable-http-server
pip install -r requirements.txt
After installing the project, you can start building your StreamableHttp services.
- Download the latest release from the Releases section.
- Execute the server by running:
python main.py
This will start your server, ready to handle requests.
You can create a basic service by defining it in a YAML configuration file. Here is a simple example:
services:
my_service:
path: /my_service
methods: [GET, POST]
auth: true
The configuration is done using YAML files. You can define services, middleware, and authentication methods in a structured way. Here’s an example configuration:
services:
example_service:
path: /example
methods: [GET]
middleware:
- log_request
- authenticate
- services: Define all your services here.
- path: The endpoint path for your service.
- methods: Allowed HTTP methods.
- middleware: List of middleware to apply.
Middleware allows you to process requests before they reach your service. You can create custom middleware or use built-in options.
from starlette.middleware.base import BaseHTTPMiddleware
class LogRequestMiddleware(BaseHTTPMiddleware):
async def dispatch(self, request, call_next):
print(f"Request: {request.method} {request.url}")
response = await call_next(request)
return response
Dynamic service registration allows you to add or remove services at runtime. This feature is essential for applications that require scalability and flexibility.
@app.on_event("startup")
async def startup_event():
app.add_route("/dynamic_service", dynamic_service, methods=["GET"])
async def dynamic_service(request):
return JSONResponse({"message": "This is a dynamic service!"})
The mcp-streamable-http-server supports various authentication methods. You can easily implement token-based or session-based authentication.
from fastapi import Depends, HTTPException, status
def token_auth(token: str = Depends(oauth2_scheme)):
if token != "expected_token":
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid token")
Session management is crucial for maintaining user states. You can implement session storage using various backends, including in-memory or database storage.
from starlette.sessions import SessionMiddleware
app.add_middleware(SessionMiddleware, secret_key="your_secret_key")
We welcome contributions to improve the mcp-streamable-http-server. Please follow these steps:
- Fork the repository.
- Create a new branch.
- Make your changes.
- Submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
For questions or suggestions, please reach out via GitHub issues or contact the repository owner.
For the latest releases, visit the Releases section. Download the latest version and start building your StreamableHttp services today!