/api/v1/search keeps to one repository for ?repo=owner/name and repo: in q, as the MCP search tool does
Live: /api/v1/search?q=Modrinth finds no trevato/forge issue (#17865, #17867): unscoped search reads only the first MAX_SEARCH_REPOS (50) visible repos, trevato/forge isn't among them. SearchInput.repo reaches past that cap and the MCP tool uses it (#16463, reads.ts searchRun); the REST route never passes it: ?repo= is ignored and q=repo:trevato/forge sweep searches the literal text. (/search page: same gap; API only here.)
src/http/api.ts: import repoQualifier from ../core/search.ts; above the search route add
/** The repository a search's `?repo=`/`repo:` names: 422 if not owner/name; the 404 of a missing one if unreadable. */functionsearchScope(ctx:Ctx, named:string):Repo|Response{const[owner, name,...rest]= named.split("/");if(!owner ||!name || rest.length>0)returnapiError("invalid_repo",422,"repo is owner/name");const repo =getRepo(ctx.app.db, owner, name);return repo !==undefined&&canRead(ctx.app.db, repo, ctx.auth.user)? repo :notFound();}
In the route, replace const query = q.get("q") ?? ""; with
// `repo:owner/name` in the words is the `repo` scope, as on the MCP tool (#16463).const qualified =repoQualifier(q.get("q")??"");const query = qualified.q;if(qualified.repo!==undefined&& q.has("repo")&& q.get("repo")!== qualified.repo)returnapiError("invalid_repo",422,"q names one repository with repo: and repo another: give one");const named = qualified.repo?? q.get("repo")??undefined;const only = named ===undefined?undefined:searchScope(ctx, named);if(only instanceofResponse)return only;const mine =runRepos(ctx.app, ctx.auth);const within = mine ===undefined|| only ===undefined? mine : mine.filter((r)=> r.id=== only.id);if(only !==undefined&& within !==undefined&& within.length===0)returnnotFound();
then drop the old const mine = runRepos(...) in the try, add ...(only !== undefined ? { repo: only } : {}), to input, use within for mine in the search/searchWithin call, and searchNote(query, kind).
Test, test/mcp-search.test.ts, in describe("MCP search") after the "repo: written into q" test (reuses pebble, secretpebble, noisy's SEARCH_LIMIT+5 newer glow issues):
test("/api/v1/search takes the same scope, as ?repo= or repo: in q; a second, malformed or unreadable one is refused",async()=>{const api =async(path:string, token?:string)=>{const res =awaitfetch(`${servers.url}/api/v1/search?${path}`, token ===undefined?{}:{ headers:{ authorization:`Bearer ${token}`}});const text =await res.text();return{ status: res.status, body:(text ===""?{}:JSON.parse(text))asany};};const names =(r:{ body:any})=> r.body.issues.map((i:any)=> i.repo.name);expect(names(awaitapi("q=glow&kind=issues", aliceRo))).not.toContain("pebble");for(const p of["q=glow&kind=issues&repo=alice/pebble","q=glow%20repo:alice/pebble&kind=issues","q=REPO:alice/pebble%20glow&kind=issues&repo=alice/pebble"])expect(names(awaitapi(p, aliceRo))).toEqual(["pebble"]);expect(names(awaitapi("q=glow%20repo:alice/pebble&kind=issues"))).toEqual(["pebble"]);expect((awaitapi("q=glow%20repo:alice/pebble&repo=alice/noisy", aliceRo)).body.error).toBe("invalid_repo");for(const repo of["pebble","alice/","a/b/c",""])expect((awaitapi(`q=glow&repo=${repo}`, aliceRo)).status).toBe(422);expect((awaitapi("q=glow&repo=alice/secretpebble", bobRo)).status).toBe(404);expect((awaitapi("q=glow&repo=alice/nothing-here", aliceRo)).status).toBe(404);});
On main it fails at the first toEqual(["pebble"]) (repo ignored). Risk: none to an unscoped search.
/api/v1/search keeps to one repository for ?repo=owner/name and repo: in q, as the MCP search tool does
Live:
/api/v1/search?q=Modrinthfinds no trevato/forge issue (#17865, #17867): unscoped search reads only the first MAX_SEARCH_REPOS (50) visible repos, trevato/forge isn't among them.SearchInput.reporeaches past that cap and the MCP tool uses it (#16463, reads.ts searchRun); the REST route never passes it:?repo=is ignored andq=repo:trevato/forge sweepsearches the literal text. (/search page: same gap; API only here.)src/http/api.ts: import
repoQualifierfrom ../core/search.ts; above the search route addIn the route, replace
const query = q.get("q") ?? "";withthen drop the old
const mine = runRepos(...)in the try, add...(only !== undefined ? { repo: only } : {}),toinput, usewithinforminein the search/searchWithin call, andsearchNote(query, kind).Contract getApiV1Search.ts: query
repo: "string"; refusalsinvalid_repo(422),not_found(404).Test, test/mcp-search.test.ts, in describe("MCP search") after the "repo: written into q" test (reuses pebble, secretpebble, noisy's SEARCH_LIMIT+5 newer glow issues):
On main it fails at the first toEqual(["pebble"]) (repo ignored). Risk: none to an unscoped search.