sew-slm / sew_tools /mcp_server.py
Flickwire's picture
Upload sew-slm model, tokenizer, ONNX exports and agent tools
3801a9b verified
Raw History Blame Contribute Delete
1.7 kB
"""MCP server exposing Simple English Wikipedia `search` and `read` tools.
pip install mcp # works with mcp 1.x (FastMCP) and 2.x (MCPServer)
python -m sew_tools.mcp_server # live simple.wikipedia.org
python -m sew_tools.mcp_server --offline data/articles.jsonl
Claude Code: claude mcp add simple-wikipedia -- python -m sew_tools.mcp_server
"""
import argparse
try: # mcp >= 2
from mcp.server.mcpserver import MCPServer as _Server
except ImportError: # mcp 1.x
from mcp.server.fastmcp import FastMCP as _Server
from .backends import DEFAULT_UA, LocalWiki, WikipediaAPI
from .schema import dispatch
def build_server(backend):
mcp = _Server("simple-wikipedia")
@mcp.tool()
def search(query: str, n: int = 3) -> dict:
"""Search Simple English Wikipedia. Returns the best-matching articles, each with its
title and opening sentences."""
return dispatch("search", {"query": query, "n": n}, backend)
@mcp.tool()
def read(title: str, max_chars: int = 900) -> dict:
"""Read the opening paragraphs of a Simple English Wikipedia article by title."""
return dispatch("read", {"title": title, "max_chars": max_chars}, backend)
return mcp
def main():
p = argparse.ArgumentParser()
p.add_argument("--offline", default=None, help="articles.jsonl to serve instead of the live API")
p.add_argument("--user-agent", default=None, help=f"default: $SEW_TOOLS_USER_AGENT or {DEFAULT_UA!r}")
a = p.parse_args()
backend = LocalWiki(a.offline) if a.offline else WikipediaAPI(user_agent=a.user_agent)
build_server(backend).run()
if __name__ == "__main__":
main()