This document provides comprehensive API documentation for the MCP FastAPI server with authentication.
http://localhost:8000
Most endpoints require authentication using JWT tokens. Include the token in the Authorization header:
Authorization: Bearer YOUR_JWT_TOKEN_HERE
All API responses follow this structure:
{
"data": "response_data",
"status": "success"
}{
"error": "Error Type",
"message": "Detailed error message",
"status_code": 400
}GET /healthDescription: Check server health status
Authentication: Not required
Response:
{
"status": "healthy",
"timestamp": 1609459200.0,
"service": "MCP FastAPI Template",
"version": "0.1.0"
}GET /Description: Get comprehensive server information
Authentication: Not required
Response:
{
"service": "MCP FastAPI Template",
"version": "0.1.0",
"description": "A production-ready MCP server template",
"mcp_server": {
"name": "mcp-fastapi-template",
"version": "0.1.0",
"capabilities": {
"tools": true,
"resources": true,
"prompts": true,
"logging": true
}
},
"endpoints": {
"health": "/health",
"metrics": "/metrics",
"auth": "/api/v1/auth",
"mcp": "/api/v1/mcp",
"docs": "/docs",
"redoc": "/redoc"
},
"authentication": {
"enabled": true,
"login_endpoint": "/api/v1/auth/login",
"register_endpoint": "/api/v1/auth/register"
}
}GET /metricsDescription: Prometheus metrics endpoint
Authentication: Configurable (default: not required)
Response: Prometheus format metrics
POST /api/v1/auth/loginDescription: Authenticate user and receive JWT token
Authentication: Not required
Request Body:
{
"username": "admin",
"password": "admin123"
}Response:
{
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
"token_type": "bearer",
"expires_in": 1800
}Error Responses:
401 Unauthorized: Invalid credentials401 Unauthorized: Account disabled
POST /api/v1/auth/registerDescription: Register a new user account
Authentication: Not required
Request Body:
{
"username": "newuser",
"email": "user@example.com",
"password": "securepassword",
"role": "user"
}Response:
{
"message": "User registered successfully",
"user_id": "3",
"username": "newuser"
}Error Responses:
400 Bad Request: Username already exists400 Bad Request: Email already exists400 Bad Request: Invalid role
GET /api/v1/auth/meDescription: Get current authenticated user information
Authentication: Required
Response:
{
"user_id": "1",
"username": "admin",
"email": "admin@example.com",
"role": "admin"
}GET /api/v1/auth/permissionsDescription: Get current user's role and permissions
Authentication: Required
Response:
{
"user_id": "1",
"username": "admin",
"role": "admin",
"permissions": [
"read", "write", "delete", "admin",
"tools:execute", "tools:list",
"resources:read", "resources:write",
"prompts:read", "prompts:write"
]
}POST /api/v1/auth/refreshDescription: Refresh JWT access token
Authentication: Required (current valid token)
Request Headers:
Authorization: Bearer CURRENT_TOKEN
Response:
{
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
"token_type": "bearer",
"expires_in": 1800
}POST /api/v1/auth/logoutDescription: Logout current user (token blacklisting)
Authentication: Required
Response:
{
"message": "Successfully logged out"
}All MCP endpoints require authentication when authentication is enabled.
GET /api/v1/mcp/healthDescription: MCP-specific health check with uptime
Authentication: Required
Response:
{
"status": "healthy",
"timestamp": "2024-01-01T12:00:00Z",
"version": "0.1.0",
"uptime": 3600.5
}GET /api/v1/mcp/infoDescription: Get MCP server information
Authentication: Required
Response:
{
"name": "mcp-fastapi-template",
"version": "0.1.0",
"capabilities": {
"tools": true,
"resources": true,
"prompts": true,
"logging": true
}
}POST /api/v1/mcp/Description: Main MCP protocol endpoint
Authentication: Required
Permission: read
Request Body (example initialize):
{
"method": "initialize",
"id": "req-1"
}Response:
{
"id": "req-1",
"result": {
"serverInfo": {
"name": "mcp-fastapi-template",
"version": "0.1.0"
},
"capabilities": {
"tools": true,
"resources": true,
"prompts": true,
"logging": true
}
}
}GET /api/v1/mcp/toolsDescription: Get list of available MCP tools
Authentication: Required
Permission: tools:list
Response:
{
"tools": [
{
"name": "echo",
"description": "Echo back the provided message",
"input_schema": {
"type": "object",
"properties": {
"message": {
"type": "string",
"description": "The message to echo back"
}
},
"required": ["message"]
}
},
{
"name": "get_current_time",
"description": "Get the current UTC time",
"input_schema": {
"type": "object",
"properties": {},
"required": []
}
}
]
}POST /api/v1/mcp/tools/{tool_name}/callDescription: Execute a specific MCP tool
Authentication: Required
Permission: tools:execute
URL Parameters:
tool_name(string): Name of the tool to execute
Request Body (echo example):
{
"message": "Hello, World!"
}Response:
{
"result": ["Echo: Hello, World!"]
}Request Body (get_current_time example):
{}Response:
{
"result": ["Current UTC time: 2024-01-01T12:00:00Z"]
}Error Responses:
404 Not Found: Tool not found400 Bad Request: Invalid arguments
GET /api/v1/mcp/resourcesDescription: Get list of available MCP resources
Authentication: Required
Permission: resources:read
Response:
{
"resources": [
{
"name": "server_info",
"description": "Information about the MCP server",
"uri": "server://info"
}
]
}GET /api/v1/mcp/resources/{resource_name}Description: Get specific MCP resource content
Authentication: Required
Permission: resources:read
URL Parameters:
resource_name(string): Name of the resource
Response:
{
"contents": [
{
"uri": "server://info",
"mimeType": "application/json",
"text": "{\"server\": \"mcp-fastapi-template\", \"version\": \"0.1.0\"}"
}
]
}GET /api/v1/mcp/promptsDescription: Get list of available MCP prompts
Authentication: Required
Permission: prompts:read
Response:
{
"prompts": [
{
"name": "greeting",
"description": "Generate a personalized greeting",
"arguments": [
{
"name": "name",
"description": "Name of the person to greet",
"required": true
}
]
}
]
}POST /api/v1/mcp/prompts/{prompt_name}/generateDescription: Generate content for a specific prompt
Authentication: Required
Permission: prompts:read
URL Parameters:
prompt_name(string): Name of the prompt
Request Body:
{
"name": "Alice"
}Response:
{
"prompt": "Hello, Alice! Welcome to the MCP FastAPI server."
}| Role | Description | Default Permissions |
|---|---|---|
guest |
Basic read-only access | read, tools:list |
user |
Standard user access | read, write, tools:execute, tools:list, resources:read, prompts:read |
moderator |
Extended access with deletion rights | All user permissions + delete, resources:write, prompts:write |
admin |
Full system access | All permissions including admin |
| Permission | Description |
|---|---|
read |
Basic read access |
write |
Write/modify access |
delete |
Delete access |
admin |
Administrative functions |
tools:list |
List available tools |
tools:execute |
Execute tools |
resources:read |
Read resources |
resources:write |
Write/modify resources |
prompts:read |
Read prompts |
prompts:write |
Write/modify prompts |
| Status Code | Description | Common Causes |
|---|---|---|
400 |
Bad Request | Invalid input, malformed JSON |
401 |
Unauthorized | Missing/invalid token, expired token |
403 |
Forbidden | Insufficient permissions |
404 |
Not Found | Resource/endpoint not found |
429 |
Too Many Requests | Rate limit exceeded |
500 |
Internal Server Error | Server error, check logs |
The API implements rate limiting with the following defaults:
- Rate: 100 requests per minute per IP
- Headers: Rate limit information in response headers
X-RateLimit-Remaining: Requests remainingX-RateLimit-Reset: Reset timestamp
Configuration:
RATE_LIMIT_REQUESTS_PER_MINUTE=100# 1. Login
curl -X POST http://localhost:8000/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{"username": "admin", "password": "admin123"}'
# Extract token from response
export TOKEN="your-jwt-token-here"
# 2. Get user info
curl -H "Authorization: Bearer $TOKEN" \
http://localhost:8000/api/v1/auth/me
# 3. List tools
curl -H "Authorization: Bearer $TOKEN" \
http://localhost:8000/api/v1/mcp/tools
# 4. Execute tool
curl -X POST http://localhost:8000/api/v1/mcp/tools/echo/call \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{"message": "Hello API!"}'
# 5. Logout
curl -X POST http://localhost:8000/api/v1/auth/logout \
-H "Authorization: Bearer $TOKEN"# Test as different users
# Admin user (full access)
curl -X POST http://localhost:8000/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{"username": "admin", "password": "admin123"}'
# Regular user (limited access)
curl -X POST http://localhost:8000/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{"username": "user", "password": "user123"}'When the server is running, visit these URLs for interactive API documentation:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
These interfaces allow you to test all endpoints directly in your browser with proper authentication.