1 Star 0 Fork 0

tmfll/mcp-golang

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
8个月前
8个月前
8个月前
Loading...
README
MIT
Statusphere logo

MCP Golang

GitHub stars GitHub forks GitHub issues GitHub pull requests GitHub license GitHub contributors GitHub last commit

MCP golang is an unofficial implementaion of the Model Context Protocol in Go.

Docs can be found at https://mcpgolang.com

Example Usage

type Content struct {
	Title       string  `json:"title" jsonschema:"required,description=The title to submit"`
	Description *string `json:"description" jsonschema:"description=The description to submit"`
}
type MyFunctionsArguments struct {
	Submitter string  `json:"submitter" jsonschema:"required,description=The name of the thing calling this tool (openai, google, claude, etc)"`
	Content   Content `json:"content" jsonschema:"required,description=The content of the message"`
}

func main() {
	done := make(chan struct{})

	server := mcp_golang.NewServer(stdio.NewStdioServerTransport())
	err := server.RegisterTool("hello", "Say hello to a person", func(arguments MyFunctionsArguments) (*mcp_golang.ToolResponse, error) {
		return mcp_golang.NewToolReponse(mcp_golang.NewTextContent(fmt.Sprintf("Hello, %server!", arguments.Submitter))), nil
	})
	if err != nil {
		panic(err)
	}

	err = server.RegisterPrompt("promt_test", "This is a test prompt", func(arguments Content) (*mcp_golang.PromptResponse, error) {
		return mcp_golang.NewPromptResponse("description", mcp_golang.NewPromptMessage(mcp_golang.NewTextContent(fmt.Sprintf("Hello, %server!", arguments.Title)), mcp_golang.RoleUser)), nil
	})
	if err != nil {
		panic(err)
	}

	err = server.RegisterResource("test://resource", "resource_test", "This is a test resource", "application/json", func() (*mcp_golang.ResourceResponse, error) {
		return mcp_golang.NewResourceResponse(mcp_golang.NewTextEmbeddedResource("test://resource", "This is a test resource", "application/json")), nil
	})

	err = server.Serve()
	if err != nil {
		panic(err)
	}

	<-done
}

This will start a server using the stdio transport (used by claude desktop), host a tool called "hello" that will say hello to the user who submitted it.

You can use raw go structs as the input to your tools, the library handles generating the messages, deserialization, etc.

Library Goals and non-goals

  • The library should bias towards maintaining type safety, even when adding extra complexity (reflection to check types etc)
  • The libary api should be simple and easy to use for basic cases of the protocol but we are explicitly aiming to support production use cases firs
  • Where complexity arises, the library will have sane defaults and allow the user to override them if needed.
  • The library aims to support servers first and foremost, when the server features are stable, we will work on adding client support.

Contributions

Contributions are more than welcome! Please check out our contribution guidelines.

Discord

Got any suggestions, have a question on the api or usage? Ask on the discord server. A maintainer will be happy to help you out.

Server Feature Implementation

Tools

  • Tool Calls
  • Programatically generated tool list endpoint

Prompts

  • Prompt Calls
  • Programatically generated prompt list endpoint

Resources

  • Resource Calls
  • Programatically generated resource list endpoint

Transports

  • Stdio
  • SSE
  • Custom transport support
  • HTTPS with custom auth support - in progress. Not currently part of the spec but we'll be adding experimental support for it.

Client Feature Implementation

Currently under development

MIT License Copyright (c) 2024 Metoro Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

暂无描述 展开 收起
README
MIT
取消

发行版

暂无发行版

贡献者 (3)

全部

语言

近期动态

1个月前同步了仓库
4个月前创建了仓库
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/tmfll/mcp-golang.git
git@gitee.com:tmfll/mcp-golang.git
tmfll
mcp-golang
mcp-golang
Chrisbattarbee-patch-1

搜索帮助