rails-pg-extras-mcp 0.0.1
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 +7 -0
- data/.gitattributes +2 -0
- data/.github/workflows/ci.yml +34 -0
- data/.gitignore +7 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +52 -0
- data/Rakefile +5 -0
- data/lib/rails-pg-extras-mcp.rb +103 -0
- data/lib/rails_pg_extras_mcp/version.rb +5 -0
- data/pg-extras-mcp.png +0 -0
- data/rails-pg-extras-diagnose.png +0 -0
- data/rails-pg-extras-mcp.gemspec +28 -0
- data/spec/smoke_spec.rb +69 -0
- data/spec/spec_helper.rb +5 -0
- metadata +145 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f2b38c7170279b40f497842e8b52683e94ec21ed567f9081ca4e0041fac00cc0
|
4
|
+
data.tar.gz: d099ef809db25a1cadacc15faea3fc6bc7ba49dc8e60f985f7e1835ce962e127
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c4fd58adbed92be275183094e26afb12ef156a214170f55c5e3e563d39e2fabdf59b4c7676401f97b820346e5173feef8630d41343d48d4d086961ece3dd4c93
|
7
|
+
data.tar.gz: f8365a1506c36a6c9475bddadce4d97a0651b4a20e5a05100020ccfb49730f0691407e805503bc462403e24de9a800ad072984dfc8f452797cd11c560ae1a9c9
|
data/.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
name: Ruby CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ main ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ main ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
strategy:
|
13
|
+
fail-fast: false
|
14
|
+
matrix:
|
15
|
+
ruby-version: ['3.4', '3.3', '3.2', '3.1']
|
16
|
+
steps:
|
17
|
+
- uses: actions/checkout@v4
|
18
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
19
|
+
uses: ruby/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
ruby-version: ${{ matrix.ruby-version }}
|
22
|
+
- name: Setup dependencies
|
23
|
+
run: |
|
24
|
+
gem install bundler -v 2.4.22
|
25
|
+
sudo apt-get update --allow-releaseinfo-change
|
26
|
+
sudo apt install postgresql-client
|
27
|
+
sudo apt install libpq-dev
|
28
|
+
bundle config set --local path 'vendor/bundle'
|
29
|
+
bundle install
|
30
|
+
sleep 10
|
31
|
+
- name: Run tests
|
32
|
+
run: |
|
33
|
+
bundle exec rspec spec/
|
34
|
+
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright © Paweł Urbanek 2025
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Rails PG Extras MCP [](https://badge.fury.io/rb/rails-pg-extras-mcp) [](https://github.com/pawurb/rails-pg-extras-mcp/actions)
|
2
|
+
|
3
|
+
|
4
|
+
MCP ([Model Context Protocol](https://modelcontextprotocol.io/introduction)) interface for [rails-pg-extras](https://github.com/pawurb/rails-pg-extras) gem.
|
5
|
+
|
6
|
+
A tool for those adventurous enough to connect LLMs directly to the database.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
```bash
|
11
|
+
bundle add rails-pg-extras
|
12
|
+
bundle add rails-pg-extras-mcp
|
13
|
+
```
|
14
|
+
|
15
|
+
Library supports MCP protocol via HTTP SSE interface.
|
16
|
+
|
17
|
+
`config/routes.rb`
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
# Authentication is not yet supported
|
21
|
+
mount RailsPgExtras.mcp_app, at: "pg-extras-mcp"
|
22
|
+
```
|
23
|
+
|
24
|
+
Install [mcp-remote](https://github.com/geelen/mcp-remote):
|
25
|
+
|
26
|
+
```bash
|
27
|
+
npm install -g mcp-remote
|
28
|
+
```
|
29
|
+
|
30
|
+
and in your LLM of choice:
|
31
|
+
|
32
|
+
```json
|
33
|
+
{
|
34
|
+
"mcpServers": {
|
35
|
+
"pg-extras": {
|
36
|
+
"command": "npx",
|
37
|
+
"args": [
|
38
|
+
"mcp-remote",
|
39
|
+
"http://localhost:3000/pg-extras-mcp/sse"
|
40
|
+
]
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|
44
|
+
```
|
45
|
+
|
46
|
+
You can now ask LLM questions about the metadata and performance metrics of your database.
|
47
|
+
|
48
|
+

|
49
|
+
|
50
|
+
## Status
|
51
|
+
|
52
|
+
Project is in an early beta, so proceed with caution.
|
data/Rakefile
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "fast_mcp"
|
4
|
+
require "rack"
|
5
|
+
require "ruby-pg-extras"
|
6
|
+
require "rails-pg-extras"
|
7
|
+
|
8
|
+
SKIP_QUERIES = %i[
|
9
|
+
add_extensions
|
10
|
+
pg_stat_statements_reset
|
11
|
+
kill_pid
|
12
|
+
kill_all
|
13
|
+
mandelbrot
|
14
|
+
]
|
15
|
+
|
16
|
+
QUERY_TOOL_CLASSES = RubyPgExtras::QUERIES.reject { |q| SKIP_QUERIES.include?(q) }.map do |query_name|
|
17
|
+
Class.new(FastMcp::Tool) do
|
18
|
+
description RubyPgExtras.description_for(query_name: query_name)
|
19
|
+
|
20
|
+
define_method :call do
|
21
|
+
RailsPgExtras.public_send(query_name, in_format: :hash)
|
22
|
+
end
|
23
|
+
|
24
|
+
define_singleton_method :name do
|
25
|
+
query_name.to_s
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class MissingFkConstraintsTool < FastMcp::Tool
|
31
|
+
description "Shows missing foreign key constraints"
|
32
|
+
|
33
|
+
def call
|
34
|
+
RailsPgExtras.missing_fk_constraints(in_format: :hash)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.name
|
38
|
+
"missing_fk_constraints"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class MissingFkIndexesTool < FastMcp::Tool
|
43
|
+
description "Shows missing foreign key indexes"
|
44
|
+
|
45
|
+
def call
|
46
|
+
RailsPgExtras.missing_fk_indexes(in_format: :hash)
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.name
|
50
|
+
"missing_fk_indexes"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class DiagnoseTool < FastMcp::Tool
|
55
|
+
description "Performs a health check of the database"
|
56
|
+
|
57
|
+
def call
|
58
|
+
RailsPgExtras.diagnose(in_format: :hash)
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.name
|
62
|
+
"diagnose"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
class ReadmeResource < FastMcp::Resource
|
67
|
+
uri "https://raw.githubusercontent.com/pawurb/rails-pg-extras/refs/heads/main/README.md"
|
68
|
+
resource_name "README"
|
69
|
+
description "The README for RailsPgExtras"
|
70
|
+
mime_type "text/plain"
|
71
|
+
|
72
|
+
def content
|
73
|
+
File.read(uri)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
module RailsPgExtrasMcp
|
78
|
+
class App
|
79
|
+
def self.build
|
80
|
+
app = lambda do |_env|
|
81
|
+
[200, { "Content-Type" => "text/html" },
|
82
|
+
["<html><body><h1>Hello from Rack!</h1><p>This is a simple Rack app with MCP middleware.</p></body></html>"]]
|
83
|
+
end
|
84
|
+
|
85
|
+
# Create the MCP middleware
|
86
|
+
mcp_app = FastMcp.rack_middleware(
|
87
|
+
app,
|
88
|
+
name: "rails-pg-extras-mcp", version: RailsPgExtrasMcp::VERSION,
|
89
|
+
path_prefix: "/pg-extras-mcp",
|
90
|
+
logger: Logger.new($stdout),
|
91
|
+
) do |server|
|
92
|
+
server.register_tools(DiagnoseTool)
|
93
|
+
server.register_tools(MissingFkConstraintsTool)
|
94
|
+
server.register_tools(MissingFkIndexesTool)
|
95
|
+
server.register_tools(*QUERY_TOOL_CLASSES)
|
96
|
+
|
97
|
+
server.register_resource(ReadmeResource)
|
98
|
+
|
99
|
+
Rack::Builder.new { run mcp_app }
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
data/pg-extras-mcp.png
ADDED
Binary file
|
Binary file
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "rails_pg_extras_mcp/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "rails-pg-extras-mcp"
|
8
|
+
s.version = RailsPgExtrasMcp::VERSION
|
9
|
+
s.authors = ["pawurb"]
|
10
|
+
s.email = ["contact@pawelurbanek.com"]
|
11
|
+
s.summary = %q{ MCP interface for rails-pg-extras }
|
12
|
+
s.description = %q{ MCP interface for rails-pg-extras. It enables LLMs to analyze the PostgreSQL metadata and performance metrics. }
|
13
|
+
s.homepage = "http://github.com/pawurb/rails-pg-extras-mcp"
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = s.files.grep(%r{^(spec)/})
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.license = "MIT"
|
18
|
+
s.add_dependency "rails-pg-extras", "~> 5.6"
|
19
|
+
s.add_dependency "rails"
|
20
|
+
s.add_dependency "fast-mcp"
|
21
|
+
s.add_development_dependency "rake"
|
22
|
+
s.add_development_dependency "rspec"
|
23
|
+
s.add_development_dependency "rufo"
|
24
|
+
|
25
|
+
if s.respond_to?(:metadata=)
|
26
|
+
s.metadata = { "rubygems_mfa_required" => "true" }
|
27
|
+
end
|
28
|
+
end
|
data/spec/smoke_spec.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
require "rails-pg-extras"
|
5
|
+
|
6
|
+
describe RailsPgExtras do
|
7
|
+
SKIP_QUERIES = %i[
|
8
|
+
kill_all
|
9
|
+
table_schema
|
10
|
+
table_foreign_keys
|
11
|
+
]
|
12
|
+
|
13
|
+
RailsPgExtras::QUERIES.reject { |q| SKIP_QUERIES.include?(q) }.each do |query_name|
|
14
|
+
it "#{query_name} query can be executed" do
|
15
|
+
expect do
|
16
|
+
RailsPgExtras.run_query(
|
17
|
+
query_name: query_name,
|
18
|
+
in_format: :hash,
|
19
|
+
)
|
20
|
+
end.not_to raise_error
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it "runs the custom methods" do
|
25
|
+
expect do
|
26
|
+
RailsPgExtras.diagnose(in_format: :hash)
|
27
|
+
end.not_to raise_error
|
28
|
+
|
29
|
+
expect do
|
30
|
+
RailsPgExtras.index_info(in_format: :hash)
|
31
|
+
end.not_to raise_error
|
32
|
+
|
33
|
+
expect do
|
34
|
+
RailsPgExtras.table_info(in_format: :hash)
|
35
|
+
end.not_to raise_error
|
36
|
+
end
|
37
|
+
|
38
|
+
it "collecting queries data works" do
|
39
|
+
output = RailsPgExtras.measure_queries { RailsPgExtras.diagnose(in_format: :hash) }
|
40
|
+
expect(output.fetch(:count) > 0).to eq(true)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "supports custom RAILS_PG_EXTRAS_DATABASE_URL" do
|
44
|
+
ENV["RAILS_PG_EXTRAS_DATABASE_URL"] = ENV["DATABASE_URL"]
|
45
|
+
puts ENV["RAILS_PG_EXTRAS_DATABASE_URL"]
|
46
|
+
|
47
|
+
expect do
|
48
|
+
RailsPgExtras.calls
|
49
|
+
end.not_to raise_error
|
50
|
+
|
51
|
+
ENV["RAILS_PG_EXTRAS_DATABASE_URL"] = nil
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "missing_fk_indexes" do
|
55
|
+
it "works" do
|
56
|
+
expect {
|
57
|
+
RailsPgExtras.missing_fk_indexes
|
58
|
+
}.not_to raise_error
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "missing_fk_constraints" do
|
63
|
+
it "works" do
|
64
|
+
expect {
|
65
|
+
RailsPgExtras.missing_fk_constraints
|
66
|
+
}.not_to raise_error
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails-pg-extras-mcp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- pawurb
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-06-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails-pg-extras
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: fast-mcp
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rufo
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: " MCP interface for rails-pg-extras. It enables LLMs to analyze the PostgreSQL
|
98
|
+
metadata and performance metrics. "
|
99
|
+
email:
|
100
|
+
- contact@pawelurbanek.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitattributes"
|
106
|
+
- ".github/workflows/ci.yml"
|
107
|
+
- ".gitignore"
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- lib/rails-pg-extras-mcp.rb
|
113
|
+
- lib/rails_pg_extras_mcp/version.rb
|
114
|
+
- pg-extras-mcp.png
|
115
|
+
- rails-pg-extras-diagnose.png
|
116
|
+
- rails-pg-extras-mcp.gemspec
|
117
|
+
- spec/smoke_spec.rb
|
118
|
+
- spec/spec_helper.rb
|
119
|
+
homepage: http://github.com/pawurb/rails-pg-extras-mcp
|
120
|
+
licenses:
|
121
|
+
- MIT
|
122
|
+
metadata:
|
123
|
+
rubygems_mfa_required: 'true'
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubygems_version: 3.5.16
|
140
|
+
signing_key:
|
141
|
+
specification_version: 4
|
142
|
+
summary: MCP interface for rails-pg-extras
|
143
|
+
test_files:
|
144
|
+
- spec/smoke_spec.rb
|
145
|
+
- spec/spec_helper.rb
|