Skip to content

Commit 27eda5e

Browse files
committed
Merge remote-tracking branch 'upstream/main'
2 parents 30f4e17 + f382bd1 commit 27eda5e

3 files changed

Lines changed: 113 additions & 6 deletions

File tree

.github/workflows/test-mcp-servers.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,95 @@ jobs:
7676
fi
7777
7878
echo "✓ All MCP server checks passed!"
79+
80+
test-mcp-config-flag:
81+
runs-on: ubuntu-latest
82+
steps:
83+
- name: Checkout repository
84+
uses: actions/checkout@v4
85+
86+
- name: Setup Bun
87+
uses: oven-sh/setup-bun@v2
88+
89+
- name: Install dependencies
90+
run: |
91+
bun install
92+
cd test/mcp-test
93+
bun install
94+
95+
- name: Debug environment paths (--mcp-config test)
96+
run: |
97+
echo "=== Environment Variables (--mcp-config test) ==="
98+
echo "HOME: $HOME"
99+
echo "XDG_CONFIG_HOME: ${XDG_CONFIG_HOME:-not set}"
100+
echo "CLAUDE_CONFIG_DIR: ${CLAUDE_CONFIG_DIR:-not set}"
101+
echo ""
102+
echo "=== Expected Config Paths ==="
103+
echo "GitHub action writes to: $HOME/.claude/settings.json"
104+
if [ -n "${XDG_CONFIG_HOME:-}" ]; then
105+
echo "Claude might read from: $XDG_CONFIG_HOME/claude/settings.json"
106+
else
107+
echo "Claude should read from: $HOME/.claude/settings.json"
108+
fi
109+
echo ""
110+
echo "=== Actual File System ==="
111+
ls -la $HOME/.claude/ || echo "No $HOME/.claude directory"
112+
if [ -n "${XDG_CONFIG_HOME:-}" ]; then
113+
ls -la $XDG_CONFIG_HOME/ || echo "No $XDG_CONFIG_HOME directory"
114+
ls -la $XDG_CONFIG_HOME/claude/ || echo "No $XDG_CONFIG_HOME/claude directory"
115+
fi
116+
117+
- name: Run Claude Code with --mcp-config flag
118+
uses: ./
119+
id: claude-config-test
120+
with:
121+
prompt: "List all available tools"
122+
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
123+
mcp_config: '{"mcpServers":{"test-server":{"type":"stdio","command":"bun","args":["simple-mcp-server.ts"],"env":{}}}}'
124+
env:
125+
# Change to test directory so bun can find the MCP server script
126+
CLAUDE_WORKING_DIR: ${{ github.workspace }}/test/mcp-test
127+
128+
- name: Check MCP server output with --mcp-config
129+
run: |
130+
echo "Checking Claude output for MCP servers with --mcp-config flag..."
131+
132+
# Parse the JSON output
133+
OUTPUT_FILE="${RUNNER_TEMP}/claude-execution-output.json"
134+
135+
if [ ! -f "$OUTPUT_FILE" ]; then
136+
echo "Error: Output file not found!"
137+
exit 1
138+
fi
139+
140+
echo "Output file contents:"
141+
cat $OUTPUT_FILE
142+
143+
# Check if mcp_servers field exists in the init event
144+
if jq -e '.[] | select(.type == "system" and .subtype == "init") | .mcp_servers' "$OUTPUT_FILE" > /dev/null; then
145+
echo "✓ Found mcp_servers in output"
146+
147+
# Check if test-server is connected
148+
if jq -e '.[] | select(.type == "system" and .subtype == "init") | .mcp_servers[] | select(.name == "test-server" and .status == "connected")' "$OUTPUT_FILE" > /dev/null; then
149+
echo "✓ test-server is connected"
150+
else
151+
echo "✗ test-server not found or not connected"
152+
jq '.[] | select(.type == "system" and .subtype == "init") | .mcp_servers' "$OUTPUT_FILE"
153+
exit 1
154+
fi
155+
156+
# Check if mcp tools are available
157+
if jq -e '.[] | select(.type == "system" and .subtype == "init") | .tools[] | select(. == "mcp__test-server__test_tool")' "$OUTPUT_FILE" > /dev/null; then
158+
echo "✓ MCP test tool found"
159+
else
160+
echo "✗ MCP test tool not found"
161+
jq '.[] | select(.type == "system" and .subtype == "init") | .tools' "$OUTPUT_FILE"
162+
exit 1
163+
fi
164+
else
165+
echo "✗ No mcp_servers field found in init event"
166+
jq '.[] | select(.type == "system" and .subtype == "init")' "$OUTPUT_FILE"
167+
exit 1
168+
fi
169+
170+
echo "✓ All MCP server checks passed with --mcp-config flag!"

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ runs:
120120
121121
- name: Install Claude Code
122122
shell: bash
123-
run: npm install -g @anthropic-ai/claude-code@1.0.24
123+
run: npm install -g @anthropic-ai/claude-code@1.0.31
124124

125125
- name: Run Claude Code Action
126126
shell: bash

src/setup-claude-code-settings.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
import { $ } from "bun";
22
import { homedir } from "os";
3+
import { join } from "path";
4+
5+
/**
6+
* Get Claude's config directory using XDG path when available
7+
* Priority order:
8+
* 1. XDG_CONFIG_HOME/claude (XDG Base Directory spec)
9+
* 2. ~/.claude (legacy fallback)
10+
*/
11+
function getClaudeConfigHomeDir(): string {
12+
if (process.env.XDG_CONFIG_HOME) {
13+
return join(process.env.XDG_CONFIG_HOME, "claude");
14+
}
15+
16+
return join(homedir(), ".claude");
17+
}
318

419
export async function setupClaudeCodeSettings() {
5-
const home = homedir();
6-
const settingsPath = `${home}/.claude/settings.json`;
20+
const configDir = getClaudeConfigHomeDir();
21+
const settingsPath = join(configDir, "settings.json");
722
console.log(`Setting up Claude settings at: ${settingsPath}`);
823

9-
// Ensure .claude directory exists
10-
console.log(`Creating .claude directory...`);
11-
await $`mkdir -p ${home}/.claude`.quiet();
24+
// Ensure config directory exists
25+
console.log(`Creating config directory...`);
26+
await $`mkdir -p ${configDir}`.quiet();
1227

1328
let settings: Record<string, unknown> = {};
1429
try {

0 commit comments

Comments
 (0)