Token导航 LogoToken导航TokenDH.com
MCP Embedded Ui Python logo
开发工具stdio官方级别未说明来源级核验

MCP Embedded Ui Python

MCP Server

一个为MCP服务器提供的浏览器界面工具,支持工具列表浏览、架构检查、尝试执行等功能。

工具数

0

提示词数

0

GitHub Stars

0

资源数

0
开发工具FastAPIPython

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

aiperceivable

提供方

aiperceivable

最后核验

2026/5/17 20:23

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

命令预览

pip install mcp-embedded-ui

详细介绍

mcp嵌入式ui(Python)

这是什么?

如果你用Python构建一个MCP服务器,你的用户会通过原始JSON与工具交互——没有视觉反馈,没有模式浏览器,也没有快速的测试方法。此库为您的服务器添加了一个完整的浏览器UI 一个导入,一个挂载.

┌───────────────────────────────────┐
│  Browser                          │
│  Tool list → Schema → Try it      │
└──────────────┬────────────────────┘
               │ HTTP / JSON
┌──────────────▼────────────────────┐
│  Your Python MCP Server           │
│  + mcp-embedded-ui                │
│    (FastAPI / Starlette / ASGI)   │
└───────────────────────────────────┘

UI提供了什么?

  • 工具列表 --浏览所有带有描述和注释徽章的注册工具
  • 模式检查器 --展开任何工具以查看其完整的JSON模式(inputSchema)
  • 试试控制台 --键入JSON参数,执行工具,立即查看结果
  • cURL导出 --复制现成的cURL命令以执行任何操作
  • 身份验证支持 --在UI中输入与所有请求一起发送的Bearer令牌

无构建步骤。没有CDN。没有外部依赖关系。整个UI是嵌入在包中的单个自包含的HTML页面。

安装

pip install mcp-embedded-ui

需要Python 3.10+和 斯塔雷特 >= 0.14.

快速开始

FastAPI/Starlette

from fastapi import FastAPI
from mcp_embedded_ui import create_mount

app = FastAPI()

# Mount at /explorer (default), enable tool execution
app.routes.append(create_mount(tools=my_tools, handle_call=my_handler, allow_execute=True))

# Or specify a custom prefix
app.routes.append(create_mount("/mcp-ui", tools=my_tools, handle_call=my_handler, allow_execute=True))

# Visit http://localhost:8000/explorer/

任何ASGI框架

from mcp_embedded_ui import create_app

# Returns a standard ASGI app — mount in any ASGI-compatible framework
ui_app = create_app(tools=my_tools, handle_call=my_handler, allow_execute=True)

完整工作示例

from fastapi import FastAPI
from mcp_embedded_ui import create_mount

# 1. Define your tools (any object with .name, .description, .inputSchema)
class MyTool:
    def __init__(self, name, description, input_schema):
        self.name = name
        self.description = description
        self.inputSchema = input_schema

tools = [
    MyTool("greet", "Say hello", {
        "type": "object",
        "properties": {"name": {"type": "string"}},
    }),
]

# 2. Define a handler: (name, args) -> (content, is_error, trace_id)
async def handle_call(name, args):
    if name == "greet":
        return [{"type": "text", "text": f"Hello, {args.get('name', 'world')}!"}], False, None
    return [{"type": "text", "text": f"Unknown tool: {name}"}], True, None

# 3. Mount the UI
app = FastAPI()
app.routes.append(create_mount(tools=tools, handle_call=handle_call, allow_execute=True))

带身份验证挂钩

from contextlib import contextmanager
from fastapi import Request

@contextmanager
def my_auth(request: Request):
    token = request.headers.get("authorization", "")
    if not token.startswith("Bearer "):
        raise ValueError("Unauthorized")
    # Verify the token with your own logic (JWT, API key, session, etc.)
    yield

# Pass auth_hook to enable, omit to disable
app.routes.append(create_mount(
    tools=tools,
    handle_call=handle_call,
    allow_execute=True,
    auth_hook=my_auth,
))

仅授权警卫 POST /tools/{name}/call发现端点始终是公开的。UI有一个内置的令牌输入字段——在那里输入你的Bearer令牌,它会随着每个执行请求一起发送。

附带的演示(examples/fastapi_demo.py)使用硬编码 Bearer demo-secret-token --令牌在启动时打印,因此您知道要粘贴到UI中的内容。

动态工具

# Sync callable — re-evaluated on every request
def get_tools():
    return registry.list_tools()

# Async callable
async def get_tools():
    return await registry.async_list_tools()

app = create_app(tools=get_tools, handle_call=my_handler, allow_execute=True)

API

三倍API

函数返回用例
create_mount(prefix, *, tools, handle_call, **config)MountFastAPI/Starlette——在URL前缀下挂载
create_app(tools, handle_call, **config)ASGIApp任何ASGI框架——独立应用
build_ui_routes(tools, handle_call, **config)list[Route]高级用户——细粒度路由控制

参数

参数类型默认值说明
tools`list \Callable \AsyncCallable`_必需的_MCP工具对象(.name, .description, .inputSchema)
handle_callToolCallHandler_必需的_async (name, args) -> (content, is_error, trace_id)
allow_executeboolFalse启用/禁用工具执行(强制服务器端)
auth_hook`AuthHook \None`None用于身份验证的同步/异步上下文管理器工厂
titlestr"MCP Tool Explorer"页面标题(HTML自动转义)
project_name`str \None`None页脚中显示的项目名称
project_url`str \None`None页脚中链接的项目URL(需要 project_name)

身份验证挂钩

auth_hook 收到Starlette Request 并返回一个上下文管理器(同步或异步)。提高内部拒绝401。错误响应总是 {"error": "Unauthorized"} --内部细节从未泄露。

from contextlib import contextmanager

@contextmanager
def my_auth(request):
    token = request.headers.get("Authorization")
    if not valid(token):
        raise ValueError("Bad token")
    my_identity_var.set(decode(token))
    yield

仅授权警卫 POST /tools/{name}/call.发现端点(GET /tools, GET /tools/{name})总是公开的。

端点

方法路径描述
得到/独立的HTML资源管理器页面
得到/tools所有工具的摘要列表
得到/tools/{name}完整的工具细节 inputSchema
职位/tools/{name}/call执行工具,返回MCP CallToolResult

发展

# Install in editable mode with dev dependencies
pip install -e ".[dev]"

# Run the demo (auth enabled with a demo token)
python examples/fastapi_demo.py
# Visit http://localhost:8000/explorer/
# Paste "Bearer demo-secret-token" in the UI's token field to execute tools

# Run tests
pytest

跨语言规范

此包实现了 mcp嵌入式ui 规范。规范仓库包含:

许可证

阿帕奇-2.0

目录标签

目录标签

开发工具FastAPIPythonMCP工具本地部署浏览器界面JSON处理

接入字段

传输方式(transport,传输协议)

stdio

鉴权方式(authType,认证方式)

api-key

工具数量(toolCount,工具数)

0

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

stdioapi-key部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

来源信息

继续浏览同类 MCP