Skip to main content
Glama

Demo MCP Server

by jeffrade
main.py871 B
from contextlib import asynccontextmanager from fastapi import FastAPI from fastmcp import FastMCP mcp = FastMCP("demo-mcp") mcp_app = mcp.http_app(path='/mcp') @mcp.tool def add_nums(a: int, b: int) -> int: """Add two numbers.""" return a + b @asynccontextmanager async def app_lifespan(app: FastAPI): # Startup print("Starting up the app...") # Initialize database, cache, etc. yield # Shutdown print("Shutting down the app...") # Combine both lifespans @asynccontextmanager async def combined_lifespan(app: FastAPI): # Run both lifespans async with app_lifespan(app): async with mcp_app.lifespan(app): yield # Use the combined lifespan app = FastAPI(lifespan=combined_lifespan) app.mount("/llm", mcp_app) @app.get("/", operation_id="read_root") def read_root(): return {"message": "hello world"}

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/jeffrade/mcp-demo'

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