MTG Card Lookup MCP Server
Enables fuzzy lookup of Magic: The Gathering cards by name using the Scryfall API, returning card details including type, oracle text, mana value, and images.
README
README.md
Week 1 — Hobby Track: mtg.card_lookup
This is a minimal MCP server in Python that exposes two tools:
health.check— returns version, current time, and a simple learning streak counter stored instreak.json.mtg.card_lookup— Day 1 returns a fake response (proves wiring). On Day 2, switch to Scryfall API.
Quick start
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install --upgrade pip
pip install mcp uvloop (optional on Windows)
# Run the server over stdio (default)
python src/server.py
If your client expects a command, point it at
python src/server.py.
Files
/mcp-mtg-week1
├─ src/
│ ├─ server.py # MCP server entry point
│ └─ tools/
│ ├─ __init__.py
│ └─ card_lookup.py # tool implementation (fake → real)
├─ logs/
└─ streak.json # created on first run
Day 2 switch (Scryfall)
- Replace the fake result in
card_lookup.lookup()with a real HTTP call to Scryfall's named endpoint:https://api.scryfall.com/cards/named?fuzzy=<name>
- Keep the same return schema.
src/server.py
import asyncio import json import logging from datetime import datetime, timezone from pathlib import Path
try: import uvloop # type: ignore asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) except Exception: pass
from mcp.server import Server from mcp.types import TextContent
from tools.card_lookup import lookup as mtg_lookup, FakeCardLookupError
APP_VERSION = "0.1.0" BASE_DIR = Path(file).resolve().parent.parent LOG_DIR = BASE_DIR / "logs" LOG_DIR.mkdir(parents=True, exist_ok=True) STREAK_FILE = BASE_DIR / "streak.json"
logging.basicConfig( level=logging.INFO, format="%(asctime)s | %(levelname)s | %(name)s | %(message)s", handlers=[ logging.FileHandler(LOG_DIR / "week1.log"), logging.StreamHandler() ] ) logger = logging.getLogger("mcp-mtg-week1")
server = Server("mcp-mtg-week1")
def _load_streak() -> int: if STREAK_FILE.exists(): try: data = json.loads(STREAK_FILE.read_text()) return int(data.get("streak_days", 0)) except Exception: return 0 return 0
def _save_streak(days: int) -> None: STREAK_FILE.write_text(json.dumps({"streak_days": days}, indent=2))
@server.tool() async def health_check() -> dict: """Return server version, current time (UTC), and learning streak days.""" now = datetime.now(timezone.utc).isoformat() days = _load_streak() # Nudge the counter once per run (simple Day-1 behavior) _save_streak(days + 1) payload = {"version": APP_VERSION, "now": now, "streak_days": days + 1} logger.info("health.check -> %s", payload) return payload
@server.tool() async def mtg_card_lookup(name: str) -> dict: """Fuzzy-lookup a Magic card by name. Day-1: fake response to prove wiring.""" start = datetime.now(timezone.utc) try: result = await mtg_lookup(name=name) logger.info("mtg.card_lookup name=%r -> ok", name) return result except FakeCardLookupError as e: logger.warning("mtg.card_lookup name=%r -> not_found: %s", name, e) return { "error": "not_found", "message": str(e), "suggestion": "Try a different name or check spelling." } finally: end = datetime.now(timezone.utc) elapsed_ms = int((end - start).total_seconds() * 1000) logger.info("mtg.card_lookup elapsed_ms=%d", elapsed_ms)
async def amain() -> None: # Default transport: stdio await server.run_stdio_async()
if name == "main": asyncio.run(amain())
src/tools/init.py
Intentionally empty; makes tools a package.
src/tools/card_lookup.py
import asyncio from dataclasses import dataclass
@dataclass class FakeCardLookupError(Exception): query: str def str(self) -> str: return f"No fake match for query: {self.query}"
async def lookup(name: str) -> dict: """ Day-1 fake implementation. - Accepts any name containing 'atraxa' (case-insensitive) and returns a fixed object. - Otherwise raises FakeCardLookupError so the server can return a friendly error.
Day-2: replace this with a real HTTP call to Scryfall's `named?fuzzy=...` endpoint.
"""
if not isinstance(name, str) or not name.strip():
raise FakeCardLookupError(query=name)
await asyncio.sleep(0.05) # small delay to exercise logging
if "atraxa" in name.lower():
return {
"name": "Atraxa, Grand Unifier",
"type_line": "Legendary Creature — Phyrexian Angel",
"oracle_text": (
"Flying, vigilance, deathtouch, lifelink — When Atraxa, Grand Unifier "
"enters the battlefield, reveal the top ten cards of your library. For each "
"card type, you may put a card of that type from among them into your hand."
),
"mana_value": 7,
"image_small": "https://cards.scryfall.io/small/front/5/9/59....jpg",
"rulings_uri": "https://api.scryfall.com/cards/xxxx/rulings"
}
raise FakeCardLookupError(query=name)
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。