Shared MCP framework: McpServer + McpTool + PlatformHttpClient + per-tool RBAC backed by mcp_tool_grants and the task-02 epoch broadcast
Project description
3tears-mcp
Shared MCP (Model Context Protocol) framework. Per-product MCP servers compose this framework instead of reimplementing stdio transport, JWT auth, error mapping, and per-tool RBAC.
What's in here
| Module | Responsibility |
|---|---|
server |
McpServer -- wraps the official mcp.server.Server. Owns tool registration, RBAC gating before handler dispatch, structured error mapping per the MCP spec. |
tool |
McpTool dataclass (name, description, input_schema, required_permission, handler) and register_tool decorator. |
http_client |
PlatformHttpClient -- typed httpx client with JWT login + refresh-on-401. Used by both MCP server tool handlers (calling /api/v1/...) and CLI scripts. One HTTP-client implementation, two transports. |
auth |
Identity dataclass + IdentityProvider Protocol + EnvVarIdentityProvider (stdio impl). Authorizer Protocol + LocalGrantAuthorizer (default impl backed by McpToolGrantCollection). |
rbac |
McpToolGrantCollection -- BaseCollection over mcp_tool_grants. Exposes the in-memory grant cache that LocalGrantAuthorizer consults. |
migrations/ |
v01_create_mcp_tool_grants -- platform-scope DDL. Consumers register via MigrationRunner.register(epoch_pkg) (same shape as threetears.epoch). |
RBAC model
Per-tool, default-deny. Each McpTool declares a required_permission string (e.g. "conversations.read", "audit.read"). On every dispatch:
- The framework calls
Authorizer.allows(identity, required_permission). LocalGrantAuthorizerchecks whether the caller's identity matches an active grant inMcpToolGrantCollectionfor the requested permission.- If denied, the framework returns a structured MCP error to the client (not a Python exception in the response body).
The configured admin identity (env-var creds in the stdio impl) is auto-granted in memory at server startup. The grant is logged but NOT written to mcp_tool_grants. This keeps the table truthful (only operator-added grants live there).
Grant changes propagate cross-pod via the mcp.rbac epoch broadcast. LocalGrantAuthorizer subscribes to Subjects.mcp_rbac_epoch() via an EpochListener; on bump it reloads the grant cache from L3. Cold-start primes from EpochClient.current(...). Missed broadcasts recover via the standard pull-on-stale path.
Identity in v1
EnvVarIdentityProvider returns one fixed Identity for the lifetime of the server, derived from env-var credentials. v2 (HTTP transport + per-call bearer-token identity) plugs in by adding a BearerTokenIdentityProvider; the rest of the framework is unchanged. The Authorizer.allows(identity, permission) interface is unchanged between v1 and v2.
Stdio transport discipline
Every byte on stdout/stderr from a stdio MCP server confuses the client. The framework configures logging to a file or to NATS; no module under threetears.mcp should write to sys.stdout / sys.stderr. An AST enforcement test guards this.
Postgres backing
CREATE TABLE IF NOT EXISTS mcp_tool_grants (
grant_id UUID PRIMARY KEY,
principal_type TEXT NOT NULL, -- 'user' | 'group' | 'role'
principal_id UUID NOT NULL,
tool_name TEXT NOT NULL,
permission TEXT NOT NULL,
date_created TIMESTAMPTZ NOT NULL DEFAULT now()
);
Mutation paths (admin POST /admin/mcp/grants, DELETE /admin/mcp/grants/{id}) bump Subjects.mcp_rbac_epoch() after the row commit; sibling pods reload via the epoch listener.
Project details
Release history Release notifications | RSS feed
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 3tears_mcp-0.17.9.tar.gz.
File metadata
- Download URL: 3tears_mcp-0.17.9.tar.gz
- Upload date:
- Size: 51.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d400c97e4ba146fb2ddf9d7c7489f3d94eac84de3820bccf396e86e1af35364
|
|
| MD5 |
f0914062743dba84ef79c444f658c166
|
|
| BLAKE2b-256 |
516a25b23d06d667ebeb4b670b8a56506233d34a8494f9bd7c5dc5f1010579b7
|
Provenance
The following attestation bundles were made for 3tears_mcp-0.17.9.tar.gz:
Publisher:
release.yml on pacepace/3tears
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
3tears_mcp-0.17.9.tar.gz -
Subject digest:
2d400c97e4ba146fb2ddf9d7c7489f3d94eac84de3820bccf396e86e1af35364 - Sigstore transparency entry: 2230623212
- Sigstore integration time:
-
Permalink:
pacepace/3tears@6432fd6528b7dccd45bfa7d6884283163ca937f8 -
Branch / Tag:
refs/tags/v0.17.9 - Owner: https://github.com/pacepace
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@6432fd6528b7dccd45bfa7d6884283163ca937f8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file 3tears_mcp-0.17.9-py3-none-any.whl.
File metadata
- Download URL: 3tears_mcp-0.17.9-py3-none-any.whl
- Upload date:
- Size: 34.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ac0934dacb597915ef08ea40185c774ae9fe99c684dc3645e4771d0bf8a5011
|
|
| MD5 |
857128a0d1556b61ad7c887624da783c
|
|
| BLAKE2b-256 |
5bd8e8308fd6f35b3fc3d286cf18e9e3aab4f448857c1d657e869ba926eebf57
|
Provenance
The following attestation bundles were made for 3tears_mcp-0.17.9-py3-none-any.whl:
Publisher:
release.yml on pacepace/3tears
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
3tears_mcp-0.17.9-py3-none-any.whl -
Subject digest:
9ac0934dacb597915ef08ea40185c774ae9fe99c684dc3645e4771d0bf8a5011 - Sigstore transparency entry: 2230630433
- Sigstore integration time:
-
Permalink:
pacepace/3tears@6432fd6528b7dccd45bfa7d6884283163ca937f8 -
Branch / Tag:
refs/tags/v0.17.9 - Owner: https://github.com/pacepace
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@6432fd6528b7dccd45bfa7d6884283163ca937f8 -
Trigger Event:
push
-
Statement type: