Metadata-Version: 2.5
Name: langchain-noderings
Version: 0.1.0
Summary: LangChain tools for NodeRings: search the hosting marketplace, order and manage virtual machines, DNS and SSH keys from an agent.
Project-URL: Homepage, https://noderings.com
Project-URL: Documentation, https://docs.noderings.com/docs/client-guides/langchain
Project-URL: Repository, https://github.com/noderings/langchain-noderings
Project-URL: Issues, https://github.com/noderings/langchain-noderings/issues
Project-URL: Changelog, https://github.com/noderings/langchain-noderings/blob/main/CHANGELOG.md
Author-email: NodeRings <partners@noderings.com>
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: agents,cloud,dns,langchain,langgraph,llm-tools,noderings,vps
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: System :: Systems Administration
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: langchain-core<2,>=1.4.7
Requires-Dist: noderings<0.2,>=0.1.0
Description-Content-Type: text/markdown

# langchain-noderings

[![CI](https://github.com/noderings/langchain-noderings/actions/workflows/ci.yml/badge.svg)](https://github.com/noderings/langchain-noderings/actions/workflows/ci.yml)
[![PyPI](https://img.shields.io/pypi/v/langchain-noderings.svg)](https://pypi.org/project/langchain-noderings/)
[![Python versions](https://img.shields.io/pypi/pyversions/langchain-noderings.svg)](https://pypi.org/project/langchain-noderings/)
[![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/noderings/langchain-noderings/badge)](https://scorecard.dev/viewer/?uri=github.com/noderings/langchain-noderings)
[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE)

LangChain tools for [NodeRings](https://noderings.com), a hosting marketplace. An agent built with LangChain or
LangGraph can search Compute Instance (VPS) plans from independent providers, order a virtual machine, power it,
take snapshots, and manage hosted DNS and SSH keys. The tools are a thin, safe layer over the official
[`noderings`](https://github.com/noderings/noderings-python) Python SDK: read-only by default, with several
opt-ins and checks before anything is changed.

## Install

```sh
pip install langchain-noderings
```

Full guide: <https://docs.noderings.com/docs/client-guides/langchain>

Python 3.10 to 3.14. It installs `noderings` and `langchain-core`; add `langchain` (and a model provider package)
to build agents.

## Authentication

Create a service account in the NodeRings console (**Organization → Access Control → Service accounts**) and
give it only the permissions the agent needs. Then set:

| Variable | Required | Purpose |
|---|---|---|
| `NODERINGS_TOKEN` | yes | The service-account token. |
| `NODERINGS_ORGANIZATION_ID` | no | Act in another organization the account belongs to. |
| `NODERINGS_BASE_URL` | no | Another API endpoint. Default `https://api.noderings.com`. |

Or pass `token=`, `organization_id=`, `base_url=` to `NodeRingsToolkit`. Never commit tokens. The token is read
when a tool first runs, never at import time, and it never appears in tool output or error messages.

## Quick start

```python
from langchain_noderings import NodeRingsToolkit

toolkit = NodeRingsToolkit()  # read-only tools
tools = toolkit.get_tools()

search = next(t for t in tools if t.name == "noderings_search_plans")
print(search.invoke({"query": "2 vcpu 4 GB in Amsterdam", "limit": 3}))
```

Every tool returns compact JSON with stable keys. For example `noderings_list_virtual_machines`:

```json
{"virtual_machines": [{"id": "…", "hostname": "web-1", "status": "started",
  "provider": "…", "city": "Amsterdam", "country": "Netherlands", "plan_code": "…",
  "vcpus": 2, "memory_mb": 4096, "ipv4": "203.0.113.10", "ipv6": "2001:db8::10",
  "tags": ["agent-managed"], "created": "2026-11-29T10:00:00Z"}], "total": 1, "truncated": false}
```

Lists are capped at `max_list_items` (default 50); `"truncated": true` says more exist. Enum values are short
lower-case words (`started`, `usage`). Errors come back as a message starting with `NodeRings error:` that tells
the model what to do next.

## Tools

R = read, W = write (needs `mode="read_write"`), D = destructive (also needs `allow_destructive=True`).

| Tool | Kind | What it does |
|---|---|---|
| `noderings_search_plans` | R | Search VM plans with a short query such as "2 vcpu 4 GB in Amsterdam". |
| `noderings_get_plan` | R | One plan: specs, prices, rating and its regions. |
| `noderings_list_locations` | R | Cities and countries where VM plans are sold. |
| `noderings_compare_providers` | R | Providers selling one plan code in one city, with prices and IPv6/capacity. |
| `noderings_list_distros` | R | Operating systems a new VM can run. |
| `noderings_list_ssh_keys` | R | Saved SSH public keys (id, name, type, fingerprint). |
| `noderings_list_virtual_machines` | R | VMs with status, location, IPs and tags; filter by status or tag. |
| `noderings_get_virtual_machine` | R | One VM in detail. |
| `noderings_list_snapshots` | R | Snapshots of one VM. |
| `noderings_list_dns_zones` | R | Hosted DNS zones with nameservers and delegation state. |
| `noderings_list_dns_records` | R | Records in a zone, optionally by name and type. |
| `noderings_get_account` | R | Which organization the token acts for. |
| `noderings_create_ssh_key` | W | Save an SSH **public** key. |
| `noderings_create_virtual_machine` | W | Order a VM (spends money); optionally wait for its IPs. |
| `noderings_power_virtual_machine` | W | Start, stop or restart a VM. |
| `noderings_tag_virtual_machine` | W | Add or remove VM tags. |
| `noderings_create_snapshot` | W | Snapshot a VM's disk. |
| `noderings_create_dns_zone` | W | Create an empty zone for an apex domain. |
| `noderings_upsert_dns_record` | W | Create an A, AAAA, CNAME, MX or TXT record; replace only with `allow_overwrite`. |
| `noderings_reinstall_virtual_machine` | D | Reinstall a VM's OS, erasing its disk. |
| `noderings_delete_virtual_machine` | D | Delete a VM with its snapshots and backups. |
| `noderings_delete_dns_record` | D | Delete the records with one name and type. |
| `noderings_delete_ssh_key` | D | Remove a saved SSH key. |

How an agent orders a server: `noderings_search_plans` (plan_id, region_id, price) → `noderings_list_distros`
(`DISTRO_UBUNTU_24_04`) → `noderings_list_ssh_keys` (or `noderings_create_ssh_key` with a public key) →
`noderings_create_virtual_machine(..., wait=True)` → the user connects with their own private key, usually
`ssh root@<ipv4>`. Passwords and private keys are never handled.

## Safety model

```python
toolkit = NodeRingsToolkit(
    mode="read_only",  # "read_only" (default) or "read_write"
    allow_destructive=False,  # delete/reinstall tools also need this
    include=None,  # only these tool names
    exclude=None,  # never these tool names
    vm_tag_scope=None,  # e.g. "agent-managed"
    dry_run=False,  # describe write calls instead of making them
    max_list_items=50,
)
toolkit.write_tool_names()  # for HumanInTheLoopMiddleware
toolkit.destructive_tool_names()
```

1. **Read-only by default.** Write tools are only returned with `mode="read_write"`.
2. **Destructive tools need a second opt-in.** Delete VM, reinstall VM, delete DNS record and delete SSH key
   also need `allow_destructive=True`.
3. **Allowlist and denylist.** `include` and `exclude` filter by tool name. Unknown names, or an `include` of a
   tool the mode hides, raise `ValueError` when the toolkit is built.
4. **Confirmation arguments.** Every write tool has a required `confirm` argument. Unless it is `true`, the tool
   sends no request and tells the model to ask the user first. Delete and reinstall also need
   `confirm_hostname` equal to the VM's current hostname (the tool reads the VM first).
   `noderings_create_virtual_machine` returns the plan's price with its result, and refuses a `region_id` that
   is not one of the plan's regions.
5. **Tag scope.** With `vm_tag_scope="agent-managed"`, power, tag, snapshot, reinstall and delete refuse VMs
   without that tag (and the tag cannot be removed), and new VMs always get it.
6. **Dry run.** With `dry_run=True`, write tools validate input and run their read checks (hostname, tag scope,
   existing DNS records, plan price), then return
   `{"dry_run": true, "would_call": "<METHOD> <path>", "body": {...}}` instead of changing anything.
7. **Framework approval.** For any agent with write tools, also pause for a person before each change with
   LangChain's [human-in-the-loop middleware](https://docs.langchain.com/oss/python/langchain/human-in-the-loop)
   and a checkpointer (see below).
8. **No secrets in or out.** No tool accepts a password, a private key or raw cloud-init `user_data`.
   `noderings_create_ssh_key` rejects anything that looks like a private key without echoing it. Output never
   contains tokens, public key bodies or console URLs.

The SDK retries rate limits and transient errors, and VM creates carry an idempotency key, so a retry never
orders a second server. `noderings_upsert_dns_record` refuses to replace an existing record unless
`allow_overwrite=true`.

## Agents

Read-only ([examples/agent_readonly.py](examples/agent_readonly.py)):

```python
from langchain.agents import create_agent
from langchain_noderings import NodeRingsToolkit

agent = create_agent(model="provider:model-name", tools=NodeRingsToolkit().get_tools())
agent.invoke({"messages": [{"role": "user", "content": "Which of my servers are stopped?"}]})
```

With write tools and human approval ([examples/agent_hitl.py](examples/agent_hitl.py)):

```python
from langchain.agents import create_agent
from langchain.agents.middleware import HumanInTheLoopMiddleware
from langgraph.checkpoint.memory import InMemorySaver
from langgraph.types import Command

from langchain_noderings import NodeRingsToolkit

toolkit = NodeRingsToolkit(mode="read_write", vm_tag_scope="agent-managed")

agent = create_agent(
    model="provider:model-name",  # any tool-calling chat model you have configured
    tools=toolkit.get_tools(),
    system_prompt=(
        "You manage NodeRings servers. Quote prices only from noderings_search_plans. "
        "Ask before any action that costs money or changes resources."
    ),
    middleware=[
        HumanInTheLoopMiddleware(
            interrupt_on={name: {"allowed_decisions": ["approve", "reject"]} for name in toolkit.write_tool_names()},
        )
    ],
    checkpointer=InMemorySaver(),
)

config = {"configurable": {"thread_id": "demo-1"}}
result = agent.invoke(
    {
        "messages": [
            {
                "role": "user",
                "content": "Find the cheapest 2 vCPU server in Amsterdam and order it as web-1 with my 'laptop' SSH key.",
            }
        ]
    },
    config,
)
# result["__interrupt__"] holds the pending noderings_create_virtual_machine call. Show it to the user, then:
agent.invoke(Command(resume={"decisions": [{"type": "approve"}]}), config)
```

Async agents work the same way: every tool has a native async implementation on `AsyncNodeRings`.

## Not supported

The NodeRings API does not offer these, so the tools do not either:

- Block volumes, load balancers, and resizing or upgrading the plan of a running VM (a VM's tags are the only
  thing that can be updated).
- Custom image upload. The OS comes from the distro catalog, a saved cloud-init profile
  (`cloud_init_user_data_id`) or an Instant App.
- Webhooks or event subscriptions. Waiting is done by polling (`wait=true`).

Not exposed as tools in this version, although the API has them: snapshot restore and delete, backups, Instant
Apps, firewalls and DNS zone deletion. Use the [`noderings`](https://pypi.org/project/noderings/)
SDK for those.

## Links

- LangChain guide: <https://docs.noderings.com/docs/client-guides/langchain>
- Usage guide: [docs/noderings.md](docs/noderings.md)
- NodeRings docs: <https://docs.noderings.com>
- Python SDK: <https://github.com/noderings/noderings-python>
- Hosted MCP server: `https://mcp.noderings.com/mcp`
- API description: <https://api.noderings.com/v1/openapi.json>

## License

[Apache-2.0](LICENSE)
