djcrud_client¶
djcrud-client is the standalone client package (pip install djcrud-client) for
talking to djcrud DRF JSON APIs over HTTP. It powers remote stdio MCP agents and can
be used directly as a library (no Django, no FastMCP required).
It is automatically included when you do pip install --pre "djcrud[mcp]" on the
host, but agents / external tools only need the lightweight client wheel.
Install¶
pip install djcrud-client
# during development / prereleases:
pip install --pre djcrud-client
CLI Usage¶
The entry point djcrud-client can run as a stdio MCP server or invoke a single tool.
Basic:
export DJCRUD_BASE_URL=http://localhost:8000
export DJCRUD_TOKEN=...
djcrud-client -mcp # stdio MCP server for agents
djcrud-client --call article_list --json '{}'
djcrud-client --call article_publish --json '{"pk": 1}'
Full options (see djcrud-client --help):
-mcp: run FastMCP stdio server--call TOOL+--json '...': one-shot call, print JSON result--registry KEY: select profile (default resolved from host)--user/--password: fallback to login exchange
Environment variables¶
Variable |
Purpose |
Fallbacks |
|---|---|---|
|
Target API root |
|
|
Bearer token |
|
|
Login credentials (only if no token) |
(same with legacy prefixes) |
Library Usage (build your own client)¶
Import surface (no Django dependency):
from djcrud_client import (
CrudApi, McpProfile,
create_mcp_server,
build_tools_for_profile, build_tools_from_schema,
get_base_url, get_token, login,
)
High-level: create a ready-to-run MCP server¶
from djcrud_client.server import create_mcp_server
mcp = create_mcp_server(
base_url="http://localhost:8000",
token=os.environ["DJCRUD_TOKEN"],
# registry=... or profile=...
)
mcp.run(transport="stdio")
Low-level: build tools yourself + direct API calls¶
from djcrud_client import McpProfile
from djcrud_client.api import CrudApi
from djcrud_client.schema import build_tools_from_schema
profile = McpProfile.from_dict(...) # or load_profile(...)
schema = ... # from /api/schema/ or fetch_schema
tools = build_tools_from_schema(schema, prefixes={"article": "/api/article/"})
api = CrudApi(base_url=..., token=...)
resp = api.request("GET", "/api/article/")
print(resp.json())
# or use login()
token = login(base_url=base, username=..., password=...)
See also the source of djcrud_client.server and djcrud_client.tools
for render_path, split_arguments, etc.
Public API¶
Stdio MCP bridge for djcrud JSON APIs (no Django required).
- class djcrud_client.CrudApi(*, base_url, token, timeout=30.0, extra_headers=None)[source]¶
Bases:
object- Parameters:
- class djcrud_client.McpProfile[source]¶
Bases:
objectWire-format MCP profile fetched from
GET /api/mcp/profiles/{key}/.
- djcrud_client.create_mcp_server(*, base_url=None, token=None, profile=None, registry=None, extra_headers=None)[source]¶
- djcrud_client.get_registry_key(*, base_url=None)[source]¶
Host default profile key from
GET /api/mcp/profiles/(not an env var).
- djcrud_client.profile_meta(profile)[source]¶
- Parameters:
profile (McpProfile)
- Return type:
- djcrud_client.run_stdio(*, registry=None)[source]¶
- Parameters:
registry (str | None)
- Return type:
None
Core modules:
- class djcrud_client.profile.McpProfile[source]¶
Bases:
objectWire-format MCP profile fetched from
GET /api/mcp/profiles/{key}/.
- djcrud_client.schema.prefix_map_from_profile(profile)[source]¶
Build
{model_name: api_prefix}from host-publishedapi_prefixes.- Parameters:
profile (McpProfile)
- Return type: