Python client library for connecting to the Civic MCP Hub.
Project description
Civic MCP Client
Python client library for connecting to the Civic MCP Hub with direct bearer token auth or RFC 8693 token exchange.
Install
uv sync
Install optional integration extras:
uv sync --extra pydanticai --extra langchain --extra fastmcp
Quick Start
from civic_mcp_client import CivicMCPClient
client = CivicMCPClient(
auth={"token": "your-civic-access-token"},
civic_profile="7c9e6679-7425-40de-944b-e07fc1f90ae7",
)
tools = await client.get_tools()
instructions = await client.get_server_instructions()
result = await client.call_tool(name="tool-name", args={"foo": "bar"})
await client.close()
Token Exchange (RFC 8693)
import os
from civic_mcp_client import CivicMCPClient
client = CivicMCPClient(
auth={
"token_exchange": {
"client_id": os.environ["CIVIC_CLIENT_ID"],
"client_secret": os.environ["CIVIC_CLIENT_SECRET"],
"subject_token": lambda: "external-token",
"expires_in": 3600, # optional requested lifetime in seconds
}
},
civic_profile="7c9e6679-7425-40de-944b-e07fc1f90ae7",
)
The token exchange manager provides:
- cache + expiry handling
- token change detection
- in-flight deduplication for concurrent calls
- expiry buffer of
min(30s, expires_in / 2)
Current access token can be retrieved via:
token = await client.get_access_token()
Testing
uv run --extra test python -m pytest
uv run --extra test python -m pytest -m integration
Manual Test Examples
Runnable scripts are available in examples/.
uv run python examples/direct_token.py
uv run python examples/token_exchange.py
uv run python examples/langchain_adapter.py
uv run python examples/pydanticai_adapter.py
uv run python examples/fastmcp_backend.py
To load environment variables from a .env file:
uv sync --extra examples
cp .env.example .env
uv run python -m dotenv run -- python examples/direct_token.py
Or, if you prefer running from inside the examples/ directory:
cd examples
cp ../.env.example .env
uv run python -m dotenv run -- python direct_token.py
Library Integrations
Use await client.adapt_for(...) with the adapter for your framework. It returns either a new CivicMCPClient (for backend adapters like FastMCP) or adapter-native tool output (e.g. list of schemas or tool definitions).
PydanticAI
from civic_mcp_client import CivicMCPClient
from civic_mcp_client.adapters.pydanticai import pydanticai
client = CivicMCPClient(auth={"token": "your-civic-access-token"})
tools = await client.adapt_for(pydanticai())
LangChain
from civic_mcp_client import CivicMCPClient
from civic_mcp_client.adapters.langchain import execute_langchain_tool_call, langchain
client = CivicMCPClient(auth={"token": "your-civic-access-token"})
tool_schemas = await client.adapt_for(langchain())
# model = model.bind_tools(tool_schemas)
# response = model.invoke("...")
# tool_result = await execute_langchain_tool_call(client, response.tool_calls[0])
FastMCP
from civic_mcp_client import CivicMCPClient
from civic_mcp_client.adapters.fastmcp import fastmcp
client = CivicMCPClient(
auth={"token": "your-civic-access-token"},
civic_profile="optional-profile-id",
)
fastmcp_client = await client.adapt_for(fastmcp())
# fastmcp_client is a CivicMCPClient with FastMCP backend; auth/headers come from config
tools = await fastmcp_client.get_tools()
Interface Notes
civic_accountwas removed from Python client config to match the updated TypeScript direction.civic_profileremains supported and maps tox-civic-profile-id.TokenExchangeConfigsupportsexpires_inandlock_to_profile(account lock removed).
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 civic_mcp_client-0.1.0.tar.gz.
File metadata
- Download URL: civic_mcp_client-0.1.0.tar.gz
- Upload date:
- Size: 14.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e9193b28a18a0691fe9abc3d04d786fd8cf5bd1aa4260e3b76e81ab73f106d8
|
|
| MD5 |
786999074c87594daafceab7d8a88a83
|
|
| BLAKE2b-256 |
b97296b535970c16efc3efc1c2bd6be7665b76fc495609aa3def3d83595d69b2
|
Provenance
The following attestation bundles were made for civic_mcp_client-0.1.0.tar.gz:
Publisher:
python-publish.yml on civicteam/python-civic-mcp-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
civic_mcp_client-0.1.0.tar.gz -
Subject digest:
7e9193b28a18a0691fe9abc3d04d786fd8cf5bd1aa4260e3b76e81ab73f106d8 - Sigstore transparency entry: 1132686952
- Sigstore integration time:
-
Permalink:
civicteam/python-civic-mcp-client@6e88d402af4be2bb68017178f51fb3970bace78c -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/civicteam
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@6e88d402af4be2bb68017178f51fb3970bace78c -
Trigger Event:
release
-
Statement type:
File details
Details for the file civic_mcp_client-0.1.0-py3-none-any.whl.
File metadata
- Download URL: civic_mcp_client-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f088322fe72e19659457105293c9a190f92abdf45167bf86861e33469e785d3
|
|
| MD5 |
2e2f2d633cd09c5f96a5414f9d58766f
|
|
| BLAKE2b-256 |
f9f79dffa03f5ef56bbad92cefa08acbb18f4c67a6bb462b6d10cbd7c9e2bb49
|
Provenance
The following attestation bundles were made for civic_mcp_client-0.1.0-py3-none-any.whl:
Publisher:
python-publish.yml on civicteam/python-civic-mcp-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
civic_mcp_client-0.1.0-py3-none-any.whl -
Subject digest:
1f088322fe72e19659457105293c9a190f92abdf45167bf86861e33469e785d3 - Sigstore transparency entry: 1132687055
- Sigstore integration time:
-
Permalink:
civicteam/python-civic-mcp-client@6e88d402af4be2bb68017178f51fb3970bace78c -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/civicteam
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@6e88d402af4be2bb68017178f51fb3970bace78c -
Trigger Event:
release
-
Statement type: