[PR #13700] x/tools/mcp: add MCP protocol support for external tool servers #61048

Open
opened 2026-04-29 16:07:25 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/13700
Author: @Code4me2
Created: 1/13/2026
Status: 🔄 Open

Base: mainHead: mcp-tools-adapter


📝 Commits (3)

  • 52cd231 x/tools/mcp: add MCP JSON-RPC client
  • 052f3c3 x/tools/mcp: add tool adapter and manager
  • 666f694 x/cmd: wire MCP tools into experimental agent loop

📊 Changes

6 files changed (+1096 additions, -0 deletions)

View changed files

📝 x/cmd/run.go (+29 -0)
x/tools/mcp/client.go (+525 -0)
x/tools/mcp/config.go (+118 -0)
x/tools/mcp/integration_test.go (+137 -0)
x/tools/mcp/mcp_test.go (+108 -0)
x/tools/mcp/tool.go (+179 -0)

📄 Description

Summary

Adds support for Model Context Protocol (MCP) servers, enabling ollama to connect to external tool providers via JSON-RPC over stdio. This integrates with the existing experimental agent loop (--experimental flag).

  • MCP servers are configured via ~/.ollama/mcp-servers.json
  • Tools from MCP servers are registered alongside native tools (bash, websearch)
  • Tools are namespaced as servername:toolname to avoid conflicts
  • Runtime security is handled by the existing approval system

Example Configuration

{
  "servers": [
    {
      "name": "memory",
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-memory"]
    }
  ]
}

Changes

  1. x/tools/mcp/client.go - JSON-RPC 2.0 client for MCP protocol
  2. x/tools/mcp/tool.go - Tool adapter implementing tools.Tool interface
  3. x/tools/mcp/config.go - Configuration loading and validation
  4. x/cmd/run.go - Integration with experimental agent loop (+29 lines)

Closes #7865


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/13700 **Author:** [@Code4me2](https://github.com/Code4me2) **Created:** 1/13/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `mcp-tools-adapter` --- ### 📝 Commits (3) - [`52cd231`](https://github.com/ollama/ollama/commit/52cd2317df838183b118ef70f7f6dfdd22abbe04) x/tools/mcp: add MCP JSON-RPC client - [`052f3c3`](https://github.com/ollama/ollama/commit/052f3c3958f50e7a388b02ef75ec79f19eb0b4eb) x/tools/mcp: add tool adapter and manager - [`666f694`](https://github.com/ollama/ollama/commit/666f6942cc797121c6dace1e3e60356a9f455790) x/cmd: wire MCP tools into experimental agent loop ### 📊 Changes **6 files changed** (+1096 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `x/cmd/run.go` (+29 -0) ➕ `x/tools/mcp/client.go` (+525 -0) ➕ `x/tools/mcp/config.go` (+118 -0) ➕ `x/tools/mcp/integration_test.go` (+137 -0) ➕ `x/tools/mcp/mcp_test.go` (+108 -0) ➕ `x/tools/mcp/tool.go` (+179 -0) </details> ### 📄 Description ## Summary Adds support for [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) servers, enabling ollama to connect to external tool providers via JSON-RPC over stdio. This integrates with the existing experimental agent loop (`--experimental` flag). - MCP servers are configured via `~/.ollama/mcp-servers.json` - Tools from MCP servers are registered alongside native tools (bash, websearch) - Tools are namespaced as `servername:toolname` to avoid conflicts - Runtime security is handled by the existing approval system ## Example Configuration ```json { "servers": [ { "name": "memory", "command": "npx", "args": ["-y", "@modelcontextprotocol/server-memory"] } ] } ``` ## Changes 1. **x/tools/mcp/client.go** - JSON-RPC 2.0 client for MCP protocol 2. **x/tools/mcp/tool.go** - Tool adapter implementing `tools.Tool` interface 3. **x/tools/mcp/config.go** - Configuration loading and validation 4. **x/cmd/run.go** - Integration with experimental agent loop (+29 lines) Closes #7865 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-29 16:07:25 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#61048