-
-
Notifications
You must be signed in to change notification settings - Fork 247
Expand file tree
/
Copy pathprobe-xcode-mcpbridge.ts
More file actions
87 lines (73 loc) · 2.56 KB
/
probe-xcode-mcpbridge.ts
File metadata and controls
87 lines (73 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
import { CompatibilityCallToolResultSchema } from '@modelcontextprotocol/sdk/types.js';
import process from 'node:process';
function parseArgs(argv: string[]): { limit: number; callWindows: boolean } {
let limit = 20;
let callWindows = true;
for (let i = 2; i < argv.length; i += 1) {
const arg = argv[i];
if (arg === '--limit' && argv[i + 1]) {
limit = Number(argv[i + 1]);
i += 1;
continue;
}
if (arg === '--no-windows') {
callWindows = false;
continue;
}
}
return { limit: Number.isFinite(limit) ? limit : 20, callWindows };
}
function mapXcodeEnvForMcpBridge(env: NodeJS.ProcessEnv): Record<string, string> {
const mapped: Record<string, string> = {};
for (const [key, value] of Object.entries(env)) {
if (typeof value === 'string') {
mapped[key] = value;
}
}
if (typeof env.XCODEBUILDMCP_XCODE_PID === 'string' && mapped.MCP_XCODE_PID === undefined) {
mapped.MCP_XCODE_PID = env.XCODEBUILDMCP_XCODE_PID;
}
if (
typeof env.XCODEBUILDMCP_XCODE_SESSION_ID === 'string' &&
mapped.MCP_XCODE_SESSION_ID === undefined
) {
mapped.MCP_XCODE_SESSION_ID = env.XCODEBUILDMCP_XCODE_SESSION_ID;
}
return mapped;
}
async function main(): Promise<void> {
const { limit, callWindows } = parseArgs(process.argv);
const transport = new StdioClientTransport({
command: 'xcrun',
args: ['mcpbridge'],
stderr: 'inherit',
env: mapXcodeEnvForMcpBridge(process.env),
});
const client = new Client({ name: 'xcodebuildmcp-probe', version: '0.0.0' });
await client.connect(transport, { timeout: 15_000 });
const serverInfo = client.getServerVersion();
const capabilities = client.getServerCapabilities();
console.log('serverInfo:', serverInfo);
console.log('capabilities.tools.listChanged:', capabilities?.tools?.listChanged ?? false);
const toolsResult = await client.listTools(undefined, { timeout: 15_000 });
console.log(`tools: ${toolsResult.tools.length}`);
console.log(
'first tools:',
toolsResult.tools.slice(0, limit).map((t) => t.name),
);
if (callWindows) {
const windows = await client.request(
{ method: 'tools/call', params: { name: 'XcodeListWindows', arguments: {} } },
CompatibilityCallToolResultSchema,
{ timeout: 15_000 },
);
console.log('XcodeListWindows:', windows);
}
await client.close();
}
main().catch((error) => {
console.error(error);
process.exit(1);
});