MCP: tools, search and categories
Polaris is one MCP server (/api/mcp) for every app installed in it. A model
connects once and reaches home, mail, calendar, games and the rest through it, so
two things matter more than any single tool: the model has to be able to find
what it is looking for, and a person has to be able to read what they are
granting. This page is how to add to it without breaking either.
| Piece | Where |
|---|---|
Protocol, McpTool, toolCategory |
apps/web/src/lib/mcp/protocol.ts |
| Scopes and categories | apps/web/src/lib/mcp/scope-table.ts |
| Core tools and search providers | apps/web/src/lib/mcp/tools/*.ts, listed in tools/index.ts |
polaris_search, polaris_tools |
apps/web/src/lib/mcp/tools/discovery.ts, lib/mcp/search.ts |
| Tolerant matching | packages/core/src/entity-match.ts |
| Labels | apps/web/messages/<locale>/mcp.json |
Add a tool
- Write it with
defineMcpTool(core) orhost.mcp.defineTool(an installable app). Required:name(<app>_<verb>, lowercase),description(the first sentence is whatpolaris_toolsshows), a Zodinput,scope, andreadOnly. Setdestructiveandidempotenton anything that writes. categoryis optional: without it the tool is listed under its first scope's category. Set it only when that would be wrong.- Register it. Core: add it to the list in
tools/index.ts. An app: return it from themcpToolshook of its extension (seeapps/places/src/lib/places-extension.ts). The catalogue (lib/mcp/catalog.ts) drops, and logs, an app tool whose name is taken or whose scope is not in the table. - If it takes a search text, match with
findEntities/matchForModelfrom@polaris/core, neverincludes(). They fold accents and case, know the English and Spanish words for each kind of thing ("puerta" finds a lock), forgive typos, and never answer empty while something is reachable: with no match they return the closest rows, bounded, with a sentence that says so. A store too large to list (mail) filters in its own query first and ranks what comes back. - Enforce everything finer than the scope inside
run, with the same checks the app's screens use (placesReach, the task layer's visible scope). The scope only says the credential may use the tool. - Test it the way
test/mcp/app-tools-places-games.test.tsdoes: throughhandleMcpMessage, with the scopes a real grant would carry.
Add a search provider
Every app that owns things a person names (devices, servers, notes) should be
findable from polaris_search. A provider:
host.mcp.defineSearch({
id: "databases.connections", // unique, <app>.<what>
app: "databases",
category: "databases",
scope: "databases.read", // or a list, any one of which will do
async search(query, caller, limit) {
const rows = await reachableConnections(caller.userId, limit);
return rows.map((row) => ({
id: row.id,
name: row.name,
kind: "database",
where: row.server,
keywords: [row.engine], // found by these, not shown
next: [{ tool: "databases_query", args: { connectionId: row.id } }]
}));
}
});- Return candidates, not a verdict. Ranking happens once, in
searchEverywhere, so every app's hits are ordered by the same rule. A provider that reads more rows thanlimitpasses them throughpreferMatchesso what it drops is what the query did not name. - Return only what the caller reaches. The provider is asked only when the caller holds its scope; per-item access is the provider's job.
- It has
PROVIDER_TIMEOUT_MS(4 s) andPROVIDER_LIMIT(200 hits). One that throws or runs out of time is left out and named in the answer; the search still answers. nextsteps naming a tool the caller cannot call are removed for you.- Register it: core in
MCP_SEARCH_PROVIDERS(tools/index.ts), an app from themcpSearchhook of its extension.
Add a category
- Add the id to
MCP_CATEGORIESinscope-table.ts, where the order is the order screens andpolaris_toolsshow them. - Add
categories.<id>tomessages/<locale>/mcp.jsonin every locale. A test (test/mcp/scope-table.test.ts) fails while any locale lacks it. - File scopes under it: a permission in
PERMISSION_CATEGORIES(aRecordover every permission, so a new permission without a category does not compile), a finer MCP-only scope by itscategoryinMCP_ONLY_SCOPES.
Add a scope
One line in scope-table.ts and its label scopes.<area>_<verb> in each
locale's mcp.json. Mark it sensitive when it acts outside Polaris or on the
physical world (sending mail, unlocking a door): the consent screen never ticks
it for the person, and a category's "allow everything" box leaves it alone.