51
export async function startServerAndWaitForLiveTools(server: IMcpServer, opts?: IMcpServerStartOpts, token?: CancellationToken): Promise<boolean> {
52
const r = await server.start(opts);
54
>
const store = new DisposableStore();
55
>
const ok = await new Promise<boolean>(resolve => {
56
>
if (token?.isCancellationRequested || r.state === McpConnectionState.Kind.Error || r.state === McpConnectionState.Kind.Stopped) {
57
return resolve(false);
58
}
60
>
if (token) {
61
store.add(token.onCancellationRequested(() => {
62
resolve(false);
63
}));
64
}
66
>
store.add(autorun(reader => {
67
>
const connState = server.connectionState.read(reader).state;
68
>
if (connState === McpConnectionState.Kind.Error || connState === McpConnectionState.Kind.Stopped) {
69
resolve(false); // some error, don't block the request
70
}
72
>
const toolState = server.cacheState.read(reader);
73
>
if (toolState === McpServerCacheState.Live) {
74
>
resolve(true); // got tools, all done
75
>
}
76
>
}));
77
>
});
78
>
store.dispose();
79
>
80
>
if (ok) {
81
>
await timeout(0); // let the tools register in the language model contribution
82
>
}
83
>
84
>
return ok;
85
>
}
86
87
export function mcpServerToSourceData(server: IMcpServer, reader?: IReader): ToolDataSource {