rails_mcp_code_search 0.1.0 → 0.2.0

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: 6e1c670e94a061746f627ec212078736dca6e7398a6ca1260872eb829ee53d31
4
- data.tar.gz: 38cfa6d2f88765590d1db57432e5639637c0f4ef3a4fa075f9e668d54a423bb4
3
+ metadata.gz: c858fcf548559d7ecbfac6d211a8c5b56e0e060d147a0ad4792d622a7cd04f44
4
+ data.tar.gz: 15947e6986cbfa2c22c6f7f1010f842b81285627581711bc62085cb4c61210c9
5
5
  SHA512:
6
- metadata.gz: 4e06c7f98f2bdaca1c3169d48d9753fdd0456ca3cc3e42f1e7951afd36c88dd704e2e00efe2b2ac268650dce37509c4488a9ee5e9039d9a0562e430dae01e845
7
- data.tar.gz: 20a0b55ad4f2a8e1498697d3b16941a3361c1165b1e17a6eb1ef15aca82d5cf85f777de415810bf042c847733b7553f2df5911bcd7c6948acff94520db48c942
6
+ metadata.gz: 1664358410f167994426d8ef6555e081266a4d3ad84f1d924c6820296caa114f0a8a55744781ae6618aefa57ffd738d234e90870f7ce5ec0d4359ccdfbfe9e72
7
+ data.tar.gz: 03db6c43580f87cbd41c67404d145f1d42efd4eaab854aa51beee07db1253d6078d32a078231ccab3e5cbd301d18da1fef078e9b33d56028428471ea51cae358
data/README.md CHANGED
@@ -37,23 +37,11 @@
37
37
 
38
38
  ```sh
39
39
  gem install rails_mcp_code_search
40
+ cd your-project
41
+ rails-mcp-code-search --setup
40
42
  ```
41
43
 
42
- Requires Ruby 4.0+. The first run downloads the embedding model (~80 MB) to `~/.cache/informers/`.
43
-
44
- Add to `~/.claude/settings.json`:
45
-
46
- ```json
47
- {
48
- "mcpServers": {
49
- "code-search": {
50
- "command": "rails-mcp-code-search"
51
- }
52
- }
53
- }
54
- ```
55
-
56
- That's it. Claude Code launches the server automatically when you open a project.
44
+ Requires Ruby 4.0+. Run `--setup` inside each project you want to index. It creates a version-independent wrapper script (`~/.local/bin/`) and a per-project `.mcp.json` that configures Claude Code automatically. The first search downloads the embedding model (~80 MB) to `~/.cache/informers/`.
57
45
 
58
46
  ## Tools
59
47
 
@@ -2,4 +2,8 @@
2
2
 
3
3
  require "rails_mcp_code_search"
4
4
 
5
- RailsMcpCodeSearch::Server.start
5
+ if ARGV.include?("--setup")
6
+ RailsMcpCodeSearch::Setup.run
7
+ else
8
+ RailsMcpCodeSearch::Server.start
9
+ end
@@ -8,12 +8,33 @@ module RailsMcpCodeSearch
8
8
  Tools::StatusTool
9
9
  ].freeze
10
10
 
11
+ INSTRUCTIONS = <<~TEXT
12
+ Use the code-search tools to find code by concept or behavior using natural language.
13
+ This is semantic search — it finds code by meaning, not by exact string matching.
14
+
15
+ When to use search vs Grep:
16
+ - Use `search` when looking for concepts like "authentication", "payment processing", or "error handling"
17
+ - Use `Grep` when looking for exact identifiers like a class name, method name, or string literal
18
+
19
+ Workflow:
20
+ 1. The index builds automatically in the background when the server starts
21
+ 2. Use `status` to check if indexing is complete
22
+ 3. Use `search` with natural language queries to find relevant code
23
+ 4. Use `reindex` after major code changes, or with full=true to rebuild from scratch
24
+
25
+ Tips:
26
+ - Scores above 0.7 are strong matches, 0.5-0.7 are partial matches
27
+ - Use `file_pattern` to narrow results (e.g. "app/models/**/*.rb")
28
+ - Changed files are automatically re-indexed on each search
29
+ TEXT
30
+
11
31
  def self.start(project_path: Dir.pwd, db_path: nil)
12
32
  runtime = Runtime.boot(project_path:, db_path:)
13
33
 
14
34
  server = ::MCP::Server.new(
15
35
  name: "rails-mcp-code-search",
16
36
  version: VERSION,
37
+ instructions: INSTRUCTIONS,
17
38
  tools: TOOLS,
18
39
  server_context: { runtime: }
19
40
  )
@@ -0,0 +1,101 @@
1
+ require "json"
2
+ require "fileutils"
3
+
4
+ module RailsMcpCodeSearch
5
+ module Setup
6
+ WRAPPER_DIR = File.join(Dir.home, ".local", "bin")
7
+ WRAPPER_PATH = File.join(WRAPPER_DIR, "rails-mcp-code-search")
8
+
9
+ class << self
10
+ def run
11
+ puts "Setting up rails-mcp-code-search...\n\n"
12
+
13
+ create_wrapper
14
+ configure_claude_code
15
+
16
+ puts "\nDone! Restart Claude Code in this project to start using semantic search."
17
+ end
18
+
19
+ private
20
+
21
+ def create_wrapper
22
+ FileUtils.mkdir_p WRAPPER_DIR
23
+
24
+ init_command = detect_ruby_manager
25
+ wrapper = <<~BASH
26
+ #!/bin/bash
27
+ #{init_command}
28
+
29
+ # Auto-update once per day
30
+ UPDATE_STAMP="$HOME/.local/share/rails-mcp-code-search/.last_update_check"
31
+ UPDATE_INTERVAL=86400
32
+ mkdir -p "$(dirname "$UPDATE_STAMP")"
33
+ if [ -f "$UPDATE_STAMP" ]; then
34
+ last_check=$(cat "$UPDATE_STAMP")
35
+ else
36
+ last_check=0
37
+ fi
38
+ now=$(date +%s)
39
+ if [ $((now - last_check)) -gt $UPDATE_INTERVAL ]; then
40
+ gem install rails_mcp_code_search --no-document >/dev/null 2>&1
41
+ echo "$now" > "$UPDATE_STAMP"
42
+ fi
43
+
44
+ exec rails-mcp-code-search "$@"
45
+ BASH
46
+
47
+ File.write WRAPPER_PATH, wrapper
48
+ File.chmod 0o755, WRAPPER_PATH
49
+ puts "Created wrapper script: #{WRAPPER_PATH}"
50
+ end
51
+
52
+ def detect_ruby_manager
53
+ if rbenv_path = find_executable("rbenv")
54
+ "eval \"$(#{rbenv_path} init - bash)\""
55
+ elsif asdf_path = find_asdf
56
+ ". #{asdf_path}"
57
+ elsif chruby_path = find_chruby
58
+ "source #{chruby_path}\nchruby ruby"
59
+ else
60
+ "# System Ruby — no version manager detected"
61
+ end
62
+ end
63
+
64
+ def find_executable(name)
65
+ [
66
+ "/opt/homebrew/bin/#{name}",
67
+ "/usr/local/bin/#{name}",
68
+ File.join(Dir.home, ".#{name}", "bin", name)
69
+ ].find { File.executable?(_1) }
70
+ end
71
+
72
+ def find_asdf
73
+ path = File.join(Dir.home, ".asdf", "asdf.sh")
74
+ path if File.exist?(path)
75
+ end
76
+
77
+ def find_chruby
78
+ [
79
+ "/opt/homebrew/share/chruby/chruby.sh",
80
+ "/usr/local/share/chruby/chruby.sh"
81
+ ].find { File.exist?(_1) }
82
+ end
83
+
84
+ def configure_claude_code
85
+ mcp_config_path = File.join(Dir.pwd, ".mcp.json")
86
+
87
+ config = if File.exist?(mcp_config_path)
88
+ JSON.parse File.read(mcp_config_path)
89
+ else
90
+ {}
91
+ end
92
+
93
+ config["mcpServers"] ||= {}
94
+ config["mcpServers"]["code-search"] = { "command" => WRAPPER_PATH }
95
+
96
+ File.write mcp_config_path, JSON.pretty_generate(config) + "\n"
97
+ puts "Configured Claude Code: #{mcp_config_path}"
98
+ end
99
+ end
100
+ end
101
+ end
@@ -9,6 +9,7 @@ module RailsMcpCodeSearch
9
9
  autoload :Runtime, "rails_mcp_code_search/runtime"
10
10
  autoload :RubyParser, "rails_mcp_code_search/ruby_parser"
11
11
  autoload :Server, "rails_mcp_code_search/server"
12
+ autoload :Setup, "rails_mcp_code_search/setup"
12
13
  autoload :SlidingWindowParser, "rails_mcp_code_search/sliding_window_parser"
13
14
 
14
15
  module Embeddings
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_mcp_code_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Lopez Prat
@@ -152,6 +152,7 @@ files:
152
152
  - lib/rails_mcp_code_search/ruby_parser.rb
153
153
  - lib/rails_mcp_code_search/runtime.rb
154
154
  - lib/rails_mcp_code_search/server.rb
155
+ - lib/rails_mcp_code_search/setup.rb
155
156
  - lib/rails_mcp_code_search/sliding_window_parser.rb
156
157
  - lib/rails_mcp_code_search/tools/base_tool.rb
157
158
  - lib/rails_mcp_code_search/tools/reindex_tool.rb