@goke/mcp 0.0.7 → 0.0.9
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 +86 -31
- package/dist/__test__/add-cli-tools-to-mcp.test.d.ts +5 -0
- package/dist/__test__/add-cli-tools-to-mcp.test.d.ts.map +1 -0
- package/dist/__test__/add-cli-tools-to-mcp.test.js +399 -0
- package/dist/__test__/create-mcp-action.test.d.ts +8 -0
- package/dist/__test__/create-mcp-action.test.d.ts.map +1 -0
- package/dist/__test__/create-mcp-action.test.js +274 -0
- package/dist/cli-to-mcp.d.ts +28 -0
- package/dist/cli-to-mcp.d.ts.map +1 -1
- package/dist/cli-to-mcp.js +44 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +28 -16
- package/src/__test__/add-cli-tools-to-mcp.test.ts +459 -0
- package/src/__test__/create-mcp-action.test.ts +353 -0
- package/src/cli-to-mcp.ts +68 -0
- package/src/index.ts +2 -2
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for createMcpAction — turning a CLI into a stdio MCP server.
|
|
3
|
+
*
|
|
4
|
+
* Uses InMemoryTransport (via createTransport option) to avoid actual stdio.
|
|
5
|
+
* Simulates the goke runtime by setting matchedCommandName before calling the action.
|
|
6
|
+
*/
|
|
7
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
8
|
+
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
|
|
9
|
+
import { goke, wrapJsonSchema } from "goke";
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
import { describe, expect, it } from "vitest";
|
|
12
|
+
import { createMcpAction } from "../cli-to-mcp.js";
|
|
13
|
+
function firstTextContent(result) {
|
|
14
|
+
const content = "content" in result ? result.content : [];
|
|
15
|
+
return content.find((entry) => entry.type === "text")?.text ?? "";
|
|
16
|
+
}
|
|
17
|
+
describe("createMcpAction", () => {
|
|
18
|
+
it("returns an action function", () => {
|
|
19
|
+
const cli = goke("test");
|
|
20
|
+
const action = createMcpAction({ cli });
|
|
21
|
+
expect(typeof action).toBe("function");
|
|
22
|
+
});
|
|
23
|
+
it("starts an MCP server exposing CLI commands, excluding the mcp command", async () => {
|
|
24
|
+
const cli = goke("test");
|
|
25
|
+
cli
|
|
26
|
+
.command("greet", "Say hello")
|
|
27
|
+
.option("--name <name>", z.string().describe("Person to greet"))
|
|
28
|
+
.action((options) => `Hello ${options.name}!`);
|
|
29
|
+
cli
|
|
30
|
+
.command("add", "Add numbers")
|
|
31
|
+
.option("--a <a>", z.number().describe("First"))
|
|
32
|
+
.option("--b <b>", z.number().describe("Second"))
|
|
33
|
+
.action((options) => ({ sum: options.a + options.b }));
|
|
34
|
+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
35
|
+
cli.command("mcp", "Start MCP server").action(createMcpAction({
|
|
36
|
+
cli,
|
|
37
|
+
createTransport: () => serverTransport,
|
|
38
|
+
}));
|
|
39
|
+
// Simulate goke matching the "mcp" command (normally set by cli.parse())
|
|
40
|
+
cli.matchedCommandName = "mcp";
|
|
41
|
+
// Fire the action — starts the MCP server on the in-memory transport
|
|
42
|
+
const mcpCommand = cli.commands.find((c) => c.name === "mcp");
|
|
43
|
+
await mcpCommand.commandAction({});
|
|
44
|
+
const client = new Client({ name: "test-client", version: "1.0.0" }, { capabilities: {} });
|
|
45
|
+
await client.connect(clientTransport);
|
|
46
|
+
try {
|
|
47
|
+
const tools = await client.listTools();
|
|
48
|
+
const toolNames = tools.tools.map((t) => t.name).sort();
|
|
49
|
+
expect(toolNames).toEqual(["add", "greet"]);
|
|
50
|
+
const greetResult = await client.callTool({
|
|
51
|
+
name: "greet",
|
|
52
|
+
arguments: { name: "World" },
|
|
53
|
+
});
|
|
54
|
+
expect(firstTextContent(greetResult)).toBe("Hello World!");
|
|
55
|
+
const addResult = await client.callTool({
|
|
56
|
+
name: "add",
|
|
57
|
+
arguments: { a: 3, b: 7 },
|
|
58
|
+
});
|
|
59
|
+
expect(firstTextContent(addResult)).toBe('{\n "sum": 10\n}');
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
await client.close();
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
it("composes user commandFilter with auto-exclusion", async () => {
|
|
66
|
+
const cli = goke("test");
|
|
67
|
+
cli.command("public-cmd", "Public command").action(() => "public");
|
|
68
|
+
cli.command("secret-cmd", "Secret command").action(() => "secret");
|
|
69
|
+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
70
|
+
cli.command("mcp", "Start MCP server").action(createMcpAction({
|
|
71
|
+
cli,
|
|
72
|
+
commandFilter: (name) => name !== "secret-cmd",
|
|
73
|
+
createTransport: () => serverTransport,
|
|
74
|
+
}));
|
|
75
|
+
cli.matchedCommandName = "mcp";
|
|
76
|
+
const mcpCommand = cli.commands.find((c) => c.name === "mcp");
|
|
77
|
+
await mcpCommand.commandAction({});
|
|
78
|
+
const client = new Client({ name: "test-client", version: "1.0.0" }, { capabilities: {} });
|
|
79
|
+
await client.connect(clientTransport);
|
|
80
|
+
try {
|
|
81
|
+
const tools = await client.listTools();
|
|
82
|
+
const toolNames = tools.tools.map((t) => t.name).sort();
|
|
83
|
+
// Both "mcp" (auto-excluded) and "secret-cmd" (user filter) excluded
|
|
84
|
+
expect(toolNames).toEqual(["public-cmd"]);
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
await client.close();
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
it("works with multi-word command names", async () => {
|
|
91
|
+
const cli = goke("test");
|
|
92
|
+
cli
|
|
93
|
+
.command("db migrate", "Run migrations")
|
|
94
|
+
.action(() => "migrated");
|
|
95
|
+
cli
|
|
96
|
+
.command("db seed", "Seed database")
|
|
97
|
+
.action(() => "seeded");
|
|
98
|
+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
99
|
+
cli.command("serve mcp", "Start MCP server").action(createMcpAction({
|
|
100
|
+
cli,
|
|
101
|
+
createTransport: () => serverTransport,
|
|
102
|
+
}));
|
|
103
|
+
cli.matchedCommandName = "serve mcp";
|
|
104
|
+
const mcpCommand = cli.commands.find((c) => c.name === "serve mcp");
|
|
105
|
+
await mcpCommand.commandAction({});
|
|
106
|
+
const client = new Client({ name: "test-client", version: "1.0.0" }, { capabilities: {} });
|
|
107
|
+
await client.connect(clientTransport);
|
|
108
|
+
try {
|
|
109
|
+
const tools = await client.listTools();
|
|
110
|
+
const toolNames = tools.tools.map((t) => t.name).sort();
|
|
111
|
+
expect(toolNames).toEqual(["db_migrate", "db_seed"]);
|
|
112
|
+
const migrateResult = await client.callTool({
|
|
113
|
+
name: "db_migrate",
|
|
114
|
+
arguments: {},
|
|
115
|
+
});
|
|
116
|
+
expect(firstTextContent(migrateResult)).toBe("migrated");
|
|
117
|
+
}
|
|
118
|
+
finally {
|
|
119
|
+
await client.close();
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
it("end-to-end: MCP client connects, discovers tools with schemas, calls tools, handles errors", async () => {
|
|
123
|
+
const cli = goke("my-app");
|
|
124
|
+
// String option command
|
|
125
|
+
cli
|
|
126
|
+
.command("search", "Search for items")
|
|
127
|
+
.option("--query <query>", z.string().describe("Search query"))
|
|
128
|
+
.option("--limit [limit]", z.number().default(10).describe("Max results"))
|
|
129
|
+
.action((options) => {
|
|
130
|
+
return { results: [`result for "${options.query}"`], limit: options.limit };
|
|
131
|
+
});
|
|
132
|
+
// Boolean flag + positional arg command
|
|
133
|
+
cli
|
|
134
|
+
.command("deploy <env>", "Deploy to environment")
|
|
135
|
+
.option("--dry-run", z.boolean().default(false).describe("Simulate deployment"))
|
|
136
|
+
.action((env, options) => {
|
|
137
|
+
return options.dryRun ? `dry-run deploy to ${env}` : `deployed to ${env}`;
|
|
138
|
+
});
|
|
139
|
+
// Command that returns a CallToolResult directly
|
|
140
|
+
cli
|
|
141
|
+
.command("status", "Get system status")
|
|
142
|
+
.action(() => ({
|
|
143
|
+
content: [{ type: "text", text: "all systems operational" }],
|
|
144
|
+
}));
|
|
145
|
+
// Command that throws an error (should be caught and returned as isError)
|
|
146
|
+
cli
|
|
147
|
+
.command("fail", "Always fails")
|
|
148
|
+
.action(() => {
|
|
149
|
+
throw new Error("something went wrong");
|
|
150
|
+
});
|
|
151
|
+
// Wrapped JSON schema command
|
|
152
|
+
cli
|
|
153
|
+
.command("config set", "Set a config value")
|
|
154
|
+
.option("--key <key>", wrapJsonSchema({ type: "string", description: "Config key" }))
|
|
155
|
+
.option("--value <value>", wrapJsonSchema({ type: "string", description: "Config value" }))
|
|
156
|
+
.action((options) => {
|
|
157
|
+
return `set ${options.key} = ${options.value}`;
|
|
158
|
+
});
|
|
159
|
+
// Commands without actions (should NOT appear as tools)
|
|
160
|
+
cli.command("no-action", "This has no action handler");
|
|
161
|
+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
162
|
+
cli.command("mcp", "Start MCP server").action(createMcpAction({
|
|
163
|
+
cli,
|
|
164
|
+
serverName: "my-app-mcp",
|
|
165
|
+
serverVersion: "2.5.0",
|
|
166
|
+
createTransport: () => serverTransport,
|
|
167
|
+
}));
|
|
168
|
+
cli.matchedCommandName = "mcp";
|
|
169
|
+
const mcpCommand = cli.commands.find((c) => c.name === "mcp");
|
|
170
|
+
await mcpCommand.commandAction({});
|
|
171
|
+
const client = new Client({ name: "e2e-test-client", version: "1.0.0" }, { capabilities: {} });
|
|
172
|
+
await client.connect(clientTransport);
|
|
173
|
+
try {
|
|
174
|
+
// ── Server info ──
|
|
175
|
+
const serverInfo = client.getServerVersion();
|
|
176
|
+
expect(serverInfo).toMatchObject({ name: "my-app-mcp", version: "2.5.0" });
|
|
177
|
+
// ── Tool discovery ──
|
|
178
|
+
const tools = await client.listTools();
|
|
179
|
+
const toolNames = tools.tools.map((t) => t.name).sort();
|
|
180
|
+
// "mcp" auto-excluded, "no-action" has no handler → not mounted
|
|
181
|
+
expect(toolNames).toEqual(["config_set", "deploy", "fail", "search", "status"]);
|
|
182
|
+
// ── Verify schemas are propagated ──
|
|
183
|
+
const searchTool = tools.tools.find((t) => t.name === "search");
|
|
184
|
+
expect(searchTool.description).toBe("Search for items");
|
|
185
|
+
expect(searchTool.inputSchema.properties).toHaveProperty("query");
|
|
186
|
+
expect(searchTool.inputSchema.properties).toHaveProperty("limit");
|
|
187
|
+
expect(searchTool.inputSchema.required).toEqual(["query"]);
|
|
188
|
+
const deployTool = tools.tools.find((t) => t.name === "deploy");
|
|
189
|
+
expect(deployTool.inputSchema.properties).toHaveProperty("env");
|
|
190
|
+
expect(deployTool.inputSchema.properties).toHaveProperty("dryRun");
|
|
191
|
+
expect(deployTool.inputSchema.required).toEqual(["env"]);
|
|
192
|
+
// ── Call tool with schema-based options ──
|
|
193
|
+
const searchResult = await client.callTool({
|
|
194
|
+
name: "search",
|
|
195
|
+
arguments: { query: "hello", limit: 5 },
|
|
196
|
+
});
|
|
197
|
+
expect(firstTextContent(searchResult)).toBe('{\n "results": [\n "result for \\"hello\\""\n ],\n "limit": 5\n}');
|
|
198
|
+
// ── Call tool with positional args ──
|
|
199
|
+
const deployResult = await client.callTool({
|
|
200
|
+
name: "deploy",
|
|
201
|
+
arguments: { env: "production", dryRun: true },
|
|
202
|
+
});
|
|
203
|
+
expect(firstTextContent(deployResult)).toBe("dry-run deploy to production");
|
|
204
|
+
// ── Call tool that returns a raw CallToolResult ──
|
|
205
|
+
const statusResult = await client.callTool({
|
|
206
|
+
name: "status",
|
|
207
|
+
arguments: {},
|
|
208
|
+
});
|
|
209
|
+
expect(firstTextContent(statusResult)).toBe("all systems operational");
|
|
210
|
+
// ── Call tool that throws → error is caught and returned as isError ──
|
|
211
|
+
const failResult = await client.callTool({
|
|
212
|
+
name: "fail",
|
|
213
|
+
arguments: {},
|
|
214
|
+
});
|
|
215
|
+
expect(failResult.isError).toBe(true);
|
|
216
|
+
expect(firstTextContent(failResult)).toBe("something went wrong");
|
|
217
|
+
// ── Call tool with multi-word command name ──
|
|
218
|
+
const configResult = await client.callTool({
|
|
219
|
+
name: "config_set",
|
|
220
|
+
arguments: { key: "theme", value: "dark" },
|
|
221
|
+
});
|
|
222
|
+
expect(firstTextContent(configResult)).toBe("set theme = dark");
|
|
223
|
+
// ── Call nonexistent tool → MCP error ──
|
|
224
|
+
await expect(client.callTool({ name: "nonexistent", arguments: {} })).rejects.toThrow(/not found/i);
|
|
225
|
+
}
|
|
226
|
+
finally {
|
|
227
|
+
await client.close();
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
it("returns empty tool list when only the mcp command exists", async () => {
|
|
231
|
+
const cli = goke("empty-app");
|
|
232
|
+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
233
|
+
cli.command("mcp", "Start MCP server").action(createMcpAction({
|
|
234
|
+
cli,
|
|
235
|
+
createTransport: () => serverTransport,
|
|
236
|
+
}));
|
|
237
|
+
cli.matchedCommandName = "mcp";
|
|
238
|
+
const mcpCommand = cli.commands.find((c) => c.name === "mcp");
|
|
239
|
+
await mcpCommand.commandAction({});
|
|
240
|
+
const client = new Client({ name: "test-client", version: "1.0.0" }, { capabilities: {} });
|
|
241
|
+
await client.connect(clientTransport);
|
|
242
|
+
try {
|
|
243
|
+
const tools = await client.listTools();
|
|
244
|
+
expect(tools.tools).toEqual([]);
|
|
245
|
+
}
|
|
246
|
+
finally {
|
|
247
|
+
await client.close();
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
it("exposes all commands when matchedCommandName is not set", async () => {
|
|
251
|
+
const cli = goke("test");
|
|
252
|
+
cli.command("ping", "Ping").action(() => "pong");
|
|
253
|
+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
254
|
+
cli.command("mcp", "Start MCP server").action(createMcpAction({
|
|
255
|
+
cli,
|
|
256
|
+
createTransport: () => serverTransport,
|
|
257
|
+
}));
|
|
258
|
+
// Do NOT set matchedCommandName — simulates programmatic invocation
|
|
259
|
+
// without cli.parse(). All commands including "mcp" should be exposed.
|
|
260
|
+
const mcpCommand = cli.commands.find((c) => c.name === "mcp");
|
|
261
|
+
await mcpCommand.commandAction({});
|
|
262
|
+
const client = new Client({ name: "test-client", version: "1.0.0" }, { capabilities: {} });
|
|
263
|
+
await client.connect(clientTransport);
|
|
264
|
+
try {
|
|
265
|
+
const tools = await client.listTools();
|
|
266
|
+
const toolNames = tools.tools.map((t) => t.name).sort();
|
|
267
|
+
// Without matchedCommandName, auto-exclusion can't kick in
|
|
268
|
+
expect(toolNames).toEqual(["mcp", "ping"]);
|
|
269
|
+
}
|
|
270
|
+
finally {
|
|
271
|
+
await client.close();
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
});
|
package/dist/cli-to-mcp.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
8
8
|
import type { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
9
|
+
import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
9
10
|
import { type Goke } from "goke";
|
|
10
11
|
export interface AddCliToolsToMcpOptions {
|
|
11
12
|
cli: Goke;
|
|
@@ -13,5 +14,32 @@ export interface AddCliToolsToMcpOptions {
|
|
|
13
14
|
commandFilter?: (commandName: string) => boolean;
|
|
14
15
|
sanitizeToolName?: (commandName: string) => string;
|
|
15
16
|
}
|
|
17
|
+
export interface CreateMcpActionOptions {
|
|
18
|
+
/** The CLI instance whose commands will be exposed as MCP tools */
|
|
19
|
+
cli: Goke;
|
|
20
|
+
/** Additional filter for which commands to expose. The MCP command itself is always excluded. */
|
|
21
|
+
commandFilter?: (commandName: string) => boolean;
|
|
22
|
+
/** Custom tool name sanitizer */
|
|
23
|
+
sanitizeToolName?: (commandName: string) => string;
|
|
24
|
+
/** MCP server name. Defaults to the CLI name or 'cli-mcp-server' */
|
|
25
|
+
serverName?: string;
|
|
26
|
+
/** MCP server version. Defaults to '1.0.0' */
|
|
27
|
+
serverVersion?: string;
|
|
28
|
+
/** Custom transport factory. Defaults to StdioServerTransport (stdin/stdout). */
|
|
29
|
+
createTransport?: () => Transport | Promise<Transport>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Create a goke action callback that starts an MCP server over stdio.
|
|
33
|
+
*
|
|
34
|
+
* Exposes all CLI commands as MCP tools, automatically excluding the
|
|
35
|
+
* command this action is attached to.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* cli.command('mcp', 'Start MCP server over stdio')
|
|
40
|
+
* .action(createMcpAction({ cli }))
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function createMcpAction(options: CreateMcpActionOptions): (...args: any[]) => Promise<void>;
|
|
16
44
|
export declare function addCliToolsToMcp(options: AddCliToolsToMcpOptions): void;
|
|
17
45
|
//# sourceMappingURL=cli-to-mcp.d.ts.map
|
package/dist/cli-to-mcp.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli-to-mcp.d.ts","sourceRoot":"","sources":["../src/cli-to-mcp.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;
|
|
1
|
+
{"version":3,"file":"cli-to-mcp.d.ts","sourceRoot":"","sources":["../src/cli-to-mcp.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACxE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+CAA+C,CAAC;AAS/E,OAAO,EAAmD,KAAK,IAAI,EAA6B,MAAM,MAAM,CAAC;AAwD7G,MAAM,WAAW,uBAAuB;IACtC,GAAG,EAAE,IAAI,CAAC;IACV,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,aAAa,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC;IACjD,gBAAgB,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,MAAM,CAAC;CACpD;AA4XD,MAAM,WAAW,sBAAsB;IACrC,mEAAmE;IACnE,GAAG,EAAE,IAAI,CAAC;IACV,iGAAiG;IACjG,aAAa,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC;IACjD,iCAAiC;IACjC,gBAAgB,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,MAAM,CAAC;IACnD,oEAAoE;IACpE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,8CAA8C;IAC9C,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iFAAiF;IACjF,eAAe,CAAC,EAAE,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;CACxD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAsClG;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,IAAI,CAyCvE"}
|
package/dist/cli-to-mcp.js
CHANGED
|
@@ -342,6 +342,50 @@ function getOrInstallState(server) {
|
|
|
342
342
|
});
|
|
343
343
|
return state;
|
|
344
344
|
}
|
|
345
|
+
/**
|
|
346
|
+
* Create a goke action callback that starts an MCP server over stdio.
|
|
347
|
+
*
|
|
348
|
+
* Exposes all CLI commands as MCP tools, automatically excluding the
|
|
349
|
+
* command this action is attached to.
|
|
350
|
+
*
|
|
351
|
+
* @example
|
|
352
|
+
* ```ts
|
|
353
|
+
* cli.command('mcp', 'Start MCP server over stdio')
|
|
354
|
+
* .action(createMcpAction({ cli }))
|
|
355
|
+
* ```
|
|
356
|
+
*/
|
|
357
|
+
export function createMcpAction(options) {
|
|
358
|
+
const { cli, commandFilter: userFilter, sanitizeToolName, serverName, serverVersion, createTransport } = options;
|
|
359
|
+
return async () => {
|
|
360
|
+
// At call time, goke has already matched the command and set matchedCommandName.
|
|
361
|
+
// We use it to auto-exclude the MCP command itself from the tool list.
|
|
362
|
+
const mcpCommandName = cli.matchedCommandName;
|
|
363
|
+
const { Server: ServerClass } = await import("@modelcontextprotocol/sdk/server/index.js");
|
|
364
|
+
const server = new ServerClass({
|
|
365
|
+
name: serverName || cli.name || "cli-mcp-server",
|
|
366
|
+
version: serverVersion || "1.0.0",
|
|
367
|
+
}, { capabilities: {} });
|
|
368
|
+
addCliToolsToMcp({
|
|
369
|
+
cli,
|
|
370
|
+
server,
|
|
371
|
+
commandFilter: (name) => {
|
|
372
|
+
if (mcpCommandName && name === mcpCommandName)
|
|
373
|
+
return false;
|
|
374
|
+
return userFilter ? userFilter(name) : true;
|
|
375
|
+
},
|
|
376
|
+
sanitizeToolName,
|
|
377
|
+
});
|
|
378
|
+
let transport;
|
|
379
|
+
if (createTransport) {
|
|
380
|
+
transport = await createTransport();
|
|
381
|
+
}
|
|
382
|
+
else {
|
|
383
|
+
const { StdioServerTransport } = await import("@modelcontextprotocol/sdk/server/stdio.js");
|
|
384
|
+
transport = new StdioServerTransport();
|
|
385
|
+
}
|
|
386
|
+
await server.connect(transport);
|
|
387
|
+
};
|
|
388
|
+
}
|
|
345
389
|
export function addCliToolsToMcp(options) {
|
|
346
390
|
const { cli, commandFilter, sanitizeToolName = defaultSanitizeToolName } = options;
|
|
347
391
|
const server = resolveServer(options.server);
|
package/dist/index.d.ts
CHANGED
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
43
43
|
import type { Goke } from "goke";
|
|
44
44
|
import type { McpOAuthConfig } from "./types.js";
|
|
45
|
-
export { addCliToolsToMcp } from "./cli-to-mcp.js";
|
|
46
|
-
export type { AddCliToolsToMcpOptions } from "./cli-to-mcp.js";
|
|
45
|
+
export { addCliToolsToMcp, createMcpAction } from "./cli-to-mcp.js";
|
|
46
|
+
export type { AddCliToolsToMcpOptions, CreateMcpActionOptions } from "./cli-to-mcp.js";
|
|
47
47
|
export type { Transport };
|
|
48
48
|
export type { McpOAuthConfig, McpOAuthState } from "./types.js";
|
|
49
49
|
export interface CachedMcpTools {
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+CAA+C,CAAC;AAC/E,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAKjC,OAAO,KAAK,EAAE,cAAc,EAAiB,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+CAA+C,CAAC;AAC/E,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAKjC,OAAO,KAAK,EAAE,cAAc,EAAiB,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACpE,YAAY,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAGvF,YAAY,EAAE,SAAS,EAAE,CAAC;AAC1B,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhE,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,KAAK,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,WAAW,CAAC,EAAE,OAAO,CAAC;KACvB,CAAC,CAAC;IACH,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAID,MAAM,WAAW,qBAAqB;IACpC,GAAG,EAAE,IAAI,CAAC;IACV;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,MAAM,GAAG,SAAS,CAAC;IAErC;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,CAAC,SAAS,CAAC,EAAE,MAAM,KAAK,SAAS,GAAG,IAAI,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC;IAEvF;;;;;;;;;;;;;;OAcG;IACH,KAAK,CAAC,EAAE,cAAc,CAAC;IAEvB;;OAEG;IACH,SAAS,EAAE,MAAM,cAAc,GAAG,SAAS,CAAC;IAE5C;;OAEG;IACH,SAAS,EAAE,CAAC,KAAK,EAAE,cAAc,GAAG,SAAS,KAAK,IAAI,CAAC;CACxD;AAmID;;;;;;;;GAQG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CAyMlF"}
|
package/dist/index.js
CHANGED
|
@@ -45,7 +45,7 @@ import { wrapJsonSchema } from "goke";
|
|
|
45
45
|
import yaml from "js-yaml";
|
|
46
46
|
import { FileOAuthProvider } from "./oauth-provider.js";
|
|
47
47
|
import { startOAuthFlow, isAuthRequiredError } from "./auth.js";
|
|
48
|
-
export { addCliToolsToMcp } from "./cli-to-mcp.js";
|
|
48
|
+
export { addCliToolsToMcp, createMcpAction } from "./cli-to-mcp.js";
|
|
49
49
|
const CACHE_TTL_MS = 60 * 60 * 1000; // 1 hour
|
|
50
50
|
/**
|
|
51
51
|
* Check if a schema represents a complex type (object/array) for help text display.
|
package/package.json
CHANGED
|
@@ -1,29 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goke/mcp",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "Dynamically generate CLI commands from MCP server tools",
|
|
3
|
+
"version": "0.0.9",
|
|
5
4
|
"type": "module",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
5
|
+
"description": "Dynamically generate CLI commands from MCP server tools",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/remorses/goke",
|
|
9
|
+
"directory": "mcp"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/remorses/goke/tree/main/mcp",
|
|
12
|
+
"bugs": "https://github.com/remorses/goke/issues",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"mcp",
|
|
15
|
+
"cli",
|
|
16
|
+
"goke",
|
|
17
|
+
"model-context-protocol"
|
|
18
|
+
],
|
|
19
|
+
"main": "./dist/index.js",
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
8
21
|
"exports": {
|
|
22
|
+
"./package.json": "./package.json",
|
|
9
23
|
".": {
|
|
10
24
|
"types": "./dist/index.d.ts",
|
|
11
|
-
"
|
|
25
|
+
"default": "./dist/index.js"
|
|
12
26
|
},
|
|
13
|
-
"./src
|
|
27
|
+
"./src": {
|
|
14
28
|
"types": "./src/index.ts",
|
|
15
|
-
"
|
|
29
|
+
"default": "./src/index.ts"
|
|
30
|
+
},
|
|
31
|
+
"./src/*": {
|
|
32
|
+
"types": "./src/*.ts",
|
|
33
|
+
"default": "./src/*.ts"
|
|
16
34
|
}
|
|
17
35
|
},
|
|
18
36
|
"files": [
|
|
19
37
|
"dist",
|
|
20
38
|
"src"
|
|
21
39
|
],
|
|
22
|
-
"keywords": [
|
|
23
|
-
"mcp",
|
|
24
|
-
"cli",
|
|
25
|
-
"goke"
|
|
26
|
-
],
|
|
27
40
|
"author": "Tommaso De Rossi, morse <beats.by.morse@gmail.com>",
|
|
28
41
|
"license": "MIT",
|
|
29
42
|
"dependencies": {
|
|
@@ -38,12 +51,11 @@
|
|
|
38
51
|
"@types/node": "^22.19.7",
|
|
39
52
|
"vitest": "^3.1.0",
|
|
40
53
|
"zod": "^4.3.6",
|
|
41
|
-
"goke": "^6.
|
|
54
|
+
"goke": "^6.3.0"
|
|
42
55
|
},
|
|
43
56
|
"scripts": {
|
|
44
57
|
"clean": "rm -rf dist",
|
|
45
|
-
"build": "pnpm clean && tsc
|
|
46
|
-
"test": "vitest --run"
|
|
47
|
-
"watch": "tsc -w"
|
|
58
|
+
"build": "pnpm clean && tsc",
|
|
59
|
+
"test": "vitest --run"
|
|
48
60
|
}
|
|
49
61
|
}
|