Skip to content

use_mcp_tool

The use_mcp_tool tool enables interaction with external tools provided by connected Model Context Protocol (MCP) servers. It extends VJSP's domain-specific capabilities through standardized protocols.

Parameter Description

This tool accepts the following parameters:

  • server_name (required): The name of the MCP server that provides the tool
  • tool_name (required): The name of the tool to execute
  • arguments (optional/required): A JSON object containing input parameters for the tool, which must follow the tool's input schema. For tools that don't require input, this parameter is optional.

Function Overview

This tool allows VJSP to call professional functions provided by external MCP servers. Each MCP server can offer multiple tools with unique capabilities, expanding beyond VJSP's native functionality. The system validates input parameters based on schemas, manages server connections, and handles responses in various content types (text, images, resources).

Application Scenarios

  • When needing professional functions not provided by core tools
  • When needing to execute domain-specific operations
  • When needing to integrate with external systems or services
  • When needing to perform specific data processing or analysis
  • When needing to call proprietary tools through standardized interfaces

Core Features

  • Built on the @modelcontextprotocol/sdk development package, adopting the standardized MCP protocol
  • Supports multiple transport mechanisms (standard input/output client transport, server-sent events client transport)
  • Based on the Zod schema validation framework, with bidirectional validation of input parameters on both client and server sides
  • Supports processing multiple response content types: text, images, resource references
  • Supports server lifecycle management, with automatic restart when server code changes
  • Provides an "Always Allow" mechanism to skip execution approval processes for trusted tools
  • Works in conjunction with the accompanying access_mcp_resource tool to enable resource retrieval
  • Offers comprehensive error tracking and handling for failed operations
  • Supports configurable timeout periods (1-3600 seconds, default 60 seconds)
  • Supports file listeners to automatically detect server code changes and trigger reloads

Limitations

  • Depends on available and connected external MCP servers
  • Can only call tools provided by connected servers
  • Tool capabilities vary across different MCP servers
  • Network issues may affect service reliability and performance
  • User approval is required before tool execution (except for tools added to the "Always Allow" list)
  • Does not support simultaneous execution of multiple MCP tool operations

Server Configuration

MCP servers support two configuration methods: global configuration and project-level configuration:

  • Global Configuration: Managed through VJSP extension settings in VS Code, with configurations applying to all projects and can be overridden by project-level configurations.
  • Project-level Configuration: Defined in the .vjsp/mcp.json file in the project root directory, supporting configuration of dedicated servers for specific projects.
  • If global and project-level configurations have servers with the same name, the project-level configuration takes precedence.
  • The .vjsp/mcp.json file can be committed to version control systems to facilitate team configuration sharing.

Workflow

When calling the use_mcp_tool tool, the system executes the following workflow:

  1. Initialization and Validation

    • Verify the availability of the MCP central service
    • Confirm that the specified server exists and is connected
    • Verify that the tool to be called is deployed on the target server
    • Validate input parameters based on the tool's schema definition
    • Extract timeout settings from server configuration (default 60 seconds)
  2. Execution and Communication

    • The system selects an appropriate transport mechanism:
      • Standard input/output client transport: Communicates with local processes via standard input/output
      • Server-sent events client transport: Communicates with HTTP servers via server-sent events
    • Sends requests carrying valid server name, tool name, and input parameters
    • Implements standardized communication interactions based on the @modelcontextprotocol/sdk development package
    • Tracks request execution processes and prevents operation hangs through timeout handling
  3. Response Processing

    • Responses support multiple content types:
      • Text content: Response results in plain text format
      • Image content: Binary image data with MIME type information
      • Resource references: Uniform Resource Identifiers for accessing server resources (working in conjunction with the access_mcp_resource tool)
    • The system detects the isError flag to determine whether error handling logic needs to be executed
    • Formats results to meet VJSP interface display requirements
  4. Resource and Error Handling

    • Adopts a weak reference design pattern to prevent memory leaks
    • Implements error tracking and management through continuous error counters
    • Monitors server code changes based on file listeners and triggers automatic restarts
    • The security model requires user approval before tool execution (except for tools added to the "Always Allow" list)

Security and Permission Control

The MCP architecture provides multiple security features:

  • User approval is required by default before tool execution
  • Specific tools can be marked as "Always Allow" to enable automatic approval execution
  • Validates server configuration through Zod schemas to ensure configuration integrity
  • Supports configurable timeout periods to prevent operation hangs (1-3600 seconds)
  • Allows enabling or disabling server connections through a visual interface

Typical Application Examples

  • Analyze professional data formats using server-side processing tools
  • Generate images or other media resources through AI models deployed on external servers
  • Directly execute complex domain-specific calculations without local implementation
  • Access proprietary application programming interfaces or services through controlled interfaces
  • Retrieve data from professional databases or data sources

Usage Examples

Call a tool to get text-format weather forecast data

<use_mcp_tool>
<server_name>weather-server</server_name>
<tool_name>get_forecast</tool_name>
<arguments>
{
  "city": "San Francisco",
  "days": 5,
  "format": "text"
}
</arguments>
</use_mcp_tool>

Call a tool to analyze source code and get JSON-format analysis results

<use_mcp_tool>
<server_name>code-analysis</server_name>
<tool_name>complexity_metrics</tool_name>
<arguments>
{
  "language": "typescript",
  "file_path": "src/app.ts",
  "include_functions": true,
  "metrics": ["cyclomatic", "cognitive"]
}
</arguments>
</use_mcp_tool>

Call a tool to generate an image by passing specified parameters

<use_mcp_tool>
<server_name>image-generation</server_name>
<tool_name>create_image</tool_name>
<arguments>
{
  "prompt": "A futuristic city with flying cars",
  "style": "photorealistic",
  "dimensions": {
    "width": 1024,
    "height": 768
  },
  "format": "webp"
}
</arguments>
</use_mcp_tool>

Call a tool that returns a resource reference to implement resource access

<use_mcp_tool>
<server_name>database-connector</server_name>
<tool_name>query_and_store</tool_name>
<arguments>
{
  "database": "users",
  "type": "select",
  "fields": ["name", "email", "last_login"],
  "where": {
    "status": "active"
  },
  "store_as": "active_users"
}
</arguments>
</use_mcp_tool>

Call a tool that doesn't require input parameters

<use_mcp_tool>
<server_name>system-monitor</server_name>
<tool_name>get_current_status</tool_name>
<arguments>
{}
</arguments>
</use_mcp_tool>