AH

akhilraghav0/hamr

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

21 stars 2 forks 质量 66 趋势 14MIT

Go 框架用于构建 MCP 服务器。你的结构标签就是你的模式。

概览

用 Go 构建 Hamr MCP 服务器。针对代币成本进行了优化。 MCP(模型上下文协议)让 AI 助手如 Claude、Cursor 和 Windsurf 调用外部工具。MCP 服务器基本上是一个插件,赋予 AI 功能——查询数据库、检查 Kubernetes 集群、搜索代码库,做任何你需要的操作。 问题在于,在 Go 里构建 MCP 服务器意味着要写大量模板代码。你必须手动定义 JSON 模式,处理 JSON-RPC 帧,解析和验证输入,连接传输,管理错误——最终你还得在真正写逻辑之前就有 200+ 行的程序。 Hamr 解决了这个问题。你为输入写一个 Go struct,为逻辑写一个函数,还有一行用于注册。hamr 负责其他所有事务——模式生成、验证、传输、中间件,整个协议。你的结构标签就是你的模式。 可以把它想象成 Cobra,但只不过是针对 MCP 服务器而不是 CLI 应用。 就这样。

概述(AI 翻译)

哈姆尔 用 Go 构建 MCP 服务器。针对代币成本进行了优化。


这是什么?

MCP(模型上下文协议)让 AI 助手如 Claude、Cursor 和 Windsurf 调用外部工具。MCP 服务器基本上是一个插件,赋予 AI “做事”的能力——查询数据库、检查 Kubernetes 集群、搜索代码库,做任何你需要的事。

问题在于,在 Go 里构建 MCP 服务器意味着要写大量模板代码。你必须手动定义 JSON 模式,处理 JSON-RPC 帧,解析和验证输入,连接传输,管理错误——最终你还得在真正写逻辑之前就有 200+ 行的程序。

HAMR解决了这个问题。你为输入写一个Go结构,为逻辑写一个函数,还有一行来注册。hamr负责其他所有事情——模式生成、验证、传输、中间件,整个协议。你的struct标签就是你的schema。

可以把它想象成 Cobra,但只不过是针对 MCP 服务器而不是 CLI 应用。

给我看看代码

这是一个完整的、可运行的MCP服务器:

就这些。构建它,指向Claude Desktop的二进制文件,Claude就可以调用你的搜索工具了。

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

hamr Build MCP servers in Go. Optimized for token cost.


What is this?

MCP (Model Context Protocol) lets AI assistants like Claude, Cursor, and Windsurf call external tools. An MCP server is basically a plugin that gives AI the ability to do things — query your database, check your Kubernetes cluster, search your codebase, whatever you need.

The problem is that building an MCP server in Go means writing a ton of boilerplate. You have to manually define JSON schemas, handle JSON-RPC framing, parse and validate inputs, wire up transport, manage errors — and you end up with 200+ lines of ceremony before you even get to your actual logic.

hamr fixes that. You write a Go struct for your input, a function for your logic, and one line to register it. hamr handles everything else — schema generation, validation, transport, middleware, the whole protocol. Your struct tags are your schema.

Think of it like Cobra but for MCP servers instead of CLI apps.

Show me the code

Here’s a complete, working MCP server:

package main

import (
    "context"
    "log"

    "github.com/AKhilRaghav0/hamr"
)

type SearchInput struct {
    Query      string `json:"query" desc:"search query"`
    MaxResults int    `json:"max_results" desc:"max results" default:"10"`
    Format     string `json:"format" desc:"output format" enum:"json,text,csv"`
}

func Search(ctx context.Context, input SearchInput) (string, error) {
    // your actual search logic here
    return "results for: " + input.Query, nil
}

func main() {
    s := hamr.New("my-server", "1.0.0")
    s.Tool("search", "Search for information", Search)
    log.Fatal(s.Run())
}
在 GitHub 查看完整 README

安装

This server does not publish a one-line install command.

Open the repository installation guide 新手?先看 mcpskill.org 教程 →

配置

{ "mcpServers": { "my-server": { "command": "/absolute/path/to/my-server" } } }