-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathmcp.ts
More file actions
93 lines (74 loc) · 2.54 KB
/
mcp.ts
File metadata and controls
93 lines (74 loc) · 2.54 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
import chalk from 'chalk';
import {
addMCPServerToClientsStep,
removeMCPServerFromClientsStep,
} from './steps/add-mcp-server-to-clients';
import clack from './utils/clack';
import { abort } from './utils/clack-utils';
import type { CloudRegion } from './utils/types';
import opn from 'opn';
import { getCloudUrlFromRegion } from './utils/urls';
import { sleep } from './lib/helper-functions';
export const runMCPInstall = async (options: {
signup: boolean;
region?: CloudRegion;
}) => {
clack.intro('Installing the PostHog MCP server.');
await addMCPServerToClientsStep({
cloudRegion: options.region,
askPermission: false,
});
clack.outro(`${chalk.green(
'You might need to restart your MCP clients to see the changes.',
)}
Get started with some prompts like:
- What feature flags do I have active?
- Add a new feature flag for our homepage redesign
- What are my most common errors?
`);
};
export const runMCPRemove = async () => {
const results = await removeMCPServerFromClientsStep({});
if (results.length === 0) {
clack.outro(`No PostHog MCP servers found to remove.`);
return;
}
clack.outro(`PostHog MCP server removed from:
${results.map((c) => `- ${c}`).join('\n ')}
${chalk.green(
'You might need to restart your MCP clients to see the changes.',
)}`);
};
export const getPersonalApiKey = async (options: {
cloudRegion: CloudRegion;
}): Promise<string> => {
const cloudUrl = getCloudUrlFromRegion(options.cloudRegion);
const urlToOpen = `${cloudUrl}/settings/user-api-keys?preset=mcp_server`;
const spinner = clack.spinner();
spinner.start(
`Opening your project settings so you can get a Personal API key...`,
);
await sleep(1500);
spinner.stop(
`Opened your project settings. If the link didn't open automatically, open the following URL in your browser to get a Personal API key: \n\n${chalk.cyan(
urlToOpen,
)}`,
);
opn(urlToOpen, { wait: false }).catch(() => {
// opn throws in environments that don't have a browser (e.g. remote shells) so we just noop here
});
const personalApiKey = await clack.password({
message: 'Paste in your Personal API key:',
validate(value) {
if (value.length === 0) return `Value is required!`;
if (!value.startsWith('phx_')) {
return `That doesn't look right, are you sure you copied the right key? It should start with 'phx_'`;
}
},
});
if (!personalApiKey) {
await abort('Unable to proceed without a personal API key.');
return '';
}
return personalApiKey as string;
};