add model context protocol provider (#665)

# What does this PR do?
Changes:
* Adds a new API to discover tools available on a runtime
* Adds a new model context protocol provider


## Test Plan

```
# clone python sdk for mcp and start the simple-tool server
uv run mcp-simple-tool --transport sse --port 56000

curl -X POST 'http://localhost:5000/alpha/toolgroups/register' \
-H 'Content-Type: application/json' \
-d '{
  "tool_group": { "name": "simple_mcp_group",
    "type": "model_context_protocol",
    "endpoint": {"uri": "http://localhost:56000/sse"}
  },
  "provider_id": "model-context-protocol"
}'

curl -X POST 'http://localhost:5000/alpha/tool-runtime/invoke' \
-H 'Content-Type: application/json' \
-d '{
    "tool_id": "fetch",
    "args": {
        "url": "http://google.com/"
    }
}'

```
This commit is contained in:
Dinesh Yeduguru 2024-12-19 16:14:23 -08:00 committed by GitHub
parent dc21e14f64
commit e95c168bc0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 160 additions and 10 deletions

View file

@ -4,11 +4,11 @@
# This source code is licensed under the terms described in the LICENSE file in
# the root directory of this source tree.
from typing import Any, Dict
from typing import Any, Dict, List
import requests
from llama_stack.apis.tools import Tool, ToolInvocationResult, ToolRuntime
from llama_stack.apis.tools import Tool, ToolGroup, ToolInvocationResult, ToolRuntime
from llama_stack.distribution.request_headers import NeedsRequestProviderData
from llama_stack.providers.datatypes import ToolsProtocolPrivate
@ -42,6 +42,9 @@ class BraveSearchToolRuntimeImpl(
)
return provider_data.api_key
async def discover_tools(self, tool_group: ToolGroup) -> List[Tool]:
raise NotImplementedError("Brave search tool group not supported")
async def invoke_tool(
self, tool_id: str, args: Dict[str, Any]
) -> ToolInvocationResult: