matter.work
Building Apps / The SDK

Search

Answer searches in ⌘K and the @ menu with your app's own records, and let agents read them.

Your app can answer searches. When a member types in the command menu (⌘K) or the @ menu, Matter asks one of your tools too, and shows what it finds under your app’s name. Picking a result in ⌘K opens your app at the result’s path. Picking one in the @ menu writes a link to it, which an agent can follow to read the record. This is how records that aren’t in any table can be found.

Name two of your tools in search: one that finds records, and, if agents may read them, one that reads one.

matter.json
{
  "tools": {
    "search_mail": {
      "description": "Mail matching what the member typed.",
      "input": {
        "type": "object",
        "properties": { "query": { "type": "string" }, "limit": { "type": "integer" } },
        "required": ["query"]
      }
    },
    "read_mail": {
      "description": "One message, by its path.",
      "input": { "type": "object", "properties": { "path": { "type": "string" } }, "required": ["path"] }
    }
  },
  "search": { "find": "search_mail", "read": "read_mail" }
}
src/tools.ts
export default defineTools({
  search_mail: async ({ query, limit }) => {
    const found = await mailbox.find(query, limit)
    return found.map((message) => ({
      title: message.subject,
      subtitle: message.from,
      icon: 'mail',
      path: `/mail/${message.id}`,
    }))
  },
  read_mail: async ({ path }) => {
    const message = await mailbox.get(path.replace('/mail/', ''))
    return message ? { title: message.subject, text: `From: ${message.from}\n\n${message.body}` } : null
  },
})

Matter 0.5.31 and newer asks; older versions ignore search. Like your other tools, these run on whichever of the member’s computers they’re searching from, so they find what that computer can reach: your tables, the member’s connections, the web. Files your worker keeps on another computer aren’t there.

Answering#

  • Answer fast. Matter asks a moment after the member stops typing, waits under a second, then goes on without your answer. Its own results never wait for yours. The first search after a while starts your tools, which takes a moment more.
  • The find tool gets { query, limit } and returns at most limit results (5), as a list or as { results }. Matter shows five per app.
  • title and subtitle show as plain text on one line, cut at 120 and 160 characters. icon is a Lucide icon name.
  • path is a route of your app: one leading /, with a query string if it needs one, and no #. Results with any other path are left out.
  • A tool that throws, or answers late, shows nothing for that search.

Reading records#

A result picked in the @ menu becomes a link like matter://app/<app id>/mail/42. An agent reading the message follows it with its read_app_link tool, which calls your read tool with { path }. Return the record as text (Markdown is fine), or { title, text }, up to 50,000 characters; return null for one that isn’t there. Agents are told the text is your app’s data, not instructions.