Command line JSON-RPC client for Mathesar
Project description
mathesar-cli
A local CLI and optional MCP server for Mathesar's JSON-RPC API.
The project provides three access layers:
- Friendly CLI groups for common database work:
db,schema,table,column, andrecord. - Universal CLI access for every exposed Mathesar RPC method:
api,call, andrpc. - Optional MCP tools for agent runtimes that support structured tool calls.
Requirements
- Python 3.10+
- uv
- A reachable Mathesar instance
Development
Set up the project:
uv sync --extra dev --extra mcp
Run tests:
uv run pytest
Run the CLI locally:
uv run mathesar --help
Build distribution artifacts:
uv build
Install
From a checkout:
uv tool install --from . mathesar-cli
With MCP support:
uv tool install --from '.[mcp]' mathesar-cli
During development, prefer:
uv run mathesar ...
uv run mathesar-mcp
Log In
uv run mathesar --url http://localhost login --username USER
Omit --password for an interactive prompt. For non-interactive use:
uv run mathesar --url http://localhost login --username USER --password PASS
The CLI saves only the Mathesar URL and session cookies:
~/.config/mathesar-cli/config.json
It does not save the username or password. Override the config location with MATHESAR_CLI_CONFIG_DIR.
Discover Methods
uv run mathesar methods list
uv run mathesar methods help records.list
uv run mathesar methods signature records.list
Friendly Commands
List configured databases:
uv run mathesar db list
uv run mathesar db get -d 1
Manage schemas:
uv run mathesar schema list -d 1
uv run mathesar schema create -d 1 reporting
uv run mathesar schema delete -d 1 17505
Manage tables:
uv run mathesar table list -d 1 -s 2200
uv run mathesar table get -d 1 -t 17500 --metadata
uv run mathesar table create -d 1 -s 2200 contacts --columns '[{"name":"name","type":"text"}]'
uv run mathesar table patch -d 1 -t 17500 --name contacts_archive --description "Archived contacts"
uv run mathesar table delete -d 1 -t 17507
Manage columns:
uv run mathesar column list -d 1 -t 17500
uv run mathesar column add -d 1 -t 17500 --columns '[{"name":"email","type":"text"}]'
uv run mathesar column patch -d 1 -t 17500 --columns '[{"id":2,"name":"full_name"}]'
uv run mathesar column delete -d 1 -t 17500 3
Manage records:
uv run mathesar record list -d 1 -t 17500 --limit 20
uv run mathesar record get -d 1 -t 17500 1
uv run mathesar record add -d 1 -t 17500 --data '{"2":"Alice"}'
uv run mathesar record patch -d 1 -t 17500 1 --data '{"2":"Bob"}'
uv run mathesar record delete -d 1 -t 17500 1
Mathesar records are keyed by column attnum, not column name. Use mathesar column list -d DATABASE_ID -t TABLE_OID to find attnums.
Universal API Access
Use api for readable path-style access to every RPC method:
uv run mathesar api records list -p database_id=1 -p table_oid=22031 -p limit=20
uv run mathesar api databases configured list
uv run mathesar api schemas privileges list-direct -p database_id=1 -p schema_oid=2200
Hyphens in path segments become underscores, so list-direct calls list_direct.
Use call when you prefer method names:
uv run mathesar call records.list -p database_id=1 -p table_oid=22031
uv run mathesar call records list --params-json '{"database_id": 1, "table_oid": 22031}'
Use rpc for exact JSON-RPC terminology:
uv run mathesar rpc users.list
Values passed with -p are parsed as JSON when possible, so numbers, booleans, arrays, objects, and null work naturally.
Environment Variables
export MATHESAR_URL=http://localhost
export MATHESAR_SESSIONID=...
export MATHESAR_CSRFTOKEN=...
MCP Server
Install MCP support:
uv sync --extra mcp
Start the server over stdio:
uv run mathesar-mcp
Useful MCP tools include:
mathesar_loginmathesar_list_methodsmathesar_method_helpmathesar_method_signaturemathesar_callmathesar_list_databasesmathesar_list_schemasmathesar_create_schemamathesar_delete_schemasmathesar_list_tablesmathesar_create_tablemathesar_patch_tablemathesar_delete_tablemathesar_list_columnsmathesar_add_columnsmathesar_patch_columnsmathesar_delete_columnsmathesar_list_recordsmathesar_add_recordmathesar_patch_recordmathesar_delete_records
Use MCP tools when an agent runtime supports MCP. Use CLI commands for manual shell work, transcripts, and environments without MCP.
Publishing
Build:
uv build
Validate the distribution metadata with Twine:
uv run --extra publish twine check dist/*
Publish to TestPyPI:
TWINE_USERNAME="__token__" TWINE_PASSWORD="$TEST_PYPI_TOKEN" \
uv run --extra publish twine upload --repository-url https://test.pypi.org/legacy/ dist/*
Publish to PyPI:
TWINE_USERNAME="__token__" TWINE_PASSWORD="$PYPI_TOKEN" \
uv run --extra publish twine upload dist/*
Before publishing, confirm the package name is available and set final project URLs in pyproject.toml.
License
GNU General Public License v3.0 or later. See LICENSE.
Method Coverage
Mathesar's upstream JSON-RPC API is not guaranteed to be stable yet, so method names, parameters, signatures, and response shapes may break between Mathesar releases. Run mathesar methods list, mathesar methods help METHOD, and mathesar methods signature METHOD against your target instance when building automation.
This client was tested against a local Mathesar instance on 2026-05-28 reporting:
last_confirmed_sql_version:0.10.1system.listMethods: 106 exposed RPC methods
See docs/METHODS.md for the method list observed from that instance during development.
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 mathesar_cli-0.1.0.tar.gz.
File metadata
- Download URL: mathesar_cli-0.1.0.tar.gz
- Upload date:
- Size: 77.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9bdc5b9431eb6c8ca83f2ea5085774d679def9c9560f94116d4f0e2d2a066617
|
|
| MD5 |
49c0921be594093026c58b8e778813c9
|
|
| BLAKE2b-256 |
41f5a1b51a676fb0d41e9e73e92be1efa9127f586cf323c22ad61c2137e38fe3
|
File details
Details for the file mathesar_cli-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mathesar_cli-0.1.0-py3-none-any.whl
- Upload date:
- Size: 27.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eac3949e6380a453b8d7bc28cc5582347cdaa49cb5512350bd90cb08ba069e89
|
|
| MD5 |
59bf01020379c64754a0b3388d1ca2df
|
|
| BLAKE2b-256 |
eedb9638cce7b60883ec67dd8300b5f7a1a06ef0eb42e73f5d48702e8dcaf57f
|