rails-pg-extras-mcp 0.1.0 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e8d771e114f631fe7a9708fca02ae9466ab30a3da437ad14bf2085ec3a723592
4
- data.tar.gz: e96491dbe241a9bb66484e8bc9088cdb1d933f09ae62a1d89d9b65b44e5ebad5
3
+ metadata.gz: 2b57d865e11d3ed07608432c2ccd25a067fa7543107fca64363988d377e05adb
4
+ data.tar.gz: e4cbc30b81b2fc09315c212f55bc99117643db0b3feaf841d314f117c5d13bf4
5
5
  SHA512:
6
- metadata.gz: 9aefce0884fb505759dcaafbadbfdbcf821826400273c74f20a1a5d8a69cc41e81d4130789f5b07f36cb5b526e75c2c6b01ac6356562f78233769de582403221
7
- data.tar.gz: 0ec7f68987e6ee2e358745827d060e2723f9f68c53cdf2232b051ad6d723d8f873e325acbe52a1e46d2c0e6df9945a376abecab2dd93a75666045e4f57763891
6
+ metadata.gz: be8e2c87865728bbfb73bd78c1731932f08f55c7792efd2df934d505b4470d3c2002a9a2c86112fdc043aaaf6f69262dbf857cd55c16041d384d6d542f900f70
7
+ data.tar.gz: 1f885e3663310dfc73f8e73e7d2b6af97334c1eea9ab885f6100153775c4a7227c34a13afa2c78b46bc4968c2171d6a63f5ba4eb6c7cc25f9ca45472c824607d
data/README.md CHANGED
@@ -16,10 +16,15 @@ The library supports MCP protocol via HTTP SSE interface.
16
16
  `config/routes.rb`
17
17
 
18
18
  ```ruby
19
- # Authentication is not yet supported
20
19
  mount RailsPgExtras.mcp_app, at: "pg-extras-mcp"
21
20
  ```
22
21
 
22
+ with optional authorization:
23
+
24
+ ```ruby
25
+ mount RailsPgExtras.mcp_app(auth_token: "secret"), at: "pg-extras-mcp"
26
+ ```
27
+
23
28
  Install [mcp-remote](https://github.com/geelen/mcp-remote):
24
29
 
25
30
  ```bash
@@ -35,7 +40,9 @@ and in your LLM of choice:
35
40
  "command": "npx",
36
41
  "args": [
37
42
  "mcp-remote",
38
- "http://localhost:3000/pg-extras-mcp/sse"
43
+ "http://localhost:3000/pg-extras-mcp/sse",
44
+ "--header",
45
+ "Authorization: secret"
39
46
  ]
40
47
  }
41
48
  }
@@ -75,6 +75,7 @@ class ExplainBaseTool < FastMcp::Tool
75
75
  grant,
76
76
  begin,
77
77
  commit,
78
+ ;
78
79
  ]
79
80
 
80
81
  arguments do
@@ -100,10 +101,14 @@ class ExplainTool < ExplainBaseTool
100
101
  description "EXPLAIN a query. It must be an SQL string, without the EXPLAIN prefix"
101
102
 
102
103
  def self.name
103
- "explain_analyze"
104
+ "explain"
104
105
  end
105
106
 
106
107
  def call(query:)
108
+ if query.downcase.include?("analyze")
109
+ raise "This query is not allowed. It contains a denied ANALYZE keyword."
110
+ end
111
+
107
112
  super(query: "EXPLAIN #{query}")
108
113
  end
109
114
  end
@@ -133,19 +138,29 @@ end
133
138
 
134
139
  module RailsPgExtrasMcp
135
140
  class App
136
- def self.build
141
+ def self.build(auth_token: nil)
137
142
  app = lambda do |_env|
138
143
  [200, { "Content-Type" => "text/html" },
139
144
  ["<html><body><h1>Hello from Rack!</h1><p>This is a simple Rack app with MCP middleware.</p></body></html>"]]
140
145
  end
141
146
 
142
- # Create the MCP middleware
143
- mcp_app = FastMcp.rack_middleware(
144
- app,
145
- name: "rails-pg-extras-mcp", version: RailsPgExtrasMcp::VERSION,
147
+ opts = {
148
+ name: "rails-pg-extras-mcp",
149
+ version: RailsPgExtrasMcp::VERSION,
146
150
  path_prefix: "/pg-extras-mcp",
147
151
  logger: Logger.new($stdout),
148
- ) do |server|
152
+ }
153
+
154
+ if auth_token.present?
155
+ opts[:auth_token] = auth_token
156
+ end
157
+
158
+ rack_method_name = auth_token.present? ? :authenticated_rack_middleware : :rack_middleware
159
+
160
+ # Create the MCP middleware
161
+ mcp_app = FastMcp.public_send(rack_method_name,
162
+ app,
163
+ **opts) do |server|
149
164
  server.register_tools(DiagnoseTool)
150
165
  server.register_tools(MissingFkConstraintsTool)
151
166
  server.register_tools(MissingFkIndexesTool)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsPgExtrasMcp
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-pg-extras-mcp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - pawurb
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-06-21 00:00:00.000000000 Z
11
+ date: 2025-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails-pg-extras