WeBWorK MCP渲染服务器
一个MCP(模型上下文协议)服务器,将Claude Desktop、Claude Code和Cursor等人工智能工具连接到托管的WeBWorK PG渲染器。这使您可以直接从AI助手编写、渲染和验证WeBWorK作业问题,而不需要本地Perl或Docker设置。
它的作用
此服务器通过MCP公开了5个工具:
| 工具 | 它做什么 |
|---|---|
webwork_render_problem | 呈现PG/PGML源代码并返回HTML输出、答案数据和错误 |
webwork_validate_syntax | 快速通过/失败语法检查——比完整渲染迭代更快 |
webwork_render_multi_seed | 在多个随机种子之间呈现问题,以捕捉随机化错误 |
webwork_check_answer | 提交问题的答案并检查答案是否正确 |
webwork_list_macros | 列出可用的WeBWorK PG宏文件及其说明 |
建筑
Claude Desktop / Claude Code / Cursor
│
▼ (MCP over HTTPS)
Caddy reverse proxy (TLS)
│
▼ (localhost:3001)
MCP Server (Node.js + Express)
│
▼ (localhost:3000)
WeBWorK PG Renderer (Docker)MCP服务器是一个无状态的可流式HTTP端点。每个请求都有自己的MCP传输——无需管理会话。
客户端设置
一旦你有服务器运行(见下面的自托管),将你的AI工具连接到它。
克劳德代码
claude mcp add --transport http webwork-renderer \
https://your-domain.example.com/mcp克劳德桌面版
Claude Desktop在其配置文件中不支持远程HTTP MCP服务器。使用 mcp-remote 桥接(需要Node.js 18+):
编辑 ~/Library/Application Support/Claude/claude_desktop_config.json (macOS)或 %APPDATA%\Claude\claude_desktop_config.json (Windows):
{
"mcpServers": {
"webwork-renderer": {
"command": "npx",
"args": [
"mcp-remote",
"https://your-domain.example.com/mcp",
"--transport",
"http-only"
]
}
}
}保存后重新启动Claude Desktop。首次发射可能需要一段时间 npx 下载 mcp-remote.
光标
编辑 ~/.cursor/mcp.json:
{
"mcpServers": {
"webwork-renderer": {
"command": "npx",
"args": [
"mcp-remote",
"https://your-domain.example.com/mcp",
"--transport",
"http-only"
]
}
}
}推荐:WeBWorK写作技巧
为了获得最佳体验,请将此MCP服务器与 网络作家 技能。MCP服务器为Claude提供了 *工具* 渲染和验证问题——这项技能赋予了克劳德 *知识* PG/PGML编写最佳实践、常见陷阱和问题结构约定。
克劳德桌面版
此repo包含一个适应MCP的技能版本,该版本直接使用MCP工具(不需要本地渲染器):
- 下载
skills/webwork-writer.zip来自此repo - 在Claude Desktop中,转到 自定义>技能,单击 +,并上传ZIP
克劳德代码
对于Claude Code,使用上游技能插件,其中包括额外的工具:
claude plugin marketplace add https://github.com/vosslab/vosslab-skills
claude plugin install vosslab-skills然后调用它 /vosslab-skills:webwork-writer.
自我寄宿
先决条件
- Node.js 22+
- Docker&Docker编写
- WeBWorK PG渲染器实例(例如。, voslab/webwork pg渲染器)
设置
git clone https://github.com/johnnylibretexts/webwork-renderer-mcp-server.git
cd webwork-renderer-mcp-server
npm install创建一个 .env 文件:
PORT=3001
RENDERER_URL=http://localhost:3000
NODE_ENV=development运行渲染器
git clone https://github.com/vosslab/webwork-pg-renderer.git
cd webwork-pg-renderer
docker compose up -d运行MCP服务器
# Development (hot reload)
npm run dev
# Production
npm run build
npm start测试
# Unit tests (no Docker required)
npm test
# Integration tests run automatically if the renderer is reachable at RENDERER_URL测试提示
将这些复制粘贴到Claude Desktop或Claude Code中,以验证一切正常。答案已包含在内,因此您可以查看结果。
______________________________________________________________________
提示1:简单导数
写一个WeBWorK问题,要求学生找到f(x)=3x^2+5x-7的导数。渲染它以确保它有效,然后检查答案。
预期答案: 6x + 5
幂律:取下指数并减去1。因此,3x^2变为6x,5x变为5,常数-7下降。
______________________________________________________________________
提示2:二次方程
创建一个WeBWorK问题,要求学生解决x^2-5x+6=0。使用PGML格式。渲染并验证正确答案。
预期答案: 2, 3 (两个根)
系数为(x-2)(x-3)=0,因此x=2或x=3。
______________________________________________________________________
提示3:多项选择
写一个WeBWorK的多项选择题,问:“2x的积分是多少?”,选项a)x^2,B)x^2+C,C)2,D)x。正确答案应该是B。渲染它并确认它有效。
预期答案: B) x^2 + C
2x的积分是x^2加上任意常数C。
______________________________________________________________________
提示4:分数算术
创建一个WeBWorK问题,要求学生简化3/4+1/6。使用contextFraction宏,因此答案必须是精确的分数。渲染并检查答案。
预期答案: 11/12
公分母是12:9/12+2/12=11/12。
______________________________________________________________________
提示5:多种子压力测试
写一个随机系数的WeBWorK问题,要求学生计算一个边长在1到20之间的随机整数矩形的面积。在10个不同的种子上渲染它,以确保没有种子产生错误。
预期答案:因种子而异(随机)。渲染应该传递所有10个种子,没有错误。
______________________________________________________________________
提示6:系统检查
使用webwork_list_macros工具向我显示所有可用的宏,然后验证此代码: `` DOCUMENT(); loadMacros("PGstandard.pl", "PGML.pl", "MathObjects.pl", "PGcourse.pl"); TEXT(beginproblem()); Context("Numeric"); $answer = Compute("42"); BEGIN_PGML What is the answer to life, the universe, and everything? [_____]{$answer} END_PGML ENDDOCUMENT(); ``预期答案: 42。验证应无错误通过。
______________________________________________________________________
致谢
这个项目是建立在以下工作之上的 尼尔·R·沃斯 (罗斯福大学生物学副教授):
- webwork pg渲染器 --为该MCP服务器提供动力的WeBWorK PG渲染引擎。没有它,这个项目就不会存在。
- 沃斯特拉布技能 --The
webwork-writerClaude技能及其关于PG/PGML创作、常见陷阱和渲染器API使用的广泛参考文档为该服务器的工具设计和错误处理提供了信息。
