llama-stack-mirror/llama_stack/templates
Shrey 30ef1c3680
feat: Add model context protocol tools with ollama provider (#1283)
# What does this PR do?
Model context protocol (MCP) allows for remote tools to be connected
with Agents. The current Ollama provider does not support it. This PR
adds necessary code changes to ensure that the integration between
Ollama backend and MCP works.

This PR is an extension of #816 for Ollama. 

## Test Plan
[Describe the tests you ran to verify your changes with result
summaries. *Provide clear instructions so the plan can be easily
re-executed.*]

1. Run llama-stack server with the command:
```
llama stack build --template ollama --image-type conda
llama stack run ./templates/ollama/run.yaml \
  --port $LLAMA_STACK_PORT \
  --env INFERENCE_MODEL=$INFERENCE_MODEL \
  --env OLLAMA_URL=http://localhost:11434
```

2. Run the sample client agent with MCP tool:
```
from llama_stack_client.lib.agents.agent import Agent
from llama_stack_client.lib.agents.event_logger import EventLogger
from llama_stack_client.types.agent_create_params import AgentConfig
from llama_stack_client.types.shared_params.url import URL
from llama_stack_client import LlamaStackClient
from termcolor import cprint

## Start the local MCP server
# git clone https://github.com/modelcontextprotocol/python-sdk
# Follow instructions to get the env ready
# cd examples/servers/simple-tool
# uv run mcp-simple-tool --transport sse --port 8000

# Connect to the llama stack server
base_url="http://localhost:8321"
model_id="meta-llama/Llama-3.2-3B-Instruct"
client = LlamaStackClient(base_url=base_url)


# Register MCP tools
client.toolgroups.register(
    toolgroup_id="mcp::filesystem",
    provider_id="model-context-protocol",
    mcp_endpoint=URL(uri="http://localhost:8000/sse"))

# Define an agent with MCP toolgroup 
agent_config = AgentConfig(
    model=model_id,
    instructions="You are a helpful assistant",
    toolgroups=["mcp::filesystem"],
    input_shields=[],
    output_shields=[],
    enable_session_persistence=False,
)
agent = Agent(client, agent_config)
user_prompts = [
    "Fetch content from https://www.google.com and print the response"
]

# Run a session with the agent
session_id = agent.create_session("test-session")
for prompt in user_prompts:
    cprint(f"User> {prompt}", "green")
    response = agent.create_turn(
        messages=[
            {
                "role": "user",
                "content": prompt,
            }
        ],
        session_id=session_id,
    )
    for log in EventLogger().log(response):
        log.print()
```
# Documentation
The file docs/source/distributions/self_hosted_distro/ollama.md is
updated to indicate the MCP tool runtime availability.

Signed-off-by: Shreyanand <shanand@redhat.com>
2025-02-26 15:38:18 -08:00
..
bedrock ModelAlias -> ProviderModelEntry 2025-02-20 14:02:36 -08:00
cerebras chore: move embedding deps to RAG tool where they are needed (#1210) 2025-02-21 11:33:41 -08:00
ci-tests feat: add (openai, anthropic, gemini) providers via litellm (#1267) 2025-02-25 22:07:33 -08:00
dell chore: move embedding deps to RAG tool where they are needed (#1210) 2025-02-21 11:33:41 -08:00
dev fix: make vision and embedding tests pass with openai, anthropic and gemini 2025-02-26 11:24:01 -08:00
experimental-post-training feat: [post training] support save hf safetensor format checkpoint (#845) 2025-02-25 23:29:08 -08:00
fireworks test: add a ci-tests distro template for running e2e tests (#1237) 2025-02-24 14:43:21 -08:00
groq feat: Add Groq distribution template (#1173) 2025-02-25 14:16:56 -08:00
hf-endpoint fix!: update eval-tasks -> benchmarks (#1032) 2025-02-13 16:40:58 -08:00
hf-serverless chore: move embedding deps to RAG tool where they are needed (#1210) 2025-02-21 11:33:41 -08:00
meta-reference-gpu fix!: update eval-tasks -> benchmarks (#1032) 2025-02-13 16:40:58 -08:00
meta-reference-quantized-gpu fix!: update eval-tasks -> benchmarks (#1032) 2025-02-13 16:40:58 -08:00
nvidia test(client-sdk): Update embedding test types to use latest imports (#1203) 2025-02-21 08:09:17 -08:00
ollama feat: Add model context protocol tools with ollama provider (#1283) 2025-02-26 15:38:18 -08:00
passthrough feat: inference passthrough provider (#1166) 2025-02-19 21:47:00 -08:00
remote-vllm chore: move embedding deps to RAG tool where they are needed (#1210) 2025-02-21 11:33:41 -08:00
sambanova ModelAlias -> ProviderModelEntry 2025-02-20 14:02:36 -08:00
tgi chore: move embedding deps to RAG tool where they are needed (#1210) 2025-02-21 11:33:41 -08:00
together chore: move embedding deps to RAG tool where they are needed (#1210) 2025-02-21 11:33:41 -08:00
vllm-gpu chore: move embedding deps to RAG tool where they are needed (#1210) 2025-02-21 11:33:41 -08:00
__init__.py Auto-generate distro yamls + docs (#468) 2024-11-18 14:57:06 -08:00
template.py build: format codebase imports using ruff linter (#1028) 2025-02-13 10:06:21 -08:00