jisho-mcp 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -0
- package/dist/api.d.ts +10 -0
- package/dist/api.js +70 -0
- package/dist/license.d.ts +8 -0
- package/dist/license.js +79 -0
- package/dist/server.js +38 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -45,3 +45,22 @@ This project is intentionally narrow. It should be treated as a practical helper
|
|
|
45
45
|
## Try it
|
|
46
46
|
|
|
47
47
|
After building, connect the server through your MCP client. The repository root also contains `smoke-test.mjs` for projects covered by the shared harness. A typical tool call starts with `search_words`.
|
|
48
|
+
|
|
49
|
+
<!-- paywall -->
|
|
50
|
+
## Premium tools
|
|
51
|
+
|
|
52
|
+
These tools need a license key:
|
|
53
|
+
|
|
54
|
+
* `all_senses`
|
|
55
|
+
* `words_by_reading`
|
|
56
|
+
|
|
57
|
+
Buy a key at https://mcp-marketplace.io/server/io-github-mrfentmen-jisho-mcp and set it in your MCP client config:
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
"env": { "MCP_LICENSE_KEY": "mcp_live_..." }
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
The key is checked against MCP Marketplace, cached for 24 hours, and keeps
|
|
64
|
+
working offline once one check has succeeded. Every other tool on this server
|
|
65
|
+
stays free.
|
|
66
|
+
<!-- /paywall -->
|
package/dist/api.d.ts
CHANGED
|
@@ -28,3 +28,13 @@ export declare function searchWords(keyword: string, limit?: number): Promise<Wo
|
|
|
28
28
|
*/
|
|
29
29
|
export declare function searchByTag(keyword: string, limit?: number): Promise<WordResult[]>;
|
|
30
30
|
export declare function formatWord(w: WordResult, index?: number): string;
|
|
31
|
+
export interface AllSensesArgs {
|
|
32
|
+
keyword: string;
|
|
33
|
+
limit?: number;
|
|
34
|
+
}
|
|
35
|
+
export declare function allSenses(args: AllSensesArgs): Promise<string>;
|
|
36
|
+
export interface WordsByReadingArgs {
|
|
37
|
+
reading: string;
|
|
38
|
+
limit?: number;
|
|
39
|
+
}
|
|
40
|
+
export declare function wordsByReading(args: WordsByReadingArgs): Promise<string>;
|
package/dist/api.js
CHANGED
|
@@ -75,3 +75,73 @@ export function formatWord(w, index = 0) {
|
|
|
75
75
|
}
|
|
76
76
|
return lines.join("\n");
|
|
77
77
|
}
|
|
78
|
+
async function jishoWords(keyword) {
|
|
79
|
+
const res = await fetch(`${BASE}/words?keyword=${encodeURIComponent(keyword)}`, {
|
|
80
|
+
headers: { Accept: "application/json", "User-Agent": "jisho-mcp/1.0" },
|
|
81
|
+
});
|
|
82
|
+
if (res.status === 404)
|
|
83
|
+
return [];
|
|
84
|
+
if (!res.ok)
|
|
85
|
+
throw new JishoError(`Jisho API error ${res.status}: ${res.statusText}`);
|
|
86
|
+
const data = (await res.json());
|
|
87
|
+
return data.data ?? [];
|
|
88
|
+
}
|
|
89
|
+
const jishoForms = (entry) => (entry.japanese ?? [])
|
|
90
|
+
.map((j) => `${j.word ?? "(kana only)"}${j.reading ? ` (${j.reading})` : ""}`)
|
|
91
|
+
.join(" / ") || String(entry.slug ?? "?");
|
|
92
|
+
const jishoDef = (d) => (d.length > 200 ? `${d.slice(0, 200)}...` : d);
|
|
93
|
+
export async function allSenses(args) {
|
|
94
|
+
const keyword = (args.keyword ?? "").trim();
|
|
95
|
+
if (!keyword)
|
|
96
|
+
throw new JishoError("Provide a keyword, e.g. '水'.");
|
|
97
|
+
const limit = Math.max(1, Math.min(args.limit ?? 3, 8));
|
|
98
|
+
const entries = await jishoWords(keyword);
|
|
99
|
+
if (!entries.length)
|
|
100
|
+
return `No Jisho results for "${keyword}".`;
|
|
101
|
+
return `Every Jisho sense for "${keyword}" (${Math.min(entries.length, limit)} of ${entries.length} entries):\n` +
|
|
102
|
+
entries.slice(0, limit).map((entry, i) => {
|
|
103
|
+
const senses = entry.senses ?? [];
|
|
104
|
+
const lines = [`${i + 1}. ${jishoForms(entry)}${entry.is_common ? " (common)" : ""}`];
|
|
105
|
+
lines.push(` ${senses.length} sense(s)${entry.jlpt?.length ? ` | JLPT ${entry.jlpt.join(", ")}` : ""}${entry.tags?.length ? ` | tags ${entry.tags.join(", ")}` : ""}`);
|
|
106
|
+
senses.forEach((s, n) => {
|
|
107
|
+
const pos = s.parts_of_speech?.length ? ` [${s.parts_of_speech.join(", ")}]` : "";
|
|
108
|
+
lines.push(` ${n + 1}. ${pos || "[part of speech not reported]"}`);
|
|
109
|
+
for (const d of s.english_definitions ?? [])
|
|
110
|
+
lines.push(` - ${jishoDef(d)}`);
|
|
111
|
+
if (s.restrictions?.length)
|
|
112
|
+
lines.push(` restrictions: ${s.restrictions.join(", ")}`);
|
|
113
|
+
if (s.tags?.length)
|
|
114
|
+
lines.push(` tags: ${s.tags.join(", ")}`);
|
|
115
|
+
if (s.see_also?.length)
|
|
116
|
+
lines.push(` see also: ${s.see_also.join(", ")}`);
|
|
117
|
+
if (s.antonyms?.length)
|
|
118
|
+
lines.push(` antonyms: ${s.antonyms.join(", ")}`);
|
|
119
|
+
for (const l of s.links ?? [])
|
|
120
|
+
lines.push(` ${l.text ?? "link"}: ${l.url ?? "url not reported"}`);
|
|
121
|
+
});
|
|
122
|
+
return lines.join("\n");
|
|
123
|
+
}).join("\n\n");
|
|
124
|
+
}
|
|
125
|
+
export async function wordsByReading(args) {
|
|
126
|
+
const reading = (args.reading ?? "").trim();
|
|
127
|
+
if (!reading)
|
|
128
|
+
throw new JishoError("Provide a reading in kana or romaji, e.g. 'みず'.");
|
|
129
|
+
const limit = Math.max(1, Math.min(args.limit ?? 12, 20));
|
|
130
|
+
const entries = await jishoWords(reading);
|
|
131
|
+
if (!entries.length)
|
|
132
|
+
return `No Jisho entries found for the reading "${reading}".`;
|
|
133
|
+
const rows = entries.slice(0, limit);
|
|
134
|
+
return [
|
|
135
|
+
`Jisho entries for the reading "${reading}" (${rows.length} of ${entries.length} found):`,
|
|
136
|
+
...rows.map((e, i) => {
|
|
137
|
+
const readings = [...new Set((e.japanese ?? []).map((j) => j.reading).filter(Boolean))];
|
|
138
|
+
const first = e.senses?.[0];
|
|
139
|
+
const defs = first?.english_definitions?.slice(0, 3).join("; ") ?? "no definition reported";
|
|
140
|
+
return [
|
|
141
|
+
`${i + 1}. ${jishoForms(e)}${e.is_common ? " (common)" : ""}`,
|
|
142
|
+
` ${defs}`,
|
|
143
|
+
` readings: ${readings.join(", ") || "not reported"} | ${e.senses?.length ?? 0} sense(s)${e.jlpt?.length ? ` | JLPT ${e.jlpt.join(", ")}` : ""}`,
|
|
144
|
+
].join("\n");
|
|
145
|
+
}),
|
|
146
|
+
].join("\n");
|
|
147
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns null when the caller may run the tool, or a short message telling
|
|
3
|
+
* them how to get a key.
|
|
4
|
+
*
|
|
5
|
+
* A good key is remembered for an hour, so a busy session does not hit the
|
|
6
|
+
* license server on every call and keeps working through a brief outage.
|
|
7
|
+
*/
|
|
8
|
+
export declare function premiumRequired(tool: string): Promise<string | null>;
|
package/dist/license.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Premium tools on this server need a license key bought from MCP Marketplace.
|
|
2
|
+
// Buyers put the key in their MCP client config as MCP_LICENSE_KEY. Every tool
|
|
3
|
+
// that is not listed in PREMIUM keeps working without a key.
|
|
4
|
+
const SLUG = "jisho-mcp";
|
|
5
|
+
// Tools that need a key. Everything else is free.
|
|
6
|
+
const PREMIUM = new Set([
|
|
7
|
+
"all_senses",
|
|
8
|
+
"words_by_reading",
|
|
9
|
+
]);
|
|
10
|
+
const BUY_URL = `https://mcp-marketplace.io/server/io-github-mrfentmen-${SLUG}`;
|
|
11
|
+
// The license check calls the marketplace's verify endpoint directly instead of
|
|
12
|
+
// using @mcp_marketplace/license. That SDK sends no `apikey` header, so every
|
|
13
|
+
// check it makes is rejected by Supabase before it reaches the function. The
|
|
14
|
+
// publishable key below is public by design - it ships in mcp-marketplace.io's
|
|
15
|
+
// own JavaScript and only ever reaches their licence check.
|
|
16
|
+
const DEFAULT_VERIFY_URL = "https://virupvwhtkpkjsiskckg.supabase.co/functions/v1/verify-key";
|
|
17
|
+
const PUBLISHABLE_KEY = "sb_publishable_BuqlW96Ke8C_zzJG-LQv1Q_YHi_r_4h";
|
|
18
|
+
const OK_CACHE_MS = 60 * 60 * 1000;
|
|
19
|
+
const BAD_CACHE_MS = 60 * 1000;
|
|
20
|
+
const seen = new Map();
|
|
21
|
+
const REASONS = {
|
|
22
|
+
missing_key: "no key is set",
|
|
23
|
+
invalid_format: "that key is not a valid MCP Marketplace key",
|
|
24
|
+
not_found: "that key was not found",
|
|
25
|
+
revoked: "that key has been revoked",
|
|
26
|
+
rotated: "that key was rotated, use your new one",
|
|
27
|
+
expired: "that key has expired, renew it",
|
|
28
|
+
rate_limited: "there were too many checks just now, try again shortly",
|
|
29
|
+
network_error: "the license server could not be reached",
|
|
30
|
+
};
|
|
31
|
+
function blocked(tool, reason) {
|
|
32
|
+
const why = REASONS[reason] ?? `the license server answered "${reason}"`;
|
|
33
|
+
return `"${tool}" needs a license key, but ${why}. ` +
|
|
34
|
+
`Set MCP_LICENSE_KEY in your MCP client config. Get a key: ${BUY_URL}`;
|
|
35
|
+
}
|
|
36
|
+
async function verify(key) {
|
|
37
|
+
const res = await fetch(process.env.MCP_LICENSE_VERIFY_URL || DEFAULT_VERIFY_URL, {
|
|
38
|
+
method: "POST",
|
|
39
|
+
headers: {
|
|
40
|
+
apikey: PUBLISHABLE_KEY,
|
|
41
|
+
Authorization: `Bearer ${PUBLISHABLE_KEY}`,
|
|
42
|
+
"Content-Type": "application/json",
|
|
43
|
+
},
|
|
44
|
+
body: JSON.stringify({ key, slug: SLUG }),
|
|
45
|
+
// an unusable key answers 400 with a JSON body, so read the body either way
|
|
46
|
+
signal: AbortSignal.timeout(15000),
|
|
47
|
+
});
|
|
48
|
+
const data = (await res.json());
|
|
49
|
+
if (typeof data?.valid !== "boolean")
|
|
50
|
+
return { valid: false, reason: "unexpected_response" };
|
|
51
|
+
return data;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Returns null when the caller may run the tool, or a short message telling
|
|
55
|
+
* them how to get a key.
|
|
56
|
+
*
|
|
57
|
+
* A good key is remembered for an hour, so a busy session does not hit the
|
|
58
|
+
* license server on every call and keeps working through a brief outage.
|
|
59
|
+
*/
|
|
60
|
+
export async function premiumRequired(tool) {
|
|
61
|
+
if (!PREMIUM.has(tool))
|
|
62
|
+
return null;
|
|
63
|
+
const key = process.env.MCP_LICENSE_KEY;
|
|
64
|
+
if (!key)
|
|
65
|
+
return blocked(tool, "missing_key");
|
|
66
|
+
const hit = seen.get(key);
|
|
67
|
+
if (hit && Date.now() - hit.at < (hit.valid ? OK_CACHE_MS : BAD_CACHE_MS)) {
|
|
68
|
+
return hit.valid ? null : blocked(tool, hit.reason ?? "invalid");
|
|
69
|
+
}
|
|
70
|
+
let result;
|
|
71
|
+
try {
|
|
72
|
+
result = await verify(key);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
result = { valid: false, reason: "network_error" };
|
|
76
|
+
}
|
|
77
|
+
seen.set(key, { ...result, at: Date.now() });
|
|
78
|
+
return result.valid ? null : blocked(tool, result.reason ?? "invalid");
|
|
79
|
+
}
|
package/dist/server.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import { JishoError, formatWord, searchByTag, searchWords, } from "./api.js";
|
|
3
|
+
import { JishoError, formatWord, searchByTag, searchWords, allSenses, wordsByReading } from "./api.js";
|
|
4
|
+
import { premiumRequired } from "./license.js";
|
|
4
5
|
const text = (t) => ({ content: [{ type: "text", text: t }] });
|
|
5
6
|
const textError = (t) => ({ content: [{ type: "text", text: t }], isError: true });
|
|
6
7
|
const READ_ONLY = { readOnlyHint: true, openWorldHint: true };
|
|
@@ -52,6 +53,42 @@ export function createServer() {
|
|
|
52
53
|
return textError(errorMessage(e));
|
|
53
54
|
}
|
|
54
55
|
});
|
|
56
|
+
server.registerTool("all_senses", {
|
|
57
|
+
title: "All senses",
|
|
58
|
+
description: "Every sense Jisho lists for a word, with all English definitions, parts of speech, usage restrictions, see-also and antonym cross references and external reference links.",
|
|
59
|
+
inputSchema: z.object({ keyword: z.string().describe("e.g. '水' or 'daijoubu'"), limit: z.number().int().min(1).max(8).default(3).describe("Max entries") }),
|
|
60
|
+
annotations: READ_ONLY,
|
|
61
|
+
}, async (args) => {
|
|
62
|
+
// ---- paywall: all_senses ----
|
|
63
|
+
const paywallMessage = await premiumRequired("all_senses");
|
|
64
|
+
if (paywallMessage)
|
|
65
|
+
return { content: [{ type: "text", text: paywallMessage }], isError: true };
|
|
66
|
+
// ---- paywall: end ----
|
|
67
|
+
try {
|
|
68
|
+
return text(await allSenses(args));
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
return textError(errorMessage(e));
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
server.registerTool("words_by_reading", {
|
|
75
|
+
title: "Words by reading",
|
|
76
|
+
description: "Index a Japanese reading: every Jisho entry sharing that kana or romaji reading, with its written forms, sense count and JLPT level.",
|
|
77
|
+
inputSchema: z.object({ reading: z.string().describe("Reading in kana or romaji, e.g. 'みず'."), limit: z.number().int().min(1).max(20).default(12).describe("Max entries") }),
|
|
78
|
+
annotations: READ_ONLY,
|
|
79
|
+
}, async (args) => {
|
|
80
|
+
// ---- paywall: words_by_reading ----
|
|
81
|
+
const paywallMessage = await premiumRequired("words_by_reading");
|
|
82
|
+
if (paywallMessage)
|
|
83
|
+
return { content: [{ type: "text", text: paywallMessage }], isError: true };
|
|
84
|
+
// ---- paywall: end ----
|
|
85
|
+
try {
|
|
86
|
+
return text(await wordsByReading(args));
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
return textError(errorMessage(e));
|
|
90
|
+
}
|
|
91
|
+
});
|
|
55
92
|
return server;
|
|
56
93
|
}
|
|
57
94
|
function errorMessage(e) {
|
package/package.json
CHANGED