Skip to main content

Bastion

PyPI CI Python License: Apache 2.0

A local-first control plane for your AI agent's tools. Bastion is a gateway that sits between an AI agent (Claude Code, Cursor, Claude Desktop, …) and the MCP servers it uses — capping spend, rate-limiting, enforcing per-tool permissions, redacting or blocking dangerous arguments, and auditing every call.

One config file, one command, no cloud, no database.

Why

Model Context Protocol won — every major AI vendor ships it and there are 17,000+ MCP servers. But agents call those servers with no spend caps, no rate limits, no permissions, and no audit trail. A looping agent can burn real money in minutes, and you have no record of what it did.

Bastion is the missing control layer. One config file, one command, no cloud, no database.

How it works

Your agent points at Bastion instead of at its MCP servers directly. Bastion is both an MCP server (to the agent) and an MCP client (to the real "upstream" servers). It aggregates your upstreams behind one endpoint and enforces rules on every tools/call:

  AI agent  ──MCP──▶  Bastion  ──MCP──▶  upstream server A
                      (policy +          upstream server B
                       audit)            upstream server C

Install

pip install bastion-mcp

This installs the bastion command. To run it without installing globally, use uv:

uvx --from bastion-mcp bastion --help

To hack on Bastion itself, see CONTRIBUTING.md.

Quickstart

Create bastion.yaml:

upstreams:
  files:
    command: npx
    args: ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/project"]

Validate it:

bastion validate

Point your agent at the gateway — e.g. for Claude Code:

claude mcp add --transport stdio bastion -- bastion run --config ./bastion.yaml

Your agent now reaches the filesystem server through Bastion. With a single upstream, tools keep their original names; configure several and Bastion namespaces each tool by its upstream key (files_read_file, search_query, …) so they never collide.

Configuration

bastion.yaml — upstreams is required; everything else is optional. A small example with permissions and audit:

upstreams:
  files:
    command: npx
    args: ["-y", "@modelcontextprotocol/server-filesystem", "/data"]

audit:
  enabled: true
  path: ./bastion-audit.jsonl

policy:
  default: allow
  permissions:
    - { tool: "files_read_*",   action: allow }
    - { tool: "files_delete_*", action: deny  }

A denied call is blocked before reaching the upstream and recorded in the audit log. Rate limits, budgets (call-count and cost), and argument guards (block or redact) layer onto the same policy section.

See docs/configuration.md for the full reference of every section, docs/security.md for the security model (secrets in the audit log, unauthenticated surfaces), and examples/ for runnable starter configurations.

Dashboard

bastion dashboard serves a local web view of the audit log — every tool call, live, with arguments, outcomes, and timings:

bastion dashboard --config bastion.yaml   # then open http://127.0.0.1:8787

Milestones

Bastion shipped one feature per release, milestone by milestone:

  • M0 — multi-upstream proxy (stdio + HTTP), config schema, CLI
  • M1 — audit log: every tool call recorded to JSONL
  • M2 — permissions: per-tool allow/deny rules
  • M3 — first PyPI release (pip install bastion-mcp)
  • M4 — rate limiting: per-tool and global token buckets
  • M5 — budgets: call-count and cost caps with on-disk checkpoint
  • M6 — argument guards: regex-on-JSONPath, block or redact
  • M7 — live log viewer (bastion tail/logs/stats/init) + Windows CI
  • M8 — docs, examples, v1.0.0 🎉

Contributing

Issues and PRs welcome — see CONTRIBUTING.md.

License

Apache 2.0

Metadata

Release files for bastion-mcp 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bastion-mcp 1.0.2
File Size Uploaded Provenance
bastion_mcp-1.0.2.tar.gz 50.6 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for bastion-mcp 1.0.2
File Interpreter ABI Platform
bastion_mcp-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 87.5 kB

Release files / bastion_mcp-1.0.2.tar.gz

Download URL bastion_mcp-1.0.2.tar.gz
Size 50.6 kB
Tags Source
SHA-256 checksum
How to use checksums
001e56da94d956b73c68bbb9e33aad34a1f15e0fb9b781b5e075e322295764a0
BLAKE2b-256 checksum
How to use checksums
b317c6517529726cb479aeba6c5270caa6164a86c4576d55a4c018c8fa88a473
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 29, 2026.

Transparency log

Release files / bastion_mcp-1.0.2-py3-none-any.whl

Download URL bastion_mcp-1.0.2-py3-none-any.whl
Size 36.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1b23d56c6dde757e900af2f0a1357bcfe7c6b0db4a9035f02a4abbeb027f5f57
BLAKE2b-256 checksum
How to use checksums
9b1ecbe67a265338ad551da2747d161d4edbdc75322729b42352b0f5e14c2a12
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 29, 2026.

Transparency log

Security for bastion-mcp 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for bastion_mcp-1.0.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page