trustgraph/docs/cli/tg-set-mcp-tool.md
cybermaggedon 89be656990
Release/v1.2 (#457)
* Bump setup.py versions for 1.1

* PoC MCP server (#419)

* Very initial MCP server PoC for TrustGraph

* Put service on port 8000

* Add MCP container and packages to buildout

* Update docs for API/CLI changes in 1.0 (#421)

* Update some API basics for the 0.23/1.0 API change

* Add MCP container push (#425)

* Add command args to the MCP server (#426)

* Host and port parameters

* Added websocket arg

* More docs

* MCP client support (#427)

- MCP client service
- Tool request/response schema
- API gateway support for mcp-tool
- Message translation for tool request & response
- Make mcp-tool using configuration service for information
  about where the MCP services are.

* Feature/react call mcp (#428)

Key Features

  - MCP Tool Integration: Added core MCP tool support with ToolClientSpec and ToolClient classes
  - API Enhancement: New mcp_tool method for flow-specific tool invocation
  - CLI Tooling: New tg-invoke-mcp-tool command for testing MCP integration
  - React Agent Enhancement: Fixed and improved multi-tool invocation capabilities
  - Tool Management: Enhanced CLI for tool configuration and management

Changes

  - Added MCP tool invocation to API with flow-specific integration
  - Implemented ToolClientSpec and ToolClient for tool call handling
  - Updated agent-manager-react to invoke MCP tools with configurable types
  - Enhanced CLI with new commands and improved help text
  - Added comprehensive documentation for new CLI commands
  - Improved tool configuration management

Testing

  - Added tg-invoke-mcp-tool CLI command for isolated MCP integration testing
  - Enhanced agent capability to invoke multiple tools simultaneously

* Test suite executed from CI pipeline (#433)

* Test strategy & test cases

* Unit tests

* Integration tests

* Extending test coverage (#434)

* Contract tests

* Testing embeedings

* Agent unit tests

* Knowledge pipeline tests

* Turn on contract tests

* Increase storage test coverage (#435)

* Fixing storage and adding tests

* PR pipeline only runs quick tests

* Empty configuration is returned as empty list, previously was not in response (#436)

* Update config util to take files as well as command-line text (#437)

* Updated CLI invocation and config model for tools and mcp (#438)

* Updated CLI invocation and config model for tools and mcp

* CLI anomalies

* Tweaked the MCP tool implementation for new model

* Update agent implementation to match the new model

* Fix agent tools, now all tested

* Fixed integration tests

* Fix MCP delete tool params

* Update Python deps to 1.2

* Update to enable knowledge extraction using the agent framework (#439)

* Implement KG extraction agent (kg-extract-agent)

* Using ReAct framework (agent-manager-react)
 
* ReAct manager had an issue when emitting JSON, which conflicts which ReAct manager's own JSON messages, so refactored ReAct manager to use traditional ReAct messages, non-JSON structure.
 
* Minor refactor to take the prompt template client out of prompt-template so it can be more readily used by other modules. kg-extract-agent uses this framework.

* Migrate from setup.py to pyproject.toml (#440)

* Converted setup.py to pyproject.toml

* Modern package infrastructure as recommended by py docs

* Install missing build deps (#441)

* Install missing build deps (#442)

* Implement logging strategy (#444)

* Logging strategy and convert all prints() to logging invocations

* Fix/startup failure (#445)

* Fix loggin startup problems

* Fix logging startup problems (#446)

* Fix logging startup problems (#447)

* Fixed Mistral OCR to use current API (#448)

* Fixed Mistral OCR to use current API

* Added PDF decoder tests

* Fix Mistral OCR ident to be standard pdf-decoder (#450)

* Fix Mistral OCR ident to be standard pdf-decoder

* Correct test

* Schema structure refactor (#451)

* Write schema refactor spec

* Implemented schema refactor spec

* Structure data mvp (#452)

* Structured data tech spec

* Architecture principles

* New schemas

* Updated schemas and specs

* Object extractor

* Add .coveragerc

* New tests

* Cassandra object storage

* Trying to object extraction working, issues exist

* Validate librarian collection (#453)

* Fix token chunker, broken API invocation (#454)

* Fix token chunker, broken API invocation (#455)

* Knowledge load utility CLI (#456)

* Knowledge loader

* More tests
2025-08-18 20:56:09 +01:00

7.4 KiB

tg-set-mcp-tool

Synopsis

tg-set-mcp-tool [OPTIONS] --name NAME --tool-url URL

Description

The tg-set-mcp-tool command configures and registers MCP (Model Control Protocol) tools in the TrustGraph system. It allows defining MCP tool configurations with name and URL. Tools are stored in the 'mcp' configuration group for discovery and execution.

This command is useful for:

  • Registering MCP tool endpoints for agent use
  • Configuring external MCP server connections
  • Managing MCP tool registry for agent workflows
  • Integrating third-party MCP tools into TrustGraph

The command stores MCP tool configurations in the 'mcp' configuration group, separate from regular agent tools.

Options

  • -u, --api-url URL

    • TrustGraph API URL for configuration storage
    • Default: http://localhost:8088/ (or TRUSTGRAPH_URL environment variable)
    • Should point to a running TrustGraph API instance
  • --name NAME

    • Required. MCP tool name identifier
    • Used to reference the MCP tool in configurations
    • Must be unique within the MCP tool registry
  • --tool-url URL

    • Required. MCP tool URL endpoint
    • Should point to the MCP server endpoint providing the tool functionality
    • Must be a valid URL accessible by the TrustGraph system
  • -h, --help

    • Show help message and exit

Examples

Basic MCP Tool Registration

Register a weather service MCP tool:

tg-set-mcp-tool --name weather --tool-url "http://localhost:3000/weather"

Calculator MCP Tool

Register a calculator MCP tool:

tg-set-mcp-tool --name calculator --tool-url "http://mcp-tools.example.com/calc"

Remote MCP Service

Register a remote MCP service:

tg-set-mcp-tool --name document-processor \
                --tool-url "https://api.example.com/mcp/documents"

Custom API URL

Register MCP tool with custom TrustGraph API:

tg-set-mcp-tool -u http://trustgraph.example.com:8088/ \
                --name custom-mcp --tool-url "http://custom.mcp.com/api"

Local Development Setup

Register MCP tools for local development:

tg-set-mcp-tool --name dev-tool --tool-url "http://localhost:8080/mcp"

MCP Tool Configuration

MCP tools are configured with minimal metadata:

  • name: Unique identifier for the tool
  • url: Endpoint URL for the MCP server

The configuration is stored as JSON in the 'mcp' configuration group:

{
  "name": "weather",
  "url": "http://localhost:3000/weather"
}

Advanced Usage

Updating Existing MCP Tools

Update an existing MCP tool configuration:

# Update MCP tool URL
tg-set-mcp-tool --name weather --tool-url "http://new-weather-server:3000/api"

Batch MCP Tool Registration

Register multiple MCP tools in a script:

#!/bin/bash
# Register a suite of MCP tools
tg-set-mcp-tool --name search --tool-url "http://search-mcp:3000/api"
tg-set-mcp-tool --name translate --tool-url "http://translate-mcp:3000/api"
tg-set-mcp-tool --name summarize --tool-url "http://summarize-mcp:3000/api"

Environment-Specific Configuration

Configure MCP tools for different environments:

# Development environment
export TRUSTGRAPH_URL="http://dev.trustgraph.com:8088/"
tg-set-mcp-tool --name dev-mcp --tool-url "http://dev.mcp.com/api"

# Production environment
export TRUSTGRAPH_URL="http://prod.trustgraph.com:8088/"
tg-set-mcp-tool --name prod-mcp --tool-url "http://prod.mcp.com/api"

MCP Tool Validation

Verify MCP tool registration:

# Register MCP tool and verify
tg-set-mcp-tool --name test-mcp --tool-url "http://test.mcp.com/api"

# Check if MCP tool was registered
tg-show-mcp-tools | grep test-mcp

Error Handling

The command handles various error conditions:

  • Missing required arguments: Both name and tool-url must be provided
  • Invalid URLs: Tool URLs must be valid and accessible
  • API connection errors: If the TrustGraph API is unavailable
  • Configuration errors: If MCP tool data cannot be stored

Common error scenarios:

# Missing required field
tg-set-mcp-tool --name tool1
# Output: Exception: Must specify --tool-url for MCP tool

# Missing name
tg-set-mcp-tool --tool-url "http://example.com/mcp"
# Output: Exception: Must specify --name for MCP tool

# Invalid API URL
tg-set-mcp-tool -u "invalid-url" --name tool1 --tool-url "http://mcp.com"
# Output: Exception: [API connection error]

Integration with Other Commands

With MCP Tool Management

View registered MCP tools:

# Register MCP tool
tg-set-mcp-tool --name new-mcp --tool-url "http://new.mcp.com/api"

# View all MCP tools
tg-show-mcp-tools

With Agent Workflows

Use MCP tools in agent workflows:

# Register MCP tool
tg-set-mcp-tool --name weather --tool-url "http://weather.mcp.com/api"

# Invoke MCP tool directly
tg-invoke-mcp-tool --name weather --input "location=London"

With Configuration Management

MCP tools integrate with configuration management:

# Register MCP tool
tg-set-mcp-tool --name config-mcp --tool-url "http://config.mcp.com/api"

# View configuration including MCP tools
tg-show-config

Best Practices

  1. Clear Naming: Use descriptive, unique MCP tool names
  2. Reliable URLs: Ensure MCP endpoints are stable and accessible
  3. Health Checks: Verify MCP endpoints are operational before registration
  4. Documentation: Document MCP tool capabilities and usage
  5. Error Handling: Implement proper error handling for MCP endpoints
  6. Security: Use secure URLs (HTTPS) when possible
  7. Monitoring: Monitor MCP tool availability and performance

Troubleshooting

MCP Tool Not Appearing

If a registered MCP tool doesn't appear in listings:

  1. Verify the MCP tool was registered successfully
  2. Check MCP tool registry with tg-show-mcp-tools
  3. Ensure the API URL is correct
  4. Verify TrustGraph API is running

MCP Tool Registration Errors

If MCP tool registration fails:

  1. Check all required arguments are provided
  2. Verify the tool URL is accessible
  3. Ensure the MCP endpoint is operational
  4. Check API connectivity
  5. Review error messages for specific issues

MCP Tool Connectivity Issues

If MCP tools aren't working as expected:

  1. Verify MCP endpoint is accessible from TrustGraph
  2. Check MCP server logs for errors
  3. Ensure MCP protocol compatibility
  4. Review network connectivity and firewall rules
  5. Test MCP endpoint directly

MCP Protocol

The Model Control Protocol (MCP) is a standardized interface for AI model tools:

  • Standardized API: Consistent interface across different tools
  • Extensible: Support for complex tool interactions
  • Stateful: Can maintain state across multiple interactions
  • Secure: Built-in security and authentication mechanisms

Security Considerations

When registering MCP tools:

  1. URL Validation: Ensure URLs are legitimate and secure
  2. Network Security: Use HTTPS when possible
  3. Access Control: Implement proper authentication for MCP endpoints
  4. Input Validation: Validate all inputs to MCP tools
  5. Error Handling: Don't expose sensitive information in error messages

See Also

  • MCP Protocol Documentation
  • TrustGraph MCP Integration Guide
  • Agent Tool Configuration Guide