-
-
Notifications
You must be signed in to change notification settings - Fork 254
Expand file tree
/
Copy pathfake-xcode-tools-server.mjs
More file actions
122 lines (110 loc) · 2.71 KB
/
fake-xcode-tools-server.mjs
File metadata and controls
122 lines (110 loc) · 2.71 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import * as z from 'zod';
const server = new McpServer(
{ name: 'fake-xcode-tools', version: '0.0.0' },
{
capabilities: {
tools: { listChanged: true },
},
},
);
let alphaRegistered;
let betaRegistered;
let gammaRegistered;
function registerInitialTools() {
alphaRegistered = server.registerTool(
'Alpha',
{
description: 'Alpha tool',
inputSchema: z
.object({
value: z.string(),
})
.passthrough(),
annotations: { readOnlyHint: true, title: 'Alpha' },
},
async (args) => ({
content: [{ type: 'text', text: `Alpha:${args.value}` }],
isError: false,
}),
);
betaRegistered = server.registerTool(
'Beta',
{
description: 'Beta tool',
inputSchema: z
.object({
n: z.number().int(),
})
.passthrough(),
},
async (args) => ({
content: [{ type: 'text', text: `Beta:${args.n}` }],
isError: false,
}),
);
server.registerTool(
'TriggerChange',
{
description: 'Mutate tool catalog and emit list_changed',
inputSchema: z.object({}).passthrough(),
},
async () => {
applyCatalogChange();
return { content: [{ type: 'text', text: 'changed' }], isError: false };
},
);
server.registerTool(
'Echo',
{
description: 'Echoes back received arguments as JSON',
inputSchema: z
.object({
filePath: z.string(),
tabIdentifier: z.string().optional(),
})
.passthrough(),
},
async (args) => ({
content: [{ type: 'text', text: JSON.stringify(args) }],
isError: false,
}),
);
}
function applyCatalogChange() {
betaRegistered?.remove();
betaRegistered = undefined;
alphaRegistered?.remove();
alphaRegistered = server.registerTool(
'Alpha',
{
description: 'Alpha tool (changed schema)',
inputSchema: z
.object({
value: z.string(),
extra: z.string().optional(),
})
.passthrough(),
},
async (args) => ({
content: [{ type: 'text', text: `Alpha2:${args.value}:${args.extra ?? ''}` }],
isError: false,
}),
);
gammaRegistered?.remove();
gammaRegistered = server.registerTool(
'Gamma',
{
description: 'Gamma tool',
inputSchema: z.object({ ok: z.boolean() }).passthrough(),
},
async (args) => ({
content: [{ type: 'text', text: `Gamma:${args.ok}` }],
isError: false,
}),
);
server.sendToolListChanged();
}
registerInitialTools();
await server.connect(new StdioServerTransport());