From 2b8d34bb5499e3f26d52ffc405a436dee8d7586c Mon Sep 17 00:00:00 2001 From: Nathan Weinshenker Date: Wed, 3 Sep 2025 18:02:08 -0600 Subject: [PATCH 1/3] Adds get_repository_file mcp tool Supports the get_repository_file tool by appending the following framework definition to the files API endpoint. Related: https://gitlab.com/gitlab-org/gitlab/-/issues/566140 Changelog: added EE: true --- lib/api/files.rb | 1 + spec/requests/api/files_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/api/files.rb b/lib/api/files.rb index 047d7c028e4a70..f90a1a6ae46e25 100644 --- a/lib/api/files.rb +++ b/lib/api/files.rb @@ -230,6 +230,7 @@ def blob_data requires :ref, type: String, desc: 'The name of branch, tag or commit', allow_blank: false, documentation: { example: 'main' } end + route_setting :mcp, tool_name: :get_repository_file, params: [:id, :file_path, :ref] get ":id/repository/files/:file_path", requirements: FILE_ENDPOINT_REQUIREMENTS do # Loads metadata for @blob as a side effect, but not not the actual data # diff --git a/spec/requests/api/files_spec.rb b/spec/requests/api/files_spec.rb index b2e5750fcc3798..697a03ce45abb4 100644 --- a/spec/requests/api/files_spec.rb +++ b/spec/requests/api/files_spec.rb @@ -154,6 +154,23 @@ def expect_to_send_git_blob(url, params) end describe 'HEAD /projects/:id/repository/files/:file_path' do + shared_examples 'an endpoint with route setting' do |expected_tool, expected_params| + it "has the correct mcp route setting configured" do + get api(route(file_path), current_user, **options), params: request_params + + expect(response).to have_gitlab_http_status(:ok) + + # Access current endpoint responding to the request that + # is append to the API endpoint + # https://gitlab.com/gitlab-org/gitlab/-/merge_requests/201838 + endpoint = request.env['api.endpoint'] + actual_value = endpoint.route_setting('mcp') + + expect(actual_value[:tool_name]).to eq(expected_tool.to_sym) + expect(actual_value[:params]).to eq(expected_params) if expected_params + end + end + shared_examples_for 'repository files' do let(:options) { {} } @@ -167,6 +184,8 @@ def expect_to_send_git_blob(url, params) subject { head api(route(absolute_path), current_user, **options), params: params } end + include_examples 'an endpoint with route setting', :get_repository_file + it 'returns file attributes in headers' do head api(route(file_path), current_user, **options), params: params @@ -203,6 +222,7 @@ def expect_to_send_git_blob(url, params) expect(response).to have_gitlab_http_status(:ok) expect(response.headers['X-Gitlab-File-Name']).to eq('commit.js.coffee') + expect(response.headers['X-Gitlab-Ref']).to eq(params[:ref]) expect(response.headers['X-Gitlab-Content-Sha256']).to eq('08785f04375b47f81f46e68cc125d5ef368aa20576ddb53f91f4d83f1d04b929') end -- GitLab From 57b6caa8e93b548d252e28628b1de1b372b1bd33 Mon Sep 17 00:00:00 2001 From: Nathan Weinshenker Date: Thu, 4 Sep 2025 11:24:27 -0600 Subject: [PATCH 2/3] Fixes improper parameter being called in test removes an error associated to the following change --- spec/requests/api/files_spec.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/spec/requests/api/files_spec.rb b/spec/requests/api/files_spec.rb index 697a03ce45abb4..1cda3275e512f4 100644 --- a/spec/requests/api/files_spec.rb +++ b/spec/requests/api/files_spec.rb @@ -154,18 +154,16 @@ def expect_to_send_git_blob(url, params) end describe 'HEAD /projects/:id/repository/files/:file_path' do - shared_examples 'an endpoint with route setting' do |expected_tool, expected_params| + shared_examples 'an endpoint with mcp route setting' do |expected_tool, expected_params| it "has the correct mcp route setting configured" do - get api(route(file_path), current_user, **options), params: request_params + get api(route(file_path), current_user, **options), params: params expect(response).to have_gitlab_http_status(:ok) - # Access current endpoint responding to the request that - # is append to the API endpoint - # https://gitlab.com/gitlab-org/gitlab/-/merge_requests/201838 endpoint = request.env['api.endpoint'] - actual_value = endpoint.route_setting('mcp') + actual_value = endpoint.route_setting(:mcp) + expect(actual_value).to be_present expect(actual_value[:tool_name]).to eq(expected_tool.to_sym) expect(actual_value[:params]).to eq(expected_params) if expected_params end -- GitLab From b15ba1e19b1742b78b85dd3d923e233935a8cc92 Mon Sep 17 00:00:00 2001 From: Nathan Weinshenker Date: Thu, 4 Sep 2025 12:31:29 -0600 Subject: [PATCH 3/3] Something --- spec/requests/api/files_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/requests/api/files_spec.rb b/spec/requests/api/files_spec.rb index 1cda3275e512f4..3bf0b74f5b2b3d 100644 --- a/spec/requests/api/files_spec.rb +++ b/spec/requests/api/files_spec.rb @@ -182,7 +182,7 @@ def expect_to_send_git_blob(url, params) subject { head api(route(absolute_path), current_user, **options), params: params } end - include_examples 'an endpoint with route setting', :get_repository_file + include_examples 'an endpoint with mcp route setting', :get_repository_file it 'returns file attributes in headers' do head api(route(file_path), current_user, **options), params: params -- GitLab