Skip to content

Commit 365d929

Browse files
author
Daniele Briggi
committed
feat(tools); dynamically add custom tools
1 parent 40f2428 commit 365d929

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/server.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,28 @@ export class SQLiteCloudMcpServer {
4242
return transport
4343
}
4444

45+
addCustomTool(
46+
name: string,
47+
description: string,
48+
parameters: z.ZodRawShape,
49+
handler: (parameters: any, transport: SQLiteCloudMcpTransport) => Promise<any>
50+
): void {
51+
// TODO: keep a registered list of tools to check existence and to implement removal
52+
this.mcpServer.tool(name, description, parameters, async (parameters, extra) => {
53+
if (!extra.sessionId) {
54+
throw new Error('Session ID is required')
55+
}
56+
57+
const customerResult = await handler(parameters, this.getTransport(extra.sessionId))
58+
59+
return { content: [{ type: 'text', text: JSON.stringify(customerResult) }] }
60+
})
61+
}
62+
63+
removeCustomTool(name: string): void {
64+
throw new Error('Not implemented')
65+
}
66+
4567
private initializeServer(): McpServer {
4668
return new McpServer(
4769
{

0 commit comments

Comments
 (0)