这是一个小型命令行聊天客户端,具有以下特点:
config.json中声明启动时,客户端会启动每个服务器,获取它们的工具模式,前缀工具名称(如postgres.*,filesystem.*等),并将合并后的列表提供给模型。
大语言模型决定针对每个用户请求调用哪个服务器。
| 功能 | 备注 |
|---|---|
| 本地大语言模型优先 | 默认模型是qwen3:14b,但任何Ollama暴露的功能调用模型都可以工作。不需要云密钥。 |
| 多服务器开箱即用 | PostgreSQL、文件系统或您自己的MCP服务器可以并排运行;所有服务器都在config.json中定义。 |
| 无冲突工具名称 | 工具以<server>.<tool>的形式暴露,因此名称永远不会冲突。 |
| 组件 | 测试版本 |
|---|---|
| Python | ≥ 3.12 |
| Ollama | ≥ 0.8.0 |
| MCP服务器 | 支持stdio传输的任何服务器 |
# 1. 克隆
git clone https://github.com/Nagharjun17/MCP-Ollama-Client.git
cd mcp-ollama-client
# 2. 设置环境
uv venv
source .venv/bin/activate
uv pip sync pyproject.toml # 或:uv pip install -r uv.lock
# 3. 拉取本地模型
ollama pull qwen3:14b
# 4. 编辑`config.json`中的模型名称、DATABASE_URI等,并下载所需的MCP服务器。在我的情况下:
uv pip install postgres-mcp
# 5. 运行
uv run client.py
启动日志示例:
🔌 启动MCP服务器:postgres
🔌 启动MCP服务器:filesystem
🛠️ 聚合工具:['postgres.list_schemas', 'filesystem.read_file', ...]
>>>

输入自然语言查询;模型将决定何时以及如何调用暴露的工具。
config.json 格式{
"llm": {
"model": "qwen3:14b",
"temperature": 0.7,
"max_tokens": 2048
},
"mcpServers": {
"postgres": {
"command": "postgres-mcp",
"args": ["--access-mode=restricted"],
"env": {
"DATABASE_URI": "postgresql://user:pass@localhost:5432/db"
}
},
"filesystem": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"/mnt/smbshare/"
]
}
}
}
mcpServers下的键成为前缀(如*postgres.*,filesystem.***)。*
每个服务器作为其自身的*stdio*子进程启动。
添加或删除服务器无需修改*client.py**。*
一切保持本地化,所有内容在单个文件中可配置。