Skip to content

Commit d6c86ed

Browse files
authored
Merge pull request #46 from cvaldit/add-random-string-tool-name
add random string
2 parents 38b32de + ed2e858 commit d6c86ed

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/tools/index.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,43 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
22
import { executeSqlToolHandler, executeSqlSchema } from "./execute-sql.js";
33
import { listConnectorsToolHandler } from "./list-connectors.js";
44

5+
/**
6+
* Generate a random string of specified length
7+
*/
8+
function generateRandomString(length: number): string {
9+
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
10+
let result = '';
11+
const charactersLength = characters.length;
12+
for (let i = 0; i < length; i++) {
13+
result += characters.charAt(Math.floor(Math.random() * charactersLength));
14+
}
15+
return result;
16+
}
17+
18+
// Generate tool names with random suffixes when the module is loaded
19+
const EXECUTE_SQL_TOOL_NAME = `execute_sql_${generateRandomString(8)}`;
20+
const LIST_CONNECTORS_TOOL_NAME = `list_connectors_${generateRandomString(8)}`;
21+
522
/**
623
* Register all tool handlers with the MCP server
724
*/
825
export function registerTools(server: McpServer): void {
926
// Tool to run a SQL query (read-only for safety)
1027
server.tool(
11-
"execute_sql",
28+
EXECUTE_SQL_TOOL_NAME,
1229
"Execute a SQL query on the current database",
1330
executeSqlSchema,
1431
executeSqlToolHandler
1532
);
1633

1734
// Tool to list available database connectors
1835
server.tool(
19-
"list_connectors",
36+
LIST_CONNECTORS_TOOL_NAME,
2037
"List all available database connectors",
2138
{},
2239
listConnectorsToolHandler
2340
);
2441
}
42+
43+
// Export the tool names so they can be accessed from other modules if needed
44+
export { EXECUTE_SQL_TOOL_NAME, LIST_CONNECTORS_TOOL_NAME };

0 commit comments

Comments
 (0)