@@ -88,77 +88,21 @@ async def handle_list_tools() -> list[types.Tool]:
88
88
"""List available tools"""
89
89
tools = [
90
90
types .Tool (
91
- name = "read- query" ,
92
- description = "Execute a SELECT query on the DuckDB database" ,
91
+ name = "query" ,
92
+ description = "Execute a query on the DuckDB database" ,
93
93
inputSchema = {
94
94
"type" : "object" ,
95
95
"properties" : {
96
96
"query" : {
97
97
"type" : "string" ,
98
- "description" : "SELECT SQL query to execute" ,
98
+ "description" : "SQL query to execute" ,
99
99
},
100
100
},
101
101
"required" : ["query" ],
102
102
},
103
103
),
104
- types .Tool (
105
- name = "list-tables" ,
106
- description = "List all tables in the DuckDB database" ,
107
- inputSchema = {
108
- "type" : "object" ,
109
- "properties" : {},
110
- },
111
- ),
112
- types .Tool (
113
- name = "describe-table" ,
114
- description = "Get the schema information for a specific table" ,
115
- inputSchema = {
116
- "type" : "object" ,
117
- "properties" : {
118
- "table_name" : {
119
- "type" : "string" ,
120
- "description" : "Name of the table to describe" ,
121
- },
122
- },
123
- "required" : ["table_name" ],
124
- },
125
- ),
126
104
]
127
105
128
- if not config .readonly :
129
- tools .extend (
130
- [
131
- types .Tool (
132
- name = "write-query" ,
133
- description = "Execute an INSERT, UPDATE, or DELETE query on the DuckDB database" ,
134
- inputSchema = {
135
- "type" : "object" ,
136
- "properties" : {
137
- "query" : {
138
- "type" : "string" ,
139
- "description" : "SQL query to execute" ,
140
- },
141
- },
142
- "required" : ["query" ],
143
- },
144
- ),
145
- types .Tool (
146
- name = "create-table" ,
147
- description = "Create a new table in the DuckDB database" ,
148
- inputSchema = {
149
- "type" : "object" ,
150
- "properties" : {
151
- "query" : {
152
- "type" : "string" ,
153
- "description" : "CREATE TABLE SQL statement" ,
154
- },
155
- },
156
- "required" : ["query" ],
157
- },
158
- ),
159
- ]
160
- )
161
-
162
106
return tools
163
107
164
108
@server .call_tool ()
@@ -167,35 +111,12 @@ async def handle_call_tool(
167
111
) -> list [types .TextContent | types .ImageContent | types .EmbeddedResource ]:
168
112
"""Handle tool execution requests"""
169
113
try :
170
- if name == "list-tables" :
171
- results = db .execute_query ("SELECT * FROM information_schema.tables;" )
172
- return [types .TextContent (type = "text" , text = str (results ))]
173
-
174
- elif name == "describe-table" :
175
- if not arguments or "table_name" not in arguments :
176
- raise ValueError ("Missing table_name argument" )
177
- results = db .execute_query ("PRAGMA table_info(?)" , [arguments ["table_name" ]])
178
- return [types .TextContent (type = "text" , text = str (results ))]
179
-
180
114
if not arguments :
181
115
raise ValueError ("Missing arguments" )
182
116
183
- if name == "read-query" :
184
- results = db .execute_query (arguments ["query" ])
185
- return [types .TextContent (type = "text" , text = str (results ))]
186
-
187
- elif name == "write-query" :
188
- if arguments ["query" ].strip ().upper ().startswith ("SELECT" ):
189
- raise ValueError ("SELECT queries are not allowed for write-query" )
117
+ if name == "query" :
190
118
results = db .execute_query (arguments ["query" ])
191
119
return [types .TextContent (type = "text" , text = str (results ))]
192
-
193
- elif name == "create-table" :
194
- if not arguments ["query" ].strip ().upper ().startswith ("CREATE TABLE" ):
195
- raise ValueError ("Only CREATE TABLE statements are allowed" )
196
- db .execute_query (arguments ["query" ])
197
- return [types .TextContent (type = "text" , text = "Table created successfully" )]
198
-
199
120
else :
200
121
raise ValueError (f"Unknown tool: { name } " )
201
122
0 commit comments