Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
6c460ce
Add aitools mcp serve, the stdio proxy for managed MCP servers
simonfaltum Nov 12, 2026
528b449
Reject --log-file stdout on aitools mcp serve
simonfaltum Nov 12, 2026
88704f6
Make the serve-binding-errors byte count portable
simonfaltum Nov 12, 2026
cebf51c
Adapt serve acceptance to the shared state file and binding messages
simonfaltum Nov 12, 2026
136ce71
Set a 10 s connect timeout on the serve upstream transport
simonfaltum Nov 13, 2026
2ebe983
Update serve binding-error goldens for the named-server messages
simonfaltum Nov 13, 2026
96f258e
cmd/root: take the exit status from errors that set one
simonfaltum Nov 13, 2026
4264f58
cmd/root: refuse stdout logs for commands whose stdout is a protocol
simonfaltum Nov 13, 2026
506b5eb
serve: keep the session through cancelled requests and the shutdown D…
simonfaltum Nov 13, 2026
8c5fb6e
serve acceptance: LOG files, native config path, unknown agent accepted
simonfaltum Nov 13, 2026
75f18d1
cmd/root: check the stdout log file by identity; exit status by named…
simonfaltum Nov 13, 2026
02e0d3f
cmd/root: refuse a stdout log before the logger is installed
simonfaltum Nov 13, 2026
f8e7d53
serve: exit 2 for binding and token failures, print each once, check …
simonfaltum Nov 13, 2026
14e1fea
cmd/root: check stdout against the streams it is given
simonfaltum Nov 13, 2026
d64f9c1
cmd/root: compare stdout by identity only for regular files on Windows
simonfaltum Nov 13, 2026
be0b52b
cmd/root: allow a log file that is stderr when stdout is the same file
simonfaltum Nov 13, 2026
fb642e9
cmd/root: close the log file and restore the logger when Execute returns
simonfaltum Nov 13, 2026
e8bb12e
libs/aitools/mcp/proxy: let Authenticate skip the session DELETE
simonfaltum Nov 13, 2026
7e1311d
cmd/aitools: stop a refresh-failed serve cleanly and say why
simonfaltum Nov 13, 2026
a3e3809
libs/testserver: answer 404 for an MCP service the workspace does not…
simonfaltum Nov 13, 2026
6e2c717
cmd/root: test the stale-version skip for protocol commands; simplify…
simonfaltum Nov 13, 2026
1e0c584
cmd/aitools: serve takes add's flag names from mcpconfig and inlines …
simonfaltum Nov 13, 2026
6516374
acceptance: show the serve command line in its goldens
simonfaltum Nov 13, 2026
a3a3cb1
cmd/root: restore the standard log writer and flags after Execute
simonfaltum Nov 13, 2026
75c0f69
cmd/root: treat a stream that cannot be stat'ed as not stdout
simonfaltum Nov 13, 2026
42a7590
libs/testserver: match MCP service names without regard to case
simonfaltum Nov 13, 2026
459756c
acceptance: check serve's stdout framing line by line
simonfaltum Nov 13, 2026
00477df
cmd/aitools, cmd/root, libs/testserver: refactor serve tests and helpers
simonfaltum Nov 13, 2026
7655352
cmd/aitools, cmd/root: document serve's binding limitation and the Wi…
simonfaltum Nov 13, 2026
da97402
cmd/root: allow the standard log import in the logger restore
simonfaltum Nov 13, 2026
16ba1c0
aitools mcp serve: fail only the request on a transient token failure
simonfaltum Nov 13, 2026
10450c9
aitools mcp serve: no login hint for a transient token failure
simonfaltum Nov 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[logfood]
host = $DATABRICKS_HOST
token = test-token-logfood
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cloud = false
41 changes: 41 additions & 0 deletions acceptance/cmd/aitools/mcp/serve-binding-errors/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

=== The bound profile is not in the config file

>>> errcode [CLI] aitools mcp serve --profile gone --service system.ai.genie_one_mcp
MCP server system.ai.genie_one_mcp needs Databricks profile "gone", which does not exist in [TEST_TMP_DIR]/.databrickscfg. Set it up with: databricks auth login --profile gone

Exit code: 2
stdout bytes: 0

=== The profile now points at another host than the one recorded

>>> errcode [CLI] aitools mcp serve --profile logfood --service system.ai.genie_one_mcp
MCP server genie_one_mcp-logfood was set up for https://other.test, but profile "logfood" now points at [DATABRICKS_URL]. Run: databricks aitools mcp remove --names genie_one_mcp-logfood and add it again

Exit code: 2
stdout bytes: 0

=== Flags are required and validated before the binding checks

>>> errcode [CLI] aitools mcp serve --service system.ai.genie_one_mcp
Error: --profile is required

Exit code: 1

>>> errcode [CLI] aitools mcp serve --profile logfood --service github
Error: --service needs a full service name such as system.ai.github

Exit code: 1

>>> errcode [CLI] aitools mcp serve --profile logfood --service system.ai.genie_one_mcp --output json
Error: --output does not apply to serve: its stdout carries the MCP protocol

Exit code: 1

=== A log file on stdout is refused before anything is logged

>>> errcode [CLI] aitools mcp serve --profile logfood --service system.ai.genie_one_mcp --log-file stdout --log-level debug
Error: databricks aitools mcp serve writes protocol messages to stdout, so its logs cannot go to stdout; use --log-file stderr or a file

Exit code: 1
stdout bytes: 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"test-client","version":"0.0.1"}}}
{"jsonrpc":"2.0","method":"notifications/initialized"}
{"jsonrpc":"2.0","id":2,"method":"tools/list"}
{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"echo","arguments":{"text":"hello"}}}
55 changes: 55 additions & 0 deletions acceptance/cmd/aitools/mcp/serve-binding-errors/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Isolate HOME so the state file written below lands in this test directory.
sethome home
envsubst < .databrickscfg > out && mv out .databrickscfg
export DATABRICKS_CONFIG_FILE=.databrickscfg

# The state records the config file as the binary spells it. Git Bash's $PWD is /c/..., which the Windows binary does
# not match, so there use pwd -W, as sethome does.
case "$OSTYPE" in
msys*|cygwin*) cfgdir="$(pwd -W)" ;;
*) cfgdir="$PWD" ;;
esac

# Binding failures exit 2 with one message on stderr. Nothing reaches stdout, and stdin is not read.
title "The bound profile is not in the config file"
trace errcode $CLI aitools mcp serve --profile gone --service system.ai.genie_one_mcp < requests.ndjson > LOG.stdout
echo "stdout bytes: $(wc -c < LOG.stdout | tr -d ' ')"

# A state record for logfood that points at another host: the proxy never follows the profile.
mkdir -p home/.databricks/aitools/skills
cat > home/.databricks/aitools/skills/.state.json <<JSON
{
"schema_version": 3,
"mcp": {
"servers": [
{
"name": "genie_one_mcp-logfood",
"service": "system.ai.genie_one_mcp",
"profile": "logfood",
"host": "https://other.test",
"workspace_id": "",
"sign_in_required": false,
"command": "",
"config_file": "$cfgdir/.databrickscfg",
"agents": {},
"installed_at": "2026-01-01T00:00:00Z",
"cli_version": "0.0.0"
}
]
}
}
JSON

title "The profile now points at another host than the one recorded"
trace errcode $CLI aitools mcp serve --profile logfood --service system.ai.genie_one_mcp < requests.ndjson > LOG.stdout
echo "stdout bytes: $(wc -c < LOG.stdout | tr -d ' ')"

title "Flags are required and validated before the binding checks"
trace errcode $CLI aitools mcp serve --service system.ai.genie_one_mcp < requests.ndjson > LOG.stdout
trace errcode $CLI aitools mcp serve --profile logfood --service github < requests.ndjson > LOG.stdout
trace errcode $CLI aitools mcp serve --profile logfood --service system.ai.genie_one_mcp --output json < requests.ndjson > LOG.stdout

# Logs and the stale-version warning never share stdout with the protocol, even at debug level.
title "A log file on stdout is refused before anything is logged"
trace errcode $CLI aitools mcp serve --profile logfood --service system.ai.genie_one_mcp --log-file stdout --log-level debug < requests.ndjson > LOG.stdout
echo "stdout bytes: $(wc -c < LOG.stdout | tr -d ' ')"
3 changes: 3 additions & 0 deletions acceptance/cmd/aitools/mcp/serve-passthrough/.databrickscfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[logfood]
host = $DATABRICKS_HOST
token = test-token-logfood
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cloud = false
23 changes: 23 additions & 0 deletions acceptance/cmd/aitools/mcp/serve-passthrough/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

=== Stdout holds one JSON-RPC message per line; the notification gets no reply
{"id":1,"instructions":"Fake Databricks MCP service for tests.\n\nThis server is bound to Databricks workspace [DATABRICKS_URL] (CLI profile \"logfood\"). Its tools act on that workspace only.","tools":[],"text":null,"error":null}
{"id":2,"instructions":null,"tools":["echo"],"text":null,"error":null}
{"id":3,"instructions":null,"tools":[],"text":"hello","error":null}

=== Diagnostics go to stderr only

>>> cat LOG.stderr

>>> [CLI] aitools mcp serve --profile logfood --service system.ai.genie_one_mcp --agent claude-code
No install record for system.ai.genie_one_mcp on profile "logfood"; using its current host [DATABRICKS_URL]

=== An agent this binary does not know is accepted
{"id":1,"instructions":"Fake Databricks MCP service for tests.\n\nThis server is bound to Databricks workspace [DATABRICKS_URL] (CLI profile \"logfood\"). Its tools act on that workspace only.","tools":[],"text":null,"error":null}
{"id":2,"instructions":null,"tools":["echo"],"text":null,"error":null}
{"id":3,"instructions":null,"tools":[],"text":"hello","error":null}

>>> cat LOG.future

>>> [CLI] aitools mcp serve --profile logfood --service system.ai.genie_one_mcp --agent future-agent
No install record for system.ai.genie_one_mcp on profile "logfood"; using its current host [DATABRICKS_URL]
unknown agent "future-agent"; it is left out of the User-Agent
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"test-client","version":"0.0.1"}}}
{"jsonrpc":"2.0","method":"notifications/initialized"}
{"jsonrpc":"2.0","id":2,"method":"tools/list"}
{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"echo","arguments":{"text":"hello"}}}
25 changes: 25 additions & 0 deletions acceptance/cmd/aitools/mcp/serve-passthrough/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Isolate HOME so the proxy finds no state file and no agent config, as on a fresh machine.
sethome home
envsubst < .databrickscfg > out && mv out .databrickscfg
export DATABRICKS_CONFIG_FILE=.databrickscfg

# DATABRICKS_HOST points elsewhere; the proxy must still talk to the profile's host.
export DATABRICKS_HOST=https://elsewhere.test

# The service the proxy serves, created in the fake workspace. The fake answers 404 for a service it does not have.
MSYS_NO_PATHCONV=1 $CLI api post "/api/2.1/unity-catalog/mcp-services?parent=schemas/system.ai&mcp_service_id=genie_one_mcp" --profile logfood --json '{"comment": "Ask questions about your data"}' &> LOG.create-genie_one_mcp-logfood

# Each stdout line must be one complete JSON value, so a pretty-printed or doubled-up message fails the filter. Responses
# may arrive in any order, so they are sorted by id.
frames='split("\n") | map(select(length > 0) | fromjson) | sort_by(.id)[] | {id, instructions: .result.instructions, tools: [.result.tools[]?.name], text: .result.content[0].text, error}'

title "Stdout holds one JSON-RPC message per line; the notification gets no reply"
trace $CLI aitools mcp serve --profile logfood --service system.ai.genie_one_mcp --agent claude-code < requests.ndjson 2> LOG.stderr | jq -Rsc "$frames"

title "Diagnostics go to stderr only"
trace cat LOG.stderr

# An agent this binary does not know still serves; it is left out of the User-Agent, with one line on stderr.
title "An agent this binary does not know is accepted"
trace $CLI aitools mcp serve --profile logfood --service system.ai.genie_one_mcp --agent future-agent < requests.ndjson 2> LOG.future | jq -Rsc "$frames"
trace cat LOG.future
1 change: 1 addition & 0 deletions cmd/aitools/mcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func NewMcpCmd() *cobra.Command {
cmd.AddCommand(NewMcpAddCmd())
cmd.AddCommand(NewMcpListCmd())
cmd.AddCommand(NewMcpRemoveCmd())
cmd.AddCommand(NewMcpServeCmd())
return cmd
}

Expand Down
22 changes: 22 additions & 0 deletions cmd/aitools/mcp_add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,28 @@ func TestMcpAddRejectedTokenIsAuthFailed(t *testing.T) {
assert.NoFileExists(t, filepath.Join(home, ".claude.json"))
}

// TestMcpAddBindingFailureExitsOne checks that a binding failure is an ordinary failure of add: it exits 1 in text and
// in JSON mode. Exit 2 is serve's status for binding failures, which an agent restarts on.
func TestMcpAddBindingFailureExitsOne(t *testing.T) {
home := withHome(t)
withDatabricksBinary(t)
server := noRequestServer(t)
writeHomeConfig(t, home, "[logfood]\nhost = "+server.URL+"\nauth_type = pat\ntoken = dapi-logfood\n")
require.NoError(t, mcp.SaveState(t.Context(), &mcp.State{Servers: []mcp.Entry{{
Name: "github-logfood", Service: "system.ai.github", Profile: "logfood", Host: "https://adb-123.test",
}}}))
args := []string{"--profile", "logfood", "--names", "github", "--agents", "claude-code"}

_, err := newAddTestCmd(t, args...)
require.Error(t, err)
assert.Equal(t, protos.AitoolsErrorCategory(mcp.BindProfileHostChanged), errorCategory(err))
assert.Equal(t, 1, root.ExitStatus(err))

_, err = newAddTestCmd(t, append(args, "--output", "json")...)
require.ErrorIs(t, err, root.ErrAlreadyPrinted)
assert.Equal(t, 1, root.ExitStatus(err))
}

// TestMcpAddRefusesBinaryNotNamedDatabricks checks that the binary must be databricks: an argv[0] with another name, not on PATH, is refused, not replaced.
func TestMcpAddRefusesBinaryNotNamedDatabricks(t *testing.T) {
home := withHome(t)
Expand Down
Loading
Loading