Agentor enables you to build a custom MCP Server as a FastAPI app. You can integrate it with your existing FastAPI app or deploy it as a standalone MCP Server.
LiteMCP - Lightweight MCP Server
To build MCP Servers with Agentor, you can use the LiteMCP class.
from agentor.mcp import LiteMCP
# Create the app
app = LiteMCP()
# Register a tool
@app.tool(description="Get weather")
def get_weather(location: str) -> str:
return f"Weather in {location}: Sunny"
# Run the server
if __name__ == "__main__":
app.run()
LiteMCP vs FastMCP
LiteMCP has a more transparent design and FastAPI primitives such as middlewares and dependency injection are immediately available, while FastMCP requires mounting as a sub-application, diverging from standard FastAPI primitives.
| Feature | LiteMCP | FastMCP |
| Integration Pattern | Native ASGI app | Requires mounting |
| FastAPI Primitives | ✅ Standard patterns | ⚠️ Diverges (sub-app) |
| With Existing Backend | ✅ Easy | ⚠️ Complex |
| Decorator API | ✅ Yes | ✅ Yes |
| Custom Methods | ✅ Full support | ⚠️ Limited |
| Lightweight | ✅ Minimal deps | ⚠️ More deps |
Connecting MCP endpoint to existing FastAPI app
Using FastMCPfrom starlette.applications import Starlette
from starlette.routing import Mount
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("My App")
app = Starlette(
routes=[
Mount("/mcp", app=mcp.streamable_http_app()) # Separate ASGI app
]
)
Using LiteMCPfrom agentor.mcp import LiteMCP
from fastapi import FastAPI
# Create the app
app = FastAPI()
mcp = LiteMCP()
app.include_router(mcp.get_fastapi_router()) # Include MCP endpoints like a regular APIRouter
When to Use Each
Use LiteMCP when:
- You want to serve MCP tools alongside your existing FastAPI/Starlette backend
- You prefer standard FastAPI patterns and routing
- You want full control over custom JSON-RPC methods
- You want minimal dependencies
Use FastMCP when:
- You’re building a standalone MCP server
- You want the official SDK implementation
- You don’t need to integrate with existing web services
Configuration
Constructor Parameters
LiteMCP(
host="0.0.0.0", # Host to bind (for run() method)
port=8000, # Port to bind (for run() method)
enable_cors=True, # Enable CORS middleware
name="mcp-server", # Server name
version="1.0.0", # Server version
instructions="...", # Server instructions
website_url="...", # Website URL
icons=[...], # Server icons
prefix="/mcp", # MCP endpoint prefix
)
Decorators
Register a tool that can be called by MCP clients:
@app.tool(
name="custom_name", # Optional: defaults to function name
description="Tool description",
input_schema={...}, # Optional: auto-generated from function signature
)
def my_tool(param1: str, param2: int = 10) -> str:
return f"Result: {param1} {param2}"
@app.prompt()
Register a prompt template:
@app.prompt(
name="custom_name", # Optional: defaults to function name
description="Prompt description",
arguments=[...], # Optional: auto-generated from function signature
)
def my_prompt(context: str, style: str = "formal") -> str:
return f"Generate a {style} response about {context}"
@app.resource()
Register a resource that can be read by MCP clients:
@app.resource(
uri="resource://path",
name="Resource Name",
description="Resource description",
mime_type="text/plain",
)
def my_resource(uri: str) -> str:
return "Resource content"
Last modified on November 5, 2025