@tiny-fish/cli 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -0
- package/dist/commands/connect.d.ts +4 -0
- package/dist/commands/connect.js +100 -37
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,6 +26,18 @@ The command replaces existing user- and local-scope TinyFish registrations. It i
|
|
|
26
26
|
leaves project-scoped `.mcp.json` entries unchanged because those are shared repository
|
|
27
27
|
configuration.
|
|
28
28
|
|
|
29
|
+
### Connect Codex
|
|
30
|
+
|
|
31
|
+
Add TinyFish, complete MCP OAuth, and start the interactive walkthrough with one command:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npx -y @tiny-fish/cli@latest connect codex --launch
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
One-command OAuth requires a Codex release whose `codex mcp add` command supports
|
|
38
|
+
`--oauth-resource`. Update Codex if support is unavailable, or add TinyFish manually with
|
|
39
|
+
`codex mcp add`.
|
|
40
|
+
|
|
29
41
|
## Authentication
|
|
30
42
|
|
|
31
43
|
Get your API key from [agent.tinyfish.ai](https://agent.tinyfish.ai).
|
|
@@ -4,4 +4,8 @@ export declare function connectClaudeCode(options: {
|
|
|
4
4
|
mcpUrl: string;
|
|
5
5
|
launch: boolean;
|
|
6
6
|
}): void;
|
|
7
|
+
export declare function connectCodex(options: {
|
|
8
|
+
mcpUrl: string;
|
|
9
|
+
launch: boolean;
|
|
10
|
+
}): void;
|
|
7
11
|
export declare function registerConnect(program: Command): void;
|
package/dist/commands/connect.js
CHANGED
|
@@ -5,22 +5,69 @@ const NON_INTERACTIVE_TIMEOUT_MS = 10_000;
|
|
|
5
5
|
const MCP_LOGIN_UNAVAILABLE_MESSAGE = "This Claude Code installation does not expose `claude mcp login`, which is required for " +
|
|
6
6
|
"one-command MCP authentication. Update Claude Code and retry, or authenticate TinyFish " +
|
|
7
7
|
"manually from /mcp.";
|
|
8
|
-
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
const CODEX_OAUTH_RESOURCE_UNAVAILABLE_MESSAGE = "This Codex installation does not support one-command MCP authentication. Update Codex and " +
|
|
9
|
+
"retry, or add TinyFish manually with `codex mcp add`.";
|
|
10
|
+
export const DEFAULT_ONBOARDING_PROMPT = "I just connected TinyFish. Call the guide_next_step tool now to begin. Then follow its " +
|
|
11
|
+
"instructions one step at a time. Ask for my input and wait for my reply before each subsequent " +
|
|
12
|
+
"TinyFish tool call.";
|
|
13
|
+
const CLAUDE_CODE = {
|
|
14
|
+
command: "claude",
|
|
15
|
+
displayName: "Claude Code",
|
|
16
|
+
supportCheck: {
|
|
17
|
+
args: ["mcp", "--help"],
|
|
18
|
+
pattern: /^\s*login(?:\s|\[)/m,
|
|
19
|
+
unavailableMessage: MCP_LOGIN_UNAVAILABLE_MESSAGE,
|
|
20
|
+
},
|
|
21
|
+
loginArgs: ["mcp", "login", "tinyfish"],
|
|
22
|
+
// Project scope is shared in .mcp.json; a user setup command must not rewrite it.
|
|
23
|
+
removals: [
|
|
24
|
+
{ args: ["mcp", "remove", "tinyfish", "--scope", "user"], label: "user TinyFish registration" },
|
|
25
|
+
{
|
|
26
|
+
args: ["mcp", "remove", "tinyfish", "--scope", "local"],
|
|
27
|
+
label: "local TinyFish registration",
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
addArgs: (mcpUrl) => ["mcp", "add", "--scope", "user", "--transport", "http", "tinyfish", mcpUrl],
|
|
31
|
+
};
|
|
32
|
+
const CODEX = {
|
|
33
|
+
command: "codex",
|
|
34
|
+
displayName: "Codex",
|
|
35
|
+
supportCheck: {
|
|
36
|
+
args: ["mcp", "add", "--help"],
|
|
37
|
+
pattern: /--oauth-resource(?:\s|<)/,
|
|
38
|
+
unavailableMessage: CODEX_OAUTH_RESOURCE_UNAVAILABLE_MESSAGE,
|
|
39
|
+
},
|
|
40
|
+
removals: [{ args: ["mcp", "remove", "tinyfish"], label: "TinyFish registration from Codex" }],
|
|
41
|
+
addArgs: (mcpUrl) => [
|
|
42
|
+
"mcp",
|
|
43
|
+
"add",
|
|
44
|
+
"tinyfish",
|
|
45
|
+
"--url",
|
|
46
|
+
mcpUrl,
|
|
47
|
+
"--oauth-resource",
|
|
48
|
+
mcpUrl,
|
|
49
|
+
],
|
|
50
|
+
};
|
|
51
|
+
function requireNativeMcpSupport(client) {
|
|
52
|
+
const result = spawn.sync(client.command, client.supportCheck.args, {
|
|
12
53
|
encoding: "utf8",
|
|
13
54
|
timeout: NON_INTERACTIVE_TIMEOUT_MS,
|
|
14
55
|
});
|
|
56
|
+
if (result.error?.code === "ENOENT") {
|
|
57
|
+
throw new Error(`${client.displayName} is not installed or not available on PATH.`, {
|
|
58
|
+
cause: result.error,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
15
61
|
if (result.error || result.status !== 0) {
|
|
16
|
-
throw new Error(
|
|
62
|
+
throw new Error(client.supportCheck.unavailableMessage, { cause: result.error });
|
|
17
63
|
}
|
|
18
|
-
|
|
19
|
-
|
|
64
|
+
const output = `${result.stdout ?? ""}\n${result.stderr ?? ""}`;
|
|
65
|
+
if (!client.supportCheck.pattern.test(output)) {
|
|
66
|
+
throw new Error(client.supportCheck.unavailableMessage);
|
|
20
67
|
}
|
|
21
68
|
}
|
|
22
|
-
function removeExistingRegistration(
|
|
23
|
-
const result = spawn.sync(
|
|
69
|
+
function removeExistingRegistration(client, removal) {
|
|
70
|
+
const result = spawn.sync(client.command, removal.args, {
|
|
24
71
|
encoding: "utf8",
|
|
25
72
|
timeout: NON_INTERACTIVE_TIMEOUT_MS,
|
|
26
73
|
});
|
|
@@ -30,55 +77,65 @@ function removeExistingRegistration(scope) {
|
|
|
30
77
|
if (/No MCP server named "tinyfish"/i.test(details))
|
|
31
78
|
return;
|
|
32
79
|
if (result.error) {
|
|
33
|
-
throw new Error(`Could not remove existing ${
|
|
80
|
+
throw new Error(`Could not remove existing ${removal.label}: ${details}`, {
|
|
34
81
|
cause: result.error,
|
|
35
82
|
});
|
|
36
83
|
}
|
|
37
|
-
throw new Error(`Could not remove existing ${
|
|
84
|
+
throw new Error(`Could not remove existing ${removal.label}: ${details}`);
|
|
38
85
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
86
|
+
function connectNativeMcpClient(client, options) {
|
|
87
|
+
requireNativeMcpSupport(client);
|
|
88
|
+
for (const removal of client.removals)
|
|
89
|
+
removeExistingRegistration(client, removal);
|
|
90
|
+
errLine(`Adding TinyFish to ${client.displayName}...`);
|
|
91
|
+
const addResult = spawn.sync(client.command, client.addArgs(options.mcpUrl), {
|
|
92
|
+
stdio: "inherit",
|
|
93
|
+
});
|
|
46
94
|
if (addResult.error || addResult.status !== 0) {
|
|
47
|
-
throw new Error(
|
|
95
|
+
throw new Error(`Could not add TinyFish to ${client.displayName}`, {
|
|
96
|
+
cause: addResult.error,
|
|
97
|
+
});
|
|
48
98
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
cause: loginResult.error,
|
|
99
|
+
if (client.loginArgs) {
|
|
100
|
+
errLine("Signing in to TinyFish...");
|
|
101
|
+
const loginResult = spawn.sync(client.command, client.loginArgs, {
|
|
102
|
+
stdio: "inherit",
|
|
54
103
|
});
|
|
104
|
+
if (loginResult.error || loginResult.status !== 0) {
|
|
105
|
+
throw new Error(`Could not authenticate TinyFish in ${client.displayName}`, {
|
|
106
|
+
cause: loginResult.error,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
55
109
|
}
|
|
56
110
|
if (!options.launch) {
|
|
57
|
-
errLine(
|
|
111
|
+
errLine(`TinyFish is connected. Open ${client.displayName} to start using it.`);
|
|
58
112
|
return;
|
|
59
113
|
}
|
|
60
|
-
errLine(
|
|
61
|
-
const result = spawn.sync(
|
|
114
|
+
errLine(`Starting the TinyFish walkthrough in ${client.displayName}...`);
|
|
115
|
+
const result = spawn.sync(client.command, [DEFAULT_ONBOARDING_PROMPT], { stdio: "inherit" });
|
|
62
116
|
if (result.error) {
|
|
63
|
-
throw new Error(
|
|
117
|
+
throw new Error(`Could not launch ${client.displayName}`, { cause: result.error });
|
|
64
118
|
}
|
|
65
119
|
if (result.signal === "SIGINT" || result.signal === "SIGTERM")
|
|
66
120
|
return;
|
|
67
121
|
if (result.status !== 0) {
|
|
68
|
-
throw new Error(
|
|
122
|
+
throw new Error(`${client.displayName} walkthrough exited with status ${result.status ?? "unknown"}`);
|
|
69
123
|
}
|
|
70
124
|
}
|
|
125
|
+
export function connectClaudeCode(options) {
|
|
126
|
+
connectNativeMcpClient(CLAUDE_CODE, options);
|
|
127
|
+
}
|
|
128
|
+
export function connectCodex(options) {
|
|
129
|
+
connectNativeMcpClient(CODEX, options);
|
|
130
|
+
}
|
|
71
131
|
export function registerConnect(program) {
|
|
72
132
|
program
|
|
73
133
|
.command("connect")
|
|
74
134
|
.description("Connect TinyFish to an AI agent")
|
|
75
|
-
.argument("<client>", "Agent client to connect (claude-code)")
|
|
135
|
+
.argument("<client>", "Agent client to connect (claude-code or codex)")
|
|
76
136
|
.option("--launch", "Launch the agent and start the TinyFish walkthrough")
|
|
77
137
|
.option("--url <mcpUrl>", "MCP endpoint override")
|
|
78
138
|
.action((client, options) => {
|
|
79
|
-
if (client !== "claude-code") {
|
|
80
|
-
throw new Error(`Unsupported client: ${client}. Supported client: claude-code`);
|
|
81
|
-
}
|
|
82
139
|
const mcpUrl = options.url ?? DEFAULT_MCP_URL;
|
|
83
140
|
if (mcpUrl.startsWith("-")) {
|
|
84
141
|
throw new Error(`Invalid --url value: ${mcpUrl}`);
|
|
@@ -93,9 +150,15 @@ export function registerConnect(program) {
|
|
|
93
150
|
if (!["http:", "https:"].includes(parsedUrl.protocol)) {
|
|
94
151
|
throw new Error(`Invalid --url value: ${mcpUrl}`);
|
|
95
152
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
153
|
+
const connectOptions = { mcpUrl, launch: options.launch ?? false };
|
|
154
|
+
if (client === "claude-code") {
|
|
155
|
+
connectClaudeCode(connectOptions);
|
|
156
|
+
}
|
|
157
|
+
else if (client === "codex") {
|
|
158
|
+
connectCodex(connectOptions);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
throw new Error(`Unsupported client: ${client}. Supported clients: claude-code, codex`);
|
|
162
|
+
}
|
|
100
163
|
});
|
|
101
164
|
}
|