Skip to main content

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

# 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.

uv run mcp-semantic-gateway index

3. Connect Your Agent

Point your client to the MCP Semantic Gateway Proxy. For 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:

  1. Ingestion: The Collector harvests tools from native MCP servers, "forges" new tools from OpenAPI/Swagger docs, and indexes local Agent Skills (SKILL.md).
  2. Semantic Index: A local SQLite + hnswlib vector store maintains embeddings for every tool, prompt, and skill.
  3. The Discovery Loop:
    • The Agent sets a context via mcp_semantic_gateway_context.
    • MCP Semantic Gateway intercepts the next tools/list or prompts/list request.
    • It performs a sub-millisecond k-NN search and returns only the top-k matches.
    • tools/call requests are transparently routed back to the correct upstream server.

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 /examples showing 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

  1. Fork the repo.
  2. Create a feature branch: feat/issue-number-description.
  3. Run the E2E suite: uv run pytest tests/test_e2e.py.
  4. Submit a PR!

Community

Join Dallas and the team in the OpenClaw Discord to discuss the future of agentic infrastructure.


Built by codeninja and the OpenClaw Agentic Dev Team.

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

mcp_semantic_gateway-0.1.1.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_semantic_gateway-0.1.1-py3-none-any.whl (20.5 kB view details)

Uploaded Python 3

File details

Details for the file mcp_semantic_gateway-0.1.1.tar.gz.

File metadata

  • Download URL: mcp_semantic_gateway-0.1.1.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mcp_semantic_gateway-0.1.1.tar.gz
Algorithm Hash digest
SHA256 061c6c89428fce566695a9a9431ccdd14e0bc07db86a6da453ad210b1719f914
MD5 e118e3a4978643aa3a32474c6eb98d40
BLAKE2b-256 993a982b3a5028bedadf9745a67a4c75d1dbcc88a37ef6585e337cddaea1d505

See more details on using hashes here.

File details

Details for the file mcp_semantic_gateway-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mcp_semantic_gateway-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1b25f903c436883d891990b695666841aa1e407b571a4238e2f896020a77fac1
MD5 891ea0c2d235f46a7da7629cdebb656e
BLAKE2b-256 b89a646634e760c815a7254be39dfeadaf6c25e281fca106e8fea59bdf178209

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page