以下内容基本上是 AI 生成的,我还没校对,可能质量不高
Temporary MCP Servers¶
三个 MCP 服务器原型:网页抓取、Discord API、IPython REPL。
这些是粗糙的原型实现——要找精炼的设计,去看 refined-mcp-servers。
三个 server 都基于 FastMCP 框架,可以用 uv run 直接执行远程脚本,零配置启动。
Webview MCP Server¶
用 pywebview 抓网页,转 Markdown。比 headless browser 更轻量。
uv run https://raw.githubusercontent.com/CNSeniorious000/temporary-mcp-servers/HEAD/webview-mcp.py
核心特性¶
- 单进程混合运行:MCP server 在子线程,webview GUI 在主线程
- 并发加载:同时抓取多个 URL,
ConcurrencyLimiter控制(burst 3,max concurrent 15) - 自动重试:网络问题自动重试(默认 2 次)
- Markdown 转换:
mm-read库处理 HTML → Markdown - 元数据提取:自动提取 title、excerpt、byline、site_name、language、published_time
实现细节¶
pywebview 限制 GUI 必须在主线程运行。通常做法是把 webview 放到子进程,但这个项目尝试在单个进程内同时运行 webview 和 MCP server。
倒过来的架构:
# webview-mcp.py
def main():
"""Run webview in the main thread and start MCP server in a sub-thread."""
@start # pywebview.start:主线程启动 GUI
def _():
try:
run(mcp.run_stdio_async()) # 子线程运行 MCP server
finally:
for window in windows:
window.destroy()
- 主线程:webview GUI(pywebview 强制要求)
- 子线程:MCP server stdio loop
这是一个实验性的尝试——绕过了常规做法(子进程分离),证明了单进程内混合 GUI 和异步 server 是可行的。
Discord MCP Server¶
Discord API 集成,带安全确认机制。
export DISCORD_TOKEN="your_token"
uv run https://raw.githubusercontent.com/CNSeniorious000/temporary-mcp-servers/HEAD/discord-mcp.py
特性¶
- 浏览器指纹模拟:
fake-useragent生成一致的 User-Agent 和 X-Super-Properties - 只读安全:查询工具标记
ToolAnnotations(readOnlyHint=True) - 字段过滤:自动过滤敏感字段(avatar、banner、permissions 等)
- elicit 确认:发送消息前弹出确认对话框
- 重试机制:
stamina装饰ClientConnectionError自动重试
核心实现¶
# discord-mcp.py
# 浏览器指纹生成
def generate_headers_data():
ua_data = UserAgent().getRandom
super_properties = {
"os": ua_data["os"],
"browser": ua_data["browser"],
"browser_user_agent": ua_data["useragent"],
"client_build_number": 325403,
}
x_super_properties = b64encode(json.dumps(super_properties))
return {
"User-Agent": ua.random,
"X-Super-Properties": x_super_properties,
}
# 敏感字段黑名单
fields_to_remove = {
"avatar", "banner", "permissions", "flags",
"accent_color", "public_flags", ...
}
工具列表¶
| 工具 | 功能 |
|---|---|
get_current_user |
获取当前用户信息 |
list_user_guilds |
列出所有服务器 |
list_user_dms |
列出所有私聊频道 |
get_guild_info |
获取服务器详细信息 |
list_guild_channels |
列出服务器的所有频道 |
get_channel_info |
获取频道信息 |
read_channel_messages |
读取频道消息(支持分页) |
search_channel_messages |
在频道内搜索消息 |
search_guild_messages |
在服务器内搜索消息 |
send_channel_message |
发送消息(需确认) |
IPython MCP Server¶
持久的 IPython REPL,支持会话管理和 magic 命令。
uv run https://raw.githubusercontent.com/CNSeniorious000/temporary-mcp-servers/HEAD/ipython-mcp.py
核心特性¶
- 会话持久化:使用 UUID 作为 session_id,变量和导入在会话间保持
- venv 智能检测:自动检测项目虚拟环境,必要时切换到匹配的 Python 版本
- magic 命令支持:完整支持 IPython magic 命令(
%whos、%timeit、%prun等) - 输出捕获:捕获 stdout、stderr 和 return 值
- 自定义对象打印:使用
ObjPrint提供更好的对象显示 - 异常格式化:使用 IPython 的
showtraceback格式化错误信息 - HMR 缓存:使用
@cache_across_reloads保持会话在代码重载后不丢失
核心实现¶
# ipython-mcp.py
# venv 自动检测
if venv_path := getenv("VIRTUAL_ENV"):
# 查找 pyvenv.cfg
for pyvenv_cfg in cwd.glob("*/pyvenv.cfg"):
venv_root = pyvenv_cfg.parent
# 检测 Python 版本匹配
if project_py_version != current_py_version:
# 创建临时匹配的 venv
uv venv -p python.exe --seed temp_path --link-mode symlink
# 会话管理
@cache_across_reloads
def sessions():
return {}
class IPythonSession:
def __init__(self):
self.shell = InteractiveShell()
# 包装 showtraceback 以捕获颜色输出
工具列表¶
ipython_execute_code- 执行 Python 代码,返回 session_idipython_clear_context- 重置或删除会话
常用 Magic 命令¶
# 变量检查
%whos # 列出所有变量
data? # 查看签名
obj?? # 查看源码
# 性能分析
%timeit [x**2 for x in range(1000)]
%prun func()
# 环境操作
%env VAR=value # 设置环境变量
%cd /path # 切换目录
# 文件操作
%run script.py
%%writefile file.py
共享特性¶
三个 server 都基于 FastMCP 2.x,使用 uv run 直接执行远程脚本。设置 LOGFIRE_TOKEN 环境变量可启用 Logfire 可观测性。
重要链接¶
| 链接 | 说明 |
|---|---|
| 仓库 | CNSeniorious000/temporary-mcp-servers |
| README | Raw README |
| refined-mcp-servers | 精炼版上游 |