agent-gateway
Enables web search through Baidu as a configurable search engine, returning search results and optionally fetching top pages as Markdown.
Enables web search through Brave Search as a configurable search engine, with caching, rate limits, and optional top-page fetching.
Enables web search through DuckDuckGo as a configurable search engine, with caching, rate limits, and optional top-page fetching.
Allows Google web search to be plugged in through an external command provider for the web search tool.
Provides a model gateway that accepts OpenAI-shaped API traffic and forwards chat completions to configured OpenAI-compatible providers, including streaming, model routing/remapping, usage tracking, and request/response rewriting.
Enables web search through Sogou as a configurable search engine, with caching, rate limits, and optional top-page fetching.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
agent-gateway
English | 简体中文
A self-hosted AI capability layer for desktop agents. It provides the parts an agent needs beyond the model itself — durable memory, code intelligence, web access and a model gateway — behind MCP and plain HTTP.
The package runs as a standalone Python service or as a subprocess of a larger host. It does not depend on a desktop framework, and hosts integrate through MCP tools, HTTP endpoints and JSON contracts instead of importing internals.
Status: 0.1.0. The public surface is usable, but interfaces may still change between minor releases.
Features
Durable memory
Two-tier storage. The hot layer keeps raw facts in mem0 backed by an embedded Qdrant collection. The cold layer indexes consolidated knowledge in a separate collection. Both share one embedder and one local vector store.
Write-time hygiene. Near-duplicate facts are deduplicated, contradictory memories are checked, and facts from the same episode are grouped so related context can be recalled together.
Lifecycle control. Memories move through active, superseded, archived and deleted states. Important entries can be protected, and superseded versions stay traceable instead of being overwritten.
Memory graph. A SQLite graph records version chains, episode membership, derivation, contradictions, related entries and mentions, and exposes them through
memory_graph.Bounded growth. Scheduled jobs archive stale entries, consolidate summaries and fold summary budgets, so the hot layer does not grow without limit.
Retrieval
Three retrieval arms — dense hot memory, dense cold memory and lexical project notes — are fused and gated by a single pipeline.
Relevance floors are calibrated per embedding model and can be re-calibrated when the model changes.
Responses carry a status (
ok/weak_match/no_match) and trace metadata, so callers can tell an empty result from a weak one.
Project intelligence
A resident tree-sitter indexer builds a per-project symbol and call graph for Python, Swift, JavaScript/TypeScript/TSX, Java, Kotlin, Objective-C and Vue.
project_lookupreturns definitions with one-hop caller context.project_impactwalks callers or callees to show what a change touches.project_notessearches project Markdown by meaning, using hybrid semantic, keyword and path ranking with de-duplication.
Web access
websearch_enginequeries configurable search engines, including Bing, DuckDuckGo, Brave, Sogou, 360, Baidu and Marginalia. Google can be plugged in through an external command provider.read_urlconverts pages to Markdown with trafilatura, falls back to a lighter converter for short or empty pages, and discards boilerplate.Search caching, per-engine rate limits and optional top-page fetching are built in.
Model gateway
The token proxy accepts Anthropic- and OpenAI-shaped traffic on
/v1/*, with/open/*and/raw/*aliases for compatibility and transparent forwarding.Requests are routed by exact model name across multiple providers; the upstream model can be remapped.
Streaming responses,
gzip/deflate/br/zstddecoding, SSE usage extraction and per-request accounting are handled in one place.Optional request/response rewrites include tool-output compaction, repeated skill de-duplication and a per-request annotation of what was rewritten.
Usage is stored in SQLite and exposed through
/usage/summary,/usage/toolsand/usage/layers.
Local-first operation
config.yamlis the single configuration source; environment variables override individual values.Vector data, caches, logs and SQLite databases stay under
GATEWAY_HOMEandGATEWAY_CACHE.No hosted control plane and no telemetry. The embedding model is downloaded once and then served from the local cache.
Related MCP server: atlasbrain
Architecture
flowchart TD
Client["Desktop agent / MCP client"] -->|MCP streamable HTTP| MCP["services.mcp.server"]
Client -->|HTTP| REST["/api/*"]
Client -->|Anthropic / OpenAI traffic| Proxy["services.proxy.token_proxy"]
MCP --> Memory["Hot + cold memory"]
MCP --> Graph["Code graph / notes"]
MCP --> Web["Search / read"]
REST --> LLM["llm.client"]
REST --> Summ["Summarize"]
Proxy --> Upstream["LLM providers"]
Memory --> Qdrant[("Qdrant (local)")]
Memory --> MemGraph[("SQLite memory graph")]
Graph --> TS["tree-sitter"]
Web --> Fetch["trafilatura / HTTP"]Module | Path | Responsibility |
CLI |
|
|
Core |
| Config, paths, logging, ports, prompts, l10n |
LLM |
| One exit point for model calls |
MCP |
| MCP server, REST routes, memory tools, project tools |
Memory |
| Memory graph, links, retention, consolidation |
Retrieval |
| Pipeline, fusion, gating, calibration, tracing |
Graph |
| tree-sitter indexer, resolvers, language parsers |
Search |
| Search engine registry and execution |
Read / fetch |
| Page retrieval and Markdown conversion |
Proxy |
| Token proxy, provider routing, usage accounting |
Summarize |
| Memory summarization pipeline |
Knowledge |
| Knowledge card refill job |
Scanner |
| AST symbol extractor and JS helper |
Requirements
Python 3.12 or newer.
A local directory for Qdrant data and the embedding model cache.
Optional: Node.js 18+ only if you use the JavaScript/Vue branch of the legacy AST scanner. The graph indexer is pure Python.
Install
From source:
git clone https://github.com/yuanyxh/agent-gateway.git
cd agent-gateway
python -m venv .venv
. .venv/bin/activate
pip install -e ".[proxy,memory,server]"Extras are additive; install the ones for the features you use:
Extra | Installs |
| MCP server, HTTP layer, page extraction |
| mem0, fastembed, numpy, Qdrant client |
| aiohttp and Brotli/zstd decoders |
Build a wheel for distribution:
python -m buildThe wheel includes prompts, locale files and the ast-js helper, so a host can
install it into an isolated environment without copying source files.
Quick start
Create a configuration root:
mkdir -p ~/.config/agent-gateway
export GATEWAY_HOME="$HOME/.config/agent-gateway"Write ~/.config/agent-gateway/config.yaml:
mcp:
enabled: true
qdrantPath: ~/.config/agent-gateway/data/qdrant
embedderModel: sentence-transformers/all-MiniLM-L6-v2
knowledgeBasePath: ~/notes
modelProxy:
enabled: falseCheck the environment and start the MCP service:
agent-gateway --check
agent-gateway --serve --service mcpThe first start downloads the embedding model into the cache. The service listens on
http://127.0.0.1:9001; point an MCP client at the streamable HTTP endpoint:
{
"mcpServers": {
"agent-gateway": {
"url": "http://127.0.0.1:9001/mcp"
}
}
}/health reports liveness. If mcp.port is 0, the CLI probes for a free port and
records it under GATEWAY_HOME/runtime/.
Enable the model gateway
Add one or more providers and start the proxy:
modelProxy:
enabled: true
providers:
- name: anthropic
url: https://api.anthropic.com
apiFormat: anthropic
apiKey: "your-key"
models: [claude-sonnet-5-5]agent-gateway --serve --service proxyPoint the client's base URL at http://127.0.0.1:8613. Provider URLs are base URLs
without the protocol path; the proxy appends v1/messages or
v1/chat/completions according to the client and provider formats.
MCP tools
Tool | Purpose |
| Write one fact with context, type, sources, importance and lifecycle links |
| Write several facts in one call |
| Search hot memory, cold knowledge and project notes |
| Read recent memories since a number of days, with pagination |
| Delete a memory or knowledge point |
| Set or clear processing bits on memories |
| Read one memory by id, including archived entries |
| Follow version, episode, derivation, dispute or mention edges |
| Find a symbol or file definition with one-hop callers |
| Walk callers or callees to estimate change impact |
| Search project Markdown by meaning and keywords |
| Search the web and optionally fetch top pages |
| Convert a page to Markdown |
| Load a packaged reference or script when instructed |
Skills found under <notes>/MCP/Skills are also exposed as zero-argument tools.
HTTP API
The MCP service exposes generic REST capabilities on the same port:
Method | Path | Purpose |
|
| Liveness |
|
| Summarize text with an instruction |
|
| Fetch a URL as Markdown |
|
| Run one LLM turn |
|
| Add a cold-layer knowledge entry |
|
| List recent memories |
|
| Update memory processing state |
|
| Set lifecycle status |
|
| Pre-index a project's notes |
|
| Run consolidation, optionally dry-run |
|
| Retrieval counters |
|
| Rebuild a vector index |
|
| Rebuild progress |
|
| Diagnose retrieval for a query |
|
| Calibrate relevance floors |
The token proxy adds:
Method | Path | Purpose |
Any |
| Anthropic/OpenAI-compatible forwarding |
Any |
| Legacy alias |
Any |
| Transparent forwarding without rewrites |
|
| Liveness |
|
| Token usage summary |
|
| Per-tool call counts |
|
| Request-level usage records |
Configuration
agent-gateway reads $GATEWAY_HOME/config.yaml unless GATEWAY_CONFIG points to
another file. An environment variable always wins over the YAML value; the YAML
value wins over the built-in default.
Variable | Purpose |
| State root; defaults to |
| Explicit config file |
| Cache root; defaults to |
| Legacy alias for the state root |
| Service ports |
| Vector storage and embedder |
| Model access |
| Retrieval tracing |
| Search overrides |
Main config.yaml sections:
Section | Contents |
| API key, base URL, model, timeout |
| Enable switch, port, storage paths, embedder, notes, memory limits |
| Enable switch, port, providers, output filter, skill dedup |
| Engine list, order, per-engine endpoints and rate limits |
| Topics, pool target, failure streak, retention |
| Language, log size and rotation |
contracts/env.json is generated from the implementation and lists every
environment variable the package reads. contracts/entries.json lists the module
entry points a host can start. Consumers can validate against these files instead of
scanning source across repositories.
Development
pip install -e ".[proxy,memory,server]"
pip install ruff build
ruff format --check src tests scripts
ruff check src tests scripts
PYTHONPATH=src python -m unittest discover -s tests -t .
python -m build
agent-gateway --checkThe same commands run in GitHub Actions. Enable the local hooks once:
git config core.hooksPath .githookspre-commit runs formatting and lint checks; commit-msg enforces
type(scope): summary.
Project layout
src/agent_gateway/ package source
cli/ command line and contract export
core/ config, paths, logging, lifecycle constants
llm/ single model-call exit point
services/ MCP, memory, retrieval, graph, search, read, proxy, summarize
scanner/ AST symbol extractor and JS helper
prompts/ prompt templates per language
locales/ UI strings per language
contracts/ generated JSON contracts for host integration
scripts/ maintenance and evaluation scripts
tests/ unittest suiteContributing
Issues and pull requests are welcome. Keep changes focused, add tests for behavior changes, and run the development commands above before opening a pull request.
License
MIT. See LICENSE.
This server cannot be deployed
Maintenance
Related MCP Connectors
Private-by-default, local-first memory/context/task orchestrator for MCP apps and agents.
MCP server for your apps' tools and custom tools, plus hosted AI agents and approval-gated workflows
Persistent memory, knowledge graph, task management and more for AI agents via MCP.
Nifty's MCP server — exposes tasks, projects, messages, and files as tools for AI agents.
Related MCP Servers
- AlicenseNot gradedqualityAmaintenanceA self-hosted MCP server that provides any LLM with a graph-backed memory layer of your life—tasks, email, finance, contacts, calendar—plus autonomous agent offices that act on your behalf.3Apache 2.0
- AlicenseBqualityBmaintenanceTurns a local project folder into a searchable second brain that indexes code symbols, dependencies, notes, PDFs and web snapshots, then exposes hybrid keyword and embedding search, graph traversal, impact analysis and architecture reports to MCP clients. It also lets assistants record and recall architectural decisions and learnings as Markdown, so project memory persists across conversations, all running locally through one shared HTTP service.231MIT
- FlicenseNot gradedqualityAmaintenanceExposes a governed suite of 38 tools over a single OAuth-gated MCP endpoint, letting web AI chat clients such as Claude, ChatGPT, and Grok operate on a local machine — reading and editing files, running whitelisted shell commands, searching, querying SQLite, driving browsers and DevTools, managing background jobs, ports, and clipboard. Local IDEs and Postman can also connect directly over localhost for offline, low-latency access.-
- AlicenseNot gradedqualityAmaintenanceExposes a governed suite of 38 OAuth-gated tools over one MCP endpoint, letting web-based AI chat clients read and edit files, run whitelisted shell commands, search, and use Git, SQLite, browser automation, DevTools, background tasks, ports, clipboard, notifications, and localhost services on the user's own machine. It also allows local IDEs and automation tools to connect directly over localhost for offline, low-latency access.MIT