cc0-library-mcp 0.2.4 → 0.2.5

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 CHANGED
@@ -142,10 +142,12 @@ claude mcp add cc0-library -- node "$PWD/dist/index.js"
142
142
 
143
143
  | Tool | Input | Returns |
144
144
  |---|---|---|
145
- | `search_assets` | `query`, `kind` (`image`·`audio`·`video`·`hdri`·`texture`·`model`·`artwork`·`collection`·`any`, default `any`; `any` excludes `collection`), `limit` 1–20, `page` 1–12 | CC0 assets, per-provider totals, per-provider errors |
145
+ | `search_assets` | `query`, `kind` (`image`·`audio`·`video`·`hdri`·`texture`·`model`·`artwork`·`collection`·`any`, default `any`; `any` excludes `collection`), `limit` 1–20, `page` 1–12, optional `providers` (e.g. `["iconify"]` for icons) | CC0 assets ranked by query words in title and tags, per-provider totals, per-provider errors |
146
146
  | `get_asset` | `id` from `search_assets` (`openverse:image:<uuid>`, `openverse:audio:<uuid>`, `polyhaven:<slug>`, `ambientcg:<assetId>`, `cleveland:<number>`, `met:<number>`, `commons:<pageid>`, `archive:<identifier>`, `sketchfab:<uid>`, `wpphotos:<number>`, `inaturalist:<n>`, `gbif:<n>`, `phylopic:<uuid>`, `iconify:<set>:<icon>`, `zenodo:<n>`, `blenderkit:<uuid>`, `github:<owner>/<repo>`, `huggingface:<owner>/<dataset>`) | Details plus download URLs (Poly Haven: up to 60 map/resolution/format files; Sketchfab: model page only, because downloads need the user's own login) |
147
147
  | `list_sources` | `kind` (optional) | Curated catalog, the non-CC0 list, and the pending-verification list |
148
148
 
149
+ Results are ranked by how many query words appear in each item's title (weight 2) or tags (weight 1); ties alternate between providers. Loose matches, such as a GBIF record that mentions the word only in its locality, sink below exact ones.
150
+
149
151
  If one provider fails, `search_assets` still returns results from the other providers and lists the failure in `errors`. Gateway errors (HTTP 502/503/504) are retried once.
150
152
 
151
153
  The Met's search returns object IDs only, so the server fetches each object and drops non-public-domain ones. A Met page can therefore hold fewer items than `limit`.
package/dist/http.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * Poly Haven's API terms require a User-Agent that names the calling app.
3
3
  * Openverse also asks clients to identify themselves.
4
4
  */
5
- export const USER_AGENT = "cc0-library-mcp/0.2.4 (+https://github.com/sanghyoLe/cc0-library)";
5
+ export const USER_AGENT = "cc0-library-mcp/0.2.5 (+https://github.com/sanghyoLe/cc0-library)";
6
6
  const TIMEOUT_MS = 15_000;
7
7
  export class UpstreamError extends Error {
8
8
  provider;
package/dist/library.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { readFileSync } from "node:fs";
2
2
  import { fileURLToPath } from "node:url";
3
- export { search, getAsset, interleave } from "./search.js";
3
+ export { search, getAsset, interleave, rank, relevance } from "./search.js";
4
4
  const CATALOG_PATH = fileURLToPath(new URL("../catalog/sources.json", import.meta.url));
5
5
  export function loadCatalog() {
6
6
  return JSON.parse(readFileSync(CATALOG_PATH, "utf8"));
@@ -21,6 +21,13 @@ const list = (v) => (Array.isArray(v) ? v : v ? [v] : []);
21
21
  export function sanitizeQuery(q) {
22
22
  return q.replace(/[^\p{L}\p{N}\s]/gu, " ").replace(/\b(AND|OR|NOT|TO)\b/g, " ").replace(/\s+/g, " ").trim();
23
23
  }
24
+ /**
25
+ * Items titled like an archive or disk image (e.g. "pack 2026.7z") have no
26
+ * viewable media of their own, even when filed under an image or audio mediatype.
27
+ */
28
+ export function isPackedFile(doc) {
29
+ return /\.(7z|zip|rar|tar|gz|tgz|bz2|xz|iso|img|exe|dmg|bin)$/i.test((first(doc.title) ?? "").trim());
30
+ }
24
31
  export function isCc0(doc) {
25
32
  return !!doc.licenseurl && CC0_URL_RE.test(doc.licenseurl);
26
33
  }
@@ -56,7 +63,8 @@ export async function searchArchive(fetchImpl, kind, params) {
56
63
  for (const f of ["identifier", "title", "creator", "mediatype", "licenseurl", "subject"])
57
64
  qs.append("fl[]", f);
58
65
  const data = await getJson(fetchImpl, "Internet Archive", `${BASE}/advancedsearch.php?${qs}`);
59
- return { total: data.response.numFound, assets: data.response.docs.filter(isCc0).map(toAsset) };
66
+ const assets = data.response.docs.filter((d) => isCc0(d) && !isPackedFile(d)).map(toAsset);
67
+ return { total: data.response.numFound, assets };
60
68
  }
61
69
  export async function getArchive(fetchImpl, identifier) {
62
70
  if (!/^[A-Za-z0-9._-]+$/.test(identifier))
@@ -1,4 +1,4 @@
1
- import { getJson } from "../http.js";
1
+ import { UpstreamError, getJson } from "../http.js";
2
2
  import { CC0_LICENSE_URL } from "../types.js";
3
3
  /**
4
4
  * PhyloPic silhouettes of organisms (https://api.phylopic.org, no key).
@@ -69,7 +69,16 @@ export async function searchPhylopic(fetchImpl, params) {
69
69
  page: String(params.page - 1),
70
70
  embed_items: "true",
71
71
  });
72
- const data = await getJson(fetchImpl, "PhyloPic", `${BASE}/images?${qs}`, ACCEPT);
72
+ let data;
73
+ try {
74
+ data = await getJson(fetchImpl, "PhyloPic", `${BASE}/images?${qs}`, ACCEPT);
75
+ }
76
+ catch (e) {
77
+ // The API answers 404 when no taxon has this name: that is "no results", not a failure.
78
+ if (e instanceof UpstreamError && e.status === 404)
79
+ return { total: 0, assets: [] };
80
+ throw e;
81
+ }
73
82
  const items = (data._embedded?.items ?? []).filter(isCc0).slice(0, params.limit);
74
83
  return { total: data.totalItems ?? items.length, assets: items.map(toAsset) };
75
84
  }
package/dist/search.js CHANGED
@@ -19,9 +19,12 @@ import { getZenodo, searchZenodo } from "./providers/zenodo.js";
19
19
  import { getGithub, getHuggingface, searchGithub, searchHuggingface } from "./providers/collections.js";
20
20
  import { getBlenderkit, searchBlenderkit } from "./providers/blenderkit.js";
21
21
  /**
22
- * Runs one search across the providers that serve `kind`. With kind "any",
23
- * results from each provider are interleaved so one provider cannot crowd
24
- * out the others.
22
+ * Runs one search across the providers that serve `kind`. Results are first
23
+ * interleaved by provider, so one provider cannot crowd out the others, and
24
+ * then stably sorted by `relevance`: items whose title or tags contain the
25
+ * query words come first. Providers that match loosely (taxon or full-text
26
+ * search) return items that share no word with the query; those sink to the
27
+ * end instead of filling the first page.
25
28
  */
26
29
  export async function search(fetchImpl, query, kind, limit, page, options = {}) {
27
30
  const all = [];
@@ -68,7 +71,11 @@ export async function search(fetchImpl, query, kind, limit, page, options = {})
68
71
  all.push({ name: "huggingface", run: () => searchHuggingface(fetchImpl, params) });
69
72
  }
70
73
  const skip = new Set(options.skip ?? []);
71
- const run = all.filter((j) => !skip.has(j.name.split(":")[0]));
74
+ const only = options.providers?.length ? new Set(options.providers) : null;
75
+ const run = all.filter((j) => {
76
+ const id = j.name.split(":")[0];
77
+ return !skip.has(id) && (!only || only.has(id));
78
+ });
72
79
  const settled = await Promise.allSettled(run.map((j) => j.run()));
73
80
  const totals = {};
74
81
  const errors = [];
@@ -82,7 +89,45 @@ export async function search(fetchImpl, query, kind, limit, page, options = {})
82
89
  errors.push(`${run[i].name}: ${s.reason instanceof Error ? s.reason.message : String(s.reason)}`);
83
90
  }
84
91
  });
85
- return { query, kind, page, assets: interleave(lists).slice(0, limit), totals, errors };
92
+ return { query, kind, page, assets: rank(query, interleave(lists)).slice(0, limit), totals, errors };
93
+ }
94
+ /** Words of two or more letters or digits, lowercased; works for any script. */
95
+ function words(text) {
96
+ return text.toLowerCase().match(/[\p{L}\p{N}]{2,}/gu) ?? [];
97
+ }
98
+ /** Drops a plural "s"/"es" so "footsteps" matches "footstep" and "boxes" matches "box". */
99
+ function stem(w) {
100
+ if (w.length > 4 && w.endsWith("es"))
101
+ return w.slice(0, -2);
102
+ if (w.length > 3 && w.endsWith("s") && !w.endsWith("ss"))
103
+ return w.slice(0, -1);
104
+ return w;
105
+ }
106
+ const STOPWORDS = new Set(["a", "an", "and", "the", "of", "for", "with", "in", "on", "to", "or"]);
107
+ /**
108
+ * Share of the query's words found in the asset's title (weight 2) or tags
109
+ * (weight 1), from 0 to 2. A word matches when an asset word starts with its
110
+ * stem, so "sprite" matches "sprites" and "pixel" matches "pixelart".
111
+ * Scripts without spaces (e.g. Korean "고양이") also match as substrings.
112
+ */
113
+ export function relevance(query, asset) {
114
+ const q = [...new Set(words(query).filter((w) => !STOPWORDS.has(w)).map(stem))];
115
+ if (!q.length)
116
+ return 0;
117
+ const title = words(asset.title);
118
+ const tags = words(asset.tags.join(" "));
119
+ const hit = (list, w) => list.some((t) => t.startsWith(w) || (w.length >= 2 && !/^[a-z0-9]+$/.test(w) && t.includes(w)));
120
+ let score = 0;
121
+ for (const w of q)
122
+ score += hit(title, w) ? 2 : hit(tags, w) ? 1 : 0;
123
+ return score / q.length;
124
+ }
125
+ /** Stable sort by relevance; ties keep the interleaved provider order. */
126
+ export function rank(query, assets) {
127
+ return assets
128
+ .map((a, i) => ({ a, i, s: relevance(query, a) }))
129
+ .sort((x, y) => y.s - x.s || x.i - y.i)
130
+ .map((x) => x.a);
86
131
  }
87
132
  export function interleave(lists) {
88
133
  const out = [];
package/dist/server.js CHANGED
@@ -88,7 +88,7 @@ const result = (value) => ({
88
88
  });
89
89
  const fail = (message) => ({ content: [{ type: "text", text: message }], isError: true });
90
90
  export function createServer(fetchImpl = defaultFetch) {
91
- const server = new McpServer({ name: "cc0-library", version: "0.2.4" });
91
+ const server = new McpServer({ name: "cc0-library", version: "0.2.5" });
92
92
  server.registerTool("search_assets", {
93
93
  title: "Search CC0 assets across 17 sources",
94
94
  description: "Find CC0 1.0 (public-domain dedication) images, audio, video, HDRIs, textures, 3D models and museum artworks by keyword, " +
@@ -107,7 +107,7 @@ export function createServer(fetchImpl = defaultFetch) {
107
107
  .min(1)
108
108
  .max(20)
109
109
  .default(10)
110
- .describe("Maximum results to return, 1-20. With kind 'any' the sources are interleaved, so each contributes a few"),
110
+ .describe("Maximum results to return, 1-20. Results are ranked by how many query words appear in the title or tags; ties alternate between sources"),
111
111
  page: z
112
112
  .number()
113
113
  .int()
@@ -115,10 +115,18 @@ export function createServer(fetchImpl = defaultFetch) {
115
115
  .max(12)
116
116
  .default(1)
117
117
  .describe("1-based page; each source paginates independently. Request page 2+ only if `totals` shows more matches"),
118
+ providers: z
119
+ .array(z.enum(PROVIDER_IDS))
120
+ .min(1)
121
+ .max(PROVIDER_IDS.length)
122
+ .optional()
123
+ .describe("Search only these sources. Leave out to search every source for `kind`. Useful picks: ['iconify'] for icons, " +
124
+ "['polyhaven','ambientcg'] for studio-made textures and HDRIs, ['inaturalist','gbif'] for wildlife and specimens, " +
125
+ "['cleveland','met'] for museum art, ['openverse'] for sound effects"),
118
126
  },
119
127
  outputSchema: searchOutput,
120
128
  annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true },
121
- }, async ({ query, kind, limit, page }) => result(await search(fetchImpl, query, kind, limit, page)));
129
+ }, async ({ query, kind, limit, page, providers }) => result(await search(fetchImpl, query, kind, limit, page, { providers })));
122
130
  server.registerTool("get_asset", {
123
131
  title: "Get one CC0 asset with download files",
124
132
  description: "Fetch one asset's details and download files by an id from search_assets, re-checking at the source that it is still CC0. " +
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cc0-library-mcp",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "mcpName": "io.github.sanghyoLe/cc0-library",
5
5
  "description": "MCP server and web gallery for CC0-only assets (images, audio, video, HDRIs, textures, 3D models, museum art) from 8 sources, with license evidence per result.",
6
6
  "license": "MIT",