GM

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

50 stars 4 forks 质量 59 趋势 33Apache-2.0

XGo 实现了模型上下文协议(MCP),实现了大型语言模型应用与外部数据源及工具之间的无缝集成。

概览

XGo 实现了模型上下文协议(MCP),实现了大型语言模型应用与外部数据源及工具之间的无缝集成。 该仓库包含两个XGo类文件。它们分别是mcp(MCP服务器框架)和mcptest(MCP服务器测试框架)。 classfile mcp 带有文件后缀 _mcp.gox(MCP 服务器)、_res.gox(MCP 资源或资源模板)、_tool.gox(MCP 工具)和 _prompt.gox(MCP 提示符)。classfile mcptest 带有文件后缀 _mtest.gox。 这里有一个MCP服务器的示例(源代码)。它有两个文件:main_mcp.gox(MCP服务器)和hello_tool.gox(MCP工具)。 首先,让我们初始化一个hello项目: 然后它引用 mcp 类文件: main_mcp.gox(MCP服务器)的内容如下 hello_tool.gox(MCP工具)的内容如下

概述(AI 翻译)

MCP XGo 🚀

XGo 实现了模型上下文协议(MCP),实现了大型语言模型应用与外部数据源及工具之间的无缝集成。

该仓库包含两个XGo类文件。它们分别是mcp(MCP服务器框架)和mcptest(MCP服务器测试框架)。

classfile mcp 带有文件后缀 _mcp.gox(MCP 服务器)、_res.gox(MCP 资源或资源模板)、_tool.gox(MCP 工具)和 _prompt.gox(MCP 提示符)。classfile mcptest 带有文件后缀 _mtest.gox。

mcp:MCP 服务器框架

这里有一个MCP服务器的示例(源代码)。它有两个文件:main_mcp.gox(MCP服务器)和hello_tool.gox(一个MCP工具)。

一个MCP服务器示例:hello

首先,让我们初始化一个hello项目:

然后它引用 mcp 类文件:

main_mcp.gox(MCP服务器)的内容如下

hello_tool.gox(一个MCP工具)的内容如下

执行以下命令:

现在有一个最简单的MCP服务器正在运行。

mcptest:MCP 服务器测试框架

要测试上述hello MCP服务器(源代码),只需实现一个hello_mtest.gox文件:

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

README

MCP XGo 🚀

A XGo implementation of the Model Context Protocol (MCP), enabling seamless integration between LLM applications and external data sources and tools.

This repo contains two XGo classfiles. They are mcp (MCP Server Framework) and mcptest (MCP Server Test Framework).

The classfile mcp has the file suffix _mcp.gox (the MCP Server), _res.gox (a MCP Resource or ResourceTemplate), _tool.gox (a MCP Tool) and _prompt.gox (a MCP Prompt). The classfile mcptest has the file suffix _mtest.gox.

mcp: MCP Server Framework

Here is a MCP Server example (source code). It has two files: main_mcp.gox (the MCP Server) and hello_tool.gox (a MCP Tool).

A MCP Server Example: hello

First let us initialize a hello project:

xgo mod init hello

Then we have it reference the mcp classfile:

xgo get github.com/goplus/mcp@latest

The content of main_mcp.gox (the MCP Server) is as follows

server "Tool Demo 🚀", "1.0.0"

The content of hello_tool.gox (a MCP Tool) is as follows

tool "helloWorld", => {
	description "Say hello to someone"
	string "name", => {
		required
		description "Name of the person to greet"
	}
}

name, ok := ${name}.(string)
if !ok {
	return newError("name must be a string")
}

return text("Hello, ${name}!")

Execute the following commands:

xgo mod tidy
xgo run .

A simplest MCP Server is running now.

mcptest: MCP Server Test Framework

To test the above hello MCP Server (source code), you only need to implement a hello_mtest.gox file:

mock new(MCPApp)

initialize nil
ret {}

call "helloWorld", {"name": "Ken"}
ret {
	"content": [{"type": "text", "text": "Hello, Ken!"}],
}

Then run xgo test or xgo test -v to execute the unit test.

在 GitHub 查看完整 README

安装

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

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