Add /health endpoint and /mcp/openapi.json for discovery

This commit is contained in:
Admin
2026-06-20 03:15:52 +00:00
parent d361788e62
commit 57560cddcf
+83
View File
@@ -1960,6 +1960,89 @@ async def global_exception_handler(request, exc):
) )
@app.get("/health")
async def health_check():
return {
"status": "ok",
"service": "mcp-email-server",
"version": "1.0.0"
}
@app.get("/mcp/openapi.json")
async def mcp_openapi_spec():
# Minimal OpenAPI 3.1 document for compatibility with clients
# that expect an OpenAPI spec at /mcp/openapi.json.
# Actual tool definitions are provided via MCP tools/list.
return {
"openapi": "3.1.0",
"info": {
"title": "MCP Email Server",
"version": "1.0.0",
"description": "Email assistant MCP server. Tools are exposed via MCP Streamable HTTP at POST /mcp."
},
"paths": {
"/mcp": {
"post": {
"summary": "MCP JSON-RPC endpoint",
"description": "Primary MCP endpoint (Streamable HTTP). Use JSON-RPC 2.0 with methods: initialize, tools/list, tools/call.",
"requestBody": {
"required": True,
"content": {
"application/json": {
"schema": {
"type": "object",
"description": "JSON-RPC 2.0 request or batch of requests"
}
}
}
},
"responses": {
"200": {
"description": "JSON-RPC 2.0 response",
"content": {
"application/json": {
"schema": {
"type": "object"
}
}
}
},
"400": {
"description": "Invalid JSON or JSON-RPC request"
},
"500": {
"description": "Internal server error"
}
}
}
},
"/health": {
"get": {
"summary": "Health check",
"responses": {
"200": {
"description": "Service is running",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"status": {"type": "string"},
"service": {"type": "string"},
"version": {"type": "string"}
}
}
}
}
}
}
}
}
}
}
@app.post("/mcp") @app.post("/mcp")
async def mcp_endpoint(request: Request): async def mcp_endpoint(request: Request):
if request.method != "POST": if request.method != "POST":