Semantic Tool Discovery Middleware for MCP
Project description
MCP Semantic Gateway: Semantic Discovery Middleware for MCP
Stop Bloating Your Agent's Context. Start Scaling Your Toolsets.
MCP Semantic Gateway is an open-source, local-first middleware for the Model Context Protocol (MCP). It solves the "Too Many Tools" problem by semantically filtering your tool registry, prompts, and skills on-the-fly, ensuring your LLM stays focused, accurate, and cost-efficient.
🚀 Part 1: Quick Start
What is it?
If you have 30+ MCP tools, your agent's context window is saturated with JSON definitions before it even starts thinking. This leads to hallucinations, high token costs, and declining accuracy. MCP Semantic Gateway sits as a proxy between your client (Claude Code, Cursor) and your servers, serving only the tools relevant to your current task.
Installation
From PyPI (Recommended)
pip install mcp-semantic-gateway
mcp-semantic-gateway init
From Source
# Clone the repository
gh repo clone codeninja/mcp-semantic-gateway
cd mcp-semantic-gateway
# Install dependencies and initialize
uv sync
uv run mcp-semantic-gateway init
1. Configure Your Sources
Add your MCP servers or OpenAPI specs to ~/.mcp_semantic_gateway/config.toml:
[servers.github]
type = "mcp"
command = "npx"
args = ["@modelcontextprotocol/server-github"]
[servers.weather-api]
type = "openapi"
url = "https://api.weather.gov/openapi.json"
2. Build the Semantic Index
MCP Semantic Gateway embeds your tool descriptions locally using all-MiniLM-L6-v2.
mcp-semantic-gateway index
3. Connect Your Agent
Point your client to the MCP Semantic Gateway Proxy.
For PyPI Installation (Claude Desktop):
"mcpServers": {
"mcp-semantic-gateway": {
"command": "mcp-semantic-gateway",
"args": ["proxy"]
}
}
For Source Installation (Claude Desktop):
"mcpServers": {
"mcp-semantic-gateway": {
"command": "uv",
"args": ["--directory", "/path/to/mcp-semantic-gateway", "run", "mcp-semantic-gateway", "proxy"]
}
}
4. Use It
Simply tell your agent what you're doing. The agent will call mcp_semantic_gateway_context("debugging kubernetes logs"), and MCP Semantic Gateway will instantly activate the relevant tools in the agent's registry.
🧠 Part 2: Technical Architecture
MCP Semantic Gateway operates as a Statistical Filtering Proxy. It doesn't just forward requests; it transforms the environment based on intent.
How it Works:
- Ingestion: The
Collectorharvests tools from native MCP servers, "forges" new tools from OpenAPI/Swagger docs, and indexes local Agent Skills (SKILL.md). - Semantic Index: A local SQLite + hnswlib vector store maintains embeddings for every tool, prompt, and skill.
- The Discovery Loop:
- The Agent sets a context via
mcp_semantic_gateway_context. - MCP Semantic Gateway intercepts the next
tools/listorprompts/listrequest. - It performs a sub-millisecond k-NN search and returns only the top-k matches.
tools/callrequests are transparently routed back to the correct upstream server.
- The Agent sets a context via
Deep Dive: For a full breakdown of the layered architecture, domain models, and state machines, see our Full Technical Specification.
🤝 Part 3: Contributing
We are building the "Garbage Collector for the Context Window," and we want your help!
How to Contribute
- Create a Bridge: Have a niche API? Add an example to
/examplesshowing how to bridge it. - Improve the Forge: Help us refine the OpenAPI-to-MCP transformation logic.
- New Backends: We want to support more vector stores (Chroma, pgvector) and remote embedding providers.
- Feedback: Open an issue if you find a tool-selection hallucination we can't solve.
Development Workflow
- Fork the repo.
- Create a feature branch:
feat/issue-number-description. - Run the E2E suite:
uv run pytest tests/test_e2e.py. - Submit a PR!
Built by codeninja and a Custom Agentic Development Engine
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcp_semantic_gateway-0.1.2.tar.gz.
File metadata
- Download URL: mcp_semantic_gateway-0.1.2.tar.gz
- Upload date:
- Size: 13.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3d3997b6ea3351c25c80f1dce5d0b226e13a495b9151a542db849e6eaf849343
|
|
| MD5 |
38bed70b1e43a3ef6fd1162c3eb99b37
|
|
| BLAKE2b-256 |
89b45e7c15b6e24e95831a73ab923f3ff5a579331164197c06ec3ad8b562c01e
|
File details
Details for the file mcp_semantic_gateway-0.1.2-py3-none-any.whl.
File metadata
- Download URL: mcp_semantic_gateway-0.1.2-py3-none-any.whl
- Upload date:
- Size: 20.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
af19ba10b4e6956174285bc872008ae18a9b4613c9552ad1dd36336b3f589c57
|
|
| MD5 |
47c9f48ef26e61f319aadfa2c7f9a86d
|
|
| BLAKE2b-256 |
d9947b7460071afabd408673534d93e531c2cf99daad493c7397d9c521ab1eeb
|