Skip to content

Tool templates with configurable parameter constraints and multi-exposure support #208

@JeanMertz

Description

@JeanMertz

Add a comprehensive tool templating system that allows exposing the same underlying MCP tool multiple times with different names, descriptions, and parameter constraints including defaults, enums, and fixed values.

Context

Currently, MCP tools are exposed directly to LLMs with their original schemas and parameters. There's no way to constrain tool parameters, set defaults, or expose the same tool multiple times with different configurations. This limits the ability to create context-specific tool variations and enforce security boundaries.

For example, a filesystem tool should be exposable as workspace-scoped, subfolder-scoped, or root-scoped variants. A GitHub search tool should be available both with repository parameter free-form and with repository parameter locked to the current project.

Alternatives

Manual tool duplication could work but would require maintaining separate tool implementations. Static parameter validation in tool implementation provides poor UX as LLMs wouldn't know constraints upfront. Current MCP configuration system only handles run/result modes, not parameter constraints.

Proposed Implementation

Implement a two-layer architecture:

Layer 1: Connector Source Imports

  • MCP servers and built-in connectors (fs, git, github) don't expose tools by default
  • Optional use_default_tools setting to expose tools with original schemas
  • Built-in connectors provide hardened, workspace-aware implementations
  • User-defined mcp tools allow calling custom scripts per workspace (currently called "embedded mcp")

Layer 2: Tool Templates

  • Each tool template wraps a connector's tool with custom configuration:
    • enabled - Is the wrapper currently enabled? Can be changed per query/conversation
    • name - Custom tool name exposed to LLM
    • description - Custom description
    • parameters - Parameter constraints (defaults, enums, fixed values, removal)
  • All tool calls are wrapped and validated against template constraints by JP
  • Templates can reference the same underlying tool multiple times

Example configuration:

[connectors.builtin.github]
# Built-in connector, no tools exposed by default, included by default

[connectors.mcp.my_server]  
command = ["my-mcp-server"]
# External MCP server, no tools exposed by default

[connectors.user.my_custom_tool]
# User-defined tools, calling custom scripts/etc (see current "embedded tools" feature)

[tools.search_project_github]
source = "builtin.github.github_search" 
description = "Search the current project's GitHub repository"
values.repository = "my_repo"
parameters.query.type = "required"

Tool Call Validation

  • Intercept all tool calls before execution
  • Validate parameters against template constraints
  • Reject calls that violate configured boundaries
  • Support parameter transformation (defaults, fixed values)

Tasks

  • Add ToolTemplate struct with parameter constraint support in crates/jp_mcp/src/tool.rs
  • Implement tool call validation wrapper that checks parameters against template constraints
  • Update MCP client to route tool calls through validation layer before execution
  • Add built-in connector system separate from MCP servers for hardened tools
  • Extend configuration system to support tool templates in TOML config
  • Add template parameter types: fixed, default, enum, required, optional, remove
  • Implement template engine for parameter value resolution (workspace context, etc.)
  • Update embedded server to support template-based tool exposure
  • Add configuration migration logic for existing tool configurations
  • Add comprehensive tests for parameter validation and constraint enforcement

Resources

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions