Skip to main content
Glama
hsiangjenli
by hsiangjenli
main_http.py995 B
from fastapi import FastAPI from fastmcp import FastMCP from starlette.middleware import Middleware from starlette.middleware.cors import CORSMiddleware from mcp_tools.schemas import NewEndpointRequest, NewEndpointResponse app = FastAPI( title="Python MCP Template", description="A template for creating MCP-compliant FastAPI services.", version="0.1.0", ) @app.post( "/new/endpoint/", operation_id="new_endpoint", response_model=NewEndpointResponse ) async def new_endpoint(request: NewEndpointRequest): return {"message": f"Hello, {request.name}!"} mcp = FastMCP.from_fastapi(app=app, stateless_http=True, json_response=True) starlette_app = mcp.http_app( middleware=[ Middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) ] ) # starlette_app.mount("/api", app=app) # (Optional) Keep the original FastAPI app at /api

Implementation Reference

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/hsiangjenli/mcp-slidev'

If you have feedback or need assistance with the MCP directory API, please join our Discord server