Add a pluggable server extension API with MCP Apps (#3003)
Co-authored-by: Max Isbey <224885523+maxisbey@users.noreply.github.com>
This commit is contained in:
parent
fe9723853d
commit
4b519782f1
1 changed files with 2598 additions and 24 deletions
25
docs_src/apps/tutorial002.py
Normal file
25
docs_src/apps/tutorial002.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
from mcp.server.apps import Apps, ResourceCsp, ResourcePermissions
|
||||
from mcp.server.mcpserver import MCPServer
|
||||
|
||||
DASHBOARD_HTML = "<!doctype html><title>Dashboard</title><canvas id='chart'></canvas>"
|
||||
|
||||
apps = Apps()
|
||||
|
||||
|
||||
@apps.tool(resource_uri="ui://dashboard/app.html", visibility=["app"])
|
||||
def refresh_dashboard() -> str:
|
||||
"""Refresh the dashboard data."""
|
||||
return "refreshed"
|
||||
|
||||
|
||||
apps.add_html_resource(
|
||||
"ui://dashboard/app.html",
|
||||
DASHBOARD_HTML,
|
||||
title="Dashboard",
|
||||
csp=ResourceCsp(connect_domains=["https://api.example.com"]),
|
||||
permissions=ResourcePermissions(clipboard_write={}),
|
||||
domain="dashboard.example.com",
|
||||
prefers_border=True,
|
||||
)
|
||||
|
||||
mcp = MCPServer("dashboard", extensions=[apps])
|
||||
Loading…
Reference in a new issue