mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-21 19:21:03 +02:00
More MCP management
This commit is contained in:
parent
0cb844144a
commit
962b806795
5 changed files with 274 additions and 1 deletions
|
|
@ -49,6 +49,19 @@ class Config:
|
||||||
|
|
||||||
self.request(input)
|
self.request(input)
|
||||||
|
|
||||||
|
def delete(self, keys):
|
||||||
|
|
||||||
|
# The input consists of system and prompt strings
|
||||||
|
input = {
|
||||||
|
"operation": "delete",
|
||||||
|
"keys": [
|
||||||
|
{ "type": v.type, "key": v.key }
|
||||||
|
for v in keys
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
self.request(input)
|
||||||
|
|
||||||
def list(self, type):
|
def list(self, type):
|
||||||
|
|
||||||
# The input consists of system and prompt strings
|
# The input consists of system and prompt strings
|
||||||
|
|
@ -67,7 +80,7 @@ class Config:
|
||||||
"type": type,
|
"type": type,
|
||||||
}
|
}
|
||||||
|
|
||||||
object = self.request(input)["directory"]
|
object = self.request(input)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return [
|
return [
|
||||||
|
|
|
||||||
94
trustgraph-cli/scripts/tg-delete-mcp-tool
Normal file
94
trustgraph-cli/scripts/tg-delete-mcp-tool
Normal file
|
|
@ -0,0 +1,94 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
"""
|
||||||
|
Deletes MCP (Model Control Protocol) tools from the TrustGraph system.
|
||||||
|
Removes MCP tool configurations by name from the 'mcp' configuration group.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import os
|
||||||
|
from trustgraph.api import Api, ConfigKey
|
||||||
|
import textwrap
|
||||||
|
|
||||||
|
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||||
|
|
||||||
|
def delete_mcp_tool(
|
||||||
|
url : str,
|
||||||
|
name : str,
|
||||||
|
):
|
||||||
|
|
||||||
|
api = Api(url).config()
|
||||||
|
|
||||||
|
# Check if the tool exists first
|
||||||
|
try:
|
||||||
|
values = api.get([
|
||||||
|
ConfigKey(type="mcp", key=name)
|
||||||
|
])
|
||||||
|
|
||||||
|
if not values or not values[0].value:
|
||||||
|
print(f"MCP tool '{name}' not found.")
|
||||||
|
return False
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"MCP tool '{name}' not found.")
|
||||||
|
return False
|
||||||
|
|
||||||
|
# Delete the MCP tool configuration from the 'mcp' group
|
||||||
|
try:
|
||||||
|
api.delete([
|
||||||
|
ConfigKey(type="mcp", key=name)
|
||||||
|
])
|
||||||
|
|
||||||
|
print(f"MCP tool '{name}' deleted successfully.")
|
||||||
|
return True
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error deleting MCP tool '{name}': {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
def main():
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
prog='tg-delete-mcp-tool',
|
||||||
|
description=__doc__,
|
||||||
|
epilog=textwrap.dedent('''
|
||||||
|
This utility removes MCP tool configurations from the TrustGraph system.
|
||||||
|
Once deleted, the tool will no longer be available for use.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
%(prog)s --name weather
|
||||||
|
%(prog)s --name calculator
|
||||||
|
%(prog)s --api-url http://localhost:9000/ --name file-reader
|
||||||
|
''').strip(),
|
||||||
|
formatter_class=argparse.RawDescriptionHelpFormatter
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
'-u', '--api-url',
|
||||||
|
default=default_url,
|
||||||
|
help=f'API URL (default: {default_url})',
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
'--name',
|
||||||
|
required=True,
|
||||||
|
help='MCP tool name to delete',
|
||||||
|
)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
|
if not args.name:
|
||||||
|
raise RuntimeError("Must specify --name for MCP tool to delete")
|
||||||
|
|
||||||
|
delete_mcp_tool(
|
||||||
|
url=args.api_url,
|
||||||
|
name=args.name
|
||||||
|
)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
|
||||||
|
print("Exception:", e, flush=True)
|
||||||
|
|
||||||
|
main()
|
||||||
93
trustgraph-cli/scripts/tg-set-mcp-tool
Normal file
93
trustgraph-cli/scripts/tg-set-mcp-tool
Normal file
|
|
@ -0,0 +1,93 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
"""
|
||||||
|
Configures and registers MCP (Model Control Protocol) tools in the
|
||||||
|
TrustGraph system. Allows defining MCP tool configurations with name and
|
||||||
|
URL. Tools are stored in the 'mcp' configuration group for discovery and
|
||||||
|
execution.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import os
|
||||||
|
from trustgraph.api import Api, ConfigValue
|
||||||
|
import textwrap
|
||||||
|
import json
|
||||||
|
|
||||||
|
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||||
|
|
||||||
|
def set_mcp_tool(
|
||||||
|
url : str,
|
||||||
|
name : str,
|
||||||
|
tool_url : str,
|
||||||
|
):
|
||||||
|
|
||||||
|
api = Api(url).config()
|
||||||
|
|
||||||
|
# Store the MCP tool configuration in the 'mcp' group
|
||||||
|
values = api.put([
|
||||||
|
ConfigValue(
|
||||||
|
type="mcp", key=name, value=json.dumps({
|
||||||
|
"name": name,
|
||||||
|
"url": tool_url,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
])
|
||||||
|
|
||||||
|
print(f"MCP tool '{name}' set with URL: {tool_url}")
|
||||||
|
|
||||||
|
def main():
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
prog='tg-set-mcp-tool',
|
||||||
|
description=__doc__,
|
||||||
|
epilog=textwrap.dedent('''
|
||||||
|
MCP tools are configured with just a name and URL. The URL should point
|
||||||
|
to the MCP server endpoint that provides the tool functionality.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
%(prog)s --name weather --tool-url "http://localhost:3000/weather"
|
||||||
|
%(prog)s --name calculator --tool-url "http://mcp-tools.example.com/calc"
|
||||||
|
''').strip(),
|
||||||
|
formatter_class=argparse.RawDescriptionHelpFormatter
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
'-u', '--api-url',
|
||||||
|
default=default_url,
|
||||||
|
help=f'API URL (default: {default_url})',
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
'--name',
|
||||||
|
required=True,
|
||||||
|
help='MCP tool name',
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
'--tool-url',
|
||||||
|
required=True,
|
||||||
|
help='MCP tool URL endpoint',
|
||||||
|
)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
|
if not args.name:
|
||||||
|
raise RuntimeError("Must specify --name for MCP tool")
|
||||||
|
|
||||||
|
if not args.tool_url:
|
||||||
|
raise RuntimeError("Must specify --url for MCP tool")
|
||||||
|
|
||||||
|
set_mcp_tool(
|
||||||
|
url=args.api_url,
|
||||||
|
name=args.name,
|
||||||
|
tool_url=args.tool_url
|
||||||
|
)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
|
||||||
|
print("Exception:", e, flush=True)
|
||||||
|
|
||||||
|
main()
|
||||||
|
|
||||||
70
trustgraph-cli/scripts/tg-show-mcp-tools
Executable file
70
trustgraph-cli/scripts/tg-show-mcp-tools
Executable file
|
|
@ -0,0 +1,70 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
"""
|
||||||
|
Dumps out the current agent tool configuration
|
||||||
|
"""
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import os
|
||||||
|
from trustgraph.api import Api, ConfigKey
|
||||||
|
import json
|
||||||
|
import tabulate
|
||||||
|
import textwrap
|
||||||
|
|
||||||
|
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||||
|
|
||||||
|
def show_config(url):
|
||||||
|
|
||||||
|
api = Api(url).config()
|
||||||
|
|
||||||
|
values = api.get_values(type="mcp")
|
||||||
|
|
||||||
|
for n, value in enumerate(values):
|
||||||
|
|
||||||
|
data = json.loads(value.value)
|
||||||
|
|
||||||
|
table = []
|
||||||
|
|
||||||
|
table.append(("id", value.key))
|
||||||
|
table.append(("name", data["name"]))
|
||||||
|
table.append(("url", data["url"]))
|
||||||
|
|
||||||
|
print()
|
||||||
|
print(value.key + ":")
|
||||||
|
|
||||||
|
print(tabulate.tabulate(
|
||||||
|
table,
|
||||||
|
tablefmt="pretty",
|
||||||
|
maxcolwidths=[None, 70],
|
||||||
|
stralign="left"
|
||||||
|
))
|
||||||
|
|
||||||
|
print()
|
||||||
|
|
||||||
|
def main():
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
prog='tg-show-mcp-tools',
|
||||||
|
description=__doc__,
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
'-u', '--api-url',
|
||||||
|
default=default_url,
|
||||||
|
help=f'API URL (default: {default_url})',
|
||||||
|
)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
|
show_config(
|
||||||
|
url=args.api_url,
|
||||||
|
)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
|
||||||
|
print("Exception:", e, flush=True)
|
||||||
|
|
||||||
|
main()
|
||||||
|
|
||||||
|
|
@ -46,6 +46,7 @@ setuptools.setup(
|
||||||
scripts=[
|
scripts=[
|
||||||
"scripts/tg-add-library-document",
|
"scripts/tg-add-library-document",
|
||||||
"scripts/tg-delete-flow-class",
|
"scripts/tg-delete-flow-class",
|
||||||
|
"scripts/tg-delete-mcp-tool",
|
||||||
"scripts/tg-delete-kg-core",
|
"scripts/tg-delete-kg-core",
|
||||||
"scripts/tg-dump-msgpack",
|
"scripts/tg-dump-msgpack",
|
||||||
"scripts/tg-get-flow-class",
|
"scripts/tg-get-flow-class",
|
||||||
|
|
@ -68,6 +69,7 @@ setuptools.setup(
|
||||||
"scripts/tg-put-kg-core",
|
"scripts/tg-put-kg-core",
|
||||||
"scripts/tg-remove-library-document",
|
"scripts/tg-remove-library-document",
|
||||||
"scripts/tg-save-doc-embeds",
|
"scripts/tg-save-doc-embeds",
|
||||||
|
"scripts/tg-set-mcp-tool",
|
||||||
"scripts/tg-set-prompt",
|
"scripts/tg-set-prompt",
|
||||||
"scripts/tg-set-token-costs",
|
"scripts/tg-set-token-costs",
|
||||||
"scripts/tg-set-tool",
|
"scripts/tg-set-tool",
|
||||||
|
|
@ -79,6 +81,7 @@ setuptools.setup(
|
||||||
"scripts/tg-show-kg-cores",
|
"scripts/tg-show-kg-cores",
|
||||||
"scripts/tg-show-library-documents",
|
"scripts/tg-show-library-documents",
|
||||||
"scripts/tg-show-library-processing",
|
"scripts/tg-show-library-processing",
|
||||||
|
"scripts/tg-show-mcp-tools",
|
||||||
"scripts/tg-show-processor-state",
|
"scripts/tg-show-processor-state",
|
||||||
"scripts/tg-show-prompts",
|
"scripts/tg-show-prompts",
|
||||||
"scripts/tg-show-token-costs",
|
"scripts/tg-show-token-costs",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue