Python SDK for CircuitNotion MCP Server
Project description
CircuitNotion MCP SDK
A simple Python SDK for interacting with the CircuitNotion MCP Server.
Installation
pip install cn-mcp
Or from source:
pip install -e .
Quick Start
from cn_mcp_sdk import MCPClient
# Initialize client
client = MCPClient(api_key="your-api-key", base_url="http://localhost:8000")
# Create a session
session = client.sessions.create()
print(f"Session ID: {session['session_id']}")
# Write a file
file_resp = client.files.write(
session_id=session['session_id'],
path="/output/hello.txt",
content="Hello, World!"
)
print(f"File ID: {file_resp['file_id']}")
# List files
files = client.files.list(session_id=session['session_id'])
for f in files:
print(f" {f['path']} ({f['bytes']} bytes)")
# Execute a terminal command
result = client.terminal.execute(
session_id=session['session_id'],
command="echo 'Hello' && ls -la",
timeout_minutes=5
)
print(f"Exit code: {result['exit_code']}")
print(f"Output: {result['stdout']}")
# Search the web
search_results = client.search.web("Python best practices")
for result in search_results:
print(f" {result['title']}: {result['url']}")
# Schedule a task
task = client.scheduler.schedule(
in_seconds=60,
payload={"message": "Task executed!"}
)
print(f"Task ID: {task['task_id']}")
# Control a device
device_result = client.devices.execute(
device_id="device-123",
action="turn_on",
parameters={"brightness": 100}
)
# Query the database
rows = client.db.query(
session_id=session['session_id'],
sql="SELECT * FROM users LIMIT 10"
)
# Dispose session
client.sessions.dispose(session['session_id'])
API Documentation
Sessions
# Create a session
session = client.sessions.create()
# List active sessions
sessions = client.sessions.list()
# Dispose a session
client.sessions.dispose(session_id)
Files
# Write a file
file_resp = client.files.write(session_id, path, content)
# List files in a session
files = client.files.list(session_id)
# Download a file
content = client.files.download(file_id)
# Delete a file
client.files.delete(file_id)
Terminal
# Execute a command
result = client.terminal.execute(
session_id=session_id,
command="pip list",
timeout_minutes=5,
output_limit_kb=4096
)
# Returns: {
# "exit_code": 0,
# "stdout": "...",
# "stderr": "",
# "duration_seconds": 1.23
# }
Search
# Web search
results = client.search.web("Python")
# With location
results = client.search.web("restaurants", location="New York")
# Returns: [
# {
# "title": "...",
# "url": "...",
# "snippet": "...",
# "position": 1
# },
# ...
# ]
Scheduler
# Schedule a task in N seconds
task = client.scheduler.schedule(
in_seconds=300,
payload={"data": "value"}
)
# Schedule at specific time (ISO format)
task = client.scheduler.schedule(
run_at="2026-04-08T15:30:00Z",
payload={"data": "value"}
)
# List tasks
tasks = client.scheduler.list()
# Cancel a task
client.scheduler.cancel(task_id)
Devices
# Control a device
result = client.devices.execute(
device_id="device-123",
action="turn_on",
parameters={"level": 80}
)
Database
# Query (read-only)
rows = client.db.query(
session_id=session_id,
sql="SELECT * FROM table"
)
# Execute (write operations)
result = client.db.execute(
session_id=session_id,
sql="INSERT INTO table (col) VALUES (?)",
params=["value"]
)
Cache Stats
# Get API key cache statistics
stats = client.auth.cache_stats()
# Returns: {
# "size": 45,
# "max_size": 1000,
# "ttl_seconds": 300,
# "negative_ttl_seconds": 30
# }
Configuration
Via Constructor
client = MCPClient(
api_key="your-api-key",
base_url="http://localhost:8000",
timeout=30,
verify_ssl=True
)
Via Environment Variables
export MCP_API_KEY=your-api-key
export MCP_BASE_URL=http://localhost:8000
export MCP_TIMEOUT=30
export MCP_VERIFY_SSL=true
# Uses env vars by default
client = MCPClient()
Error Handling
from cn_mcp_sdk import MCPClient, MCPError, MCPAuthError, MCPNotFoundError
try:
session = client.sessions.create()
except MCPAuthError as e:
print(f"Authentication failed: {e}")
except MCPNotFoundError as e:
print(f"Resource not found: {e}")
except MCPError as e:
print(f"API error: {e}")
Examples
See the examples/ directory for more detailed examples:
basic_usage.py- Basic session and file operationsterminal_commands.py- Running terminal commandsweb_search.py- Web search functionalityscheduled_tasks.py- Scheduling and managing tasksdevice_control.py- Controlling devicesdatabase_queries.py- Database operations
License
MIT
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 cn_mcp-0.2.1.tar.gz.
File metadata
- Download URL: cn_mcp-0.2.1.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4672570192e1d8fa480dfc8bd3dc719e4115ab95f531cb20dddcb0a996c7929a
|
|
| MD5 |
41ee027f79e4482b4b78711795092d90
|
|
| BLAKE2b-256 |
268e15ec670aa01382cdba7eeeb477e632f5faa1e69bdbf6ef9c3d12c484bea1
|
Provenance
The following attestation bundles were made for cn_mcp-0.2.1.tar.gz:
Publisher:
pypi-publish.yml on ntirushwajeanmarc/cn-mcp-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cn_mcp-0.2.1.tar.gz -
Subject digest:
4672570192e1d8fa480dfc8bd3dc719e4115ab95f531cb20dddcb0a996c7929a - Sigstore transparency entry: 1258038515
- Sigstore integration time:
-
Permalink:
ntirushwajeanmarc/cn-mcp-sdk@1d3cd5dd6ff95e2bab0f6c82583a500c0e7e06e8 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/ntirushwajeanmarc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@1d3cd5dd6ff95e2bab0f6c82583a500c0e7e06e8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file cn_mcp-0.2.1-py3-none-any.whl.
File metadata
- Download URL: cn_mcp-0.2.1-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4bea67dc32f67c2ec7ddd1f48119f06de5c3e17232db0237b6866f615411be3f
|
|
| MD5 |
5505cae3c51728bfdc0c27221780acd2
|
|
| BLAKE2b-256 |
c502b435fed67abe48dd2b33b3b5fe712a8771681a4ffd3dfc1a9079c0e56995
|
Provenance
The following attestation bundles were made for cn_mcp-0.2.1-py3-none-any.whl:
Publisher:
pypi-publish.yml on ntirushwajeanmarc/cn-mcp-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cn_mcp-0.2.1-py3-none-any.whl -
Subject digest:
4bea67dc32f67c2ec7ddd1f48119f06de5c3e17232db0237b6866f615411be3f - Sigstore transparency entry: 1258038851
- Sigstore integration time:
-
Permalink:
ntirushwajeanmarc/cn-mcp-sdk@1d3cd5dd6ff95e2bab0f6c82583a500c0e7e06e8 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/ntirushwajeanmarc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@1d3cd5dd6ff95e2bab0f6c82583a500c0e7e06e8 -
Trigger Event:
push
-
Statement type: