hub_kernel-mcp 0.9.1 → 0.11.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 +4 -4
- data/README.md +43 -1
- data/app/controllers/hub_kernel/mcp/authorizations_controller.rb +22 -2
- data/app/controllers/hub_kernel/mcp/messages_controller.rb +2 -2
- data/app/controllers/hub_kernel/mcp/tokens_controller.rb +1 -1
- data/app/models/hub_kernel/mcp/authorization_code.rb +4 -2
- data/app/models/hub_kernel/mcp/connection.rb +9 -4
- data/app/views/hub_kernel/mcp/authorizations/new.html.erb +3 -0
- data/db/migrate/20261123175537_add_account_gid_to_hub_kernel_mcp_connections.rb +5 -0
- data/db/migrate/20261123175631_add_account_gid_to_hub_kernel_mcp_authorization_codes.rb +5 -0
- data/lib/hub_kernel/mcp/version.rb +1 -1
- data/lib/hub_kernel/mcp.rb +1 -0
- data/the_local/agents/hub_kernel-mcp-develop.md +39 -13
- data/the_local/agents/hub_kernel-mcp-info.md +34 -19
- data/the_local/agents/hub_kernel-mcp-install.md +75 -16
- data/the_local/interface.yml +5 -1
- metadata +5 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5c155be6194b6cb2b7bc18afec3c1da06e65389c31fcbc7e91f13337e61b9687
|
|
4
|
+
data.tar.gz: b3f322430ac31895558ed9f52590af47d8dd87345c3b5b42db9a54712ac91222
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: af62f841adf4ad4e61071dcaf4b49ab956c5d4419366d888ecdd0a0a7141d7df12748b76c4690917b8959e893af46972169c8839cd83187cced21393f503a896
|
|
7
|
+
data.tar.gz: 11d1e059e7b9edaca4f88ded7b5d105699ec0fa381d9e17c293859f109f8cbc3665014399a8da1c7f150b38d35eafab9b0b89b62be1492722a0f8402acb16ab7
|
data/README.md
CHANGED
|
@@ -15,6 +15,11 @@ HubKernel::Mcp.person_method = :current_person
|
|
|
15
15
|
HubKernel::Mcp.account_method = :current_account
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
+
When `HubKernel::Mcp.person_method` or `HubKernel::Mcp.account_method` is not set, MCP uses
|
|
19
|
+
`HubKernel::Interface.person_method` or `HubKernel::Interface.account_method`, so a host that
|
|
20
|
+
also serves hub_kernel-api can name the caller once in hub_kernel-interface. MCP's own setting
|
|
21
|
+
is used when it is set.
|
|
22
|
+
|
|
18
23
|
The hubs served are the host's one list in hub_kernel-interface, which every interface gem
|
|
19
24
|
serves:
|
|
20
25
|
|
|
@@ -99,6 +104,9 @@ then mount its discovery documents at the site root beside the endpoint:
|
|
|
99
104
|
bin/rails hub_kernel_mcp:install:migrations db:migrate
|
|
100
105
|
```
|
|
101
106
|
|
|
107
|
+
A host upgrading the gem runs the same command again to copy in the migrations it does not have
|
|
108
|
+
yet.
|
|
109
|
+
|
|
102
110
|
```ruby
|
|
103
111
|
mount HubKernel::Mcp::Engine => "/mcp"
|
|
104
112
|
mount HubKernel::Mcp::Discovery => "/.well-known"
|
|
@@ -147,8 +155,22 @@ HubKernel::Mcp.browser_layout = "application"
|
|
|
147
155
|
`HubKernel::Mcp.check!` names each of the four a host has not set. The person the page gives is
|
|
148
156
|
kept by its global id, so it must be a record that has one.
|
|
149
157
|
|
|
158
|
+
A host whose people belong to several accounts names the accounts a person may connect an app
|
|
159
|
+
to, as a label and an account record for each:
|
|
160
|
+
|
|
161
|
+
```ruby
|
|
162
|
+
HubKernel::Mcp.approval_accounts = ->(person) { person.accounts.map { |account| [ account.name, account ] } }
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
The account must be a record that has a global id. When `approval_accounts` is not set, the
|
|
166
|
+
approval page asks for no account and every connection is made with none.
|
|
167
|
+
|
|
150
168
|
A person who is not signed in is sent through the host's sign-in. A signed-in person sees the
|
|
151
|
-
name of the app asking to connect, with an Approve and a Deny button.
|
|
169
|
+
name of the app asking to connect, with an Approve and a Deny button. When the host names
|
|
170
|
+
approval accounts, the page also lists the person's accounts and asks which one the app
|
|
171
|
+
connects to. A person with one account finds it already picked. Approving with no account
|
|
172
|
+
picked, or with an account that is not in the person's list, shows the page again with
|
|
173
|
+
`Choose the account this app connects to` and issues no code. Approving sends them back
|
|
152
174
|
to the client's redirect address with a code and the client's `state`. Denying sends them back
|
|
153
175
|
with `error=access_denied` and no code. A request missing its `client_id` or `redirect_uri`,
|
|
154
176
|
naming a client that is not registered, or naming a redirect address the client did not
|
|
@@ -211,6 +233,26 @@ end
|
|
|
211
233
|
for an expired or unknown token. Every call is made in the account the host's account method
|
|
212
234
|
gives, so that method must give one for a person signed in this way.
|
|
213
235
|
|
|
236
|
+
`HubKernel::Mcp::Connection.caller_for` takes the same token and gives both the person and the
|
|
237
|
+
account the person picked when they approved the app, so the host's account method can run the
|
|
238
|
+
call in that account:
|
|
239
|
+
|
|
240
|
+
```ruby
|
|
241
|
+
def current_caller = authenticate_with_http_token { |token| HubKernel::Mcp::Connection.caller_for(token) }
|
|
242
|
+
|
|
243
|
+
def current_person = current_caller&.person
|
|
244
|
+
|
|
245
|
+
def current_account = current_caller&.account || default_account
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
It gives `nil` for an expired or unknown token, and both lookups record when the connection was
|
|
249
|
+
last used. A connection made with no account, including every connection made before 0.11.0,
|
|
250
|
+
gives `nil` as its account, and the host decides which account such a call runs in.
|
|
251
|
+
|
|
252
|
+
Each approval makes its own connection, so connecting the same app to a second account adds a
|
|
253
|
+
second connection beside the first. A refreshed access token stays in the account its
|
|
254
|
+
connection was approved for.
|
|
255
|
+
|
|
214
256
|
A person can see the apps connected as them and disconnect one. The gem ships a section for a
|
|
215
257
|
host's settings page: the `hub_kernel/mcp/connections` partial, which lists each of the person's
|
|
216
258
|
connections with the app's name, when it connected and when it was last used, and the
|
|
@@ -12,20 +12,26 @@ module HubKernel
|
|
|
12
12
|
before_action :refuse_missing_values, :refuse_unknown_client, :refuse_unregistered_redirect
|
|
13
13
|
before_action :refuse_without_pkce
|
|
14
14
|
|
|
15
|
-
helper_method :approval_params
|
|
15
|
+
helper_method :approval_params, :account_options, :preselected_account
|
|
16
16
|
|
|
17
17
|
def new
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
def create
|
|
21
21
|
return redirect_to_client(error: "access_denied") unless params[:decision] == "approve"
|
|
22
|
+
return ask_for_account if approval_accounts && !picked_account
|
|
22
23
|
|
|
23
|
-
code = AuthorizationCode.issue(person:
|
|
24
|
+
code = AuthorizationCode.issue(person: approving_person, account: picked_account, client: @client, redirect_uri: params[:redirect_uri], code_challenge: params[:code_challenge])
|
|
24
25
|
redirect_to_client(code: code)
|
|
25
26
|
end
|
|
26
27
|
|
|
27
28
|
private
|
|
28
29
|
|
|
30
|
+
def ask_for_account
|
|
31
|
+
@account_error = "Choose the account this app connects to"
|
|
32
|
+
render :new, status: :unprocessable_content
|
|
33
|
+
end
|
|
34
|
+
|
|
29
35
|
def report_unexpected_errors
|
|
30
36
|
yield
|
|
31
37
|
rescue StandardError => error
|
|
@@ -64,6 +70,20 @@ module HubKernel
|
|
|
64
70
|
end
|
|
65
71
|
|
|
66
72
|
def approval_params = params.permit(*APPROVAL_PARAMS)
|
|
73
|
+
|
|
74
|
+
def approving_person = send(HubKernel::Mcp.browser_person_method)
|
|
75
|
+
|
|
76
|
+
def approval_accounts
|
|
77
|
+
return @approval_accounts if defined?(@approval_accounts)
|
|
78
|
+
|
|
79
|
+
@approval_accounts = HubKernel::Mcp.approval_accounts&.call(approving_person)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def account_options = approval_accounts&.map { |label, account| [ label, account.to_global_id.to_s ] }
|
|
83
|
+
|
|
84
|
+
def preselected_account = (account_options.sole.last if account_options.one?)
|
|
85
|
+
|
|
86
|
+
def picked_account = approval_accounts&.map(&:last)&.find { |account| account.to_global_id.to_s == params[:account] }
|
|
67
87
|
end
|
|
68
88
|
end
|
|
69
89
|
end
|
|
@@ -76,9 +76,9 @@ module HubKernel
|
|
|
76
76
|
|
|
77
77
|
def description(served_name, exposure) = exposure.writes ? "Changes data in the #{served_name} hub." : "Reads data from the #{served_name} hub."
|
|
78
78
|
|
|
79
|
-
def caller_person = send(HubKernel::Mcp.person_method)
|
|
79
|
+
def caller_person = send(HubKernel::Mcp.person_method || HubKernel::Interface.person_method)
|
|
80
80
|
|
|
81
|
-
def caller_account = send(HubKernel::Mcp.account_method)
|
|
81
|
+
def caller_account = send(HubKernel::Mcp.account_method || HubKernel::Interface.account_method)
|
|
82
82
|
end
|
|
83
83
|
end
|
|
84
84
|
end
|
|
@@ -33,7 +33,7 @@ module HubKernel
|
|
|
33
33
|
code = AuthorizationCode.find_by(code_digest: code_digest)
|
|
34
34
|
return stop_tokens_issued_from(code_digest) unless code
|
|
35
35
|
|
|
36
|
-
Connection.issue(person: code.person, client: code.client, code_digest: code_digest) if exchangeable?(code)
|
|
36
|
+
Connection.issue(person: code.person, account: code.account, client: code.client, code_digest: code_digest) if exchangeable?(code)
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
def stop_tokens_issued_from(code_digest)
|
|
@@ -9,9 +9,9 @@ module HubKernel
|
|
|
9
9
|
|
|
10
10
|
belongs_to :client
|
|
11
11
|
|
|
12
|
-
def self.issue(person:, client:, redirect_uri:, code_challenge:)
|
|
12
|
+
def self.issue(person:, client:, redirect_uri:, code_challenge:, account: nil)
|
|
13
13
|
code = SecureRandom.urlsafe_base64(32)
|
|
14
|
-
create!(code_digest: digest(code), person_gid: person.to_global_id.to_s, client: client, redirect_uri: redirect_uri, code_challenge: code_challenge, expires_at: LIFETIME.from_now)
|
|
14
|
+
create!(code_digest: digest(code), person_gid: person.to_global_id.to_s, account_gid: account&.to_global_id&.to_s, client: client, redirect_uri: redirect_uri, code_challenge: code_challenge, expires_at: LIFETIME.from_now)
|
|
15
15
|
code
|
|
16
16
|
end
|
|
17
17
|
|
|
@@ -19,6 +19,8 @@ module HubKernel
|
|
|
19
19
|
|
|
20
20
|
def person = GlobalID::Locator.locate(person_gid)
|
|
21
21
|
|
|
22
|
+
def account = GlobalID::Locator.locate(account_gid)
|
|
23
|
+
|
|
22
24
|
def verifies?(verifier)
|
|
23
25
|
ActiveSupport::SecurityUtils.secure_compare(Base64.urlsafe_encode64(Digest::SHA256.digest(verifier.to_s), padding: false), code_challenge)
|
|
24
26
|
end
|
|
@@ -8,14 +8,15 @@ module HubKernel
|
|
|
8
8
|
REFRESH_LIFETIME = 90.days
|
|
9
9
|
|
|
10
10
|
Tokens = Data.define(:access_token, :refresh_token)
|
|
11
|
+
Caller = Data.define(:person, :account)
|
|
11
12
|
|
|
12
13
|
belongs_to :client
|
|
13
14
|
|
|
14
15
|
scope :of, ->(person) { where(person_gid: person.to_global_id.to_s) }
|
|
15
16
|
|
|
16
|
-
def self.issue(person:, client:, code_digest: nil)
|
|
17
|
+
def self.issue(person:, client:, code_digest: nil, account: nil)
|
|
17
18
|
tokens = new_tokens
|
|
18
|
-
create!(person_gid: person.to_global_id.to_s, client: client, code_digest: code_digest, **digests_for(tokens))
|
|
19
|
+
create!(person_gid: person.to_global_id.to_s, account_gid: account&.to_global_id&.to_s, client: client, code_digest: code_digest, **digests_for(tokens))
|
|
19
20
|
tokens
|
|
20
21
|
end
|
|
21
22
|
|
|
@@ -28,12 +29,14 @@ module HubKernel
|
|
|
28
29
|
tokens if renewed == 1
|
|
29
30
|
end
|
|
30
31
|
|
|
31
|
-
def self.
|
|
32
|
+
def self.caller_for(token)
|
|
32
33
|
connection = where(expires_at: Time.current..).find_by(token_digest: digest(token.to_s))
|
|
33
34
|
connection&.touch(:last_used_at)
|
|
34
|
-
connection
|
|
35
|
+
connection && Caller.new(person: connection.person, account: connection.account)
|
|
35
36
|
end
|
|
36
37
|
|
|
38
|
+
def self.person_for(token) = caller_for(token)&.person
|
|
39
|
+
|
|
37
40
|
def self.digest(token) = Digest::SHA256.hexdigest(token)
|
|
38
41
|
|
|
39
42
|
def self.new_tokens = Tokens.new(access_token: SecureRandom.urlsafe_base64(32), refresh_token: SecureRandom.urlsafe_base64(32))
|
|
@@ -45,6 +48,8 @@ module HubKernel
|
|
|
45
48
|
private_class_method :new_tokens, :digests_for
|
|
46
49
|
|
|
47
50
|
def person = GlobalID::Locator.locate(person_gid)
|
|
51
|
+
|
|
52
|
+
def account = GlobalID::Locator.locate(account_gid)
|
|
48
53
|
end
|
|
49
54
|
end
|
|
50
55
|
end
|
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
<%= hidden_field_tag name, value %>
|
|
6
6
|
<% end %>
|
|
7
7
|
<%= hidden_field_tag :decision, "approve" %>
|
|
8
|
+
<% if account_options %>
|
|
9
|
+
<%= ui_form_field(attribute: :account, label: "Account", type: :select, options: account_options, value: preselected_account, include_blank: "Choose an account", errors: Array(@account_error)) %>
|
|
10
|
+
<% end %>
|
|
8
11
|
<%= ui_button(label: "Approve") %>
|
|
9
12
|
<% end %>
|
|
10
13
|
|
data/lib/hub_kernel/mcp.rb
CHANGED
|
@@ -15,6 +15,7 @@ module HubKernel
|
|
|
15
15
|
mattr_accessor :browser_person_method
|
|
16
16
|
mattr_accessor :browser_layout
|
|
17
17
|
mattr_accessor :registration_limit, default: 10
|
|
18
|
+
mattr_accessor :approval_accounts
|
|
18
19
|
|
|
19
20
|
BROWSER_SETTINGS = %i[browser_controller sign_in_method browser_person_method browser_layout].freeze
|
|
20
21
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: hub_kernel-mcp-develop
|
|
3
|
-
description: Use PROACTIVELY for calling a host's hub methods over MCP — connecting an MCP client to the endpoint, finding the endpoint's sign-in from a 401's WWW-Authenticate header and the two .well-known discovery documents, registering a client at the registration address and handling a registration refused past the hourly limit, sending a person to the approval page and handling the code or error it sends back, trading that code with its PKCE verifier for an access token and a refresh token at the token address, trading a refresh token for a new pair when the access token expires, reading the reason each sign-in step gives when it refuses, sending the access token on every request, sending initialize and ping, listing the tools a signed-in person may call with tools/list, calling one with tools/call, handling its tool errors and JSON-RPC errors, and reading the apps a person has connected, with when each connected
|
|
3
|
+
description: Use PROACTIVELY for calling a host's hub methods over MCP — connecting an MCP client to the endpoint, finding the endpoint's sign-in from a 401's WWW-Authenticate header and the two .well-known discovery documents, registering a client at the registration address and handling a registration refused past the hourly limit, sending a person to the approval page, where they may pick the account the app connects to, and handling the code or error it sends back, trading that code with its PKCE verifier for an access token and a refresh token at the token address, trading a refresh token for a new pair when the access token expires, reading the reason each sign-in step gives when it refuses, sending the access token on every request, sending initialize and ping, listing the tools a signed-in person may call with tools/list, calling one with tools/call, handling its tool errors and JSON-RPC errors, and reading the apps a person has connected, with when each connected, was last used and which account it was approved for — MUST BE USED instead of hand-rolling a JSON API, an MCP server, OAuth discovery documents, client registration, an OAuth approval page, an OAuth token endpoint, an OAuth refresh exchange or a query for a person's connected apps for the host's hubs.
|
|
4
4
|
tools: Read, Write, Edit, Grep
|
|
5
|
-
scope: hub MCP tools — serving the methods every hub a host serves, from hub_kernel-interface's one served list, as MCP tools at one JSON-RPC endpoint in a host Rails app, each call behind the host's own sign-in and hub_kernel-interface's permission check and account scope, with a boot check for hubs that cannot be served as tools, the OAuth discovery documents, 401 challenge and client registration that let a client such as Claude's connector screen find the endpoint's sign-in and register by itself, with each client recording the address it registered from and a configurable limit on how many clients one address may register per hour past which registration is refused, and the approval page where a person signed in to the host through the browser approves that client and is issued an authorization code, the token exchange that trades that code with its PKCE verifier for an access token lasting an hour and a refresh token, the refresh exchange that trades a refresh token for a new access token and a new refresh token and retires the one posted, and the
|
|
5
|
+
scope: hub MCP tools — serving the methods every hub a host serves, from hub_kernel-interface's one served list, as MCP tools at one JSON-RPC endpoint in a host Rails app, each call behind the host's own sign-in and hub_kernel-interface's permission check and account scope, with a boot check for hubs that cannot be served as tools, the OAuth discovery documents, 401 challenge and client registration that let a client such as Claude's connector screen find the endpoint's sign-in and register by itself, with each client recording the address it registered from and a configurable limit on how many clients one address may register per hour past which registration is refused, and the approval page where a person signed in to the host through the browser approves that client, picks the account it connects to when the host names the person's accounts, and is issued an authorization code, the token exchange that trades that code with its PKCE verifier for an access token lasting an hour and a refresh token, the refresh exchange that trades a refresh token for a new access token and a new refresh token and retires the one posted, and the lookups a host's sign-in calls to get the person a bearer token acts for, or that person and the account picked on the approval page, each recording when the connection was last used, and the settings section a host registers with settings_hub that lists a person's connections with the app's name, when it connected and when it was last used, and disconnects one that is the person's own, and the prune task a host schedules with its own job runner that removes expired authorization codes, connections whose access and refresh tokens have both expired, and clients over a day old with no connection
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
This local writes the code or configuration that talks to a host's hub_kernel-mcp
|
|
@@ -48,11 +48,18 @@ connections, or when a test needs to send requests to any of these addresses.
|
|
|
48
48
|
- `GET /authorize` — the approval page under the endpoint's path, such as
|
|
49
49
|
`/mcp/authorize`, opened in a person's browser. It sends a person who is not
|
|
50
50
|
signed in to the host through the host's sign-in, then shows the client's name
|
|
51
|
-
with an Approve and a Deny button.
|
|
52
|
-
shows
|
|
51
|
+
with an Approve and a Deny button. When the host names the accounts a person
|
|
52
|
+
may connect an app to, it also shows those accounts in a select labelled
|
|
53
|
+
`Account`, with the account already picked for a person who has one. A
|
|
54
|
+
request it cannot send back to the client shows a page whose heading is the
|
|
55
|
+
reason.
|
|
53
56
|
- `POST /authorize` — the approval page's answer. It sends the browser back to
|
|
54
57
|
the client's redirect address with a `code` and the client's `state` on
|
|
55
|
-
Approve, and with `error=access_denied` and the `state` on Deny.
|
|
58
|
+
Approve, and with `error=access_denied` and the `state` on Deny. When the host
|
|
59
|
+
names accounts, Approve carries the picked account's global id as `account`,
|
|
60
|
+
and an Approve with no account, or one not in the person's list, shows the
|
|
61
|
+
page again with status 422 and `Choose the account this app connects to`, and
|
|
62
|
+
sends nothing to the client.
|
|
56
63
|
- `POST /token` — the token address under the endpoint's path, such as
|
|
57
64
|
`/mcp/token`. It trades an approval's `code`, with the `redirect_uri` it was
|
|
58
65
|
approved for and the PKCE `code_verifier`, for an access token lasting an hour
|
|
@@ -72,7 +79,8 @@ connections, or when a test needs to send requests to any of these addresses.
|
|
|
72
79
|
must use PKCE with SHA-256.
|
|
73
80
|
- `HubKernel::Mcp::Connection.of` — takes a person record and answers an Active
|
|
74
81
|
Record relation of that person's connections, one per approval they gave,
|
|
75
|
-
each with its app's `client.name`, `created_at` and
|
|
82
|
+
each with its app's `client.name`, `created_at`, `last_used_at` and the
|
|
83
|
+
`account` picked when it was approved.
|
|
76
84
|
|
|
77
85
|
## How to use it
|
|
78
86
|
|
|
@@ -187,8 +195,17 @@ connections, or when a test needs to send requests to any of these addresses.
|
|
|
187
195
|
|
|
188
196
|
`redirect_uri` must be exactly one of the addresses registered in step 5.
|
|
189
197
|
The page runs the host's own sign-in first, then shows the client's name and
|
|
190
|
-
an Approve and a Deny button.
|
|
191
|
-
the
|
|
198
|
+
an Approve and a Deny button. On a host that names the accounts a person may
|
|
199
|
+
connect an app to, the page also asks which account the app connects to, and
|
|
200
|
+
a person with one account finds it already picked. The connection keeps the
|
|
201
|
+
picked account, and a host whose sign-in reads it runs every tool call made
|
|
202
|
+
with the tokens from this approval in that account, so a client
|
|
203
|
+
that should reach a second account sends the person through this step again
|
|
204
|
+
and picks the other one, which makes a second connection. Approving with no
|
|
205
|
+
account picked shows the page again with
|
|
206
|
+
`Choose the account this app connects to`, and the client hears nothing until
|
|
207
|
+
the person picks one. The browser comes back to `redirect_uri` with the
|
|
208
|
+
client's `state` added to any query the address already has:
|
|
192
209
|
|
|
193
210
|
| Query back | When |
|
|
194
211
|
|---|---|
|
|
@@ -256,7 +273,8 @@ connections, or when a test needs to send requests to any of these addresses.
|
|
|
256
273
|
A refresh is answered with status 200 and the same shape as step 7, holding a
|
|
257
274
|
new `access_token` and a new `refresh_token`. Replace both stored tokens with
|
|
258
275
|
the new ones at once. The refresh token posted stops working, and so does the
|
|
259
|
-
access token issued with it, even if its hour has not passed.
|
|
276
|
+
access token issued with it, even if its hour has not passed. The new access
|
|
277
|
+
token stays in the account the connection was approved for. A refresh token
|
|
260
278
|
lasts 90 days from when it was issued, and each refresh issues one that lasts
|
|
261
279
|
another 90 days.
|
|
262
280
|
|
|
@@ -374,11 +392,15 @@ connections, or when a test needs to send requests to any of these addresses.
|
|
|
374
392
|
connection.client.name # the name the app registered with
|
|
375
393
|
connection.created_at # when the person approved it
|
|
376
394
|
connection.last_used_at # when its access token last signed a request in, or nil if never
|
|
395
|
+
connection.account # the account picked on the approval page, or nil if none was
|
|
377
396
|
end
|
|
378
397
|
```
|
|
379
398
|
|
|
380
399
|
There is one connection per approval, so an app approved twice is listed
|
|
381
|
-
twice
|
|
400
|
+
twice, and an app connected to two accounts is listed once for each.
|
|
401
|
+
`account` is `nil` for a connection approved on a host that names no
|
|
402
|
+
accounts, and for every connection made before the host ran the
|
|
403
|
+
`account_gid` migrations. A refresh keeps the same connection and its `created_at`. A
|
|
382
404
|
connection stays listed after its access token expires. It leaves the list
|
|
383
405
|
when the person disconnects it, or when its access and refresh tokens have
|
|
384
406
|
both expired and the host's prune task runs. `last_used_at` is set each time the host's sign-in accepts
|
|
@@ -408,7 +430,9 @@ connections, or when a test needs to send requests to any of these addresses.
|
|
|
408
430
|
|
|
409
431
|
`approval` holds `response_type`, `client_id`, `redirect_uri`, `state`,
|
|
410
432
|
`code_challenge` and `code_challenge_method` for a client registered in the
|
|
411
|
-
test.
|
|
433
|
+
test. On a host that names accounts, the approval POST also carries
|
|
434
|
+
`account: account.to_global_id.to_s` for one of the signed-in person's
|
|
435
|
+
accounts. `code` is read from the `code` query value of the approval POST's
|
|
412
436
|
redirect, and `access_token` and `refresh_token` from a token POST's JSON
|
|
413
437
|
answer.
|
|
414
438
|
|
|
@@ -442,7 +466,9 @@ connections, or when a test needs to send requests to any of these addresses.
|
|
|
442
466
|
the endpoint's controller, sign-in, and served hubs, having the host's sign-in
|
|
443
467
|
accept an access token, naming the approval page's controller, sign-in, person
|
|
444
468
|
and layout, running the boot check, and registering the connections settings
|
|
445
|
-
section and its Disconnect action, setting the registration limit,
|
|
446
|
-
|
|
469
|
+
section and its Disconnect action, setting the registration limit, naming
|
|
470
|
+
the accounts the approval page offers, having the host's sign-in read the
|
|
471
|
+
account a token was approved for, and scheduling the prune task, which
|
|
472
|
+
belong to
|
|
447
473
|
`hub_kernel-mcp-install`, and setting which methods a hub exposes, who may
|
|
448
474
|
call them and their account scope, which belong to hub_kernel-interface.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: hub_kernel-mcp-info
|
|
3
|
-
description: Use to learn what hub_kernel-mcp offers — serving a host's hubs as MCP tools, how tools are named and scoped, how a client such as Claude's connector screen finds the endpoint's sign-in, registers itself, is approved by a person through the browser, trades its code for an access token and a refresh token and later trades the refresh token for a new pair, how each sign-in step refuses a bad request or an unexpected error, how many clients one address may register in an hour, how the host's sign-in finds the person a token acts for, how a person sees and disconnects the apps connected as them, how expired sign-in records are removed, and the vocabulary the install and develop locals assume.
|
|
3
|
+
description: Use to learn what hub_kernel-mcp offers — serving a host's hubs as MCP tools, how tools are named and scoped, how a client such as Claude's connector screen finds the endpoint's sign-in, registers itself, is approved by a person through the browser, who may pick the account it connects to, trades its code for an access token and a refresh token and later trades the refresh token for a new pair, how each sign-in step refuses a bad request or an unexpected error, how many clients one address may register in an hour, how the host's sign-in finds the person a token acts for and the account it was approved for, how a person sees and disconnects the apps connected as them, how expired sign-in records are removed, and the vocabulary the install and develop locals assume.
|
|
4
4
|
tools: Read
|
|
5
|
-
scope: hub MCP tools — serving the methods every hub a host serves, from hub_kernel-interface's one served list, as MCP tools at one JSON-RPC endpoint in a host Rails app, each call behind the host's own sign-in and hub_kernel-interface's permission check and account scope, with a boot check for hubs that cannot be served as tools, the OAuth discovery documents, 401 challenge and client registration that let a client such as Claude's connector screen find the endpoint's sign-in and register by itself, with each client recording the address it registered from and a configurable limit on how many clients one address may register per hour past which registration is refused, and the approval page where a person signed in to the host through the browser approves that client and is issued an authorization code, the token exchange that trades that code with its PKCE verifier for an access token lasting an hour and a refresh token, the refresh exchange that trades a refresh token for a new access token and a new refresh token and retires the one posted, and the
|
|
5
|
+
scope: hub MCP tools — serving the methods every hub a host serves, from hub_kernel-interface's one served list, as MCP tools at one JSON-RPC endpoint in a host Rails app, each call behind the host's own sign-in and hub_kernel-interface's permission check and account scope, with a boot check for hubs that cannot be served as tools, the OAuth discovery documents, 401 challenge and client registration that let a client such as Claude's connector screen find the endpoint's sign-in and register by itself, with each client recording the address it registered from and a configurable limit on how many clients one address may register per hour past which registration is refused, and the approval page where a person signed in to the host through the browser approves that client, picks the account it connects to when the host names the person's accounts, and is issued an authorization code, the token exchange that trades that code with its PKCE verifier for an access token lasting an hour and a refresh token, the refresh exchange that trades a refresh token for a new access token and a new refresh token and retires the one posted, and the lookups a host's sign-in calls to get the person a bearer token acts for, or that person and the account picked on the approval page, each recording when the connection was last used, and the settings section a host registers with settings_hub that lists a person's connections with the app's name, when it connected and when it was last used, and disconnects one that is the person's own, and the prune task a host schedules with its own job runner that removes expired authorization codes, connections whose access and refresh tokens have both expired, and clients over a day old with no connection
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
This local explains hub_kernel-mcp and makes no changes.
|
|
@@ -28,13 +28,14 @@ refused request tells the client where the endpoint is described, two discovery
|
|
|
28
28
|
documents name the endpoint's sign-in and its registration address, and the
|
|
29
29
|
client registers itself there with its name and redirect addresses. The client
|
|
30
30
|
then sends the person to an approval page in the host, where they sign in
|
|
31
|
-
through the host's usual browser sign-in and approve or deny the client.
|
|
32
|
-
|
|
31
|
+
through the host's usual browser sign-in and approve or deny the client. When
|
|
32
|
+
the host names the accounts a person belongs to, the page also asks which
|
|
33
|
+
account the app connects to. An approval gives the client an authorization code, which it trades at the token
|
|
33
34
|
address for an access token lasting an hour and a refresh token. When the
|
|
34
35
|
access token runs out, the client trades the refresh token at the same address
|
|
35
36
|
for a new pair, so the person does not approve the client again. The client
|
|
36
37
|
sends the access token on every request, and the host's sign-in asks the gem
|
|
37
|
-
which person the token acts for. A person using Claude's connector screen only
|
|
38
|
+
which person the token acts for, and which account the person picked for it. A person using Claude's connector screen only
|
|
38
39
|
pastes the endpoint's address.
|
|
39
40
|
|
|
40
41
|
A person can see which apps are connected as them, and cut one off. The gem
|
|
@@ -57,8 +58,9 @@ This local declares no entry points of its own.
|
|
|
57
58
|
- Adding the gem to a host, mounting the endpoint and the discovery documents,
|
|
58
59
|
installing the client, authorization code and connection tables, configuring
|
|
59
60
|
which controllers, person, account and sign-in methods and layout it uses,
|
|
60
|
-
setting the registration limit,
|
|
61
|
-
|
|
61
|
+
setting the registration limit, naming the accounts the approval page
|
|
62
|
+
offers, running the boot check, calling the token lookups from the host's
|
|
63
|
+
sign-in, registering the connections section and its
|
|
62
64
|
disconnect action with settings_hub, and scheduling the prune task are owned
|
|
63
65
|
by the install local, `hub_kernel-mcp-install`.
|
|
64
66
|
- The endpoint itself, the MCP requests it answers, the discovery documents,
|
|
@@ -71,7 +73,8 @@ This local declares no entry points of its own.
|
|
|
71
73
|
|
|
72
74
|
- To put hub_kernel-mcp into a Rails app, to let a connector screen sign in to
|
|
73
75
|
it, to point the approval page at the host's browser sign-in and layout, to
|
|
74
|
-
make the host's sign-in accept the access tokens this gem issues, to
|
|
76
|
+
make the host's sign-in accept the access tokens this gem issues, to let a
|
|
77
|
+
person pick the account an app connects to and run each call in it, to add the
|
|
75
78
|
connected apps section to the host's settings page, to raise or lower how
|
|
76
79
|
many clients one address may register in an hour, to schedule the removal of
|
|
77
80
|
expired sign-in records, or to fix a host whose boot check fails, use
|
|
@@ -137,10 +140,16 @@ This local declares no entry points of its own.
|
|
|
137
140
|
and nothing is sent to any address. A request without a SHA-256 PKCE
|
|
138
141
|
challenge is sent back to the client as an invalid request. A denial is sent
|
|
139
142
|
back to the client as access denied.
|
|
143
|
+
- **Account choice** — when the host names the accounts a person may connect
|
|
144
|
+
an app to, as a label and an account record for each, the approval page
|
|
145
|
+
lists them and asks which one the app connects to. A person with one account
|
|
146
|
+
finds it already picked. Approving with no account picked, or one not in the
|
|
147
|
+
list, shows the page again with `Choose the account this app connects to` and
|
|
148
|
+
issues no code. When the host names no accounts, the page asks for none.
|
|
140
149
|
- **Authorization code** — what an approval sends back to the client's redirect
|
|
141
150
|
address, along with the client's state. It is tied to the person, the client,
|
|
142
|
-
the redirect address
|
|
143
|
-
digest of it is stored.
|
|
151
|
+
the redirect address, the PKCE challenge and the account picked, if any,
|
|
152
|
+
lasts ten minutes, and only a digest of it is stored.
|
|
144
153
|
- **Token exchange** — the client posts its client id, its code, its redirect
|
|
145
154
|
address and its PKCE verifier to the token address, with no sign-in. A code
|
|
146
155
|
that is unknown, expired, already traded, issued to another client, sent with
|
|
@@ -151,12 +160,17 @@ This local declares no entry points of its own.
|
|
|
151
160
|
body that cannot be read is refused as an invalid request.
|
|
152
161
|
- **Access token, refresh token and connection** — what a traded code is
|
|
153
162
|
answered with: a bearer access token that lasts an hour and a refresh token
|
|
154
|
-
that lasts ninety days. The pair is stored as a connection tying the person
|
|
155
|
-
|
|
163
|
+
that lasts ninety days. The pair is stored as a connection tying the person,
|
|
164
|
+
the client and the account picked on the approval page to a digest of each
|
|
165
|
+
token, so neither token itself is stored. A connection keeps the account by
|
|
166
|
+
its global id, and one made with no account, including every one made before
|
|
167
|
+
the account was kept, has none. Each approval makes its own connection, so
|
|
168
|
+
connecting the same app to a second account makes a second connection.
|
|
156
169
|
- **Refresh exchange** — the client posts its client id and its refresh token to
|
|
157
170
|
the token address, asking for the refresh grant, with no sign-in. It is
|
|
158
171
|
answered with a new access token and a new refresh token on the same
|
|
159
|
-
connection,
|
|
172
|
+
connection, so the new access token keeps the connection's account, and the
|
|
173
|
+
new refresh token lasts another ninety days. The refresh
|
|
160
174
|
token posted and the access token it was issued with both stop working. A
|
|
161
175
|
refresh token that is unknown, already used, issued to another client, or
|
|
162
176
|
unused for ninety days is refused as an invalid grant, and of two refreshes
|
|
@@ -166,12 +180,13 @@ This local declares no entry points of its own.
|
|
|
166
180
|
with status 500 and a server error. On the approval page it shows the error
|
|
167
181
|
page instead. Either way its message is never sent to the client or shown to
|
|
168
182
|
the person, and it is reported to the host's error reporting.
|
|
169
|
-
- **Token
|
|
170
|
-
request.
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
183
|
+
- **Token lookups** — what the host's sign-in calls with the bearer token from
|
|
184
|
+
a request. One gives the person the access token acts for. The other gives
|
|
185
|
+
that person together with the account picked on the approval page, or no
|
|
186
|
+
account for a connection made with none. Both give nothing for an expired,
|
|
187
|
+
replaced or unknown token, and each lookup that finds a connection records the
|
|
188
|
+
time on it as when it was last used. The account a call is made in still
|
|
189
|
+
comes from the host's account method, which may return the looked-up account.
|
|
175
190
|
- **Connections section** — the part of a host's settings page that lists the
|
|
176
191
|
signed-in person's connections, oldest first, each with the app's name, when
|
|
177
192
|
it connected, and when it was last used or that it was never used. It is
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: hub_kernel-mcp-install
|
|
3
|
-
description: Use to hook hub_kernel-mcp into a project — adding the gem, naming the controller the endpoint inherits from and the person and account methods on it, naming the browser controller, sign-in method, person method and layout the approval page runs with, running the boot check after the served list is set, mounting the engine, and, for sign-in from a connector screen, installing the migrations, mounting the discovery documents, setting how many clients one address may register per hour, having the host's sign-in look up the person an access token acts for, registering the settings section that lists a person's connections and disconnects one, and scheduling the task that prunes sign-in records.
|
|
3
|
+
description: Use to hook hub_kernel-mcp into a project — adding the gem, naming the controller the endpoint inherits from and the person and account methods on it, naming the browser controller, sign-in method, person method and layout the approval page runs with, running the boot check after the served list is set, mounting the engine, and, for sign-in from a connector screen, installing the migrations, mounting the discovery documents, setting how many clients one address may register per hour, naming the accounts a person may pick on the approval page, having the host's sign-in look up the person an access token acts for and the account it was approved for, registering the settings section that lists a person's connections and disconnects one, and scheduling the task that prunes sign-in records.
|
|
4
4
|
tools: Bash, Read, Edit
|
|
5
|
-
scope: hub MCP tools — serving the methods every hub a host serves, from hub_kernel-interface's one served list, as MCP tools at one JSON-RPC endpoint in a host Rails app, each call behind the host's own sign-in and hub_kernel-interface's permission check and account scope, with a boot check for hubs that cannot be served as tools, the OAuth discovery documents, 401 challenge and client registration that let a client such as Claude's connector screen find the endpoint's sign-in and register by itself, with each client recording the address it registered from and a configurable limit on how many clients one address may register per hour past which registration is refused, and the approval page where a person signed in to the host through the browser approves that client and is issued an authorization code, the token exchange that trades that code with its PKCE verifier for an access token lasting an hour and a refresh token, the refresh exchange that trades a refresh token for a new access token and a new refresh token and retires the one posted, and the
|
|
5
|
+
scope: hub MCP tools — serving the methods every hub a host serves, from hub_kernel-interface's one served list, as MCP tools at one JSON-RPC endpoint in a host Rails app, each call behind the host's own sign-in and hub_kernel-interface's permission check and account scope, with a boot check for hubs that cannot be served as tools, the OAuth discovery documents, 401 challenge and client registration that let a client such as Claude's connector screen find the endpoint's sign-in and register by itself, with each client recording the address it registered from and a configurable limit on how many clients one address may register per hour past which registration is refused, and the approval page where a person signed in to the host through the browser approves that client, picks the account it connects to when the host names the person's accounts, and is issued an authorization code, the token exchange that trades that code with its PKCE verifier for an access token lasting an hour and a refresh token, the refresh exchange that trades a refresh token for a new access token and a new refresh token and retires the one posted, and the lookups a host's sign-in calls to get the person a bearer token acts for, or that person and the account picked on the approval page, each recording when the connection was last used, and the settings section a host registers with settings_hub that lists a person's connections with the app's name, when it connected and when it was last used, and disconnects one that is the person's own, and the prune task a host schedules with its own job runner that removes expired authorization codes, connections whose access and refresh tokens have both expired, and clients over a day old with no connection
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
This local follows these steps exactly and invents none. Where a step names a
|
|
@@ -31,15 +31,17 @@ a signed-in person's behalf.
|
|
|
31
31
|
- `mount HubKernel::Mcp::Discovery` — mounts the two OAuth discovery documents
|
|
32
32
|
in the host's `config/routes.rb`. It must be mounted at `"/.well-known"`,
|
|
33
33
|
since the endpoint's 401 header names that path.
|
|
34
|
-
- `bin/rails hub_kernel_mcp:install:migrations` — copies the gem's
|
|
34
|
+
- `bin/rails hub_kernel_mcp:install:migrations` — copies the gem's nine
|
|
35
35
|
migrations into the host's `db/migrate`. They create the
|
|
36
36
|
`hub_kernel_mcp_clients` table, which holds each client that registers, the
|
|
37
37
|
`hub_kernel_mcp_authorization_codes` table, which holds each code the
|
|
38
38
|
approval page issues, and the `hub_kernel_mcp_connections` table, which holds
|
|
39
39
|
each access token issued for a code. They then add the refresh token's
|
|
40
40
|
columns, a `last_used_at` column and an indexed `code_digest` column to
|
|
41
|
-
`hub_kernel_mcp_connections`,
|
|
42
|
-
`created_at`, to `hub_kernel_mcp_clients
|
|
41
|
+
`hub_kernel_mcp_connections`, a `registered_from` column, indexed with
|
|
42
|
+
`created_at`, to `hub_kernel_mcp_clients`, and a nullable `account_gid`
|
|
43
|
+
column, which holds the global id of the account picked on the approval page,
|
|
44
|
+
to both `hub_kernel_mcp_authorization_codes` and `hub_kernel_mcp_connections`.
|
|
43
45
|
- `HubKernel::Mcp.base_controller=` — the name, as a String, of the host
|
|
44
46
|
controller the endpoint inherits from. Its before-actions, including sign-in,
|
|
45
47
|
run before any hub is asked. Defaults to `"ActionController::API"`, which has
|
|
@@ -64,6 +66,17 @@ a signed-in person's behalf.
|
|
|
64
66
|
- `HubKernel::Mcp.registration_limit=` — the number, as an Integer, of clients
|
|
65
67
|
one IP address may register in the last hour. A registration past it is
|
|
66
68
|
answered with status 429 and `too_many_registrations`. Defaults to `10`.
|
|
69
|
+
- `HubKernel::Mcp.approval_accounts=` — a callable the approval page calls with
|
|
70
|
+
the signed-in person, which returns the accounts that person may connect an
|
|
71
|
+
app to, as `[[label, account], ...]`. Each account must be a record with a
|
|
72
|
+
global id. When it is set, the approval page shows the accounts in a select
|
|
73
|
+
labelled `Account` and asks which one the app connects to, a person with one
|
|
74
|
+
account finds it already picked, and approving with no account picked, or one
|
|
75
|
+
not in the list, shows the page again with
|
|
76
|
+
`Choose the account this app connects to` and issues no code. The picked
|
|
77
|
+
account is kept on the authorization code and then on the connection. When it
|
|
78
|
+
is not set, the page asks for no account and every connection is made with
|
|
79
|
+
none. No default.
|
|
67
80
|
- `HubKernel::Mcp.check!` — the boot check. Raises
|
|
68
81
|
`HubKernel::Mcp::UnservableHubError` when any served hub cannot be served as
|
|
69
82
|
tools, or when any of the four browser settings is not set, and returns
|
|
@@ -77,6 +90,14 @@ a signed-in person's behalf.
|
|
|
77
90
|
old, replaced by a refresh, or disconnected. Each time it returns a person it
|
|
78
91
|
records the time as the connection's last use. The host's sign-in on the base
|
|
79
92
|
controller calls it.
|
|
93
|
+
- `HubKernel::Mcp::Connection.caller_for` — takes the same bearer token, as a
|
|
94
|
+
String, and returns a value whose `person` is the person who approved the
|
|
95
|
+
client and whose `account` is the account they picked on the approval page.
|
|
96
|
+
`account` is `nil` for a connection made with no account, which includes every
|
|
97
|
+
connection made before the `account_gid` migration ran. Returns `nil` for the
|
|
98
|
+
same tokens `person_for` does, and records the connection's last use the same
|
|
99
|
+
way. A host that lets a person pick an account calls it in place of
|
|
100
|
+
`person_for`.
|
|
80
101
|
- `SettingsHub.section` — settings_hub's call that registers a section on the
|
|
81
102
|
host's settings page. The host calls it once to register the connections
|
|
82
103
|
section, naming the partial and the action below.
|
|
@@ -195,9 +216,9 @@ a signed-in person's behalf.
|
|
|
195
216
|
bin/rails hub_kernel_mcp:install:migrations db:migrate
|
|
196
217
|
```
|
|
197
218
|
|
|
198
|
-
This adds
|
|
219
|
+
This adds nine migrations to the host's `db/migrate` and the
|
|
199
220
|
`hub_kernel_mcp_clients`, `hub_kernel_mcp_authorization_codes` and
|
|
200
|
-
`hub_kernel_mcp_connections` tables to `db/schema.rb`. Commit all
|
|
221
|
+
`hub_kernel_mcp_connections` tables to `db/schema.rb`. Commit all ten
|
|
201
222
|
files.
|
|
202
223
|
|
|
203
224
|
10. Add the discovery mount to `config/routes.rb`, at the site root beside the
|
|
@@ -259,6 +280,33 @@ a signed-in person's behalf.
|
|
|
259
280
|
carry, such as a session or a subdomain, tell the developer and ask what it
|
|
260
281
|
should return.
|
|
261
282
|
|
|
283
|
+
Ask the developer whether a person may belong to more than one account and
|
|
284
|
+
should pick, on the approval page, the account an app connects to. If not,
|
|
285
|
+
leave `approval_accounts` unset and keep `person_for`. If so, ask how to list
|
|
286
|
+
a person's accounts and what label each shows, and do not choose either. Add
|
|
287
|
+
the answer to `config/initializers/hub_kernel_mcp.rb`:
|
|
288
|
+
|
|
289
|
+
```ruby
|
|
290
|
+
HubKernel::Mcp.approval_accounts = ->(person) { person.accounts.map { |account| [ account.name, account ] } }
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
Then have the base controller look the token up with
|
|
294
|
+
`HubKernel::Mcp::Connection.caller_for`, and take both the person and the
|
|
295
|
+
account from it:
|
|
296
|
+
|
|
297
|
+
```ruby
|
|
298
|
+
def current_caller = authenticate_with_http_token { |token| HubKernel::Mcp::Connection.caller_for(token) }
|
|
299
|
+
|
|
300
|
+
def current_person = current_caller&.person
|
|
301
|
+
|
|
302
|
+
def current_account = current_caller&.account || default_account
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
A connection approved with no account, including every connection made
|
|
306
|
+
before the `account_gid` migration ran, gives `nil` as its account. Ask the
|
|
307
|
+
developer which account such a call runs in, or whether it is refused, and
|
|
308
|
+
do not choose. `default_account` above stands for that answer.
|
|
309
|
+
|
|
262
310
|
14. Check the layout from step 4. The approval page runs inside the gem's
|
|
263
311
|
engine, so a route helper the layout calls for one of the host's own routes,
|
|
264
312
|
such as `root_path`, must be written `main_app.root_path`. If the layout
|
|
@@ -346,16 +394,27 @@ a signed-in person's behalf.
|
|
|
346
394
|
while signed out: the host's sign-in should take over. Signed in, the same
|
|
347
395
|
address with no query shows a page saying
|
|
348
396
|
`The approval request is missing client_id`.
|
|
397
|
+
- With `approval_accounts` set, check it with
|
|
398
|
+
`bin/rails runner "p HubKernel::Mcp.approval_accounts.call(User.first)"`,
|
|
399
|
+
using the host's own person model, which should print each label beside its
|
|
400
|
+
account record.
|
|
349
401
|
- With the token lookup installed, check it with
|
|
350
|
-
`bin/rails runner "p HubKernel::Mcp::Connection.person_for('unknown')"`,
|
|
351
|
-
which should print `nil`, and with
|
|
352
|
-
`Authorization: Bearer unknown`, which
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
the
|
|
358
|
-
|
|
402
|
+
`bin/rails runner "p HubKernel::Mcp::Connection.person_for('unknown')"`, or
|
|
403
|
+
`caller_for` in its place, which should print `nil`, and with
|
|
404
|
+
`curl -i -X POST <host>/mcp` carrying `Authorization: Bearer unknown`, which
|
|
405
|
+
should answer 401.
|
|
406
|
+
- Run `bin/rails hub_kernel_mcp:install:migrations db:migrate` again after
|
|
407
|
+
upgrading the gem. It copies only migrations the host does not have yet. A
|
|
408
|
+
host that installed an earlier version with fewer than nine migrations gets
|
|
409
|
+
the missing ones this way, including the two that add `account_gid`. Until
|
|
410
|
+
they are run, the registration address or the token address answers status
|
|
411
|
+
500 with `server_error`, the approval page says
|
|
412
|
+
`Signing in failed unexpectedly`, or the token lookups and the connections
|
|
413
|
+
list fail on a missing column.
|
|
414
|
+
- Each approval makes its own connection, so a person who connects the same app
|
|
415
|
+
to a second account has two connections, each listed in the connections
|
|
416
|
+
section. A refreshed access token stays in the account its connection was
|
|
417
|
+
approved for.
|
|
359
418
|
- With the prune task scheduled, run `bin/rails hub_kernel_mcp:prune` once by
|
|
360
419
|
hand. It prints nothing and exits 0. It removes only codes past their ten
|
|
361
420
|
minutes, connections with no working token, and clients over a day old with
|
data/the_local/interface.yml
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
scope: hub MCP tools — serving the methods every hub a host serves, from hub_kernel-interface's one served list, as MCP tools at one JSON-RPC endpoint in a host Rails app, each call behind the host's own sign-in and hub_kernel-interface's permission check and account scope, with a boot check for hubs that cannot be served as tools, the OAuth discovery documents, 401 challenge and client registration that let a client such as Claude's connector screen find the endpoint's sign-in and register by itself, with each client recording the address it registered from and a configurable limit on how many clients one address may register per hour past which registration is refused, and the approval page where a person signed in to the host through the browser approves that client and is issued an authorization code, the token exchange that trades that code with its PKCE verifier for an access token lasting an hour and a refresh token, the refresh exchange that trades a refresh token for a new access token and a new refresh token and retires the one posted, and the
|
|
1
|
+
scope: hub MCP tools — serving the methods every hub a host serves, from hub_kernel-interface's one served list, as MCP tools at one JSON-RPC endpoint in a host Rails app, each call behind the host's own sign-in and hub_kernel-interface's permission check and account scope, with a boot check for hubs that cannot be served as tools, the OAuth discovery documents, 401 challenge and client registration that let a client such as Claude's connector screen find the endpoint's sign-in and register by itself, with each client recording the address it registered from and a configurable limit on how many clients one address may register per hour past which registration is refused, and the approval page where a person signed in to the host through the browser approves that client, picks the account it connects to when the host names the person's accounts, and is issued an authorization code, the token exchange that trades that code with its PKCE verifier for an access token lasting an hour and a refresh token, the refresh exchange that trades a refresh token for a new access token and a new refresh token and retires the one posted, and the lookups a host's sign-in calls to get the person a bearer token acts for, or that person and the account picked on the approval page, each recording when the connection was last used, and the settings section a host registers with settings_hub that lists a person's connections with the app's name, when it connected and when it was last used, and disconnects one that is the person's own, and the prune task a host schedules with its own job runner that removes expired authorization codes, connections whose access and refresh tokens have both expired, and clients over a day old with no connection
|
|
2
2
|
|
|
3
3
|
install:
|
|
4
4
|
- gem "hub_kernel-mcp"
|
|
@@ -13,9 +13,11 @@ install:
|
|
|
13
13
|
- HubKernel::Mcp.browser_person_method=
|
|
14
14
|
- HubKernel::Mcp.browser_layout=
|
|
15
15
|
- HubKernel::Mcp.registration_limit=
|
|
16
|
+
- HubKernel::Mcp.approval_accounts=
|
|
16
17
|
- HubKernel::Mcp.check!
|
|
17
18
|
- HubKernel::Mcp::UnservableHubError
|
|
18
19
|
- HubKernel::Mcp::Connection.person_for
|
|
20
|
+
- HubKernel::Mcp::Connection.caller_for
|
|
19
21
|
- SettingsHub.section
|
|
20
22
|
- hub_kernel/mcp/connections
|
|
21
23
|
- HubKernel::Mcp::Disconnect
|
|
@@ -51,6 +53,8 @@ sources:
|
|
|
51
53
|
- db/migrate/20261009000002_add_last_used_at_to_hub_kernel_mcp_connections.rb
|
|
52
54
|
- db/migrate/20261009000003_add_code_digest_to_hub_kernel_mcp_connections.rb
|
|
53
55
|
- db/migrate/20261009000004_add_registered_from_to_hub_kernel_mcp_clients.rb
|
|
56
|
+
- db/migrate/20261123175537_add_account_gid_to_hub_kernel_mcp_connections.rb
|
|
57
|
+
- db/migrate/20261123175631_add_account_gid_to_hub_kernel_mcp_authorization_codes.rb
|
|
54
58
|
- app/models/hub_kernel/mcp/client.rb
|
|
55
59
|
- app/models/hub_kernel/mcp/authorization_code.rb
|
|
56
60
|
- app/models/hub_kernel/mcp/connection.rb
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hub_kernel-mcp
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.11.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- tylercschneider
|
|
@@ -29,14 +29,14 @@ dependencies:
|
|
|
29
29
|
requirements:
|
|
30
30
|
- - "~>"
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: '0.
|
|
32
|
+
version: '0.9'
|
|
33
33
|
type: :runtime
|
|
34
34
|
prerelease: false
|
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
|
37
37
|
- - "~>"
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
|
-
version: '0.
|
|
39
|
+
version: '0.9'
|
|
40
40
|
- !ruby/object:Gem::Dependency
|
|
41
41
|
name: keystone_ui
|
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -85,6 +85,8 @@ files:
|
|
|
85
85
|
- db/migrate/20261009000002_add_last_used_at_to_hub_kernel_mcp_connections.rb
|
|
86
86
|
- db/migrate/20261009000003_add_code_digest_to_hub_kernel_mcp_connections.rb
|
|
87
87
|
- db/migrate/20261009000004_add_registered_from_to_hub_kernel_mcp_clients.rb
|
|
88
|
+
- db/migrate/20261123175537_add_account_gid_to_hub_kernel_mcp_connections.rb
|
|
89
|
+
- db/migrate/20261123175631_add_account_gid_to_hub_kernel_mcp_authorization_codes.rb
|
|
88
90
|
- lib/hub_kernel-mcp.rb
|
|
89
91
|
- lib/hub_kernel/mcp.rb
|
|
90
92
|
- lib/hub_kernel/mcp/challenge.rb
|