mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-21 19:21:03 +02:00
Updated CLI invocation and config model for tools and mcp
This commit is contained in:
parent
a96d02da5d
commit
6c2a1824f5
5 changed files with 88 additions and 80 deletions
|
|
@ -21,27 +21,10 @@ def delete_tool(
|
|||
|
||||
api = Api(url).config()
|
||||
|
||||
# Get the current tool index
|
||||
try:
|
||||
values = api.get([
|
||||
ConfigKey(type="agent", key="tool-index")
|
||||
])
|
||||
|
||||
ix = json.loads(values[0].value)
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error reading tool index: {e}")
|
||||
return False
|
||||
|
||||
# Check if the tool exists in the index
|
||||
if id not in ix:
|
||||
print(f"Tool '{id}' not found in tool index.")
|
||||
return False
|
||||
|
||||
# Check if the tool configuration exists
|
||||
try:
|
||||
tool_values = api.get([
|
||||
ConfigKey(type="agent", key=f"tool.{id}")
|
||||
ConfigKey(type="tool", key=id)
|
||||
])
|
||||
|
||||
if not tool_values or not tool_values[0].value:
|
||||
|
|
@ -52,22 +35,12 @@ def delete_tool(
|
|||
print(f"Tool configuration for '{id}' not found.")
|
||||
return False
|
||||
|
||||
# Remove the tool ID from the index
|
||||
ix.remove(id)
|
||||
|
||||
# Delete the tool configuration and update the index
|
||||
try:
|
||||
|
||||
# Update the tool index
|
||||
api.put([
|
||||
ConfigValue(
|
||||
type="agent", key="tool-index", value=json.dumps(ix)
|
||||
)
|
||||
])
|
||||
|
||||
# Delete the tool configuration
|
||||
api.delete([
|
||||
ConfigKey(type="agent", key=f"tool.{id}")
|
||||
ConfigKey(type="agent", key=id)
|
||||
])
|
||||
|
||||
print(f"Tool '{id}' deleted successfully.")
|
||||
|
|
|
|||
|
|
@ -17,7 +17,8 @@ default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
|||
|
||||
def set_mcp_tool(
|
||||
url : str,
|
||||
name : str,
|
||||
id : str,
|
||||
remote_name : str,
|
||||
tool_url : str,
|
||||
):
|
||||
|
||||
|
|
@ -26,15 +27,13 @@ def set_mcp_tool(
|
|||
# Store the MCP tool configuration in the 'mcp' group
|
||||
values = api.put([
|
||||
ConfigValue(
|
||||
type="mcp", key=name, value=json.dumps({
|
||||
"name": name,
|
||||
type="mcp", key=id, value=json.dumps({
|
||||
"remote-name": remote_name,
|
||||
"url": tool_url,
|
||||
})
|
||||
)
|
||||
])
|
||||
|
||||
print(f"MCP tool '{name}' set with URL: {tool_url}")
|
||||
|
||||
def main():
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
|
|
@ -58,11 +57,17 @@ def main():
|
|||
)
|
||||
|
||||
parser.add_argument(
|
||||
'--name',
|
||||
'-i', '--id',
|
||||
required=True,
|
||||
help='MCP tool name',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-r', '--remote-name',
|
||||
required=False,
|
||||
help='MCP tool name',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'--tool-url',
|
||||
required=True,
|
||||
|
|
@ -73,15 +78,21 @@ def main():
|
|||
|
||||
try:
|
||||
|
||||
if not args.name:
|
||||
if not args.id:
|
||||
raise RuntimeError("Must specify --name for MCP tool")
|
||||
|
||||
if not args.tool_url:
|
||||
raise RuntimeError("Must specify --url for MCP tool")
|
||||
|
||||
if args.remote_name:
|
||||
remote_name = args.remote_name
|
||||
else:
|
||||
remote_name = args.id
|
||||
|
||||
set_mcp_tool(
|
||||
url=args.api_url,
|
||||
name=args.name,
|
||||
url=args.api_url,
|
||||
id=args.id,
|
||||
remote_name=remote_name,
|
||||
tool_url=args.tool_url
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -51,6 +51,9 @@ def set_tool(
|
|||
name : str,
|
||||
description : str,
|
||||
type : str,
|
||||
mcp_tool : str,
|
||||
collection : str,
|
||||
template : str,
|
||||
arguments : List[Argument],
|
||||
):
|
||||
|
||||
|
|
@ -60,14 +63,20 @@ def set_tool(
|
|||
ConfigKey(type="agent", key="tool-index")
|
||||
])
|
||||
|
||||
ix = json.loads(values[0].value)
|
||||
|
||||
object = {
|
||||
"id": id,
|
||||
"name": name,
|
||||
"description": description,
|
||||
"type": type,
|
||||
"arguments": [
|
||||
}
|
||||
|
||||
if mcp_tool: object["mcp-tool"] = mcp_tool
|
||||
|
||||
if collection: object["collection"] = collection
|
||||
|
||||
if template: object["template"] = template
|
||||
|
||||
if arguments:
|
||||
object["arguments"] = [
|
||||
{
|
||||
"name": a.name,
|
||||
"type": a.type,
|
||||
|
|
@ -75,17 +84,10 @@ def set_tool(
|
|||
}
|
||||
for a in arguments
|
||||
]
|
||||
}
|
||||
|
||||
if id not in ix:
|
||||
ix.append(id)
|
||||
|
||||
values = api.put([
|
||||
ConfigValue(
|
||||
type="agent", key="tool-index", value=json.dumps(ix)
|
||||
),
|
||||
ConfigValue(
|
||||
type="agent", key=f"tool.{id}", value=json.dumps(object)
|
||||
type="tool", key=f"{id}", value=json.dumps(object)
|
||||
)
|
||||
])
|
||||
|
||||
|
|
@ -100,7 +102,8 @@ def main():
|
|||
Valid tool types:
|
||||
knowledge-query - Query knowledge bases
|
||||
text-completion - Text completion/generation
|
||||
mcp-tool - Model Control Protocol tool
|
||||
mcp-tool - Model Control Protocol tool
|
||||
prompt - Prompt template query
|
||||
|
||||
Valid argument types:
|
||||
string - String/text parameter
|
||||
|
|
@ -143,13 +146,28 @@ def main():
|
|||
|
||||
parser.add_argument(
|
||||
'--type',
|
||||
help=f'Tool type, one of: knowledge-query, text-completion, mcp-tool',
|
||||
help=f'Tool type, one of: knowledge-query, text-completion, mcp-tool, prompt',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'--argument',
|
||||
nargs="*",
|
||||
help=f'Arguments, form: name:type:description',
|
||||
'--mcp-tool',
|
||||
help=f'For MCP, ID of MCP tool, as defined in TrustGraph config',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'--collection',
|
||||
help=f'For knowledge query, collection to use',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'--template',
|
||||
help=f'For prompt, template to use',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'--argument',
|
||||
nargs="*",
|
||||
help=f'For prompts, arguments in the form: name:type:description',
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
|
@ -157,7 +175,7 @@ def main():
|
|||
try:
|
||||
|
||||
valid_types = [
|
||||
"knowledge-query", "text-completion", "mcp-tool"
|
||||
"knowledge-query", "text-completion", "mcp-tool", "prompt"
|
||||
]
|
||||
|
||||
if args.id is None:
|
||||
|
|
@ -172,6 +190,8 @@ def main():
|
|||
"Type must be one of: " + ", ".join(valid_types)
|
||||
)
|
||||
|
||||
mcp_tool = args.mcp_tool
|
||||
|
||||
if args.argument:
|
||||
arguments = [
|
||||
Argument.parse(a)
|
||||
|
|
@ -181,10 +201,15 @@ def main():
|
|||
arguments = []
|
||||
|
||||
set_tool(
|
||||
url=args.api_url, id=args.id, name=args.name,
|
||||
url=args.api_url,
|
||||
id=args.id,
|
||||
name=args.name,
|
||||
description=args.description,
|
||||
type=args.type,
|
||||
arguments=arguments
|
||||
mcp_tool=mcp_tool,
|
||||
collection=args.collection,
|
||||
template=args.template,
|
||||
arguments=arguments,
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
|
|
|
|||
|
|
@ -26,11 +26,10 @@ def show_config(url):
|
|||
table = []
|
||||
|
||||
table.append(("id", value.key))
|
||||
table.append(("name", data["name"]))
|
||||
table.append(("remote-name", data["remote-name"]))
|
||||
table.append(("url", data["url"]))
|
||||
|
||||
print()
|
||||
print(value.key + ":")
|
||||
|
||||
print(tabulate.tabulate(
|
||||
table,
|
||||
|
|
|
|||
|
|
@ -17,37 +17,37 @@ def show_config(url):
|
|||
|
||||
api = Api(url).config()
|
||||
|
||||
values = api.get([
|
||||
ConfigKey(type="agent", key="tool-index")
|
||||
])
|
||||
values = api.get_values(type="tool")
|
||||
|
||||
ix = json.loads(values[0].value)
|
||||
for item in values:
|
||||
|
||||
values = api.get([
|
||||
ConfigKey(type="agent", key=f"tool.{v}")
|
||||
for v in ix
|
||||
])
|
||||
id = item.key
|
||||
data = json.loads(item.value)
|
||||
|
||||
for n, key in enumerate(ix):
|
||||
|
||||
data = json.loads(values[n].value)
|
||||
tp = data["type"]
|
||||
|
||||
table = []
|
||||
|
||||
table.append(("id", data["id"]))
|
||||
table.append(("id", id))
|
||||
table.append(("name", data["name"]))
|
||||
table.append(("description", data["description"]))
|
||||
table.append(("type", data["type"]))
|
||||
table.append(("type", tp))
|
||||
|
||||
for n, arg in enumerate(data["arguments"]):
|
||||
table.append((
|
||||
f"arg {n}",
|
||||
f"{arg['name']}: {arg['type']}\n{arg['description']}"
|
||||
))
|
||||
|
||||
if tp == "mcp-tool":
|
||||
table.append(("mcp-tool", data["mcp-tool"]))
|
||||
|
||||
if tp == "knowledge-query":
|
||||
table.append(("collection", data["collection"]))
|
||||
|
||||
if tp == "prompt":
|
||||
table.append(("template", data["template"]))
|
||||
for n, arg in enumerate(data["arguments"]):
|
||||
table.append((
|
||||
f"arg {n}",
|
||||
f"{arg['name']}: {arg['type']}\n{arg['description']}"
|
||||
))
|
||||
|
||||
print()
|
||||
print(key + ":")
|
||||
|
||||
print(tabulate.tabulate(
|
||||
table,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue