rails-pg-extras-mcp 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rails-pg-extras-mcp.rb +68 -14
- data/lib/rails_pg_extras_mcp/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72d363ce5cf74c8c22e8a636c3b908f27be10cc5a21691acd480b791ab9e8c33
|
4
|
+
data.tar.gz: 36f3cb7fd5c1784c727def8ea7ad4c6f572f21c301ce99440440e4d5843f1e62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5565add5c44d77aa22c20f238c5f87d1f6e537f03f2b1d40fee5a5bbde03ed46690d11ecfecdecf791d65c0d748a26eaae5940d8808163e2c335fc4bad3c29ef
|
7
|
+
data.tar.gz: 8f7235f0b1e8ec213379c2f98895522ca54eed4c3c4912d7c5773a377fb9e0207a638ace52f235b7a6012161ed3f543afa565ecb5281e1f5fc3a7f09039f04b5
|
data/lib/rails-pg-extras-mcp.rb
CHANGED
@@ -75,23 +75,18 @@ class ExplainBaseTool < FastMcp::Tool
|
|
75
75
|
create,
|
76
76
|
grant,
|
77
77
|
begin,
|
78
|
-
commit
|
79
|
-
;
|
78
|
+
commit
|
80
79
|
]
|
81
80
|
|
82
|
-
|
83
|
-
required(:query).filled(:string).description("The query to debug")
|
84
|
-
end
|
85
|
-
|
86
|
-
def call(query:)
|
81
|
+
def call(sql_query:)
|
87
82
|
connection = RailsPgExtras.connection
|
88
83
|
|
89
|
-
if DENYLIST.any? { |deny|
|
84
|
+
if DENYLIST.any? { |deny| sql_query.downcase.include?(deny) }
|
90
85
|
raise "This query is not allowed. It contains a denied keyword. Denylist: #{DENYLIST.join(", ")}"
|
91
86
|
end
|
92
87
|
|
93
88
|
connection.execute("BEGIN")
|
94
|
-
result = connection.execute("#{
|
89
|
+
result = connection.execute("#{sql_query}")
|
95
90
|
connection.execute("ROLLBACK")
|
96
91
|
|
97
92
|
result.to_a
|
@@ -101,28 +96,84 @@ end
|
|
101
96
|
class ExplainTool < ExplainBaseTool
|
102
97
|
description "EXPLAIN a query. It must be an SQL string, without the EXPLAIN prefix"
|
103
98
|
|
99
|
+
arguments do
|
100
|
+
required(:sql_query).filled(:string).description("The SQL query to debug")
|
101
|
+
end
|
102
|
+
|
104
103
|
def self.name
|
105
104
|
"explain"
|
106
105
|
end
|
107
106
|
|
108
|
-
def call(
|
109
|
-
if
|
107
|
+
def call(sql_query:)
|
108
|
+
if sql_query.downcase.include?("analyze")
|
110
109
|
raise "This query is not allowed. It contains a denied ANALYZE keyword."
|
111
110
|
end
|
112
111
|
|
113
|
-
super(
|
112
|
+
super(sql_query: "EXPLAIN #{sql_query}")
|
114
113
|
end
|
115
114
|
end
|
116
115
|
|
117
116
|
class ExplainAnalyzeTool < ExplainBaseTool
|
118
117
|
description "EXPLAIN ANALYZE a query. It must be an SQL string, without the EXPLAIN ANALYZE prefix"
|
119
118
|
|
119
|
+
arguments do
|
120
|
+
required(:sql_query).filled(:string).description("The SQL query to debug")
|
121
|
+
end
|
122
|
+
|
120
123
|
def self.name
|
121
124
|
"explain_analyze"
|
122
125
|
end
|
123
126
|
|
124
|
-
def call(
|
125
|
-
super(
|
127
|
+
def call(sql_query:)
|
128
|
+
super(sql_query: "EXPLAIN ANALYZE #{sql_query}")
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
class IndexInfoTool < FastMcp::Tool
|
133
|
+
description "Shows information about table indexes: name, table name, columns, index size, index scans, null frac"
|
134
|
+
|
135
|
+
arguments do
|
136
|
+
required(:table_name).filled(:string).description("The table name to get index info for")
|
137
|
+
end
|
138
|
+
|
139
|
+
def call(table_name:)
|
140
|
+
RailsPgExtras.index_info(args: { table_name: table_name }, in_format: :hash)
|
141
|
+
end
|
142
|
+
|
143
|
+
def self.name
|
144
|
+
"index_info"
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
class TableInfoTool < FastMcp::Tool
|
149
|
+
description "Shows information about a table: name, size, cache hit, estimated rows, sequential scans, indexes scans"
|
150
|
+
|
151
|
+
arguments do
|
152
|
+
required(:table_name).filled(:string).description("The table name to get info for")
|
153
|
+
end
|
154
|
+
|
155
|
+
def call(table_name:)
|
156
|
+
RailsPgExtras.table_info(args: { table_name: table_name }, in_format: :hash)
|
157
|
+
end
|
158
|
+
|
159
|
+
def self.name
|
160
|
+
"table_info"
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
class TableSchemaTool < FastMcp::Tool
|
165
|
+
description "Shows the schema of a table"
|
166
|
+
|
167
|
+
arguments do
|
168
|
+
required(:table_name).filled(:string).description("The table name to get schema for")
|
169
|
+
end
|
170
|
+
|
171
|
+
def call(table_name:)
|
172
|
+
RailsPgExtras.table_schema(args: { table_name: table_name }, in_format: :hash)
|
173
|
+
end
|
174
|
+
|
175
|
+
def self.name
|
176
|
+
"table_schema"
|
126
177
|
end
|
127
178
|
end
|
128
179
|
|
@@ -163,6 +214,9 @@ module RailsPgExtrasMcp
|
|
163
214
|
server.register_tools(DiagnoseTool)
|
164
215
|
server.register_tools(MissingFkConstraintsTool)
|
165
216
|
server.register_tools(MissingFkIndexesTool)
|
217
|
+
server.register_tools(IndexInfoTool)
|
218
|
+
server.register_tools(TableInfoTool)
|
219
|
+
server.register_tools(TableSchemaTool)
|
166
220
|
server.register_tools(*QUERY_TOOL_CLASSES)
|
167
221
|
server.register_tools(ExplainTool) if ENV["PG_EXTRAS_MCP_EXPLAIN_ENABLED"] == "true"
|
168
222
|
server.register_tools(ExplainAnalyzeTool) if ENV["PG_EXTRAS_MCP_EXPLAIN_ANALYZE_ENABLED"] == "true"
|