Spaces:
Running
Running
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -7,11 +7,7 @@ Endpoint: https://korakot-render-html.hf.space/mcp
|
|
| 7 |
from fastmcp import FastMCP
|
| 8 |
from mcp_ui_server import create_ui_resource
|
| 9 |
from mcp_ui_server.core import UIResource
|
| 10 |
-
from fastapi import FastAPI
|
| 11 |
-
from fastapi.responses import HTMLResponse
|
| 12 |
-
import uvicorn
|
| 13 |
|
| 14 |
-
# FastMCP server
|
| 15 |
mcp = FastMCP("render-html")
|
| 16 |
|
| 17 |
|
|
@@ -25,7 +21,7 @@ def render_html(html: str, title: str = "Rendered Content") -> list[UIResource]:
|
|
| 25 |
|
| 26 |
Args:
|
| 27 |
html: Complete HTML content to render. Can include style, script,
|
| 28 |
-
inline styles, SVG, images via img
|
| 29 |
title: Optional title for the rendered content.
|
| 30 |
"""
|
| 31 |
return [create_ui_resource({
|
|
@@ -68,7 +64,7 @@ def render_svg(svg: str, title: str = "SVG Diagram") -> list[UIResource]:
|
|
| 68 |
"""Render an SVG diagram inline in the conversation.
|
| 69 |
|
| 70 |
Args:
|
| 71 |
-
svg: SVG markup
|
| 72 |
title: Optional title.
|
| 73 |
"""
|
| 74 |
html = f'''<!DOCTYPE html>
|
|
@@ -83,31 +79,5 @@ def render_svg(svg: str, title: str = "SVG Diagram") -> list[UIResource]:
|
|
| 83 |
})]
|
| 84 |
|
| 85 |
|
| 86 |
-
# FastAPI wrapper for landing page + MCP mount
|
| 87 |
-
app = FastAPI(title="render-html MCP")
|
| 88 |
-
|
| 89 |
-
# Mount MCP at /mcp
|
| 90 |
-
mcp_app = mcp.http_app()
|
| 91 |
-
app.mount("/mcp", mcp_app)
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
@app.get("/", response_class=HTMLResponse)
|
| 95 |
-
async def index():
|
| 96 |
-
return """<!DOCTYPE html>
|
| 97 |
-
<html><body style="font-family:system-ui;max-width:600px;margin:40px auto;padding:0 20px;">
|
| 98 |
-
<h1>render-html MCP Server</h1>
|
| 99 |
-
<p>An MCP Apps server that renders HTML inline in AI conversations.</p>
|
| 100 |
-
<h2>Tools</h2>
|
| 101 |
-
<ul>
|
| 102 |
-
<li><b>render_html</b> - render arbitrary HTML/CSS/JS</li>
|
| 103 |
-
<li><b>render_image</b> - display an image from URL</li>
|
| 104 |
-
<li><b>render_svg</b> - render SVG diagrams</li>
|
| 105 |
-
</ul>
|
| 106 |
-
<h2>Connect</h2>
|
| 107 |
-
<p>Add as custom MCP connector:<br>
|
| 108 |
-
<code>https://korakot-render-html.hf.space/mcp</code></p>
|
| 109 |
-
</body></html>"""
|
| 110 |
-
|
| 111 |
-
|
| 112 |
if __name__ == "__main__":
|
| 113 |
-
|
|
|
|
| 7 |
from fastmcp import FastMCP
|
| 8 |
from mcp_ui_server import create_ui_resource
|
| 9 |
from mcp_ui_server.core import UIResource
|
|
|
|
|
|
|
|
|
|
| 10 |
|
|
|
|
| 11 |
mcp = FastMCP("render-html")
|
| 12 |
|
| 13 |
|
|
|
|
| 21 |
|
| 22 |
Args:
|
| 23 |
html: Complete HTML content to render. Can include style, script,
|
| 24 |
+
inline styles, SVG, images via img tags, etc.
|
| 25 |
title: Optional title for the rendered content.
|
| 26 |
"""
|
| 27 |
return [create_ui_resource({
|
|
|
|
| 64 |
"""Render an SVG diagram inline in the conversation.
|
| 65 |
|
| 66 |
Args:
|
| 67 |
+
svg: SVG markup string.
|
| 68 |
title: Optional title.
|
| 69 |
"""
|
| 70 |
html = f'''<!DOCTYPE html>
|
|
|
|
| 79 |
})]
|
| 80 |
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
if __name__ == "__main__":
|
| 83 |
+
mcp.run(transport="streamable-http", host="0.0.0.0", port=7860)
|