Skip to content

Commit f4c096c

Browse files
simonfaltumIsaac
andcommitted
Add aitools mcp login, logout and list --check
Provider sign-in for the external MCP services (GitHub, Slack and others). login opens the sign-in page, prints its URL first and polls the caller's credential until it is ACTIVE. logout deletes the credential and treats a missing one as success. add gains --login and --no-login, and list gains --check, which mints a token per profile, reads sign-in state and checks the recorded binary. The testserver serves the user-credentials GET, POST and DELETE routes. A POST completes a sign-in, which the acceptance scripts use in place of the browser. Co-authored-by: Isaac <no-reply@databricks.com>
1 parent 4ecc28f commit f4c096c

24 files changed

Lines changed: 1061 additions & 14 deletions

‎acceptance/cmd/aitools/mcp/hidden/output.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ Flags:
2727
--force Overwrite an existing server with the same name that this CLI did not write
2828
-h, --help help for add
2929
--location string Schema to resolve leaf names in, as <catalog>.<schema> (default system.ai)
30+
--login Sign in to each sign-in-required server right after it is installed
3031
--name string Server name to use instead of the generated one; only with exactly one service
3132
--names string Services to install: full names (system.ai.github) or leaf names (github), comma-separated
33+
--no-login Do not sign in; print the login commands for sign-in-required servers (default)
3234

3335
Global Flags:
3436
--debug enable debug logging
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[logfood]
2+
host = $DATABRICKS_HOST
3+
token = test-token-logfood
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Cloud = false
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
2+
=== Install a service that needs no sign-in and one that does
3+
4+
>>> [CLI] aitools mcp add --profile logfood --names system.ai.genie_one_mcp,system.ai.github --agents claude-code
5+
Profile logfood ([DATABRICKS_URL])
6+
Agents (named with --agents): claude-code
7+
8+
genie_one_mcp-logfood system.ai.genie_one_mcp
9+
claude-code installed [TEST_TMP_DIR]/home/.claude.json
10+
11+
github-logfood system.ai.github
12+
claude-code installed [TEST_TMP_DIR]/home/.claude.json
13+
system.ai.github needs sign-in. Run: databricks aitools mcp login system.ai.github --profile logfood
14+
15+
=== list --check: the token mints, and GitHub needs sign-in
16+
17+
>>> [CLI] aitools mcp list --check
18+
Profile logfood ([DATABRICKS_URL]) token ok
19+
genie_one_mcp-logfood system.ai.genie_one_mcp Claude Code
20+
github-logfood system.ai.github Claude Code sign-in needed
21+
22+
=== Once the sign-in completes, GitHub is signed in
23+
24+
>>> [CLI] api post /api/2.1/unity-catalog/mcp-services/system.ai.github/user-credentials --profile logfood --json {}
25+
26+
>>> [CLI] aitools mcp list --check
27+
Profile logfood ([DATABRICKS_URL]) token ok
28+
genie_one_mcp-logfood system.ai.genie_one_mcp Claude Code
29+
github-logfood system.ai.github Claude Code signed in
30+
31+
=== A recorded binary that is gone is reported as missing
32+
33+
>>> [CLI] aitools mcp list --check --output json
34+
{
35+
"profiles": [
36+
{
37+
"profile": "logfood",
38+
"host": "[DATABRICKS_URL]",
39+
"status": "ok",
40+
"servers": [
41+
{
42+
"name": "genie_one_mcp-logfood",
43+
"service": "system.ai.genie_one_mcp",
44+
"sign_in_required": false,
45+
"agents": [
46+
{
47+
"name": "claude-code",
48+
"path": "[TEST_TMP_DIR]/home/.claude.json",
49+
"status": "modified"
50+
}
51+
],
52+
"check": {
53+
"token": "ok",
54+
"binary": "failed"
55+
}
56+
},
57+
{
58+
"name": "github-logfood",
59+
"service": "system.ai.github",
60+
"sign_in_required": true,
61+
"agents": [
62+
{
63+
"name": "claude-code",
64+
"path": "[TEST_TMP_DIR]/home/.claude.json",
65+
"status": "installed"
66+
}
67+
],
68+
"check": {
69+
"token": "ok",
70+
"sign_in": "ok",
71+
"binary": "ok"
72+
}
73+
}
74+
]
75+
}
76+
],
77+
"unmanaged": []
78+
}
79+
80+
=== logout ends the sign-in; list --check shows it needed again
81+
82+
>>> [CLI] aitools mcp logout system.ai.github --profile logfood
83+
Signed out of system.ai.github on profile logfood.
84+
85+
>>> [CLI] aitools mcp list --check
86+
Profile logfood ([DATABRICKS_URL]) token ok
87+
genie_one_mcp-logfood system.ai.genie_one_mcp Claude Code (modified) binary missing
88+
github-logfood system.ai.github Claude Code sign-in needed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Isolate HOME so the agent config files and the state file land in this test directory.
2+
sethome home
3+
envsubst < .databrickscfg > out && mv out .databrickscfg
4+
export DATABRICKS_CONFIG_FILE=.databrickscfg
5+
6+
title "Install a service that needs no sign-in and one that does"
7+
trace $CLI aitools mcp add --profile logfood --names system.ai.genie_one_mcp,system.ai.github --agents claude-code
8+
9+
title "list --check: the token mints, and GitHub needs sign-in"
10+
trace $CLI aitools mcp list --check
11+
12+
title "Once the sign-in completes, GitHub is signed in"
13+
trace $CLI api post /api/2.1/unity-catalog/mcp-services/system.ai.github/user-credentials --profile logfood --json '{}' > /dev/null
14+
trace $CLI aitools mcp list --check
15+
16+
title "A recorded binary that is gone is reported as missing"
17+
jq '(.servers[] | select(.service == "system.ai.genie_one_mcp") | .command) = "/nonexistent/databricks"' home/.databricks/aitools/mcp/state.json > state.tmp && mv state.tmp home/.databricks/aitools/mcp/state.json
18+
trace $CLI aitools mcp list --check --output json
19+
20+
title "logout ends the sign-in; list --check shows it needed again"
21+
trace $CLI aitools mcp logout system.ai.github --profile logfood
22+
trace $CLI aitools mcp list --check
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[logfood]
2+
host = $DATABRICKS_HOST
3+
token = test-token-logfood
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Cloud = false
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
2+
=== A service that needs no sign-in exits 0 and says so
3+
4+
>>> [CLI] aitools mcp login system.ai.genie_one_mcp --profile logfood
5+
system.ai.genie_one_mcp does not need sign-in.
6+
7+
=== login prints the sign-in URL and waits; the sign-in completes in the browser
8+
9+
>>> retry --until Waiting for sign-in cat login.txt
10+
Sign in with the same account you use for Databricks profile logfood.
11+
Open this URL to sign in to system.ai.github:
12+
[DATABRICKS_URL]/mcp-service-login?name=system.ai.github&o=[WORKSPACE_ID]
13+
Waiting for sign-in...
14+
15+
>>> [CLI] api post /api/2.1/unity-catalog/mcp-services/system.ai.github/user-credentials --profile logfood --json {}
16+
17+
>>> cat login.txt
18+
Sign in with the same account you use for Databricks profile logfood.
19+
Open this URL to sign in to system.ai.github:
20+
[DATABRICKS_URL]/mcp-service-login?name=system.ai.github&o=[WORKSPACE_ID]
21+
Waiting for sign-in...
22+
Signed in to system.ai.github on profile logfood.
23+
Public repositories only until a repository owner installs https://github.com/apps/databricks-github-connector
24+
25+
=== login again when already signed in returns at once
26+
27+
>>> [CLI] aitools mcp login system.ai.github --profile logfood --output json
28+
Sign in with the same account you use for Databricks profile logfood.
29+
Signed in to system.ai.github on profile logfood.
30+
Public repositories only until a repository owner installs https://github.com/apps/databricks-github-connector
31+
{
32+
"service": "system.ai.github",
33+
"profile": "logfood",
34+
"host": "[DATABRICKS_URL]",
35+
"state": "ACTIVE",
36+
"url": "[DATABRICKS_URL]/mcp-service-login?name=system.ai.github\u0026o=[WORKSPACE_ID]"
37+
}
38+
39+
=== logout removes the sign-in; a second logout finds nothing and still exits 0
40+
41+
>>> [CLI] aitools mcp logout system.ai.github --profile logfood
42+
Signed out of system.ai.github on profile logfood.
43+
44+
>>> [CLI] aitools mcp logout system.ai.github --profile logfood --output json
45+
Not signed in to system.ai.github on profile logfood.
46+
{
47+
"service": "system.ai.github",
48+
"profile": "logfood",
49+
"host": "[DATABRICKS_URL]",
50+
"state": "NOT_SIGNED_IN"
51+
}
52+
53+
=== add --login installs the server and signs in during the same run
54+
55+
>>> retry --until Waiting for sign-in cat add.txt
56+
Profile logfood ([DATABRICKS_URL])
57+
Agents (named with --agents): claude-code
58+
59+
github-logfood system.ai.github
60+
claude-code installed [TEST_TMP_DIR]/home/.claude.json
61+
Sign in with the same account you use for Databricks profile logfood.
62+
Open this URL to sign in to system.ai.github:
63+
[DATABRICKS_URL]/mcp-service-login?name=system.ai.github&o=[WORKSPACE_ID]
64+
Waiting for sign-in...
65+
66+
>>> [CLI] api post /api/2.1/unity-catalog/mcp-services/system.ai.github/user-credentials --profile logfood --json {}
67+
68+
>>> cat add.txt
69+
Profile logfood ([DATABRICKS_URL])
70+
Agents (named with --agents): claude-code
71+
72+
github-logfood system.ai.github
73+
claude-code installed [TEST_TMP_DIR]/home/.claude.json
74+
Sign in with the same account you use for Databricks profile logfood.
75+
Open this URL to sign in to system.ai.github:
76+
[DATABRICKS_URL]/mcp-service-login?name=system.ai.github&o=[WORKSPACE_ID]
77+
Waiting for sign-in...
78+
Signed in to system.ai.github on profile logfood.
79+
Public repositories only until a repository owner installs https://github.com/apps/databricks-github-connector
80+
81+
>>> jq [.servers[] | {name, service, profile, agents: (.agents | keys)}] home/.databricks/aitools/mcp/state.json
82+
[
83+
{
84+
"name": "github-logfood",
85+
"service": "system.ai.github",
86+
"profile": "logfood",
87+
"agents": [
88+
"claude-code"
89+
]
90+
}
91+
]
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Isolate HOME so the agent config files and the state file land in this test directory.
2+
sethome home
3+
envsubst < .databrickscfg > out && mv out .databrickscfg
4+
export DATABRICKS_CONFIG_FILE=.databrickscfg
5+
# No browser: the CLI prints the sign-in URL and polls.
6+
export BROWSER=none
7+
8+
title "A service that needs no sign-in exits 0 and says so"
9+
trace $CLI aitools mcp login system.ai.genie_one_mcp --profile logfood
10+
11+
title "login prints the sign-in URL and waits; the sign-in completes in the browser"
12+
$CLI aitools mcp login system.ai.github --profile logfood > login.txt 2>&1 &
13+
PID=$!
14+
trace retry --until "Waiting for sign-in" cat login.txt
15+
trace $CLI api post /api/2.1/unity-catalog/mcp-services/system.ai.github/user-credentials --profile logfood --json '{}' > /dev/null
16+
wait $PID
17+
trace cat login.txt
18+
19+
title "login again when already signed in returns at once"
20+
trace $CLI aitools mcp login system.ai.github --profile logfood --output json
21+
22+
title "logout removes the sign-in; a second logout finds nothing and still exits 0"
23+
trace $CLI aitools mcp logout system.ai.github --profile logfood
24+
trace $CLI aitools mcp logout system.ai.github --profile logfood --output json
25+
26+
title "add --login installs the server and signs in during the same run"
27+
$CLI aitools mcp add --profile logfood --names system.ai.github --agents claude-code --login > add.txt 2>&1 &
28+
PID=$!
29+
trace retry --until "Waiting for sign-in" cat add.txt
30+
trace $CLI api post /api/2.1/unity-catalog/mcp-services/system.ai.github/user-credentials --profile logfood --json '{}' > /dev/null
31+
wait $PID
32+
trace cat add.txt
33+
trace jq '[.servers[] | {name, service, profile, agents: (.agents | keys)}]' home/.databricks/aitools/mcp/state.json
34+
rm login.txt add.txt
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# github needs sign-in and genie_one_mcp does not. The sign-in is completed by the script, which
2+
# creates the credential on the fake while login waits for it.
3+
[[Server]]
4+
Pattern = "GET /api/2.1/unity-catalog/mcp-services/system.ai.github"
5+
Response.Body = '''
6+
{
7+
"name": "mcp-services/system.ai.github",
8+
"comment": "Repositories, issues, pull requests",
9+
"config": {
10+
"source_connection": {
11+
"name": "connections/github",
12+
"options": {
13+
"oauth_provider": "github"
14+
}
15+
}
16+
}
17+
}
18+
'''
19+
20+
[[Server]]
21+
Pattern = "GET /api/2.1/unity-catalog/mcp-services/system.ai.genie_one_mcp"
22+
Response.Body = '''
23+
{
24+
"name": "mcp-services/system.ai.genie_one_mcp",
25+
"comment": "Ask questions about your data"
26+
}
27+
'''

0 commit comments

Comments
 (0)