fix: handle mcp array and object type

pull/22036/head
Novice 11 months ago
parent 9dd1cd9df8
commit 986e2794bd

@ -16,6 +16,9 @@ class CommonParameterType(StrEnum):
TOOLS_SELECTOR = "array[tools]" TOOLS_SELECTOR = "array[tools]"
# TOOL_SELECTOR = "tool-selector" # TOOL_SELECTOR = "tool-selector"
# MCP object and array type parameters
ARRAY = "array"
OBJECT = "object"
class AppSelectorScope(StrEnum): class AppSelectorScope(StrEnum):

@ -39,6 +39,10 @@ class PluginParameterType(enum.StrEnum):
# deprecated, should not use. # deprecated, should not use.
SYSTEM_FILES = CommonParameterType.SYSTEM_FILES.value SYSTEM_FILES = CommonParameterType.SYSTEM_FILES.value
# MCP object and array type parameters
ARRAY = CommonParameterType.ARRAY.value
OBJECT = CommonParameterType.OBJECT.value
class MCPServerParameterType(enum.StrEnum): class MCPServerParameterType(enum.StrEnum):
""" """
@ -143,6 +147,14 @@ def cast_parameter_value(typ: enum.StrEnum, value: Any, /):
if value and not isinstance(value, list): if value and not isinstance(value, list):
raise ValueError("The tools selector must be a list.") raise ValueError("The tools selector must be a list.")
return value return value
case PluginParameterType.ARRAY:
if not isinstance(value, list):
return [value]
return value
case PluginParameterType.OBJECT:
if not isinstance(value, dict):
return {}
return value
case _: case _:
return str(value) return str(value)
except ValueError: except ValueError:

@ -4,7 +4,6 @@ from typing import Any, Optional
from core.mcp.error import MCPAuthError, MCPConnectionError from core.mcp.error import MCPAuthError, MCPConnectionError
from core.mcp.mcp_client import MCPClient from core.mcp.mcp_client import MCPClient
from core.mcp.types import ImageContent, TextContent from core.mcp.types import ImageContent, TextContent
from core.plugin.utils.converter import convert_parameters_to_plugin_format
from core.tools.__base.tool import Tool from core.tools.__base.tool import Tool
from core.tools.__base.tool_runtime import ToolRuntime from core.tools.__base.tool_runtime import ToolRuntime
from core.tools.entities.tool_entities import ToolEntity, ToolInvokeMessage, ToolParameter, ToolProviderType from core.tools.entities.tool_entities import ToolEntity, ToolInvokeMessage, ToolParameter, ToolProviderType
@ -40,7 +39,6 @@ class MCPTool(Tool):
) -> Generator[ToolInvokeMessage, None, None]: ) -> Generator[ToolInvokeMessage, None, None]:
try: try:
with MCPClient(self.server_url, self.provider_id, self.tenant_id, authed=True) as mcp_client: with MCPClient(self.server_url, self.provider_id, self.tenant_id, authed=True) as mcp_client:
tool_parameters = convert_parameters_to_plugin_format(tool_parameters)
result = mcp_client.invoke_tool(tool_name=self.entity.identity.name, tool_args=tool_parameters) result = mcp_client.invoke_tool(tool_name=self.entity.identity.name, tool_args=tool_parameters)
except MCPAuthError as e: except MCPAuthError as e:
raise ValueError("Please auth the tool first") raise ValueError("Please auth the tool first")

Loading…
Cancel
Save