mcp-new 0.1.0 → 1.2.0
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 +206 -97
- package/dist/{chunk-QRUHMGU5.js → chunk-BHGUGEHE.js} +746 -22
- package/dist/cli.js +65 -5
- package/dist/index.d.ts +38 -7
- package/dist/index.js +14 -2
- package/package.json +1 -1
- package/templates/go/.env.example +5 -0
- package/templates/go/.gitignore.ejs +30 -0
- package/templates/go/README.md.ejs +151 -0
- package/templates/go/cmd/server/main.go.ejs +101 -0
- package/templates/go/go.mod.ejs +7 -0
- package/templates/go/internal/tools/example.go.ejs +40 -0
- package/templates/python/README.md.ejs +58 -15
- package/templates/rust/.env.example +8 -0
- package/templates/rust/.gitignore.ejs +19 -0
- package/templates/rust/Cargo.toml.ejs +18 -0
- package/templates/rust/README.md.ejs +155 -0
- package/templates/rust/src/main.rs.ejs +46 -0
- package/templates/rust/src/tools.rs.ejs +105 -0
- package/templates/typescript/README.md.ejs +56 -15
package/dist/cli.js
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
addToolCommand,
|
|
4
4
|
createCommand,
|
|
5
5
|
initCommand
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-BHGUGEHE.js";
|
|
7
7
|
|
|
8
8
|
// src/cli.ts
|
|
9
9
|
import { Command } from "commander";
|
|
@@ -15,10 +15,70 @@ var logo = `
|
|
|
15
15
|
${chalk.cyan("\u2551")} ${chalk.gray("Generate MCP servers in seconds")} ${chalk.cyan("\u2551")}
|
|
16
16
|
${chalk.cyan("\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D")}
|
|
17
17
|
`;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
var examples = `
|
|
19
|
+
${chalk.bold("Examples:")}
|
|
20
|
+
|
|
21
|
+
${chalk.gray("# Create a new MCP server with interactive wizard")}
|
|
22
|
+
${chalk.cyan("$")} mcp-new my-server
|
|
23
|
+
|
|
24
|
+
${chalk.gray("# Create TypeScript server with defaults")}
|
|
25
|
+
${chalk.cyan("$")} mcp-new my-server -t -y
|
|
26
|
+
|
|
27
|
+
${chalk.gray("# Create Python server")}
|
|
28
|
+
${chalk.cyan("$")} mcp-new my-server -p
|
|
29
|
+
|
|
30
|
+
${chalk.gray("# Create from preset template")}
|
|
31
|
+
${chalk.cyan("$")} mcp-new my-db --preset database
|
|
32
|
+
${chalk.cyan("$")} mcp-new my-api --preset rest-api
|
|
33
|
+
${chalk.cyan("$")} mcp-new my-fs --preset filesystem
|
|
34
|
+
|
|
35
|
+
${chalk.gray("# Create from OpenAPI specification")}
|
|
36
|
+
${chalk.cyan("$")} mcp-new my-api --from-openapi ./openapi.yaml
|
|
37
|
+
|
|
38
|
+
${chalk.gray("# Create using AI (requires ANTHROPIC_API_KEY)")}
|
|
39
|
+
${chalk.cyan("$")} mcp-new my-server --from-prompt
|
|
40
|
+
|
|
41
|
+
${chalk.bold("Available Presets:")}
|
|
42
|
+
|
|
43
|
+
${chalk.yellow("database")} Database CRUD tools (query, insert, update, delete, list_tables)
|
|
44
|
+
${chalk.yellow("rest-api")} REST API tools (http_get, http_post, http_put, http_delete, set_base_url)
|
|
45
|
+
${chalk.yellow("filesystem")} File system tools (read_file, write_file, list_directory, search_files, file_info)
|
|
46
|
+
|
|
47
|
+
${chalk.bold("Supported Languages:")}
|
|
48
|
+
|
|
49
|
+
${chalk.green("-t, --typescript")} TypeScript with npm
|
|
50
|
+
${chalk.green("-p, --python")} Python with pip
|
|
51
|
+
${chalk.green("-g, --go")} Go with go modules
|
|
52
|
+
${chalk.green("-r, --rust")} Rust with cargo
|
|
53
|
+
|
|
54
|
+
${chalk.bold("Learn More:")}
|
|
55
|
+
|
|
56
|
+
Documentation: ${chalk.underline("https://github.com/d1maash/mcp-new")}
|
|
57
|
+
MCP Spec: ${chalk.underline("https://spec.modelcontextprotocol.io")}
|
|
58
|
+
`;
|
|
59
|
+
program.name("mcp-new").description("CLI tool for generating MCP (Model Context Protocol) servers").version("1.2.0").addHelpText("beforeAll", logo).addHelpText("after", examples);
|
|
60
|
+
program.argument("[project-name]", "Name of the project to create").option("-t, --typescript", "Use TypeScript template").option("-p, --python", "Use Python template").option("-g, --go", "Use Go template").option("-r, --rust", "Use Rust template").option("--skip-install", "Skip dependency installation").option("--from-openapi <path>", "Generate from OpenAPI/Swagger specification").option("--from-prompt", "Generate tools using AI from text description").option("--preset <name>", "Use a preset template (database, rest-api, filesystem)").option("-y, --yes", "Skip prompts and use defaults").action(createCommand);
|
|
61
|
+
program.command("init").description("Initialize MCP server in the current directory").option("-t, --typescript", "Use TypeScript template").option("-p, --python", "Use Python template").option("-g, --go", "Use Go template").option("-r, --rust", "Use Rust template").option("--skip-install", "Skip dependency installation").option("-f, --force", "Initialize even if directory contains files").addHelpText("after", `
|
|
62
|
+
${chalk.bold("Examples:")}
|
|
63
|
+
|
|
64
|
+
${chalk.gray("# Initialize in current directory")}
|
|
65
|
+
${chalk.cyan("$")} mcp-new init
|
|
66
|
+
|
|
67
|
+
${chalk.gray("# Initialize with TypeScript")}
|
|
68
|
+
${chalk.cyan("$")} mcp-new init -t
|
|
69
|
+
|
|
70
|
+
${chalk.gray("# Force initialize (overwrite existing files)")}
|
|
71
|
+
${chalk.cyan("$")} mcp-new init -f
|
|
72
|
+
`).action(initCommand);
|
|
73
|
+
program.command("add-tool").description("Add a new tool to an existing MCP server").option("-n, --name <name>", "Tool name (snake_case)").addHelpText("after", `
|
|
74
|
+
${chalk.bold("Examples:")}
|
|
75
|
+
|
|
76
|
+
${chalk.gray("# Add tool interactively")}
|
|
77
|
+
${chalk.cyan("$")} mcp-new add-tool
|
|
78
|
+
|
|
79
|
+
${chalk.gray("# Add tool with name")}
|
|
80
|
+
${chalk.cyan("$")} mcp-new add-tool -n my_new_tool
|
|
81
|
+
`).action(addToolCommand);
|
|
22
82
|
program.parse();
|
|
23
83
|
if (process.argv.length === 2) {
|
|
24
84
|
program.help();
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
|
-
declare const LanguageSchema: z.ZodEnum<["typescript", "python"]>;
|
|
3
|
+
declare const LanguageSchema: z.ZodEnum<["typescript", "python", "go", "rust"]>;
|
|
4
4
|
type Language = z.infer<typeof LanguageSchema>;
|
|
5
5
|
declare const TransportSchema: z.ZodEnum<["stdio", "sse"]>;
|
|
6
6
|
type Transport = z.infer<typeof TransportSchema>;
|
|
@@ -80,7 +80,7 @@ type ResourceConfig = z.infer<typeof ResourceConfigSchema>;
|
|
|
80
80
|
declare const ProjectConfigSchema: z.ZodObject<{
|
|
81
81
|
name: z.ZodString;
|
|
82
82
|
description: z.ZodDefault<z.ZodString>;
|
|
83
|
-
language: z.ZodEnum<["typescript", "python"]>;
|
|
83
|
+
language: z.ZodEnum<["typescript", "python", "go", "rust"]>;
|
|
84
84
|
transport: z.ZodEnum<["stdio", "sse"]>;
|
|
85
85
|
tools: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
86
86
|
name: z.ZodString;
|
|
@@ -142,7 +142,7 @@ declare const ProjectConfigSchema: z.ZodObject<{
|
|
|
142
142
|
}, "strip", z.ZodTypeAny, {
|
|
143
143
|
name: string;
|
|
144
144
|
description: string;
|
|
145
|
-
language: "typescript" | "python";
|
|
145
|
+
language: "typescript" | "python" | "go" | "rust";
|
|
146
146
|
transport: "stdio" | "sse";
|
|
147
147
|
tools: {
|
|
148
148
|
name: string;
|
|
@@ -165,7 +165,7 @@ declare const ProjectConfigSchema: z.ZodObject<{
|
|
|
165
165
|
initGit: boolean;
|
|
166
166
|
}, {
|
|
167
167
|
name: string;
|
|
168
|
-
language: "typescript" | "python";
|
|
168
|
+
language: "typescript" | "python" | "go" | "rust";
|
|
169
169
|
transport: "stdio" | "sse";
|
|
170
170
|
description?: string | undefined;
|
|
171
171
|
tools?: {
|
|
@@ -194,12 +194,17 @@ interface GeneratorContext {
|
|
|
194
194
|
outputDir: string;
|
|
195
195
|
templateDir: string;
|
|
196
196
|
}
|
|
197
|
+
declare const PresetIdSchema: z.ZodEnum<["database", "rest-api", "filesystem"]>;
|
|
198
|
+
type PresetId$1 = z.infer<typeof PresetIdSchema>;
|
|
197
199
|
interface CLIOptions {
|
|
198
200
|
typescript?: boolean;
|
|
199
201
|
python?: boolean;
|
|
202
|
+
go?: boolean;
|
|
203
|
+
rust?: boolean;
|
|
200
204
|
skipInstall?: boolean;
|
|
201
205
|
fromOpenapi?: string;
|
|
202
206
|
fromPrompt?: boolean;
|
|
207
|
+
preset?: string;
|
|
203
208
|
yes?: boolean;
|
|
204
209
|
}
|
|
205
210
|
|
|
@@ -354,6 +359,8 @@ declare abstract class BaseGenerator {
|
|
|
354
359
|
protected installDependencies(): Promise<void>;
|
|
355
360
|
private installNodeDependencies;
|
|
356
361
|
private installPythonDependencies;
|
|
362
|
+
private installGoDependencies;
|
|
363
|
+
private installRustDependencies;
|
|
357
364
|
private checkCommand;
|
|
358
365
|
protected initializeGit(): Promise<void>;
|
|
359
366
|
protected checkOutputDir(): Promise<boolean>;
|
|
@@ -381,6 +388,23 @@ declare class PromptGenerator extends BaseGenerator {
|
|
|
381
388
|
}
|
|
382
389
|
declare function generateFromPrompt(baseConfig: Partial<ProjectConfig>): Promise<void>;
|
|
383
390
|
|
|
391
|
+
type PresetId = 'database' | 'rest-api' | 'filesystem';
|
|
392
|
+
|
|
393
|
+
declare class PresetGenerator extends BaseGenerator {
|
|
394
|
+
private presetName;
|
|
395
|
+
constructor(context: GeneratorContext, presetName: string);
|
|
396
|
+
generate(): Promise<void>;
|
|
397
|
+
}
|
|
398
|
+
interface PresetGeneratorOptions {
|
|
399
|
+
projectName?: string;
|
|
400
|
+
presetId: PresetId;
|
|
401
|
+
language?: Language;
|
|
402
|
+
skipInstall?: boolean;
|
|
403
|
+
useDefaults?: boolean;
|
|
404
|
+
}
|
|
405
|
+
declare function generateFromPreset(options: PresetGeneratorOptions): Promise<void>;
|
|
406
|
+
declare function validatePresetId(presetId: string): presetId is PresetId;
|
|
407
|
+
|
|
384
408
|
declare function parseOpenAPISpec(content: string): Promise<ParsedEndpoint[]>;
|
|
385
409
|
declare function selectEndpoints(endpoints: ParsedEndpoint[]): Promise<ParsedEndpoint[]>;
|
|
386
410
|
declare function endpointToMCPTool(endpoint: ParsedEndpoint): {
|
|
@@ -489,20 +513,27 @@ declare function promptAddResources(): Promise<boolean>;
|
|
|
489
513
|
declare function promptResourceConfig(): Promise<ResourceConfig>;
|
|
490
514
|
declare function promptMultipleResources(): Promise<ResourceConfig[]>;
|
|
491
515
|
|
|
516
|
+
type GenerationMethod = 'wizard' | 'preset' | 'openapi' | 'prompt';
|
|
517
|
+
declare function promptGenerationMethod(): Promise<GenerationMethod>;
|
|
518
|
+
|
|
519
|
+
declare function promptPreset(): Promise<PresetId>;
|
|
520
|
+
|
|
492
521
|
interface WizardOptions {
|
|
493
522
|
defaultName?: string;
|
|
494
523
|
skipDescription?: boolean;
|
|
495
524
|
skipAdvanced?: boolean;
|
|
496
|
-
presetLanguage?:
|
|
525
|
+
presetLanguage?: Language;
|
|
497
526
|
}
|
|
498
527
|
declare function runWizard(options?: WizardOptions): Promise<ProjectConfig>;
|
|
499
|
-
declare function runQuickWizard(defaultName?: string, presetLanguage?:
|
|
528
|
+
declare function runQuickWizard(defaultName?: string, presetLanguage?: Language): Promise<ProjectConfig>;
|
|
500
529
|
|
|
501
530
|
declare function createCommand(projectName: string | undefined, options: CLIOptions): Promise<void>;
|
|
502
531
|
|
|
503
532
|
interface InitOptions {
|
|
504
533
|
typescript?: boolean;
|
|
505
534
|
python?: boolean;
|
|
535
|
+
go?: boolean;
|
|
536
|
+
rust?: boolean;
|
|
506
537
|
skipInstall?: boolean;
|
|
507
538
|
force?: boolean;
|
|
508
539
|
}
|
|
@@ -513,4 +544,4 @@ interface AddToolOptions {
|
|
|
513
544
|
}
|
|
514
545
|
declare function addToolCommand(options: AddToolOptions): Promise<void>;
|
|
515
546
|
|
|
516
|
-
export { BaseGenerator, type CLIOptions, type GeneratorContext, type Language, LanguageSchema, type MCPPrompt, type MCPPromptArgument, type MCPPropertySchema, type MCPResource, type MCPServerCapabilities, type MCPServerInfo, type MCPTool, type MCPToolInputSchema, type OpenAPIComponents, OpenAPIGenerator, type OpenAPIInfo, type OpenAPIMediaType, type OpenAPIOperation, type OpenAPIParameter, type OpenAPIPathItem, type OpenAPIRequestBody, type OpenAPIResponse, type OpenAPISchema, type OpenAPIServer, type OpenAPISpec, type ParsedEndpoint, type ParsedParameter, type ParsedRequestBody, type ProjectConfig, ProjectConfigSchema, PromptGenerator, type ResourceConfig, ResourceConfigSchema, type SpinnerInstance, type ToolConfig, ToolConfigSchema, type ToolParameter, ToolParameterSchema, type Transport, TransportSchema, WizardGenerator, type WizardOptions, addToolCommand, copyDir, copyFile, createCommand, createGeneratorContext, createInitialCommit, createSpinner, endpointToMCPTool, ensureDir, exists, generateFromOpenAPI, generateFromPrompt, generateFromWizard, getGitUser, getTemplateDir, initCommand, initGitRepository, isDirectory, isGitInstalled, isInsideGitRepository, logger, parseAndValidate, parseOpenAPISpec, parsePostmanCollection, parseSwaggerSpec, projectNameRegex, promptAddResources, promptAddTools, promptIncludeExampleTool, promptLanguage, promptMultipleResources, promptMultipleTools, promptProjectDescription, promptProjectName, promptResourceConfig, promptToolConfig, promptTransport, readDir, readFile, remove, renderTemplate, renderTemplateToFile, resolveOutputPath, runQuickWizard, runWizard, safeParseAndValidate, selectEndpoints, validateFilePath, validateProjectName, validateToolName, validateUrl, walkDir, withSpinner, writeFile };
|
|
547
|
+
export { BaseGenerator, type CLIOptions, type GenerationMethod, type GeneratorContext, type Language, LanguageSchema, type MCPPrompt, type MCPPromptArgument, type MCPPropertySchema, type MCPResource, type MCPServerCapabilities, type MCPServerInfo, type MCPTool, type MCPToolInputSchema, type OpenAPIComponents, OpenAPIGenerator, type OpenAPIInfo, type OpenAPIMediaType, type OpenAPIOperation, type OpenAPIParameter, type OpenAPIPathItem, type OpenAPIRequestBody, type OpenAPIResponse, type OpenAPISchema, type OpenAPIServer, type OpenAPISpec, type ParsedEndpoint, type ParsedParameter, type ParsedRequestBody, PresetGenerator, type PresetGeneratorOptions, type PresetId$1 as PresetId, PresetIdSchema, type ProjectConfig, ProjectConfigSchema, PromptGenerator, type ResourceConfig, ResourceConfigSchema, type SpinnerInstance, type ToolConfig, ToolConfigSchema, type ToolParameter, ToolParameterSchema, type Transport, TransportSchema, WizardGenerator, type WizardOptions, addToolCommand, copyDir, copyFile, createCommand, createGeneratorContext, createInitialCommit, createSpinner, endpointToMCPTool, ensureDir, exists, generateFromOpenAPI, generateFromPreset, generateFromPrompt, generateFromWizard, getGitUser, getTemplateDir, initCommand, initGitRepository, isDirectory, isGitInstalled, isInsideGitRepository, logger, parseAndValidate, parseOpenAPISpec, parsePostmanCollection, parseSwaggerSpec, projectNameRegex, promptAddResources, promptAddTools, promptGenerationMethod, promptIncludeExampleTool, promptLanguage, promptMultipleResources, promptMultipleTools, promptPreset, promptProjectDescription, promptProjectName, promptResourceConfig, promptToolConfig, promptTransport, readDir, readFile, remove, renderTemplate, renderTemplateToFile, resolveOutputPath, runQuickWizard, runWizard, safeParseAndValidate, selectEndpoints, validateFilePath, validatePresetId, validateProjectName, validateToolName, validateUrl, walkDir, withSpinner, writeFile };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BaseGenerator,
|
|
3
3
|
OpenAPIGenerator,
|
|
4
|
+
PresetGenerator,
|
|
4
5
|
PromptGenerator,
|
|
5
6
|
WizardGenerator,
|
|
6
7
|
addToolCommand,
|
|
@@ -14,6 +15,7 @@ import {
|
|
|
14
15
|
ensureDir,
|
|
15
16
|
exists,
|
|
16
17
|
generateFromOpenAPI,
|
|
18
|
+
generateFromPreset,
|
|
17
19
|
generateFromPrompt,
|
|
18
20
|
generateFromWizard,
|
|
19
21
|
getGitUser,
|
|
@@ -29,10 +31,12 @@ import {
|
|
|
29
31
|
projectNameRegex,
|
|
30
32
|
promptAddResources,
|
|
31
33
|
promptAddTools,
|
|
34
|
+
promptGenerationMethod,
|
|
32
35
|
promptIncludeExampleTool,
|
|
33
36
|
promptLanguage,
|
|
34
37
|
promptMultipleResources,
|
|
35
38
|
promptMultipleTools,
|
|
39
|
+
promptPreset,
|
|
36
40
|
promptProjectDescription,
|
|
37
41
|
promptProjectName,
|
|
38
42
|
promptResourceConfig,
|
|
@@ -49,17 +53,18 @@ import {
|
|
|
49
53
|
safeParseAndValidate,
|
|
50
54
|
selectEndpoints,
|
|
51
55
|
validateFilePath,
|
|
56
|
+
validatePresetId,
|
|
52
57
|
validateProjectName,
|
|
53
58
|
validateToolName,
|
|
54
59
|
validateUrl,
|
|
55
60
|
walkDir,
|
|
56
61
|
withSpinner,
|
|
57
62
|
writeFile
|
|
58
|
-
} from "./chunk-
|
|
63
|
+
} from "./chunk-BHGUGEHE.js";
|
|
59
64
|
|
|
60
65
|
// src/types/config.ts
|
|
61
66
|
import { z } from "zod";
|
|
62
|
-
var LanguageSchema = z.enum(["typescript", "python"]);
|
|
67
|
+
var LanguageSchema = z.enum(["typescript", "python", "go", "rust"]);
|
|
63
68
|
var TransportSchema = z.enum(["stdio", "sse"]);
|
|
64
69
|
var ToolParameterSchema = z.object({
|
|
65
70
|
name: z.string(),
|
|
@@ -89,6 +94,7 @@ var ProjectConfigSchema = z.object({
|
|
|
89
94
|
skipInstall: z.boolean().default(false),
|
|
90
95
|
initGit: z.boolean().default(true)
|
|
91
96
|
});
|
|
97
|
+
var PresetIdSchema = z.enum(["database", "rest-api", "filesystem"]);
|
|
92
98
|
|
|
93
99
|
// src/parsers/swagger.ts
|
|
94
100
|
import YAML from "yaml";
|
|
@@ -287,6 +293,8 @@ export {
|
|
|
287
293
|
BaseGenerator,
|
|
288
294
|
LanguageSchema,
|
|
289
295
|
OpenAPIGenerator,
|
|
296
|
+
PresetGenerator,
|
|
297
|
+
PresetIdSchema,
|
|
290
298
|
ProjectConfigSchema,
|
|
291
299
|
PromptGenerator,
|
|
292
300
|
ResourceConfigSchema,
|
|
@@ -305,6 +313,7 @@ export {
|
|
|
305
313
|
ensureDir,
|
|
306
314
|
exists,
|
|
307
315
|
generateFromOpenAPI,
|
|
316
|
+
generateFromPreset,
|
|
308
317
|
generateFromPrompt,
|
|
309
318
|
generateFromWizard,
|
|
310
319
|
getGitUser,
|
|
@@ -322,10 +331,12 @@ export {
|
|
|
322
331
|
projectNameRegex,
|
|
323
332
|
promptAddResources,
|
|
324
333
|
promptAddTools,
|
|
334
|
+
promptGenerationMethod,
|
|
325
335
|
promptIncludeExampleTool,
|
|
326
336
|
promptLanguage,
|
|
327
337
|
promptMultipleResources,
|
|
328
338
|
promptMultipleTools,
|
|
339
|
+
promptPreset,
|
|
329
340
|
promptProjectDescription,
|
|
330
341
|
promptProjectName,
|
|
331
342
|
promptResourceConfig,
|
|
@@ -342,6 +353,7 @@ export {
|
|
|
342
353
|
safeParseAndValidate,
|
|
343
354
|
selectEndpoints,
|
|
344
355
|
validateFilePath,
|
|
356
|
+
validatePresetId,
|
|
345
357
|
validateProjectName,
|
|
346
358
|
validateToolName,
|
|
347
359
|
validateUrl,
|
package/package.json
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Binaries
|
|
2
|
+
*.exe
|
|
3
|
+
*.exe~
|
|
4
|
+
*.dll
|
|
5
|
+
*.so
|
|
6
|
+
*.dylib
|
|
7
|
+
<%= name %>
|
|
8
|
+
|
|
9
|
+
# Test binary
|
|
10
|
+
*.test
|
|
11
|
+
|
|
12
|
+
# Output of the go coverage tool
|
|
13
|
+
*.out
|
|
14
|
+
|
|
15
|
+
# Dependency directories
|
|
16
|
+
vendor/
|
|
17
|
+
|
|
18
|
+
# IDE
|
|
19
|
+
.idea/
|
|
20
|
+
.vscode/
|
|
21
|
+
*.swp
|
|
22
|
+
*.swo
|
|
23
|
+
|
|
24
|
+
# Environment
|
|
25
|
+
.env
|
|
26
|
+
.env.local
|
|
27
|
+
|
|
28
|
+
# Build
|
|
29
|
+
/bin/
|
|
30
|
+
/dist/
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# <%= name %>
|
|
2
|
+
|
|
3
|
+
<%= description || 'MCP Server generated with mcp-generator' %>
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This is an MCP (Model Context Protocol) server built with Go using the [mcp-go](https://github.com/mark3labs/mcp-go) SDK.
|
|
8
|
+
|
|
9
|
+
## Prerequisites
|
|
10
|
+
|
|
11
|
+
- Go 1.21 or higher
|
|
12
|
+
- Git
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
# Install dependencies
|
|
18
|
+
go mod download
|
|
19
|
+
|
|
20
|
+
# Build the server
|
|
21
|
+
go build -o <%= name %> ./cmd/server
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Running the Server
|
|
25
|
+
|
|
26
|
+
<% if (transport === 'stdio') { %>
|
|
27
|
+
### STDIO Transport
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
./<%= name %>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The server communicates via standard input/output.
|
|
34
|
+
<% } else { %>
|
|
35
|
+
### SSE Transport
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
./<%= name %>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
The server will start an HTTP server with SSE endpoint.
|
|
42
|
+
<% } %>
|
|
43
|
+
|
|
44
|
+
## Claude Desktop Configuration
|
|
45
|
+
|
|
46
|
+
Add the following to your Claude Desktop config file:
|
|
47
|
+
|
|
48
|
+
- **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
49
|
+
- **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
|
|
50
|
+
|
|
51
|
+
```json
|
|
52
|
+
{
|
|
53
|
+
"mcpServers": {
|
|
54
|
+
"<%- name %>": {
|
|
55
|
+
"command": "<%- process.cwd().replace(/\\/g, '/') %>/<%- name %>/<%- name %>"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Available Tools
|
|
62
|
+
|
|
63
|
+
<% if (includeExampleTool) { %>
|
|
64
|
+
### `example_tool`
|
|
65
|
+
|
|
66
|
+
An example tool that echoes the input.
|
|
67
|
+
|
|
68
|
+
| Parameter | Type | Required | Description |
|
|
69
|
+
|-----------|------|----------|-------------|
|
|
70
|
+
| `input` | string | Yes | Input to echo |
|
|
71
|
+
|
|
72
|
+
**Example:**
|
|
73
|
+
```json
|
|
74
|
+
{
|
|
75
|
+
"name": "example_tool",
|
|
76
|
+
"arguments": {
|
|
77
|
+
"input": "hello"
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
<% } %>
|
|
83
|
+
<% tools.forEach(function(tool) { %>
|
|
84
|
+
### `<%- tool.name %>`
|
|
85
|
+
|
|
86
|
+
<%= tool.description %>
|
|
87
|
+
|
|
88
|
+
<% if (tool.parameters && tool.parameters.length > 0) { %>
|
|
89
|
+
| Parameter | Type | Required | Description |
|
|
90
|
+
|-----------|------|----------|-------------|
|
|
91
|
+
<% tool.parameters.forEach(function(param) { %>| `<%= param.name %>` | <%= param.type %> | <%= param.required ? 'Yes' : 'No' %> | <%= param.description %> |
|
|
92
|
+
<% }); %>
|
|
93
|
+
|
|
94
|
+
**Example:**
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"name": "<%- tool.name %>",
|
|
98
|
+
"arguments": {
|
|
99
|
+
<% var reqParams = tool.parameters.filter(p => p.required); reqParams.forEach(function(param, index) { var val = param.type === 'string' ? '"value"' : param.type === 'number' ? '0' : param.type === 'boolean' ? 'true' : param.type === 'array' ? '[]' : '{}'; %> "<%- param.name %>": <%- val %><% if (index < reqParams.length - 1) { %>,<% } %>
|
|
100
|
+
<% }); %> }
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
<% } else { %>
|
|
104
|
+
*This tool has no parameters.*
|
|
105
|
+
|
|
106
|
+
**Example:**
|
|
107
|
+
```json
|
|
108
|
+
{
|
|
109
|
+
"name": "<%- tool.name %>",
|
|
110
|
+
"arguments": {}
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
<% } %>
|
|
114
|
+
|
|
115
|
+
<% }); %>
|
|
116
|
+
## Development
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
# Run in development mode
|
|
120
|
+
go run ./cmd/server
|
|
121
|
+
|
|
122
|
+
# Run tests
|
|
123
|
+
go test ./...
|
|
124
|
+
|
|
125
|
+
# Build for production
|
|
126
|
+
go build -ldflags="-s -w" -o <%= name %> ./cmd/server
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Testing with MCP Inspector
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
npx @modelcontextprotocol/inspector ./<%= name %>
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Project Structure
|
|
136
|
+
|
|
137
|
+
```
|
|
138
|
+
<%= name %>/
|
|
139
|
+
├── cmd/
|
|
140
|
+
│ └── server/
|
|
141
|
+
│ └── main.go # Server entry point
|
|
142
|
+
├── internal/
|
|
143
|
+
│ └── tools/ # Tool implementations
|
|
144
|
+
├── go.mod
|
|
145
|
+
├── go.sum
|
|
146
|
+
└── README.md
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## License
|
|
150
|
+
|
|
151
|
+
MIT
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
package main
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
"fmt"
|
|
6
|
+
"os"
|
|
7
|
+
|
|
8
|
+
"github.com/mark3labs/mcp-go/mcp"
|
|
9
|
+
"github.com/mark3labs/mcp-go/server"
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
func main() {
|
|
13
|
+
// Create MCP server
|
|
14
|
+
s := server.NewMCPServer(
|
|
15
|
+
"<%= name %>",
|
|
16
|
+
"1.0.0",
|
|
17
|
+
server.WithToolCapabilities(true),
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
<% if (includeExampleTool) { %>
|
|
21
|
+
// Register example tool
|
|
22
|
+
exampleTool := mcp.NewTool("example_tool",
|
|
23
|
+
mcp.WithDescription("An example tool that echoes the input"),
|
|
24
|
+
mcp.WithString("query",
|
|
25
|
+
mcp.Required(),
|
|
26
|
+
mcp.Description("The query to echo"),
|
|
27
|
+
),
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
s.AddTool(exampleTool, exampleToolHandler)
|
|
31
|
+
<% } %>
|
|
32
|
+
|
|
33
|
+
<% tools.forEach(function(tool) { %>
|
|
34
|
+
// Register <%= tool.name %> tool
|
|
35
|
+
<%= tool.name %>Tool := mcp.NewTool("<%= tool.name %>",
|
|
36
|
+
mcp.WithDescription("<%= tool.description %>"),
|
|
37
|
+
<% tool.parameters.forEach(function(param, index) { %>
|
|
38
|
+
<% if (param.type === 'string') { %>
|
|
39
|
+
mcp.WithString("<%= param.name %>",
|
|
40
|
+
<% } else if (param.type === 'number') { %>
|
|
41
|
+
mcp.WithNumber("<%= param.name %>",
|
|
42
|
+
<% } else if (param.type === 'boolean') { %>
|
|
43
|
+
mcp.WithBoolean("<%= param.name %>",
|
|
44
|
+
<% } else { %>
|
|
45
|
+
mcp.WithString("<%= param.name %>",
|
|
46
|
+
<% } %>
|
|
47
|
+
<% if (param.required) { %>
|
|
48
|
+
mcp.Required(),
|
|
49
|
+
<% } %>
|
|
50
|
+
mcp.Description("<%= param.description %>"),
|
|
51
|
+
),
|
|
52
|
+
<% }); %>
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
s.AddTool(<%= tool.name %>Tool, <%= tool.name %>Handler)
|
|
56
|
+
<% }); %>
|
|
57
|
+
|
|
58
|
+
<% if (transport === 'stdio') { %>
|
|
59
|
+
// Start STDIO server
|
|
60
|
+
if err := server.ServeStdio(s); err != nil {
|
|
61
|
+
fmt.Fprintf(os.Stderr, "Server error: %v\n", err)
|
|
62
|
+
os.Exit(1)
|
|
63
|
+
}
|
|
64
|
+
<% } else { %>
|
|
65
|
+
// Start SSE server
|
|
66
|
+
if err := server.ServeSSE(s, ":8080", "/messages"); err != nil {
|
|
67
|
+
fmt.Fprintf(os.Stderr, "Server error: %v\n", err)
|
|
68
|
+
os.Exit(1)
|
|
69
|
+
}
|
|
70
|
+
<% } %>
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
<% if (includeExampleTool) { %>
|
|
74
|
+
func exampleToolHandler(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|
75
|
+
query, ok := request.Params.Arguments["query"].(string)
|
|
76
|
+
if !ok {
|
|
77
|
+
return mcp.NewToolResultError("query parameter is required"), nil
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return mcp.NewToolResultText(fmt.Sprintf("Echo: %s", query)), nil
|
|
81
|
+
}
|
|
82
|
+
<% } %>
|
|
83
|
+
|
|
84
|
+
<% tools.forEach(function(tool) { %>
|
|
85
|
+
func <%= tool.name %>Handler(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|
86
|
+
// TODO: Implement <%= tool.name %> logic
|
|
87
|
+
<% tool.parameters.forEach(function(param) { %>
|
|
88
|
+
<% if (param.type === 'string') { %>
|
|
89
|
+
<%= param.name %>, _ := request.Params.Arguments["<%= param.name %>"].(string)
|
|
90
|
+
<% } else if (param.type === 'number') { %>
|
|
91
|
+
<%= param.name %>, _ := request.Params.Arguments["<%= param.name %>"].(float64)
|
|
92
|
+
<% } else if (param.type === 'boolean') { %>
|
|
93
|
+
<%= param.name %>, _ := request.Params.Arguments["<%= param.name %>"].(bool)
|
|
94
|
+
<% } else { %>
|
|
95
|
+
<%= param.name %> := request.Params.Arguments["<%= param.name %>"]
|
|
96
|
+
<% } %>
|
|
97
|
+
<% }); %>
|
|
98
|
+
|
|
99
|
+
return mcp.NewToolResultText(fmt.Sprintf("<%= tool.name %> called with: %v", request.Params.Arguments)), nil
|
|
100
|
+
}
|
|
101
|
+
<% }); %>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
package tools
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
"fmt"
|
|
6
|
+
|
|
7
|
+
"github.com/mark3labs/mcp-go/mcp"
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
// ExampleInput represents the input for the example tool
|
|
11
|
+
type ExampleInput struct {
|
|
12
|
+
Query string `json:"query"`
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// ExampleOutput represents the output of the example tool
|
|
16
|
+
type ExampleOutput struct {
|
|
17
|
+
Result string `json:"result"`
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// ExampleTool creates the example tool definition
|
|
21
|
+
func ExampleTool() mcp.Tool {
|
|
22
|
+
return mcp.NewTool("example_tool",
|
|
23
|
+
mcp.WithDescription("An example tool that echoes the input"),
|
|
24
|
+
mcp.WithString("query",
|
|
25
|
+
mcp.Required(),
|
|
26
|
+
mcp.Description("The query to echo"),
|
|
27
|
+
),
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// ExampleHandler handles the example tool execution
|
|
32
|
+
func ExampleHandler(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|
33
|
+
query, ok := request.Params.Arguments["query"].(string)
|
|
34
|
+
if !ok {
|
|
35
|
+
return mcp.NewToolResultError("query parameter is required"), nil
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
result := fmt.Sprintf("Echo: %s", query)
|
|
39
|
+
return mcp.NewToolResultText(result), nil
|
|
40
|
+
}
|