Skip to content

Build your personal knowledge base with Trilium Notes

fix(llm): some tools were async

Elian Doran09be2822e082
diff --git a/apps/server/src/services/llm/tools/attachment_tools.ts b/apps/server/src/services/llm/tools/attachment_tools.ts
index 0f050f32a7..8b40de0e59 100644
--- a/apps/server/src/services/llm/tools/attachment_tools.ts
+++ b/apps/server/src/services/llm/tools/attachment_tools.ts
@@ -13,7 +13,7 @@ export const attachmentTools = defineTools({
inputSchema: z.object({
attachmentId: z.string().describe("The ID of the attachment to retrieve")
}),
- execute: async ({ attachmentId }) => {
+ execute: ({ attachmentId }) => {
const attachment = becca.getAttachment(attachmentId);
if (!attachment) {
return { error: "Attachment not found" };
@@ -36,7 +36,7 @@ export const attachmentTools = defineTools({
inputSchema: z.object({
attachmentId: z.string().describe("The ID of the attachment to read")
}),
- execute: async ({ attachmentId }) => {
+ execute: ({ attachmentId }) => {
const attachment = becca.getAttachment(attachmentId);
if (!attachment) {
return { error: "Attachment not found" };
diff --git a/apps/server/src/services/llm/tools/attribute_tools.ts b/apps/server/src/services/llm/tools/attribute_tools.ts
index ffb9b24bee..1df91bdea0 100644
--- a/apps/server/src/services/llm/tools/attribute_tools.ts
+++ b/apps/server/src/services/llm/tools/attribute_tools.ts
@@ -15,7 +15,7 @@ export const attributeTools = defineTools({
inputSchema: z.object({
noteId: z.string().describe("The ID of the note")
}),
- execute: async ({ noteId }) => {
+ execute: ({ noteId }) => {
const note = becca.getNote(noteId);
if (!note) {
return { error: "Note not found" };
@@ -38,7 +38,7 @@ export const attributeTools = defineTools({
inputSchema: z.object({
attributeId: z.string().describe("The ID of the attribute")
}),
- execute: async ({ attributeId }) => {
+ execute: ({ attributeId }) => {
const attribute = becca.getAttribute(attributeId);
if (!attribute) {
return { error: "Attribute not found" };
diff --git a/apps/server/src/services/llm/tools/hierarchy_tools.ts b/apps/server/src/services/llm/tools/hierarchy_tools.ts
index 7daa27742f..cb75941c5e 100644
--- a/apps/server/src/services/llm/tools/hierarchy_tools.ts
+++ b/apps/server/src/services/llm/tools/hierarchy_tools.ts
@@ -60,7 +60,7 @@ export const hierarchyTools = defineTools({
inputSchema: z.object({
noteId: z.string().describe("The ID of the parent note (use 'root' for top-level)")
}),
- execute: async ({ noteId }) => {
+ execute: ({ noteId }) => {
const note = becca.getNote(noteId);
if (!note) {
return { error: "Note not found" };
@@ -81,7 +81,7 @@ export const hierarchyTools = defineTools({
noteId: z.string().describe("The ID of the root note for the subtree (use 'root' for the entire tree)"),
depth: z.number().min(1).max(MAX_DEPTH).optional().describe(`How many levels deep to traverse (1-${MAX_DEPTH}). Defaults to 2.`)
}),
- execute: async ({ noteId, depth = 2 }) => {
+ execute: ({ noteId, depth = 2 }) => {
const note = becca.getNote(noteId);
if (!note) {
return { error: "Note not found" };
diff --git a/apps/server/src/services/llm/tools/note_tools.ts b/apps/server/src/services/llm/tools/note_tools.ts
index 1702eeab54..2daa55a1ca 100644
--- a/apps/server/src/services/llm/tools/note_tools.ts
+++ b/apps/server/src/services/llm/tools/note_tools.ts
@@ -32,7 +32,7 @@ export const noteTools = defineTools({
ancestorNoteId: z.string().optional().describe("Limit search to a subtree rooted at this note ID."),
limit: z.number().optional().describe("Maximum number of results to return. Defaults to 10.")
}),
- execute: async ({ query, fastSearch, includeArchivedNotes, ancestorNoteId, limit = 10 }) => {
+ execute: ({ query, fastSearch, includeArchivedNotes, ancestorNoteId, limit = 10 }) => {
const searchContext = new SearchContext({
fastSearch,
includeArchivedNotes,
@@ -65,7 +65,7 @@ export const noteTools = defineTools({
inputSchema: z.object({
noteId: z.string().describe("The ID of the note to retrieve")
}),
- execute: async ({ noteId }) => {
+ execute: ({ noteId }) => {
const note = becca.getNote(noteId);
if (!note) {
return { error: "Note not found" };
@@ -80,7 +80,7 @@ export const noteTools = defineTools({
inputSchema: z.object({
noteId: z.string().describe("The ID of the note to read")
}),
- execute: async ({ noteId }) => {
+ execute: ({ noteId }) => {
const note = becca.getNote(noteId);
if (!note) {
return { error: "Note not found" };
diff --git a/apps/server/src/services/llm/tools/tool_registry.ts b/apps/server/src/services/llm/tools/tool_registry.ts
index b8a1b6995e..35fc225182 100644
--- a/apps/server/src/services/llm/tools/tool_registry.ts
+++ b/apps/server/src/services/llm/tools/tool_registry.ts
@@ -36,8 +36,8 @@ interface ReadOnlyToolDefinition {
description: string;
inputSchema: z.ZodType;
mutates?: false;
- /** Execute the tool. May be async for read-only operations. */
- execute: (args: any) => unknown;
+ /** Execute the tool synchronously. Kept sync for consistency with MCP. */
+ execute: (args: any) => NotAPromise<object>;
}
export type ToolDefinition = MutatingToolDefinition | ReadOnlyToolDefinition;
@@ -86,8 +86,8 @@ export class ToolRegistry implements Iterable<[string, ToolDefinition]> {
* });
* ```
*
- * Note: Mutating tools (mutates: true) MUST have synchronous execute functions
- * because better-sqlite3 transactions are synchronous.
+ * Note: All tools MUST have synchronous execute functions (no async/await)
+ * because better-sqlite3 transactions are synchronous and MCP expects sync results.
*/
export function defineTools(tools: Record<string, ToolDefinition>): ToolRegistry {
return new ToolRegistry(tools);