All skills
gogf avatar

/goframe-v2

@911705d
by GoFramegogf/skills81 stars
3

GoFrame v2 development skill. Use only when the target Go project uses or is explicitly adopting GoFrame v2: the nearest go.mod requires github.com/gogf/gf/v2, existing Go files import github.com/gogf/gf/v2 or any github.com/gogf/gf/v2/... component package, or the user asks to scaffold, migrate, or build with GoFrame. Trigger for GoFrame-backed Go work such as APIs/controllers/services, middleware, routing/config, ORM/DAO/DO/entity/database operations, gf CLI/codegen, HTTP/gRPC services, and microservice conventions. Do not trigger for generic Go projects without GoFrame evidence, frontend-only work, shell scripts, or unrelated infrastructure tasks.

Use this Skill: https://skilld.dev/gh/gogf/skills/goframe-v2

This session only. Nothing lands on disk.

exampleshttpservermcp-sseREADME.ZH.MD

≈843 tokens on demand. Your agent reads this file only when SKILL.md points to it.

GoFrame MCP 示例

本示例展示了如何使用 GoFrame 的 ghttp 服务器和 mark3labs/mcp-go SDK 实现 Model Context Protocol (MCP) 服务器。

先决条件

  • Go 1.20 或更高版本
  • MCP 客户端(例如 Claude Desktop 或 IDE 扩展)

安装

  1. 初始化模块(如果尚未完成):

    go mod tidy
  2. 运行服务器:

    go run main.go

用法

服务器暴露了两个端点:

  • GET /sse: 用于建立连接的 Server-Sent Events 端点。
  • POST /message: 用于发送 JSON-RPC 消息的端点。

连接 Claude Desktop

要在 Claude Desktop 中使用此 MCP 服务器,请将以下配置添加到您的 claude_desktop_config.json:

{
  "mcpServers": {
    "goframe-mcp": {
      "command": "go",
      "args": ["run", "path/to/your/project/httpserver/mcp/main.go"]
    }
  }
}

注意:由于此示例运行 HTTP 服务器,您可能需要使用支持 SSE 的 MCP 客户端。上述配置假设您将其作为本地进程运行。如果您想通过 HTTP (SSE) 连接,您的客户端必须支持远程 MCP 连接。

直接 SSE 测试:

  1. 启动服务器。
  2. 连接到 http://localhost:8080/sse。

MCP 客户端配置

如果你的客户端或 IDE 支持通过配置文件定义 MCP 服务器,可以在项目根目录下创建 .vscode/mcp.json,示例内容如下:

{
  "servers": {
    "add": {
      "url": "http://localhost:8080/sse",
      "type": "http"
    }
  },
  "inputs": []
}

说明:

  • servers 下的键名(例如 add)为服务器标识名称。
  • url 指向示例的 SSE 端点 http://localhost:8080/sse。
  • type 表示连接类型,此处为 http(SSE)。
  • inputs 可选,用于在客户端中预置输入。

保存后,支持该配置的客户端即可使用该文件连接到本示例 MCP 服务。

功能

  • 工具: 暴露一个 add 工具,可接收两个数字(a 和 b),返回它们的和。
  • 示例: 你可以通过 MCP 客户端发送如下计算请求:
mcp 计算 一加一

或英文:

mcp add 1 and 1

服务器将返回:

结果: 1 + 1 = 2

代码结构

  • main.go: 包含服务器设置、工具注册以及使用 ghttp.WrapH 进行的路由绑定。

Source: SKILL.md on GitHub

1 alert16d5 checks · Risk MEDIUM
  • Gen Agent Trust Hub16d

    The skill provides a comprehensive development guide and code examples for the GoFrame v2 framework. While highly informative for Go developers, it contains several examples with hardcoded placeholder secrets, tokens, and specific local file paths to sensitive configuration files (like Kubernetes credentials). These elements are provided for demonstration purposes but represent insecure practices if used in production without modification.

  • Socket16d

    5 alerts: gptSecurity, gptAnomaly

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer6mo

    227/949 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 911705d. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 4 months ago.

Steadyupdated 4 months ago
  • Go
  • Database
  • goframe
  • orm
  • http
  • grpc
  • microservices
  • crud
  • scaffolding
  • middleware

README badge

README badge for gogf/skills

Provides instruction and conventions for developing with GoFrame v2, a modular Go framework for building HTTP and gRPC services, microservices, and database operations using its ORM, CLI tooling, and project scaffolding. Use this skill when the target project has GoFrame v2 as a dependency or when the user requests scaffolding, migrations, or service development with GoFrame conventions.

Generated from the current SKILL.md.

When should I use this skill?
Use this skill only when your Go project uses GoFrame v2, indicated by github.com/gogf/gf/v2 in go.mod or imports. Do not use for generic Go projects, frontend work, or infrastructure tasks unrelated to GoFrame.
Should I manually set created_at and updated_at fields?
No. GoFrame automatically writes created_at on insert and updated_at on insert/update/save. Manually setting these fields is redundant and violates project conventions.
What should I use for database operations instead of g.Map?
Always use DO objects from internal/model/do/. DO struct fields are interface{}, unset fields remain nil and are automatically ignored by the ORM.
How does soft delete work in GoFrame?
Call Delete() on the DAO; GoFrame automatically converts it to UPDATE SET deleted_at = NOW(). Queries automatically filter out soft-deleted rows without requiring manual WhereNull conditions.
Where should I implement business logic?
Implement business logic directly in the service/ directory. Do not use the logic/ directory unless explicitly requested.

Generated from the current SKILL.md. These answers refresh after source changes.