Skip to content

Commit 67f1d0c

Browse files
committed
fix lint issues
1 parent d063c77 commit 67f1d0c

21 files changed

+449
-2038
lines changed

cmd/kmcp/cmd/add_tool.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func init() {
5555
addToolCmd.Flags().BoolVarP(&addToolInteractive, "interactive", "i", false, "Interactive tool creation")
5656
}
5757

58-
func runAddTool(cmd *cobra.Command, args []string) error {
58+
func runAddTool(_ *cobra.Command, args []string) error {
5959
toolName := args[0]
6060

6161
// Validate tool name
@@ -146,7 +146,10 @@ func createToolInteractive(toolName, toolPath string) error {
146146
if addToolDescription == "" {
147147
fmt.Printf("Enter tool description (optional): ")
148148
var desc string
149-
fmt.Scanln(&desc)
149+
_, err := fmt.Scanln(&desc)
150+
if err != nil {
151+
return fmt.Errorf("failed to read description: %w", err)
152+
}
150153
addToolDescription = desc
151154
}
152155

cmd/kmcp/cmd/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func init() {
3535
buildCmd.Flags().StringVar(&buildPlatform, "platform", "", "Target platform (e.g., linux/amd64,linux/arm64)")
3636
}
3737

38-
func runBuild(cmd *cobra.Command, args []string) error {
38+
func runBuild(_ *cobra.Command, _ []string) error {
3939
// Get current working directory
4040
cwd, err := os.Getwd()
4141
if err != nil {

cmd/kmcp/cmd/deploy.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ import (
1414
"sigs.k8s.io/yaml"
1515
)
1616

17+
const (
18+
transportHTTP = "http"
19+
transportStdio = "stdio"
20+
)
21+
1722
var deployCmd = &cobra.Command{
1823
Use: "deploy [name]",
1924
Short: "Deploy MCP server to Kubernetes",
@@ -55,7 +60,6 @@ var (
5560
deployArgs []string
5661
deployEnv []string
5762
deployForce bool
58-
deployDryRun bool
5963
deployFile string
6064
)
6165

@@ -76,7 +80,7 @@ func init() {
7680
deployCmd.Flags().StringVarP(&deployFile, "file", "f", "", "Path to kmcp.yaml file (default: current directory)")
7781
}
7882

79-
func runDeploy(cmd *cobra.Command, args []string) error {
83+
func runDeploy(_ *cobra.Command, args []string) error {
8084
// Determine project directory
8185
var projectDir string
8286
var err error
@@ -193,9 +197,9 @@ func generateMCPServer(projectManifest *manifest.ProjectManifest, deploymentName
193197
// Determine transport type
194198
transportType := v1alpha1.TransportTypeStdio
195199
if deployTransport != "" {
196-
if deployTransport == "http" {
200+
if deployTransport == transportHTTP {
197201
transportType = v1alpha1.TransportTypeHTTP
198-
} else if deployTransport == "stdio" {
202+
} else if deployTransport == transportStdio {
199203
transportType = v1alpha1.TransportTypeStdio
200204
} else {
201205
return nil, fmt.Errorf("invalid transport type: %s (must be 'stdio' or 'http')", deployTransport)

cmd/kmcp/cmd/init.go

Lines changed: 59 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ import (
1111
"kagent.dev/kmcp/pkg/templates"
1212
)
1313

14+
const (
15+
frameworkFastMCPPython = "fastmcp-python"
16+
frameworkFastMCPTS = "fastmcp-ts"
17+
templateBasic = "basic"
18+
templateDatabase = "database"
19+
templateFilesystem = "filesystem"
20+
templateAPIClient = "api-client"
21+
templateMultiTool = "multi-tool"
22+
templateWorkflow = "workflow"
23+
templateData = "data"
24+
templateHTTP = "http"
25+
)
26+
1427
var initCmd = &cobra.Command{
1528
Use: "init [project-name]",
1629
Short: "Initialize a new MCP server project",
@@ -51,7 +64,7 @@ func init() {
5164
initCmd.Flags().BoolVar(&initNonInteractive, "non-interactive", false, "Run in non-interactive mode")
5265
}
5366

54-
func runInit(cmd *cobra.Command, args []string) error {
67+
func runInit(_ *cobra.Command, args []string) error {
5568
var projectName string
5669

5770
// Get project name from args or prompt
@@ -160,10 +173,10 @@ func runInit(cmd *cobra.Command, args []string) error {
160173
fmt.Printf(" cd %s\n", projectName)
161174

162175
switch framework {
163-
case "fastmcp-python":
176+
case frameworkFastMCPPython:
164177
fmt.Printf(" uv sync\n")
165178
fmt.Printf(" uv run python src/main.py\n")
166-
case "fastmcp-ts":
179+
case frameworkFastMCPTS:
167180
fmt.Printf(" npm install\n")
168181
fmt.Printf(" kmcp build\n")
169182
}
@@ -222,18 +235,18 @@ func promptForFramework() (string, error) {
222235

223236
switch strings.TrimSpace(choice) {
224237
case "1", "":
225-
return "fastmcp-python", nil
238+
return frameworkFastMCPPython, nil
226239
case "2":
227-
return "fastmcp-ts", nil
240+
return frameworkFastMCPTS, nil
228241
default:
229-
return "fastmcp-python", nil // Default to recommended
242+
return frameworkFastMCPPython, nil // Default to recommended
230243
}
231244
}
232245

233246
func promptForTemplate(framework string) (string, error) {
234-
if framework == "fastmcp-python" {
247+
if framework == frameworkFastMCPPython {
235248
// FastMCP Python uses dynamic loading, no template selection needed
236-
return "basic", nil
249+
return templateBasic, nil
237250
}
238251

239252
fmt.Println("\nSelect a template:")
@@ -251,38 +264,47 @@ func promptForTemplate(framework string) (string, error) {
251264

252265
switch strings.TrimSpace(choice) {
253266
case "1", "":
254-
return "basic", nil
267+
return templateBasic, nil
255268
case "2":
256-
return "database", nil
269+
return templateDatabase, nil
257270
case "3":
258-
return "filesystem", nil
271+
return templateFilesystem, nil
259272
case "4":
260-
return "api-client", nil
273+
return templateAPIClient, nil
261274
case "5":
262-
return "multi-tool", nil
275+
return templateMultiTool, nil
263276
default:
264-
return "basic", nil // Default to basic
277+
return templateBasic, nil // Default to basic
265278
}
266279
}
267280

268281
func promptForAuthor() (string, error) {
269282
fmt.Print("Enter author name (optional): ")
270283
var author string
271-
fmt.Scanln(&author)
284+
_, err := fmt.Scanln(&author)
285+
if err != nil {
286+
return "", fmt.Errorf("failed to read author: %w", err)
287+
}
272288
return strings.TrimSpace(author), nil
273289
}
274290

275291
func promptForEmail() (string, error) {
276292
fmt.Print("Enter author email (optional): ")
277293
var email string
278-
fmt.Scanln(&email)
294+
_, err := fmt.Scanln(&email)
295+
if err != nil {
296+
return "", fmt.Errorf("failed to read email: %w", err)
297+
}
279298
return strings.TrimSpace(email), nil
280299
}
281300

282301
func promptForPlatform() (string, error) {
283302
fmt.Print("Enter platform (optional): ")
284303
var platform string
285-
fmt.Scanln(&platform)
304+
_, err := fmt.Scanln(&platform)
305+
if err != nil {
306+
return "", fmt.Errorf("failed to read platform: %w", err)
307+
}
286308
return strings.TrimSpace(platform), nil
287309
}
288310

@@ -359,7 +381,7 @@ func getTemplateTools(template string) map[string]manifest.ToolConfig {
359381
tools := make(map[string]manifest.ToolConfig)
360382

361383
switch template {
362-
case "basic":
384+
case templateBasic:
363385
tools["echo"] = manifest.ToolConfig{
364386
Name: "echo",
365387
Description: "Echo a message back to the client",
@@ -376,7 +398,7 @@ func getTemplateTools(template string) map[string]manifest.ToolConfig {
376398
"enabled": true,
377399
},
378400
}
379-
case "http":
401+
case templateHTTP:
380402
tools["http_client"] = manifest.ToolConfig{
381403
Name: "http_client",
382404
Description: "Make HTTP requests",
@@ -386,7 +408,7 @@ func getTemplateTools(template string) map[string]manifest.ToolConfig {
386408
"timeout": 30,
387409
},
388410
}
389-
case "data":
411+
case templateData:
390412
tools["data_processor"] = manifest.ToolConfig{
391413
Name: "data_processor",
392414
Description: "Process and manipulate data",
@@ -395,7 +417,7 @@ func getTemplateTools(template string) map[string]manifest.ToolConfig {
395417
"enabled": true,
396418
},
397419
}
398-
case "workflow":
420+
case templateWorkflow:
399421
tools["workflow_executor"] = manifest.ToolConfig{
400422
Name: "workflow_executor",
401423
Description: "Execute multi-step workflows",
@@ -405,23 +427,23 @@ func getTemplateTools(template string) map[string]manifest.ToolConfig {
405427
"max_steps": 10,
406428
},
407429
}
408-
case "multi-tool":
430+
case templateMultiTool:
409431
// Combine all tools
410-
for k, v := range getTemplateTools("basic") {
432+
for k, v := range getTemplateTools(templateBasic) {
411433
tools[k] = v
412434
}
413-
for k, v := range getTemplateTools("http") {
435+
for k, v := range getTemplateTools(templateHTTP) {
414436
tools[k] = v
415437
}
416-
for k, v := range getTemplateTools("data") {
438+
for k, v := range getTemplateTools(templateData) {
417439
tools[k] = v
418440
}
419-
for k, v := range getTemplateTools("workflow") {
441+
for k, v := range getTemplateTools(templateWorkflow) {
420442
tools[k] = v
421443
}
422444
default:
423445
// Default to basic tools
424-
return getTemplateTools("basic")
446+
return getTemplateTools(templateBasic)
425447
}
426448

427449
return tools
@@ -430,25 +452,25 @@ func getTemplateTools(template string) map[string]manifest.ToolConfig {
430452
// getFrameworkDependencies returns runtime dependencies for a framework
431453
func getFrameworkDependencies(framework, template string) []string {
432454
switch framework {
433-
case "fastmcp-python":
455+
case frameworkFastMCPPython:
434456
deps := []string{"mcp>=1.0.0", "fastmcp>=0.1.0"}
435457
switch template {
436-
case "http":
458+
case templateHTTP:
437459
deps = append(deps, "httpx>=0.25.0")
438-
case "data":
460+
case templateData:
439461
deps = append(deps, "pandas>=2.0.0", "numpy>=1.21.0")
440-
case "workflow":
462+
case templateWorkflow:
441463
deps = append(deps, "asyncio")
442464
}
443465
return deps
444-
case "fastmcp-ts":
466+
case frameworkFastMCPTS:
445467
deps := []string{"@fastmcp/core", "@modelcontextprotocol/sdk"}
446468
switch template {
447-
case "http":
469+
case templateHTTP:
448470
deps = append(deps, "axios", "fetch")
449-
case "data":
471+
case templateData:
450472
deps = append(deps, "lodash")
451-
case "workflow":
473+
case templateWorkflow:
452474
deps = append(deps, "async")
453475
}
454476
return deps
@@ -460,9 +482,9 @@ func getFrameworkDependencies(framework, template string) []string {
460482
// getFrameworkDevDependencies returns development dependencies for a framework
461483
func getFrameworkDevDependencies(framework string) []string {
462484
switch framework {
463-
case "fastmcp-python":
485+
case frameworkFastMCPPython:
464486
return []string{"pytest>=7.0.0", "pytest-asyncio>=0.21.0", "black>=22.0.0", "mypy>=1.0.0", "ruff>=0.1.0"}
465-
case "fastmcp-ts":
487+
case frameworkFastMCPTS:
466488
return []string{"@types/node", "typescript", "tsx", "vitest", "eslint", "prettier"}
467489
default:
468490
return []string{}

cmd/kmcp/cmd/regenerate_init.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,15 @@ var regenerateInitToolsDir string
3636

3737
func init() {
3838
rootCmd.AddCommand(regenerateInitCmd)
39-
regenerateInitCmd.Flags().StringVar(&regenerateInitToolsDir, "tools-dir", "src/tools", "Tools directory to regenerate __init__.py for")
39+
regenerateInitCmd.Flags().StringVar(
40+
&regenerateInitToolsDir,
41+
"tools-dir",
42+
"src/tools",
43+
"Tools directory to regenerate __init__.py for",
44+
)
4045
}
4146

42-
func runRegenerateInit(cmd *cobra.Command, args []string) error {
47+
func runRegenerateInit(_ *cobra.Command, _ []string) error {
4348
// Check if we're in a valid KMCP project
4449
if !isKMCPProject() {
4550
return fmt.Errorf("not in a KMCP project directory. Run 'kmcp init' first")

cmd/kmcp/cmd/secrets.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cmd
22

33
import (
4-
"encoding/base64"
54
"fmt"
65
"os"
76
"strings"
@@ -149,7 +148,7 @@ func runAddSecret(cmd *cobra.Command, args []string) error {
149148
return nil
150149
}
151150

152-
func runListSecrets(cmd *cobra.Command, args []string) error {
151+
func runListSecrets(cmd *cobra.Command, _ []string) error {
153152
environment, _ := cmd.Flags().GetString("environment")
154153

155154
// Load project manifest
@@ -198,7 +197,7 @@ func runListSecrets(cmd *cobra.Command, args []string) error {
198197
return nil
199198
}
200199

201-
func runGenerateK8sSecrets(cmd *cobra.Command, args []string) error {
200+
func runGenerateK8sSecrets(cmd *cobra.Command, _ []string) error {
202201
environment, _ := cmd.Flags().GetString("environment")
203202
output, _ := cmd.Flags().GetString("output")
204203

@@ -266,7 +265,7 @@ func runGenerateK8sSecrets(cmd *cobra.Command, args []string) error {
266265
return nil
267266
}
268267

269-
func runValidateSecrets(cmd *cobra.Command, args []string) error {
268+
func runValidateSecrets(cmd *cobra.Command, _ []string) error {
270269
environment, _ := cmd.Flags().GetString("environment")
271270
scanResponses, _ := cmd.Flags().GetBool("scan-responses")
272271

@@ -346,7 +345,8 @@ func runValidateSecrets(cmd *cobra.Command, args []string) error {
346345

347346
// Simple check to see if sanitization is working
348347
sanitizedBytes, _ := yaml.Marshal(sanitized)
349-
if strings.Contains(string(sanitizedBytes), "secret123") || strings.Contains(string(sanitizedBytes), "sk-1234567890abcdef") {
348+
if strings.Contains(string(sanitizedBytes), "secret123") ||
349+
strings.Contains(string(sanitizedBytes), "sk-1234567890abcdef") {
350350
fmt.Printf("❌ Potential secret leak detected in test data\n")
351351
} else {
352352
fmt.Printf("✅ Secret sanitization working correctly\n")
@@ -355,8 +355,3 @@ func runValidateSecrets(cmd *cobra.Command, args []string) error {
355355

356356
return nil
357357
}
358-
359-
// Helper function to encode string to base64 (for Kubernetes secrets)
360-
func encodeBase64(input string) string {
361-
return base64.StdEncoding.EncodeToString([]byte(input))
362-
}

0 commit comments

Comments
 (0)