About go-mcp-demo
A Go demo built with mark3labs/mcp-go for showing how an MCP server and client can use a local Ollama model to read SQL files and query MySQL through natural language.
Key features
- 01MCP server-client communication
- 02Local inference with Ollama
- 03Read local .sql files
- 04Run MySQL queries
Use cases
- 01Read SQL files with natural language
- 02Query MySQL with natural language
MCP support
The project includes an MCP server and client. The server exposes tools for reading .sql files and running SQL queries.
Configuration
Local server config is the same for every client. Copy it into your client’s MCP config file.
We haven’t collected a package or remote endpoint for this server. Follow the instructions in the project README.
Tools
Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.
Details
From the project READMEgo-mcp-demo
本项目基于 mark3labs/mcp-go 实现了一个 MCP Server 与 MCP Client 通信的演示,结合 Ollama 启动本地大语言模型,实现自然语言调用工具的能力。
✨ 功能概览
- 集成 MCP Server + Client 通信框架
- 支持基于自然语言执行:
- 读取本地
.sql文件 - 执行任意 MySQL 查询
- 读取本地
- 使用 Ollama 本地大模型进行推理(默认端口:
http://localhost:11434)
🚀 快速开始
1. 安装 Ollama
请参考官网:https://ollama.com
根据操作系统下载安装 Ollama CLI 工具。
2. 拉取并运行模型
在命令行中执行以下命令,拉取你需要的模型(示例使用 qwen2:1.5b):
ollama pull qwen2:1.5b
ollama run qwen2:1.5b
模型将监听本地端口:http://localhost:11434/api/generate
3. 修改配置文件
打开并编辑 pkg/config/config.yml:
ollama:
model: qwen2:1.5b
mysql:
host: localhost
port: 3306
user: root
password: your_password
database: your_database
sql:
sqlFilePath: E:/your/path/to/test.sql
✅ 注意事项:
model名称需与ollama pull和ollama run保持一致mysql信息替换为你本地或远程数据库连接参数sqlFilePath设置为你希望读取的.sql文件绝对路径
4. 启动主服务(Client)
进入主服务目录并运行:
cd cmd/server
go run main.go
默认监听地址:http://localhost:2001
5. 启动 MCP 服务(Server)
在新终端中启动 MCP 服务:
cd cmd/mcp-server
go run main.go
默认监听地址:http://localhost:2002
服务将自动注册以下工具:
read_file: 读取指定的.sql文件内容query_db: 执行任意 SQL 并返回查询结果
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.