mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-12-17 23:29:47 +00:00
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:
parent
dc21e14f64
commit
e95c168bc0
8 changed files with 160 additions and 10 deletions
|
|
@ -480,34 +480,40 @@ class ToolsRoutingTable(CommonRoutingTableImpl, Tools):
|
|||
|
||||
async def register_tool_group(
|
||||
self,
|
||||
name: str,
|
||||
tool_group: ToolGroup,
|
||||
provider_id: Optional[str] = None,
|
||||
) -> None:
|
||||
tools = []
|
||||
if isinstance(tool_group, MCPToolGroup):
|
||||
# TODO: first needs to be resolved to corresponding tools available in the MCP server
|
||||
raise NotImplementedError("MCP tool provider not implemented yet")
|
||||
# TODO: Actually find the right MCP provider
|
||||
if provider_id is None:
|
||||
raise ValueError("MCP provider_id not specified")
|
||||
tools = await self.impls_by_provider_id[provider_id].discover_tools(
|
||||
tool_group
|
||||
)
|
||||
for tool in tools:
|
||||
tool.provider_id = provider_id
|
||||
elif isinstance(tool_group, UserDefinedToolGroup):
|
||||
for tool in tool_group.tools:
|
||||
|
||||
tools.append(
|
||||
Tool(
|
||||
identifier=tool.name,
|
||||
tool_group=name,
|
||||
tool_group=tool_group.name,
|
||||
name=tool.name,
|
||||
description=tool.description,
|
||||
parameters=tool.parameters,
|
||||
provider_id=provider_id,
|
||||
tool_prompt_format=tool.tool_prompt_format,
|
||||
provider_resource_id=tool.name,
|
||||
metadata=tool.metadata,
|
||||
)
|
||||
)
|
||||
else:
|
||||
raise ValueError(f"Unknown tool group: {tool_group}")
|
||||
|
||||
for tool in tools:
|
||||
existing_tool = await self.get_tool(tool.name)
|
||||
existing_tool = await self.get_tool(tool.identifier)
|
||||
# Compare existing and new object if one exists
|
||||
if existing_tool:
|
||||
# Compare all fields except provider_id since that might be None in new obj
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue