fojin MCP server
An MCP server that exposes fojin's verified
cross-canon Buddhist corpus to any MCP client (Claude Desktop, ChatGPT,
research tooling). It turns fojin from "an app you visit" into infrastructure
an AI can call — every passage it returns carries a portable, resolvable
citation (fojin:cbeta/T0251.1), so a model can ground and deep-link its claims
instead of inventing scripture.
Read-only by construction: it only issues GETs against fojin's public API.
Two ways to use it:
-
Hosted endpoint (zero install) —
https://mcp.fojin.ai/mcp, streamable HTTP, anonymous, rate-limited. One line in Claude Code:claude mcp add --transport http fojin https://mcp.fojin.ai/mcp
-
Local over stdio —
uvx fojin-mcp, the classic MCP install (below).
Tools
| Tool | What it returns |
|---|---|
search_corpus(query, limit, lang) |
Semantic search hits, each with a urn, title, snippet, score |
read_passage(text_id, juan_num) |
The actual content of one fascicle (卷) + its urn |
get_parallels(text_id, juan_num) |
Cross-canon aligned parallels (Chinese↔Pali↔Tibetan), each with a urn and deep-link reader_ref — the alignment moat |
lookup_dictionary(term, limit) |
Entries across fojin's 32 dictionaries |
lookup_entity(query, limit) |
Knowledge-graph entities (people, places, works, terms) |
resolve_urn(urn) |
Resolve/verify a fojin: URN → reader URL + existence |
verify_quote(quote, cite?, juan?) |
Open-world verbatim check: does this quote exist anywhere in the canon? Returns URN-cited matches, honest cite_matched/juan_matched, or the closest near-miss window. Call it before serving any quoted scripture — LLMs invent quotes |
Every result that names a canonical passage carries a urn — fojin's stable
cross-canon identifier, interoperable with CBETA / SuttaCentral (sc/) / 84000
(84k/toh) / GRETIL / VRI numbering. Pass it back to resolve_urn, or cite it
directly.
Install & run
Once published to PyPI, no clone needed — run it with uvx (nothing to
install) or pip:
uvx fojin-mcp # zero-install, stdio transport (the MCP default)
# or
pip install fojin-mcp && fojin-mcp
From a checkout (development):
cd mcp-server && pip install -e . && python -m fojin_mcp
By default it talks to https://fojin.app/api. Point it elsewhere (self-host,
staging) with an env var:
FOJIN_API_BASE_URL=http://localhost:8000/api uvx fojin-mcp
Claude Desktop
Add to claude_desktop_config.json (Settings → Developer → Edit Config):
{
"mcpServers": {
"fojin": {
"command": "uvx",
"args": ["fojin-mcp"]
}
}
}
(or "command": "fojin-mcp" if you pip installed it, or python -m fojin_mcp
from a checkout.) Restart Claude Desktop; the six fojin tools then appear.
ChatGPT / other MCP clients
Any client that speaks MCP over stdio can launch uvx fojin-mcp (or the
fojin-mcp console script); any client that speaks streamable HTTP can point
at https://mcp.fojin.ai/mcp. Both discover the six tools automatically.
Hosting the HTTP endpoint (self-host)
The same package serves streamable HTTP (requires the http extra, which adds
uvicorn):
pip install 'fojin-mcp[http]'
fojin-mcp --transport streamable-http --port 8765 --public-host mcp.example.com
The hosted mode is stateless JSON request/response (stateless_http +
json_response): every tool call is one plain POST — no SSE streams, so it
sits safely behind Cloudflare's proxy and behind multi-worker uvicorn. It adds:
- Per-client rate limiting — sliding window keyed on
CF-Connecting-IP/X-Real-IP(falling back to the socket peer). Tune with--rate-limit/--rate-windoworFOJIN_MCP_RATE_LIMIT/FOJIN_MCP_RATE_WINDOW. - Host-header validation (DNS-rebinding protection) pinned to
--public-host/FOJIN_MCP_PUBLIC_HOSTS(defaultmcp.fojin.ai). - Access + tool logs — one JSON line per request (
fojin_mcp.access) and per tool call (fojin_mcp.tools) on stdout/stderr. /healthzfor container/proxy healthchecks.
The production deployment is the mcp service in the repo's
docker-compose.yml (it talks to the backend container directly) plus the
mcp.fojin.ai server block in deploy/host-nginx/fojin.conf.
Design
- Standalone. Talks to fojin only over HTTP; it does not import the backend,
so it installs and runs independently (deps:
mcp,httpx). - URNs built client-side. fojin's search/read/alignment endpoints expose
cbeta_id; the server builds theurnfrom it (fojin_mcp/urn.py, a vendored copy of the backend'sbuild_urn, kept behaviourally identical and round-trip-tested). So citations work today, independent of any server change.get_parallelsenriches each parallel's URN via a bounded, concurrent, best-efforttext_id → cbeta_idlookup (a miss just leavesurn: null). - Testable core. All HTTP + reshaping lives in
client.pyand is tested against a mocked transport;server.pyis a thin MCP wiring layer (SDK v2 —mcp>=2is required; 2.0 removed the 1.x module this package imported through 0.1.0), and the hosted-edge concerns live inhttp.py. - Fails soft. An upstream error returns
{"error": "..."}to the model rather than crashing the tool call.
Test
pip install -e '.[dev]'
pytest -q # unit tests (no network)
Publishing (maintainer)
CI (.github/workflows/mcp-server.yml) lints, tests, and builds the package on
every change under mcp-server/. To release to PyPI, bump version in
pyproject.toml, then push a tag:
git tag mcp-v0.2.0 && git push origin mcp-v0.2.0
.github/workflows/mcp-publish.yml builds and uploads. It needs credentials
once — set up either PyPI Trusted Publishing (recommended; no secret) for
project fojin-mcp / repo xr843/fojin / workflow mcp-publish.yml /
environment pypi, or a PYPI_API_TOKEN repo secret (then uncomment the
password: line in the workflow).
License
Apache-2.0 (same as fojin).
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fojin_mcp-0.3.2.tar.gz.
File metadata
- Download URL: fojin_mcp-0.3.2.tar.gz
- Upload date:
- Size: 21.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6457ff51c27a503b01c9c2342b9265b8f018df2e149bef7d54feaef86b6b26f3
|
|
| MD5 |
a1ef8face9cfcf8e5c637aded1e27632
|
|
| BLAKE2b-256 |
ca66fc341fc67ee654cb000ef3080c8e081860efa151e9863d03158351877fe6
|
Provenance
The following attestation bundles were made for fojin_mcp-0.3.2.tar.gz:
Publisher:
mcp-publish.yml on xr843/fojin
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fojin_mcp-0.3.2.tar.gz -
Subject digest:
6457ff51c27a503b01c9c2342b9265b8f018df2e149bef7d54feaef86b6b26f3 - Sigstore transparency entry: 2395082390
- Sigstore integration time:
-
Permalink:
xr843/fojin@f4157cc66d21369cc709faa915a0f2899d6e7621 -
Branch / Tag:
refs/tags/mcp-v0.3.2 - Owner: https://github.com/xr843
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
mcp-publish.yml@f4157cc66d21369cc709faa915a0f2899d6e7621 -
Trigger Event:
push
-
Statement type:
File details
Details for the file fojin_mcp-0.3.2-py3-none-any.whl.
File metadata
- Download URL: fojin_mcp-0.3.2-py3-none-any.whl
- Upload date:
- Size: 19.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32fe483c5e7f8c083a39e846ce3660182fbad7af794038eb8df1c9c965fd960b
|
|
| MD5 |
e126d7c54ad2a0f08b60e790fb9dec8c
|
|
| BLAKE2b-256 |
613f59e3e8d94c15a8a3fae6652d6fd83e63fe467585efe2f6057d308ff38af7
|
Provenance
The following attestation bundles were made for fojin_mcp-0.3.2-py3-none-any.whl:
Publisher:
mcp-publish.yml on xr843/fojin
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fojin_mcp-0.3.2-py3-none-any.whl -
Subject digest:
32fe483c5e7f8c083a39e846ce3660182fbad7af794038eb8df1c9c965fd960b - Sigstore transparency entry: 2395082891
- Sigstore integration time:
-
Permalink:
xr843/fojin@f4157cc66d21369cc709faa915a0f2899d6e7621 -
Branch / Tag:
refs/tags/mcp-v0.3.2 - Owner: https://github.com/xr843
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
mcp-publish.yml@f4157cc66d21369cc709faa915a0f2899d6e7621 -
Trigger Event:
push
-
Statement type: