Add your own agent tools
Give agents your app's own features, such as folders and pins, as tools Undertext's MCP server lists beside its own and forwards to your server.
Undertext's MCP server gives agents everything about documents: reading, writing, suggesting and commenting. It doesn't know about the things your app keeps itself, such as folders, pins, tags, projects or due dates. To let agents use those too, register tools of your own with Undertext. Its server lists them beside its own, at the same address, and forwards each call to your server, signed, saying which agent is calling and for whom.
By the end of this guide, an agent can file a document it just wrote into one of your folders, with nothing more for your users to connect.
How it fits
| Undertext's tools | Yours | |
|---|---|---|
| Address | Your MCP address, https://mcp.undertext.sh/acme | The same |
| Tools | Documents: read, write, suggest, comment | Your features: folders, pins, tags |
| Runs on | Undertext | Your server, called by Undertext |
| Sign-in | Undertext's, via your consent page | The same: one approval covers both |
Document ids are the same in both: doc_8Hq2Lm4R in Undertext's list_documents is the id your folders table already stores. So an agent can find a document with Undertext's tools and file it with yours, without any translation.
Keep document text in Undertext's tools. Your tools never write text into a document: words that don't come through Undertext's own tools or editor aren't credited to whoever wrote them.
Register your tools
-
Describe them. Each tool is a name, a description and a JSON Schema for its arguments, as MCP describes tools. Names can't be one of Undertext's own. Say in
instructionshow your tools relate to Undertext's, so agents use the two together.tools.ts export const TOOLS = [ { name: "list_folders", title: "List folders", description: "The person's folders, in their order, with the documents in each.", inputSchema: { type: "object", properties: {}, additionalProperties: false }, }, { name: "move_document", title: "Move document", description: "File a document in one of the person's folders, or in none with folder_id null. Only when they ask.", inputSchema: { type: "object", properties: { document_id: { type: "string" }, folder_id: { type: ["string", "null"] } }, required: ["document_id", "folder_id"], additionalProperties: false, }, }, ]; -
Register them when your server starts, with the address Undertext sends calls to and a secret of at least 32 characters, which you choose and keep:
server.ts await undertext.platform.setTools({ url: "https://acme.com/undertext/tools", secret: process.env.ACME_TOOLS_SECRET!, instructions: "Folders are the person's own: list_folders shows them, move_document files a document in one.", tools: TOOLS, });Each call replaces what you registered before. Agents see the change at their next
tools/list. -
Answer the calls. Undertext posts each call as JSON, signed in an
Undertext-Signatureheader as webhooks are:{ "tool": "move_document", "arguments": { "document_id": "doc_8Hq2Lm4R", "folder_id": "fld_2" }, "agent": { "id": "agt_3Vn8Qx2K", "name": "Claude Code", "access": "all" }, "user": "usr_5Kq2Lm8R" }useris the Undertext id of the person the agent acts for. Check the signature, run the tool for that person, and answer within 10 seconds with{ "text": … }, what to tell the agent, and optionallydata, given to it as structured content; or with{ "error": … }to refuse.tools.ts import { verifySignature } from "@undertext/sdk"; app.post("/undertext/tools", express.raw({ type: "application/json" }), async (req, res) => { if (!verifySignature(req.body, req.get("Undertext-Signature"), process.env.ACME_TOOLS_SECRET!)) return res.sendStatus(401); const call = JSON.parse(String(req.body)); const user = await db.users.findByUndertextId(call.user); if (!user) return res.json({ error: "That person has no account here." }); switch (call.tool) { case "list_folders": { const folders = await db.folders.list(user.id); return res.json({ text: folders.map((f) => `- ${f.name} (folder_id: ${f.id})`).join("\n"), data: { folders } }); } case "move_document": { const { document_id, folder_id } = call.arguments; const mine = await undertext.users.listDocuments(call.user, { ids: [document_id] }); if (!mine.data.length) return res.json({ error: `No document ${document_id} for this person.` }); await db.folders.place(user.id, document_id, folder_id); return res.json({ text: "Moved." }); } } res.json({ error: `Unknown tool ${call.tool}.` }); });Check access against Undertext, as
move_documentdoes, so your tools never reach a document the person can't open.agent.accesssays whether the agent may reach all its person's documents or only those chosen for it; refuse what an agent with chosen documents shouldn't see, such as a list of every folder.
An answer that isn't JSON, is over 1 MB, has a status other than 2xx, or doesn't come in time reaches the agent as a failed call.