词汇学习服务器

一个基于Cloudflare Workers部署的MCP服务器,通过UCB1算法管理英语词汇学习列表,适用于葡萄牙语用户学习英语。

  • by mateuskiper
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 mateuskiper/english-learning-ucb-mcp

使用说明

英语词汇UCB MCP服务器

部署在上的MCP(模型上下文协议)服务器 Cloudflare员工 管理英语词汇学习列表 基于UCB1的自适应排名设计用于实时语音代理,帮助说葡萄牙语的人学习英语。

运作原理

服务器维护一个英语单词及其葡萄牙语翻译的列表。每个单词都记录了它被问了多少次,以及学习者犯了多少错误。A. UCB1(置信上限) 算法对单词进行排序,以便:

  • 从未尝试过的言语 地表优先(勘探)。
  • 学习者难以理解的单词 靠近顶端(剥削)。
  • 众所周知的词 自然沉入海底。

语音代理呼叫 get_next_word 选出最好的单词进行测验,然后打电话 record_attempt 在学习者做出回应之后。

UCB1公式

UCB(word) = exploitation + exploration

exploitation = errors / trials
exploration  = sqrt(2 * ln(N) / trials)

N = total trials across ALL words

单词with trials = 0 获得最高分,所以他们总是先练习。

MCP工具

工具 说明
add_word 添加一个新的英语单词及其葡萄牙语翻译
list_words 返回按UCB分数排序的所有单词(最高者优先)
get_next_word 返回单个优先级最高的单词进行练习
record_attempt 记录测验结果并重新计算所有UCB分数
remove_word 从列表中删除一个单词
update_word 更新单词的翻译或例句
get_stats 返回总体学习统计数据和前5个单词进行练习

先决条件

设置

1.安装依赖项

npm install

2.创建D1数据库

npx wrangler d1 create vocabulary-db

复制 database_id 从输出并将其粘贴到 wrangler.toml:

[[d1_databases]]
binding = "DB"
database_name = "vocabulary-db"
database_id = "<YOUR_DATABASE_ID>"

3.运行数据库迁移

当地(发展):

npx wrangler d1 execute vocabulary-db --file=./schema.sql

远程(用于生产):

npx wrangler d1 execute vocabulary-db --file=./schema.sql --remote

4.地方发展

npm run dev

服务器将在以下时间启动 http://localhost:8787MCP终点位于 /mcp.

5.部署到Cloudflare

npm run deploy

您的MCP服务器将在 https://english-vocabulary-ucb-mcp.<your-subdomain>.workers.dev.

连接到克劳德桌面

将以下内容添加到您的Claude Desktop MCP配置文件中(claude_desktop_config.json):

{
  "mcpServers": {
    "english-vocabulary": {
      "type": "streamable-http",
      "url": "https://english-vocabulary-ucb-mcp.<your-subdomain>.workers.dev/mcp"
    }
  }
}

连接到Claude代理(SDK)

使用Claude Agent SDK或任何兼容MCP的客户端时,请将其指向您部署的worker /mcp 使用流式HTTP传输的端点:

https://english-vocabulary-ucb-mcp.<your-subdomain>.workers.dev/mcp

项目结构

/
├── src/
│   ├── index.ts          # Worker entrypoint + MCP server setup
│   ├── tools/            # One file per MCP tool
│   │   ├── index.ts      # Registers all tools
│   │   ├── add-word.ts
│   │   ├── list-words.ts
│   │   ├── get-next-word.ts
│   │   ├── record-attempt.ts
│   │   ├── remove-word.ts
│   │   ├── update-word.ts
│   │   └── get-stats.ts
│   ├── db/
│   │   ├── schema.ts     # TypeScript type definitions
│   │   └── queries.ts    # D1 query helpers
│   └── ucb.ts            # UCB1 calculation logic
├── schema.sql            # D1 migration file
├── wrangler.toml         # Cloudflare Workers config
├── tsconfig.json
├── package.json
└── README.md

NPM脚本

脚本 描述
npm run dev 启动本地开发服务器
npm run deploy 部署到Cloudflare Workers
npm run db:create 创建D1数据库
npm run db:migrate 在本地运行迁移
npm run db:migrate:remote 在生产环境中运行迁移

许可证

麻省理工学院