Tool Gating MCP

by ajbmachon

403 downloads Not rated yet
GitHub

About

Implements a tool gating and discovery system to preserve LLM context and focus while having access to many MCP servers

Explore

- Proxy Architecture: Single MCP server that routes to multiple backend servers
- Dynamic Tool Discovery: Find tools across all servers without manual configuration
- Semantic Search: Natural language queries to find the right tools
- Smart Provisioning: Load only relevant tools within token budgets
- Transparent Execution: Route tool calls to appropriate backend servers
- Native MCP Server: Direct integration with Claude Desktop via mcp-proxy
- Cross-Server Intelligence: Unified view of tools from Puppeteer, Exa, Context7, etc.
- Token Optimization: 90%+ reduction in context usage vs. loading all servers
- Zero Configuration: Claude Desktop needs only Tool Gating configuration

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name Tool Gating MCP
    Command (node, npx, python, etc.)

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

- Python 3.12+
- uv package manager

1. Clone the repository:

git clone https://github.com/yourusername/tool-gating-mcp.git
cd tool-gating-mcp

2. Create and activate virtual environment:

uv venv
source .venv/bin/activate # On Unix/macOS

bash

tool-gating-mcp

The system uses sensible defaults but can be configured:

- Max Tokens: Default 2000 tokens per request
- Max Tools: Default 10 tools per request
- Embedding Model: all-MiniLM-L6-v2 (384-dimensional embeddings)

An intelligent proxy/router for Model Context Protocol (MCP) that enables Claude Desktop and other MCP clients to dynamically discover and use tools from multiple MCP servers while maintaining a single connection point. This system prevents context bloat by intelligently selecting only the most relevant tools for each task.

POST /api/tools/discover
Discover relevant tools based on semantic search.

Request:

{
"query": "I need to perform calculations",
"tags": ["math", "calculation"],
"limit": 5
}

Response:

{
"tools": [
{
"tool_id": "calculator",
"name": "Calculator",
"description": "Perform mathematical calculations",
"score": 0.95,
"matched_tags": ["math", "calculation"],
"estimated_tokens": 50
}
],
"query_id": "uuid",
"timestamp": "2024-01-01T00:00:00"
}

POST /api/tools/provision
Select and format tools for LLM consumption with token budget enforcement.

Request:

{
"tool_ids": ["calculator", "web-search"],
"max_tools": 3
}

Response:

{
"tools": [
{
"name": "Calculator",
"description": "Perform mathematical calculations",
"parameters": { "type": "object", "properties": {...} },
"token_count": 50
}
],
"metadata": {
"total_tokens": 150,
"gating_applied": true
}
}

import httpx
import asyncio

async def find_math_tools():
async with httpx.AsyncClient() as client:
response = await client.post(
"http://localhost:8000/api/tools/discover",
json={
"query": "I need to solve equations",
"tags": ["math"],
"limit": 3
}
)
tools = response.json()["tools"]
print(f"Found {len(tools)} relevant tools")
for tool in tools:
print(f"- {tool['name']}: {tool['score']:.3f}")

asyncio.run(find_math_tools())

POST /api/tools/register
{
"id": "exa_research_paper_search",
"name": "research_paper_search",
"description": "Search across 100M+ research papers with full text access",
"tags": ["search", "research", "academic"],
"estimated_tokens": 250,
"server": "exa",
"parameters": {
"type": "object",
"properties": {
"query": {"type": "string"},
"numResults": {"type": "number", "default": 5}
},
"required": ["query"]
}
}


POST /api/mcp/ai/register-server
{
"server_name": "slack",
"config": {
"command": "npx",
"args": ["@slack/mcp-server"],
"env": {"SLACK_TOKEN": "xoxb-..."}
},
"tools": [
// AI provides all discovered tools with metadata
]
}

Tools can be added to the repository in services/repository.py:

python
Tool(
id="my-tool",
name="My Tool",
description="Description for semantic search",
tags=["category", "function"],
estimated_tokens=100,
parameters={
"type": "object",
"properties": {...},
"required": [...]
}
)
```

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "tool gating mcp": {
            "tool-gating-mcp": {
                "command": "uv",
                "args": [
                    "venv"
                ]
            }
        }
    }
}

McpServers

{
    "tool-gating-mcp": {
        "command": "uv",
        "args": [
            "venv"
        ]
    }
}

An intelligent proxy/router for Model Context Protocol (MCP) that enables Claude Desktop and other MCP clients to dynamically discover and use tools from multiple MCP servers while maintaining a single connection point. This system prevents context bloat by intelligently selecting only the most relevant tools for each task.

🎯 The Problem

MCP clients like Claude Desktop must load all servers at startup and cannot dynamically add servers during conversations. When using multiple MCP servers:
- Exa server: 7 search tools (web, research papers, Twitter, companies, etc.)
- Puppeteer: Browser automation tools
- Context7: Documentation search tools
- Desktop Commander: 18+ desktop automation tools

Loading all servers directly leads to:
- 🚨 Context bloat: 100+ tools consuming most of the context window
- 🔒 Static configuration: Cannot add servers without restarting Claude
- 💸 Increased costs: More tokens consumed per request
- 🎯 Poor tool selection: AI struggles to choose from too many options

💡 The Solution

Tool Gating MCP acts as an intelligent proxy that:
1. Single Connection: Claude Desktop connects only to Tool Gating
2. Backend Management: Maintains connections to multiple MCP servers
3. Smart Discovery: Finds relevant tools across all servers using semantic search
4. Dynamic Provisioning: Loads only needed tools within token budgets
5. Transparent Routing: Executes tools on appropriate backend servers

Example: Instead of configuring 10 MCP servers with 100+ tools, configure just Tool Gating. Then dynamically discover and use only the 2-3 tools you need.

🚀 Features

- Proxy Architecture: Single MCP server that routes to multiple backend servers
- Dynamic Tool Discovery: Find tools across all servers without manual configuration
- Semantic Search: Natural language queries to find the right tools
- Smart Provisioning: Load only relevant tools within token budgets
- Transparent Execution: Route tool calls to appropriate backend servers
- Native MCP Server: Direct integration with Claude Desktop via mcp-proxy
- Cross-Server Intelligence: Unified view of tools from Puppeteer, Exa, Context7, etc.
- Token Optimization: 90%+ reduction in context usage vs. loading all servers
- Zero Configuration: Claude Desktop needs only Tool Gating configuration

📋 Prerequisites

- Python 3.12+
- uv package manager

🔧 Installation

1. Clone the repository:

git clone https://github.com/yourusername/tool-gating-mcp.git
cd tool-gating-mcp

2. Create and activate virtual environment:
```bash
uv venv
source .venv/bin/activate # On Unix/macOS

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.