Skip to content

Commit e71708d

Browse files
committed
feat: use enhanced register.Tool interface
1 parent 19e1b73 commit e71708d

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

src/tools/execute-sql.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ function areAllStatementsReadOnly(sql: string, connectorType: ConnectorType): bo
9595
* @returns A handler function bound to the specified source
9696
*/
9797
export function createExecuteSqlToolHandler(sourceId?: string) {
98-
return async ({ sql }: { sql: string }, extra: any) => {
98+
return async (args: any, extra: any) => {
99+
const { sql } = args as { sql: string };
99100
const startTime = Date.now();
100101
const effectiveSourceId = sourceId || "default";
101102
let success = true;

src/tools/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ export function registerTools(server: McpServer): void {
2020
for (const sourceId of sourceIds) {
2121
const metadata = getToolMetadataForSource(sourceId);
2222

23-
server.tool(
23+
server.registerTool(
2424
metadata.name,
25-
metadata.description,
26-
metadata.schema,
25+
{
26+
description: metadata.description,
27+
inputSchema: metadata.schema,
28+
annotations: metadata.annotations,
29+
},
2730
createExecuteSqlToolHandler(sourceId)
2831
);
2932
}

src/utils/tool-metadata.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { z } from "zod";
2+
import { ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
23
import { ConnectorManager } from "../connectors/manager.js";
34
import { normalizeSourceId } from "./normalize-id.js";
45
import { executeSqlSchema } from "../tools/execute-sql.js";
@@ -29,6 +30,7 @@ export interface ToolMetadata {
2930
name: string;
3031
description: string;
3132
schema: Record<string, z.ZodType<any>>;
33+
annotations: ToolAnnotations;
3234
}
3335

3436
/**
@@ -79,19 +81,42 @@ export function zodToParameters(schema: Record<string, z.ZodType<any>>): ToolPar
7981
export function getToolMetadataForSource(sourceId: string): ToolMetadata {
8082
const sourceIds = ConnectorManager.getAvailableSourceIds();
8183
const sourceConfig = ConnectorManager.getSourceConfig(sourceId);
84+
const executeOptions = ConnectorManager.getCurrentExecuteOptions(sourceId);
8285
const dbType = sourceConfig?.type || "database";
8386

8487
// Determine tool name based on single vs multi-source configuration
8588
const toolName = sourceId === "default" ? "execute_sql" : `execute_sql_${normalizeSourceId(sourceId)}`;
8689

87-
// Determine description
90+
// Determine title (human-readable display name)
8891
const isDefault = sourceIds[0] === sourceId;
89-
const description = `Execute a SQL query on the '${sourceId}' ${dbType} database${isDefault ? " (default)" : ""}`;
92+
const title = isDefault
93+
? `Execute SQL (${dbType})`
94+
: `Execute SQL on ${sourceId} (${dbType})`;
95+
96+
// Determine description with more context
97+
const readonlyNote = executeOptions.readonly ? " [READ-ONLY MODE]" : "";
98+
const maxRowsNote = executeOptions.maxRows ? ` (limited to ${executeOptions.maxRows} rows)` : "";
99+
const description = `Execute SQL queries on the '${sourceId}' ${dbType} database${isDefault ? " (default)" : ""}${readonlyNote}${maxRowsNote}`;
100+
101+
// Build annotations object with all standard MCP hints
102+
const isReadonly = executeOptions.readonly === true;
103+
const annotations = {
104+
title,
105+
readOnlyHint: isReadonly,
106+
destructiveHint: !isReadonly, // Can be destructive if not readonly
107+
// In readonly mode, queries are more predictable (though still not strictly idempotent due to data changes)
108+
// In write mode, queries are definitely not idempotent
109+
idempotentHint: false,
110+
// In readonly mode, it's safer to operate on arbitrary tables (just reading)
111+
// In write mode, operating on arbitrary tables is more dangerous
112+
openWorldHint: isReadonly,
113+
};
90114

91115
return {
92116
name: toolName,
93117
description,
94118
schema: executeSqlSchema,
119+
annotations,
95120
};
96121
}
97122

0 commit comments

Comments
 (0)