Skip to content

Add templated embedded tool schemas with dynamic property generation #197

@JeanMertz

Description

@JeanMertz

Embedded MCP tools currently have static schemas defined in TOML files, but many tools could benefit from dynamically generated schemas based on external data sources. For example, a GitHub label management tool should have an enum of valid label names fetched from the GitHub API, ensuring the assistant only suggests valid options.

Context

When working with tools that interact with external systems, the available options or valid values often change dynamically. Currently, MCP tool schemas in .jp/mcp/tools/*.toml files have static properties definitions that cannot adapt to external data sources.

A common example is GitHub integration tools - a tool for adding labels to issues should present an enum of all available labels in the repository, but these labels are managed dynamically through GitHub's interface and can change over time.

Alternatives

Manual schema updates could work but would require constant maintenance as external data changes. Static schemas with string validation in the tool implementation could work but provide poor UX as the assistant wouldn't know valid options upfront.

Proposed Implementation

Add a preprocessor field to the MCP tool TOML configuration that points to an executable file. This executable would:

  1. Receive the current JSON schema via stdin
  2. Have access to workspace context and configuration
  3. Return the final processed schema via stdout
  4. Be executed when jp query starts and the tool is available

For caching, start with rebuilding schemas on each jp query command startup, with future TTL/caching optimizations as a follow-up enhancement.

Example TOML configuration:

[tool]
description = "Add labels to GitHub issues"
command = ["github_label_tool"]
preprocessor = "scripts/github_labels_preprocessor.sh"

[[tool.properties]]
name = "labels"
type = "array"
# This enum will be populated by the preprocessor
items = { type = "string" }

The preprocessor script would fetch available labels via GitHub API and inject them into the schema enum.

Tasks

  • Add preprocessor field to McpTool struct in crates/jp_mcp/src/tool.rs
  • Update tool loading logic in crates/jp_storage/src/lib.rs to execute preprocessor if specified
  • Add schema preprocessing to embedded server tool enumeration in crates/jp_mcp/src/server/embedded.rs
  • Add error handling for preprocessor execution failures
  • Add documentation and examples for preprocessor usage

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